Skip to content

Instantly share code, notes, and snippets.

@danhalliday
Created October 22, 2020 12:28
Show Gist options
  • Save danhalliday/603024eb311b7a6ac90aabbbd8aa3cf8 to your computer and use it in GitHub Desktop.
Save danhalliday/603024eb311b7a6ac90aabbbd8aa3cf8 to your computer and use it in GitHub Desktop.
Test case for LazyVStack scrolling behaviour with a large number of items.
struct ContentView: View {
let count = 1_000_000
var body: some View {
ScrollViewReader { reader in
VStack {
Button(action: { reader.scrollTo(100, anchor: .center) }) {
Text("Scroll to 100") // Works
}
Button(action: { reader.scrollTo(count, anchor: .center) }) {
Text("Scroll to \(count)") // Hangs above 10,000 rows
}
ScrollView {
LazyVStack {
ForEach(1...count, id: \.self) {
Text("Row \($0)").id($0)
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment