SDWebImage / SDWebImageSwiftUI

SwiftUI Image loading and Animation framework powered by SDWebImage
https://sdwebimage.github.io/SDWebImageSwiftUI
MIT License
2.09k stars 214 forks source link

Gif Animation stopped when change gif driven by state #293

Closed alfredcc closed 6 months ago

alfredcc commented 6 months ago

Dear Contributors,

I hope this message finds you well. I am reaching out to bring to your attention a small issue.

I've noticed that when the level initially changes, the GIF animation plays as expected, which is fantastic. However, I've observed that if the level changes again after the first state, the GIF does not animate.

Here's a brief outline of the behavior:

Initial level change: GIF animates correctly. Subsequent level changes: GIF does not animate.

I was wondering if there's a workaround or a fix that I could apply. Any guidance on this matter would be greatly appreciated.

@Binding var level: Level

WebImage(url: Bundle.main.url(forResource: level.gifURL, withExtension: "gif"))
    .resizable()
    .frame(width: size.width, height: size.height)
dreampiggy commented 6 months ago

Why use @Binding but not @State ? Isn't this is a current View's state ?

dreampiggy commented 6 months ago

And I even not understand what's that Bundle.main.url(forResource:) call used for. Your Level.gifURL is a URL ? Why not just pass it into WebImage

If it's a file URL (file://), SDWebImageSwiftUI also support that form, just do simple thing.

alfredcc commented 6 months ago

Why use @Binding but not @State ? Isn't this is a current View's state ?

I've just resolved it by using @State and applying changes through the onChange modifier.

Thank you for your assistance with this matter!