SDWebImage / SDWebImageSwiftUI

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

.transition(.fade) only if image isn't already in the cache? #218

Open danielkramer opened 2 years ago

danielkramer commented 2 years ago

Thanks for the slick library, it's working great. I have a LazyVGrid that arranges over 1000 images. I've added the .fade transition which is working great. Ideally tho if the image is already in the cache I'd like to just display it without the fade and only fade if it has to download the image from my server. Thanks for any pointers if this is possible.

Here's a simplified version of my lazyVgrid.. it's parent is a ScrollView.

LazyVGrid(columns: columnLayout) {
  ForEach(settings.getWallpaperArray(), id: \.name) { wallpaper in
    NavigationLink(destination: WallpaperUI(currentWallpaper: wallpaper)) {
        WebImage(url: URL(string: wallpaper.thumbUrl))
        .resizable()
        .aspectRatio(contentMode: .fit)
        .transition(.fade(duration: 0.25))
    }
  }
}
dreampiggy commented 2 years ago

Maybe you need to customize the transition modifier. This is from SwiftUI, not just from SDWebImage. There are onSuccess modifier to let you get the cache from (whether cache or network), then you need a @State to refresh and do transition.

dreampiggy commented 2 years ago

For UIKit (not SwiftUI) it actually do transition from network only. Match what you want by default...

And you need forceTransition to make it do animation for all cache from type.

However, in SwiftUI there are no such a behavior, because it's not powered by UIKit and +[UIView animationWithDuration:]