I have a SwiftUI
List, which has thousands of items. Each item is as such:
class Item: Codable, Identifiable {
var id = UUID()
var prop1 = ""
var prop2 = ""
}
Now I do this:
List(store.items.indices, id: .self) { index in
DetailView(item: self.$store.items[index])
}.id(UUID())
I iterate the indicies
because I have to pass a Binding
to the DetailView
.
Now the DetailView
has TextFields
attached to the Item
's properties.
When DetailView
changes an Item
's properties, it causes the List
to refresh ALL of the items, which I dont want.
Also, it's still important that when one of those properties changes, the main view is updated, because on macOS, the main view is still visible even when you click on one of the items.
My question is how to make it so that whenever an Item
passed in from the List
changes, only update that row?
I also tried a solution mentioned where I use a LazyVStack
, and it fixes the performance issue, but I use the List
inside of a NavigationView
, and the LazyVStack
doesn't seem to support that.
Any suggestions are greatly appreciated.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…