How can we go from one part of the tree to another? In almost all cases navigation can be implicit instead of explicit. We don't need to specify the target – navigation will happen as a consequence of individual pieces of the puzzle.
Node.onChildFinished(child: Node)can be overridden by client code to handle a child finishing
Node.finish()invokes the above method on its parent
After onboarding finishes, the user should land in the message list screen.
O3finished; if it had more children, it could switch to another; now it calls
Onboardingfinished, and switches its navigation to
Mainis initialised, and loads its default navigation target (based on product requirements) to be
Messagesis initialised, and loads its default navigation target to be
Node in the above sequence only needed to care about its own local concern.
Pressing the logout button on the profile screen should land us back to the login screen.
Rooteither implements a
logoutcallback, or subscribes to the changes of a user repository; in both cases, either the callback or the repository is passed down the tree as a dependency
Profileinvokes the callback or a
logoutmethod on the repository
Rootnotices the state change, and switches its navigation to the
Logged outloads its initial navigation target,
Note how the entire
Logged in scope is destroyed without any extra effort. The next time a login happens, all state is created anew.
Implicit navigation allows you to implement navigation without introducing unnecessary coupling in the tree, and successfully covers the majority of navigation scenarios.
In case it's not enough to meet your needs, see the next chapter, Explicit navigation