Post

Replies

Boosts

Views

Activity

[Critical Issue] Content with variable height in a LazyVStack inside a ScrollView causes stuttering / jumping
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?
7
7
7.9k
Jul ’21
Dismissing sheet with keyboard up shifts view down partially under the keyboard
I've seen this in multiple places now, but when I have a keyboard up, and then I present a modal (i.e. UIImagePickerController or PHPickerViewController) and hit "Cancel", it shifts the view down by ~30 pixels, and it becomes partially covered by the keyboard. The weird thing is, if I swipe down the UIImagePicker camera, it restores the frame just fine. So it seems to only happen when dismissing a sheet without a gesture. Could it be a bad interaction with UIViewControllerRepresentable? This is a bad bug if you're trying to have a textfield stay affixed to the top of the keyboard. For now, I've just resignedFirstResponder before pulling up the keyboard.
0
0
697
Jul ’21
SwiftUI ScrollView w/ LazyStack stutters when children contain conditionals
I've been wrestling with the challenge of performant ScrollViews for quite some time now and I can't seem to figure it out. With either a a LazyVStack or a LazyHStack within a ScrollView, when I drag beyond the top (or leading) bounds, it will jitter or flicker. I removed all of the code from the subviews of the stacks and put it back line by line until I narrowed it down to using any sort of if let statements within the child. Here's a simplified example: HStack { if let duration = item.duration { Text(duration) } } If I take out the if let and just put Text("blah"), it no longer stutters. This is a mystery to me, and I'm curious if anyone has any knowledge on the inner working of SwiftUI and why this might be happening.
0
0
1k
Mar ’21