LazyVStack + ScrollView blank issue

Originator:fernandomdr
Number:rdar://FB9747151 Date Originated:Nov 8, 2021
Status:Open Resolved:No
Product:SwiftUI Product Version:iOS 15.1
Classification: Reproducible:
 
Sometimes we face issues with LazyVStack and ScrollView on SwiftUI and the view gets completely blank out of nowhere. It stays like that until I do a tiny swipe to scroll, then the view re-appears. I notice that more often with "taller" views inside the LazyVStack.

I see this issue happening on many different scenarios. It was hard to isolate but I could get a reliable way to reproduce it.

You will notice that I'm using an "id" modifier there and also a "lineSpacing" modifier. They are not really needed to trigger the bug as I could see it happening even without it, but they make the bug to trigger easily. The bug in the example will trigger after tapping the bottom Add button sometimes, but I've seeing it to trigger even when just scrolling through the scroll view and without the id and lineSpacing modifier:

struct MyDataStruct: Identifiable {
  var id = UUID()
  var otherId = UUID()
  var text: String
}

struct ContentView: View {
  @State var contents = (0..<10).map { _ in
    MyDataStruct(
      text: (0..<40)
        .map { "looooong row \($0) long row block\n" }
        .reduce("", +)
    )
  }
  var body: some View {
    ScrollView {
      LazyVStack {
        ForEach(contents) { content in
          VStack {
            Text(content.text)
              .lineSpacing(30)
              .id(content.otherId)
          }
        }
        Button {
          contents.append(MyDataStruct(text: "X"))
          contents.remove(at: 0)
        } label: {
          Text("Add")
        }
      }
    }
  }
}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!