Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The view doesn't update when data changes #3

Open
plivesey opened this issue Nov 21, 2019 · 0 comments · May be fixed by #2
Open

The view doesn't update when data changes #3

plivesey opened this issue Nov 21, 2019 · 0 comments · May be fixed by #2

Comments

@plivesey
Copy link

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
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant