Images won't load initially on tvOS
NoahKamara opened this issue · 4 comments
Summary and/or background
Images won't load initially on tvOS
OS and what device you are using
- OS: tvOS 14.5.1
- Simulator (ATV 4K 2nd gen)
Version of URLImage library
The version of the library where the bug happens.
-
=3.0.0 (2.2.5 works)
- The bug is reproducible in the latest version.
What you expected would happen
The image should be loading and then displaying
What actually happens
- URLImage displays "empty"-view (Green color in example)
- I open and close modal sheet
- URLImage displays "inProgress"-view (Yellow in example)
- URLImage displays image
Sample code
struct TestView: View {
@State var showsSheet: Bool = false
var body: some View {
VStack {
HStack {
Button(action: {
showsSheet.toggle()
}) {
Text("Sheet Cover")
}
}
URLImage(
URL(string: "https://i.picsum.photos/id/744/1600/900.jpg?hmac=sZ_7fiJyGI0AxqtotMvJ2AhLaEjwT81zbGlAnoVekjA")!,
empty: { Color.green },
inProgress: { _ in Color.yellow },
failure: { _,_ in Color.red}
) { image, info in
image
}
}
.sheet(isPresented: $showsSheet) {
ZStack {
Blur()
VStack {
Text("Sheet Cover")
Button(action: { showsSheet.toggle() }) {
Text("CLOSE")
}
}
}
}
}
}
Test data
I'm using Lorem Picsum
Additional information
- I wasn't able to reproduce the bug on macOS or iOS. it seems tvOS-specific
- The bug also occurs when no sheet is added to the view
- Screenshots or video demonstrating a bug;
- https://user-images.githubusercontent.com/40308075/119005674-f06bf180-b98f-11eb-8d9c-b28bf68ba1d9.mov
Misc
- I read the documentation and it didn't help;
- I searched for similar issues.
Hey, thank you for detailed report and sample code. It seems that something triggers onDisappear
event that cancels loading. I'm gonna investigate later on, for now you can set .environment(\.urlImageOptions, URLImageOptions(loadOptions: [ .loadImmediately ] ))
to start load as soon as the view is initialised.
Recently I was getting many similar bug reports, so I decided to change default behaviour to start loading when the view is rendered. There's also a new section in README that explains differences: Start Loading. If you're using List
you may get better performance with old behaviour.
Thanks for the quick fix :D I added the environment key and the build seems to perform fine :D