I struggled with this as well. However, I found a different way that achieves the same objective while working on AppleTV. That is to use a TabView which when styled works like a page controller. This allows you to swipe left/right on a an array of images. Given it works page by page and loading is as-needed so it works like a lazystack. Here is a full example for you (note I styled it so that it doesn't show page markers, but you can simply use .page if you want them).
struct SlideshowViewer: View {
@State private var gallery = GalleryPublisher.shared
var body: some View {
TabView {
ForEach(gallery.slideshow, id:\.self) { slideshow in
ImageView(slideshow: slideshow)
.focusable(true)
.frame(width:UIScreen.main.bounds.width,height: UIScreen.main.bounds.height)
.edgesIgnoringSafeArea(.all)
}
}
.tabViewStyle(.page(indexDisplayMode: .never))
}
}
struct ImageView: View {
var slideshow:Slideshow
@State private var galleryImage:UIImage?
var body: some View {
if let image = galleryImage {
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode:.fill)
} else {
ZStack {
Rectangle()
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .blue))
}
.foregroundColor(.white)
.onAppear {
NetworkManager.shared.downloadImage(urlStr: slideshow.link) { image in
galleryImage = image
}
}
}
}
}
Post
Replies
Boosts
Views
Activity
Thank you for the help and confirmation. This open source library does not have a file system from any of its documentation. They support things like Cordova which has other plug-ins but that doesn't help with a native approach. At this point I am using socket.io to provide binary to the JS locally.
Thanks again for your time and expertise.
I've looked at the documentation for both, but don't see anything specific to the file system. Is there some Apple documentation or suite of methods you can point to? For the moment the only solution I can see here is to read the file natively and then socket the contents to the JS/Node side. Another method could be a multipart transfer via URLSession. Is this the kind of thing you are referring to or are you aware of other methods in JSCore or WKWeb?
Thanks.
I don't know specifically what they are using (it's a large library), however, I can also execute a script using WKWebView or URLSession. If it's possible to set aside the node.js library, is it possible for Javascript run locally to access the iOS file system given a path?
I am running a node.js server on device called Nodejs-mobile. When that is spun up it runs a JavaScript file that is also located in the app's bundle. I can interact with the JS through any number of means such as a WKWebView or a URLSession. In either case I have, at the iOS app level, the path to an on-device resource that I provide to JS. The desire here is for the local JS to then use that path to access the file. I am flexible to use differing mechanisms here if it enables JS to directly read a file. The JS uses fs.opensync in it's current attempt.
Thanks.