URLImage not loading in WidgetKit
ca13ra1 opened this issue · 2 comments
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
- OS: macOS BigSur
- iPhone simulator
Version of URLImage library
The version of the library where the bug happens.
- The bug is reproducible in the latest version.
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
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.
Thank you!