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.11k stars 96 forks source link

Image not loaded on WidgetKit #81

Closed gedeagas closed 4 years ago

gedeagas commented 4 years ago

Summary and/or background url-image is not working on WidgetKit when displaying image

OS and what device you are using iPhone simulator, iPhone 11 Pro

Version of URLImage library

What you expected would happen Working normally

What actually happens Not working

Sample code

let url = URL(string: "https://picsum.photos/200/300")

struct WidgetSmall : View {

  var body: some View {
    VStack{
      URLImage(url!) { proxy in
          proxy.image
              .resizable()
              .renderingMode(.original)
          }
          .frame(width: 100.0, height: 100.0)
    }

  }
}

Test data https://picsum.photos/200/300

Additional information: Simulator Screen Shot - iPhone 11 Pro - 2020-07-01 at 16 09 31

dmytro-anokhin commented 4 years ago

Widgets are not working on Simulator right now (https://developer.apple.com/forums/thread/650831) and I don't have a spare device to install iOS 14 beta. Let's wait for the next beta.

gedeagas commented 4 years ago

@dmytro-anokhin hi, just found out that in WidgetKit drawing the view is a synchronous operation, so you cannot use views that perform asynchronous tasks (like image fetching) directly.

Related discussion here https://developer.apple.com/forums/thread/652581

dmytro-anokhin commented 4 years ago

I see. I will keep this in mind, but I guess there is nothing I can do.