Closed TomShen1234 closed 3 years ago
Hello,
thank you for the sample code.
When the view updates, the image reloads because accessing URLCache
is asynchronous operation. The way to "fix" this is to use provided in-memory cache.
import SwiftUI
import URLImage
import URLImageStore
@main
struct URLImage_Issue159App: App {
var body: some Scene {
let urlImageService = URLImageService(fileStore: nil, inMemoryStore: URLImageInMemoryStore())
return WindowGroup {
ContentView()
.environment(\.urlImageService, urlImageService)
}
}
}
I will review implementation to see if there is some new tool in SwiftUI that can help with this particular case.
Summary and/or background When the view is refreshed (for example, via a state change), the image is always reloaded. This can be seen in the following code:
The
URLImage
will reload once thesaved
property is changed (aka when you press the return key on the text field).OS and what device you are using iOS 14 and iOS 15 beta 6
Version of URLImage library 3.1.0
What you expected would happen The image should stays without reloading.
What actually happens See above
Sample code See above
Test data Any image works
Additional information
Misc