Closed
Description
Given the following code:
struct MyView: View {
let url: URL
@State private var isAnimating = false
var body: some View {
ZStack {
WebImage(url: url, isAnimating: $isAnimating)
Button {
isAnimating = true
} label: {
Text(.localizable.gifButton)
}
}
}
}
When I tap the button, the image will never start animating. It looks like the issue is in init(url:scale:options:context:isAnimating:transaction:content:)
for WebImage
here:
// provide animated image class if the initialized `isAnimating` is true, user can still custom the image class if they want
if isAnimating.wrappedValue {
if context[.animatedImageClass] == nil {
context[.animatedImageClass] = SDAnimatedImage.self
}
}
So if the initial value of isAnimating is false, the context never gets an .animatedImageClass
and therefore the image never animates.
This is unexpected -- the init
accepts a Binding<Bool>
, so if the value changes to true
, I'd expect the image to start animating.
Here's my workaround, which I'd prefer not to do:
WebImage(url: url, context: [.animatedImageClass: SDAnimatedImage.self], isAnimating: $isAnimating)
When I do this, I can start animating the image by setting the value of my isAnimating
to true
.
Metadata
Metadata
Assignees
Labels
No labels