Skip to content

Instantly share code, notes, and snippets.

@atrinh0
Created August 29, 2022 14:41
Show Gist options
  • Save atrinh0/968e0d39f02bcfda6e92815cf9a7a773 to your computer and use it in GitHub Desktop.
Save atrinh0/968e0d39f02bcfda6e92815cf9a7a773 to your computer and use it in GitHub Desktop.
ScrollViewReader scrollTo crash on Xcode 14
import SwiftUI
struct ContentView: View {
@State private var items: [RandomItem] = (0...25).indices.map { _ in RandomItem() }
var body: some View {
ScrollViewReader { proxy in
List {
ForEach(items) { item in
Text("\(item.number)")
.id(item.id)
}
}
.onChange(of: items.count) { _ in
withAnimation {
proxy.scrollTo(items.last?.id)
}
}
Button {
items.append(RandomItem())
} label: {
Text("Add item")
}
}
}
}
struct RandomItem: Identifiable {
var id = UUID()
let number = Int.random(in: 0...100)
}
@atrinh0
Copy link
Author

atrinh0 commented Aug 29, 2022

The same code crashes on Xcode 14 (beta 6) after tapping "Add item" a few times.

Screenshot 2022-08-29 at 15 44 17

@atrinh0
Copy link
Author

atrinh0 commented Aug 29, 2022

Raised FB11402625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment