SDWebImage / SDWebImageSwiftUI

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

Fix the rare cases that WebImage will lost animation when visibility changes. #171

Closed dreampiggy closed 3 years ago

dreampiggy commented 3 years ago

Always setup player to play as defaults to avoid this.

Reproduce demo:

 @State var urlString = "https://media0.giphy.com/media/3oEjHBop7WaPmuPryg/giphy.gif?cid=c3b5a7e2fdfc7510a373e125e129e199de61e11c3907222f&rid=giphy.gif"
    var body: some View {
        print("update view", urlString)
        return VStack {
            WebImage(url: URL(string: urlString), isAnimating: .constant(true))
                .resizable()
                .placeholder {
                    Rectangle().foregroundColor(.lightGray)
                }
                .indicator(.activity)
                .transition(.fade(duration: 0.5))
                .aspectRatio(contentMode: .fit)
                .frame(width: 200, height: 200)
            Button("test") {
                if urlString == "https://media0.giphy.com/media/3oEjHBop7WaPmuPryg/giphy.gif?cid=c3b5a7e2fdfc7510a373e125e129e199de61e11c3907222f&rid=giphy.gif" {
                    urlString = "https://media4.giphy.com/media/fLskTldNGlI3fISnLA/giphy.gif?cid=c3b5a7e2v2ma8dlz57l2swklkes7xi656k671vuhr5bxnkke&rid=giphy.gif"
                } else {
                    urlString = "https://media0.giphy.com/media/3oEjHBop7WaPmuPryg/giphy.gif?cid=c3b5a7e2fdfc7510a373e125e129e199de61e11c3907222f&rid=giphy.gif"
                }
            }
        }
    }