Centralized DestinationFeature
('aka' Coordinator or NavigationRouter) withOUT iOS 16 navigationStack
#2076
MojtabaHs
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Hi @MojtabaHs I'm curious why you need a singleton for Destination ? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, most of the time we end up having multiple
navigationLink
s works exactly the same. So why don't we have a centralizedDestinationFeature
to handle all navigations of the app?Its as simple as implementing a reducer that does nothing but scoping state and actions and child like:
And here is the
State
:And here is the
Action
:And the a coordinator to wire things up:
The rest is exactly like we already know:
1- Define a
@PresentationState
in the state of the source feature:2- Define a
PresentationAction<Destination.Action>
in the source feature3- And embed the domain in the source reducer:
Of course we need to set the destination on the proper action:
And Of course we need to have a
DestinationLinkStore
inside a navigation-capable container like theNavigationView
:The Pros of this method are:
navigation style
and it can be modal, sheet and etc.And the cons are:
navigationLink
because it has some bugs in the vanilla SwiftUI (But we need it for iOS below 16).stack
style of the navigationWhat do you think?
Here is a repo containing a working example: TCA-Centralized-DestinationFeature
Beta Was this translation helpful? Give feedback.
All reactions