Closed Scocher closed 6 months ago
@Scocher seems like adding id: \.state.id
to ForEach
does the job, at least it worked for me.
Link to the original solution.
@domagojstankovic Notes the issue, which is that the identity should be based on the data in the store and not the identity of the store itself. I'm going to convert this to a discussion since it's not technically a bug with the library.
Description
When running this code the updateIndex does not update.
TabView(selection: $store.selectedID.sending(\.updateIndex)) { ForEach(Array(store.scope(state: \.rows, action: \.rows).enumerated()), id: \.element) { index, store in Text("\(store.id)").tag(store.id) .frame(maxWidth: .infinity, maxHeight: .infinity) .background((index % 2 == 0 ? Color.blue : Color.red).opacity(0.2)) } } .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
compared to this:TabView(selection: $store.selectedID.sending(\.updateIndex)) { ForEach(Array(store.rows.enumerated()), id: \.element) { index, item in Text("\(item.id)").tag(item.id) .frame(maxWidth: .infinity, maxHeight: .infinity) .background((index % 2 == 0 ? Color.blue : Color.red).opacity(0.2)) } } .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
https://github.com/pointfreeco/swift-composable-architecture/assets/2694492/bb95a754-23fa-4dc1-ab75-63f9b752eca1
SimpleProject.zip
Checklist
main
branch of this package.Expected behavior
I expect the index to update.
Actual behavior
It does not.
Steps to reproduce
Run the project I have attached.
The Composable Architecture version information
'1.8.2', 'main'
Destination operating system
iOS 17.2
Xcode version information
15.2
Swift Compiler version information