SDWebImageSwiftUI icon indicating copy to clipboard operation
SDWebImageSwiftUI copied to clipboard

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

Open danielkramer opened this issue 2 years ago • 2 comments

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))
    }
  }
}

danielkramer avatar Jul 18 '22 19:07 danielkramer

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 avatar Jul 19 '22 03:07 dreampiggy

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:]

dreampiggy avatar Jul 19 '22 03:07 dreampiggy