Send actions to store within tabView selection #1100
-
Lets say I have a TabView. Do I really need to send "selectedTab" actions? If not they will get out of sync?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In SwiftUI, this is achieved through a viewStore.binding(
get: { state in
state.selectedTab
},
send: { tab in
AppAction.selectedTab(tab)
}
} or equivalently: viewStore.binding(get: \.selectedTab, send: AppAction.selectedTab) There are other means to achieve this in the library, like using a Now, your implementation of TabView(selection: viewStore.binding(get: \.selectedTab, send: AppAction.selectedTab)) {
Color.red
.tag(.red)
Color.green
.tag(.green)
} That's how SwiftUI understands what view to display when you tap the corresponding button in the toolbar. These buttons' icons and labels can furthermore be configured using When you tap the second button for |
Beta Was this translation helpful? Give feedback.
In SwiftUI, this is achieved through a
Binding
, which is a value that you can read and write.There are several ways to achieve this in TCA, but the closest to what you have there is to replace
viewStore.selectedTab
by:or equivalently:
There are other means to achieve this in the library, like using a
binding()
higher-order reducer, but they are more involved. You can look at the case studies for more informations about them.Now, your implementation of
TabView
with a selection is not complete, even i…