swiftui-cached-async-image icon indicating copy to clipboard operation
swiftui-cached-async-image copied to clipboard

ScrollView + LazyVGrid jumps around when scrolling backward

Open danielkramer opened this issue 3 years ago • 1 comments

I have a LazyVGrid inside a Scrollview.. scrolling from start to finish works great , as I scroll backward the scrollview jumps around.. I think the issue is the scrollview content size for each grid item is changing. If I hard code the frame of the image it no longer hitches. I think I should be able to do that as all my images are the same size.. but I didn't run into this issue when trying other image caching frameworks like SDWebImageSwiftUI for example. Just thought you might want to know if it's something that can be looked at.


ScrollView {

    LazyVGrid(columns: columnLayout) {

        ForEach(settings.wallpaperDataFiltered, id: \.guid) { wallpaper in

            ZStack {
                NavigationLink(destination: WallpaperUI()) {
                   
                    KFImage.url(URL(string: wallpaper.thumbUrl))
                              .fade(duration: 0.25)
                              .resizable()
                              .aspectRatio(contentMode: .fit)
                        
                }
            
            }

        }

    }

}

danielkramer avatar Jul 24 '22 18:07 danielkramer

Maybe a little bit late... but from my experience using the .aspectRatio(..) modifier with aspectRatio: CGSize parameter helps SwiftUI to calculate the layout and dramatically improves scrolling performance and may fix your described behaviour. But it would require to know the dimensions of the resource before requesting.

tomstoermerdotcom avatar Mar 28 '24 09:03 tomstoermerdotcom