SDWebImage / SDWebImageSwiftUI

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

WebImage in a LazyVStack in a ScrollView causes stuttering #195

Closed chrysb closed 3 years ago

chrysb commented 3 years ago

Hi folks! If we embed WebImages within a LazyVStack or LazyHStack, it causes the view to stutter.

[Demo video] [StackOverflow post]

I suspect it has something to do with variable view sizing.

Unfortunately, this is a non-starter for any project where we want to embed WebImage within a ScrollView w/ a LazyVStack.

Here's my code, simplified:

ScrollView {
  LazyVStack {
    HStack { 
      Spacer()
      if let imageUrlString = item.assetUrl, let imageUrl = URL(string: imageUrlString) {
        WebImage(url: imageUrl)
          .resizable()
          .scaledToFill()
        }
    }
  }
}

I've tried removing the modifiers as well as adding fixedSize() along with a fixed size frame and it doesn't resolve the issue.

Any help or insight or resolution would be a game changer!

chrysb commented 3 years ago

After further investigation, it seems like a general problem with SwiftUI.

I've documented the issue here: https://stackoverflow.com/questions/68459594/content-with-variable-height-in-a-lazyvstack-inside-a-scrollview-causes-stutteri

Any support in reporting this to Apple would be super appreciated. I think it's the only thing holding back SwiftUI from being production ready.