My goal is to create a chat view in SwiftUI. This requires creating a ScrollView with content of varying heights .
After extensive debugging, I've determined that if you have views within a LazyVStack inside of a ScrollView that do not have a fixed height, it will stutter when you scroll to the top of the view.
––––
PROJECT: Download this project and try for yourself
struct ContentView: View {
@State var items: [String] = MockData.randomMessages(count: 100)
var body: some View {
VStack {
Button("Shuffle items") {
items = MockData.randomMessages(count: 100)
}
ScrollView {
LazyVStack(spacing: 10) {
ForEach(Array(items.enumerated()), id: \.offset) { index, item in
Text(item)
.background(colors.randomElement()!)
}
}
}
}
}
}
My conclusion right now is that LazyVStack
only works with child views that have fixed height. This issue alone prevents SwiftUI from being production ready.
Has anyone else tackled this?