dmytro-anokhin / url-image

AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.
MIT License
1.1k stars 96 forks source link

Images won't load initially on tvOS #149

Closed NoahKamara closed 3 years ago

NoahKamara commented 3 years ago

Summary and/or background Images won't load initially on tvOS

OS and what device you are using

Version of URLImage library The version of the library where the bug happens.

What you expected would happen The image should be loading and then displaying

What actually happens

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

Misc

dmytro-anokhin commented 3 years ago

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.

dmytro-anokhin commented 3 years ago

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.

NoahKamara commented 3 years ago

Thanks for the quick fix :D I added the environment key and the build seems to perform fine :D

NoahKamara commented 3 years ago

Hey there, iOS 15 DEV Beta 2 fixes this:

image

Could this be related to this issue?