SDWebImage / SDWebImageSwiftUI

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

Legacy Swift UI animation modifier required for cross fade transition to function #272

Open alexfanatics opened 1 year ago

alexfanatics commented 1 year ago

Greetings, great library.

I may be using the APIs incorrectly here, but I can only get the cross fade to function using the legacy animation modifier. Is this usage incorrect? How can I get the cross fade working properly with the modern animation modifier? Thanks!!!

import SwiftUI
import SDWebImageSwiftUI

struct ContentView: View {

    @State var url = URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic")

    var body: some View {
        VStack {
            Text("old animation modifier")
            WebImage(url: url)
                .resizable()
                .indicator(Indicator { _, _ in EmptyView()})
                .animation(.easeInOut(duration: 3))
                .transition(.fade)
                .scaledToFit()
                .aspectRatio(contentMode: .fit)
                .frame(width: 300, height: 300, alignment: .center)
            Spacer()
            Text("new animation modifier")
            WebImage(url: url)
                .resizable()
                .indicator(Indicator { _, _ in EmptyView()})
                .animation(.easeInOut(duration: 3), value: url)
                .transition(.fade)
                .scaledToFit()
                .aspectRatio(contentMode: .fit)
                .frame(width: 300, height: 300, alignment: .center)
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

https://github.com/SDWebImage/SDWebImageSwiftUI/assets/121891059/2034e0ab-6d1c-4511-9c49-0d251430f804

eccentricyan commented 1 year ago

It doesn't work with lazyvstack, animation goes weird. I think the linked PR is the correct solution.

aviwad commented 1 year ago

It doesn't work with lazyvstack, animation goes weird.

I think the linked PR is the correct solution.

Yeah animation gets erratic. I don't know what other image library to use in my SwiftUI app, because I want to share the cache with my app widget extension as well. Do you have any suggestion?