V8tr / AsyncImage

Asynchronous Image Loading from URL in SwiftUI
https://www.vadimbulavin.com/
The Unlicense
274 stars 36 forks source link

Image disappears after app resigns active #6

Open lukemorse opened 4 years ago

lukemorse commented 4 years ago

Hello,

First of all, thanks for the great code! I'm experiencing an issue when the app enters background, and then becomes active again. The image goes away, replaced by the placeholder, and the image never reloads. I get this error in the console: 2020-06-30 15:53:20.517988-0500 AsyncImage[23959:3569320] [] nw_read_request_report [C1] Receive failed with error "Software caused connection abort"

Anybody find a way to fix this?

V8tr commented 4 years ago

Hi @lukemorse ! If I correctly understood and reproduced the issue, the problem was that onDisappear() was called when view entered background, but onAppear() was never called. Could you please check again with the current version of the project? It now uses StateObject instead of ObservedObject, which, from my experience, fixed the problem.

nthState commented 3 years ago

@lukemorse This may not be the best way and it may expose other issues, but if your constructor looks like this:

init(url: URL) {
    self.url = url
  }

You can change it to this and images now show when coming back in iOS13

init(url: URL) {
    self.url = url

    load()
  }
nrj commented 3 years ago

I'm experiencing this issue too, however not when backgrounding. It seems that onAppear is not called when the bound image url changes either.

In my case when my view loads, an AsyncImage is rendered with a binding to a selectedImageURL property. The image init is called first and then onAppear is called triggering the image load, which loads the current selected image.

However when I pop up an image picker sheet and allow the user to change the selected image, which changes the selectedImageURL binding, the view is rebuilt and the init is called again, but the onAppear is not called again. This means the old selected image stays visible.