When ScrollView is initialized, the focus is on item number 6. When I do insert, the focus element is lower.
How can I make ScrollView not change the focus on the element? I want the focus to still remain on element 6 when inserting. That is, so that visually nothing changes on the screen.
@State var items = [6, 7, 8, 9, 10]
@State var newItems = [1, 2, 3, 4, 5]
Button {
items.insert(contentsOf: newItems, at: 0)
} label: {
Text("Insert")
}
ScrollView {
ForEach(items, id: \.self) { item in
Text("\(item)")
}
}