CollectionThing
CollectionThing copied to clipboard
The view doesn't update when data changes
This can be shown by the following code. When tapping on increment, the view doesn't update. This because visible rows isn't updated so it's still showing old data.
I've fixed this in #2
struct ContentView: View {
@State var data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
var body: some View {
VStack {
Button(action: incrementData) {
Text("Increment")
}
Button(action: insert) {
Text("Insert")
}
FastCollection(items: data, itemHeight: 60) { number in
Text("\(number)")
.frame(height: 60)
}
}
}
func incrementData() {
data = data.map { $0 + 1 }
}
func insert() {
data.insert(Int.random(in: data[8]+1..<100), at: 5)
}
}
extension Int: Identifiable {
public var id: Int {
return self
}
}