Tree-based navigation with multiple .navigationDestination views #3090
-
Hey! How does one have different views presented with
However, for the view part of the example, all of the cases are handled my different modifiers:
What if all of them would be
But can't get it to work yet. Am I on the right path? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This is the way to do it, but you may need to employ some tricks to work around the compiler issues. You can move your navigation view modifiers to a helper like this: extension View {
func navigation(store: Binding<StoreOf<Feature>>) -> some View {
self
.navigationDestination(
item: $store.scope(
state: \.destination?.addItem,
action: \.destination.addItem
)
) { store in
AddItemView(store: store)
}
.navigationDestination(
item: $store.scope(
state: \.destination?.editItem,
action: \.destination.editItem
)
) { store in
EditItemView(store: store)
}
.navigationDestination(
item: $store.scope(
state: \.destination?.detailItem,
action: \.destination.detailItem
)
) { store in
DetailFeatureView(store: store)
}
}
} And then you would use it like so: .navigation(store: store) That should get around any compilation problems. Also once we can release 2.0 we will be able to delete hundreds of deprecated APIs, and that too should help out the compiler. |
Beta Was this translation helpful? Give feedback.
This is the way to do it, but you may need to employ some tricks to work around the compiler issues. You can move your navigation view modifiers to a helper like this: