If I have a bunch of nested nodes, to track the ba...
# appyx
k
If I have a bunch of nested nodes, to track the backstack do I need to store all of the InteractionTargets of all nested child nodes in the root node? or if I instantiate a different BackStack for each ParentNode, does the backstack object keep track of the whole stack in the BuildContext?
a
Hi Kyle, in Appyx navigation is a local concern so you should avoid globally visible InteractionTargets and declare them locally for each ParentNode. I’m not sure I got the second question 100% right but you should have BackStack instances per ParentNode. BackStack is not a global instance and it keeps track of items which were added/deleted for each instance. BuildContext helps to restore state for each instance of your
BackStack
z
In addition to what Andrei said this might help to visualise it: https://bumble-tech.github.io/appyx/navigation/concepts/composable-navigation/ Check the gif where the tree is animated. Each
ParentNode
in that graph has their own
AppyxComponent
(it can be
BackStack
or another component too). We could pretend that whenever the tree animation changes, it’s because of the local
BackStack
in one of the `ParentNode`s is doing some operation (push, pop, etc.). There’s no global one. So in this specific image, there would be a total of 4 individual
BackStack
instances, one for each of: Root, Onboarding, Main, Messages, and each of them only sees their direct children as possible local navigation targets: • Onboarding for example can only decide to push/pop related to the *O1*/*2*/*3* onboarding screens. • Root can only decide to switch between Onboarding and Main. But while they’re local pieces, if you chain them together you get a global navigation emerging from them as illustrated on the gif.
k
What I was thinking of is in that instance if I want to go from Messages/People to Settings, and then have the backstack go back to people, Would all of the InteractionTargets need to be stored and referenced from Main? From the sounds of it that’s not the intended flow and I should be going down the explicit navigation route, although that sounds a bit messy
z
Gotcha. Yes I’d definitely not suggest storing all interaction targets in Main or some top level in general – though in this specific case both People and Settings are directly under *Main*’s responsibility. You mentioned explicit navigation so you maybe already know these, I believe one of these options would suit you: https://bumble-tech.github.io/appyx/navigation/concepts/implicit-navigation/ https://bumble-tech.github.io/appyx/navigation/concepts/explicit-navigation/
k
What would be your suggestion on how to best do it? I have a RootNode, under that an AuthenticatedNode, and then a whole bunch of nested stuff under there with one of the nodes under AuthenticatedNode being settings. I want to be able to get to that from any other Node under the AuthenticatedNode.
and the backstack from settings go back to whichever node it was clicked from
z
1. You could pass down a callback dependency in the tree
onGoToSettings: () -> Unit
which would be implemented by
AuthenticatedNode
such as:
{ backStack.push(Settings) }
. 2. You could go with the Navigator approach explained in the Explicit navigation page. The back stack that pushes Settings will also keep the previous back stack entry alive without its view – and that previous entry has its subtree still attached to it. So when you pop Settings, you’ll find yourself where you were before.