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

URLImage not loading in WidgetKit #125

Closed ca13ra1 closed 3 years ago

ca13ra1 commented 3 years ago

Summary and/or background Image not loading from URL. URL is correct as it's been verified with print but I can't seem to get it working.

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 Image to load properly

What actually happens Image doesn't seem to load.

Sample code

struct SomeEntryView : View {
    var entry: Provider.Entry

    var body: some View {
        var body: some View {
        HStack {
            URLImage(url: URL(string: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-iii/firered-leafgreen/back/1.png")!) { image in image.resizable() }
                .frame(width: 97, height: 97)
        }
    }
}

Test data

Additional information: Simulator Screen Shot - iPhone 12 - 2020-12-08 at 01 22 07

dmytro-anokhin commented 3 years ago

Hey,

this is not a bug. URLImage view won't work with WidgetKit as is: https://developer.apple.com/forums/thread/652581

The only way to make it work is to preload image and display cached one. There's no convenient API yet, but if you really want to make it work, you can use underlying RemoteImage directly. Here's a sample how to do it: https://gist.github.com/dmytro-anokhin/2d4c2ab6145bc20e74381b1d278a08fb

It also should work if the host app downloaded the image.

I'm working on improving preload API.

Cheers.

ca13ra1 commented 3 years ago

Thank you!