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

Animate appearing if needed #240

Closed temrov closed 1 year ago

temrov commented 1 year ago

I was asked to animate from placeholder to loaded image so I see no other way to do it without changing WebView code. Usage could be like this:

WebImage(url: url)
    .placeholder {
        ...
    }
    .resizable()
    .shouldAnimateAppearanceOnSuccess(perform: { _, _, cacheType in
        return cacheType.shouldAnimateAppearance
    })
public extension SDImageCacheType {
    var shouldAnimateAppearance: Bool {
        switch self {
        case .none, .disk:
            return true
        default:
            return false
        }
    }
}
dreampiggy commented 1 year ago

What's your mean animate from placeholder to loaded image

Actually, the placeholder and final loaded image, is Different View Identity. So the automatic animation provided by SwiftUI can only show the fade-in/fade-out animation

See more: https://developer.apple.com/videos/play/wwdc2021/10022/