Skip to content

Instantly share code, notes, and snippets.

@atrinh0
Created August 29, 2022 14:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

Expected behaviour, scroll to last item works on Xcode 13.4.1.

Simulator.Screen.Recording.-.iPhone.13.Pro.Max.-.2022-08-29.at.15.42.34.mp4

@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