I have a really simple SwiftUI view that is listing a bunch of Texts:
extension String: Identifiable {
public var id: String { return self }
}
struct ContentView: View {
var items: [String] = (0..<1000).map { $0.description }
var body: some View {
List(items) { str in
HStack {
Text(str)
}
}
}
}
This code seems to work fine and gives me smooth scroll performance.
If I change this so that the HStack is inside of a horizontally scrolling ScrollView:
var body: some View {
List(items) { str in
ScrollView(.horizontal) {
HStack {
Text(str)
}
}
}
}
There is an enormous performance hit and memory appears to grow unbounded as I scroll up and down through the list. There aren’t any leaks in the memory debugger.
I’m wondering if anyone knows why the performance hit is so massive and if there’s any way around it.
Update:
The HStack and Text appear to be irrelevant to the issue, even a Spacer inside the scrollView will trigger the issue.
List(items) { _ in
ScrollView(.horizontal) {
Spacer()
}
}