Hi there!
First of all, I tried to search for answers and examples concerning what I'm about to ask. However I couldn't find anything that could help me.
Following the examples:
- 03-Navigation-Lists-LoadThenNavigate
- 03-Navigation-Lists-NavigateAndLoad
- 03-Navigation-LoadThenNavigate
- 03-Navigation-NavigateAndLoad
I've been trying to have a list of two or more NavigationLink views, without using ForEach(viewStore.rows) { row in ... }
, and having two or more reducers, so that can use a different Environment
in each view.
For example, considering 03-Navigation-LoadThenNavigate, the body would look like as follows:
var body: some View {
WithViewStore(self.store) { viewStore in
Form {
Section(header: Text(readMe)) {
NavigationLink(
destination: IfLetStore(
self.store.scope(
state: { $0.optionalCounter }, action: LoadThenNavigateAction.optionalCounter),
then: CounterView.init(store:)
),
isActive: viewStore.binding(
get: { $0.isNavigationActive },
send: LoadThenNavigateAction.setNavigation(isActive:)
)
) {
HStack {
Text("Load optional counter")
if viewStore.isActivityIndicatorVisible {
Spacer()
ActivityIndicator()
}
}
}
NavigationLink(
destination: IfLetStore(
self.store.scope(
state: { $0.optionalCounter }, action: LoadThenNavigateAction.optionalCounter),
then: CounterView.init(store:)
),
isActive: viewStore.binding(
get: { $0.isNavigationActive },
send: LoadThenNavigateAction.setNavigation(isActive:)
)
) {
HStack {
Text("Load optional counter")
if viewStore.isActivityIndicatorVisible {
Spacer()
ActivityIndicator()
}
}
}
}
}
}
.navigationBarTitle("Load then navigate")
}
}
How would you then define the loadThenNavigateReducer
so that you can easily have different Environment
? one for "production" purposes and one for mock/demo purposes, for example ?
Is this actually the right approach to use? if not, do you have any other solution for this problem ?