Skip to content

The view doesn't update when data changes #3

@plivesey

Description

@plivesey

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
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions