Skip to content

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

Open
@alexfanatics

Description

@alexfanatics

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()
    }
}
crossfade_example.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions