Closed alladinian closed 4 years ago
Seems because of the nil
URL does not trigger the ImageManager.$image
observed object callback. So the internal SwiftUI.Image
does not get updated.
I can update to have a check for this case, and always update ImageManger.$image
even on error when loading.
@alladinian A more easy to debug and re-producable demo is welcomed. You just need to simplify the core code usage, don't need to put your real project.
That was a prompt reply, thanks!
Ok, this is a minimal example to reproduce the issue:
import SwiftUI
import SDWebImageSwiftUI
struct TestView: View {
// Non-working version
@State var urlString: String = ""
// Working version
@State var urlString: String = "https://via.placeholder.com/150"
var body: some View {
VStack {
WebImage(url: URL(string: self.urlString))
.frame(width: 300, height: 300, alignment: .center)
Button(action: {
self.urlString = "https://via.placeholder.com/300"
}) {
Text("Button")
}
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
I guess I could help with fixing the bug but I need to familiarize myself with the codebase first, so please let me know if there is anything I can do to help.
I'll have a check for this today and find a workaround. Please have a wait. (busy on daily job yesterday)
Decide to revert changes about performance introduced in #92.
Same root case in #103
@alladinian Please have a try again with v1.3.4
@dreampiggy Indeed, the issue seems to be resolved in v1.3.4 👍
So, I'm not sure if I'm abusing the API or it is actually a bug, but here is the problematic setup:
now, the
WebImage
takes aurl
, which of course is invalid (empty) while the fetcher is working...Something like:
WebImage(url: URL(string: observable.imageURL ?? ""))
which results in an empty image, even after the second pass of the body passes a valid image URL (verified in the debugger).
If instead of an empty URL I pass a static image URL, then everything works as expected:
WebImage(url: URL(string: observable.imageURL ?? "https://some_image_url"))
any ideas?