SwiftUI force FKImage to reload view #2018
ddtbuilder
started this conversation in
General
Replies: 1 comment 1 reply
-
It is the correct behavior. The I guess a possibly better way might be giving the @State private var kfSource: Source?
+ @State private var kfImageId = UUID()
KFImage(source: kfSource)
+ .id(kfImageId)
.onAppear {
if let uarl = URL(string: animal.picFileReference) {
kfSource = Source.network(ImageResource(downloadURL: uarl))
}
}
KingfisherManager.shared.retrieveImage(with: Source.provider(rawDP), options: [.processor(processor)]) { result in
switch result {
case .success(let value):
kfImage = value.image
let cache = ImageCache.default
cache.store(value.image, forKey: animal.picFileReference)
+ self.kfImageId = UUID()
cache.removeImage(forKey: "tmp-img", processorIdentifier: processor.identifier) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been struggling to make KFImage reload its view, and I'm hoping someone can help. Here is the problem...
Code to display KFImage:
Then I select a new image from the photo library, run it through a filter, and save it to the same cache (verified working)
But now there isn't a clean way to for KFImage to update it's view. Even though the cache holds a new image I can't figure out a way to force KFImage to "reload" or update the view. The only successful way (below) feels like a hack. Currently I have to change the source like this:
Basically I have to switch the source to a RawImageDataProvider and then back again to a URL type resource to force KFImage to update its view. Is this expected behavior? Is there a better approach to tell KFImage that the image in the cache has changed?
Beta Was this translation helpful? Give feedback.
All reactions