Is it possible to track multiple backstacks? Scena...
# appyx
k
Is it possible to track multiple backstacks? Scenario: I have a bottom bar with 4 links. I go to link A, click through a bunch of nodes, then click link B. If I click link A again, I want to go back to the last node I was on. Same for the last node of link B.
z
You could use the
singleTop
operation instead of
push
on the top level back stack. If A or B already exists in the stack, it will restore that along with its node subtree: https://bumble-tech.github.io/appyx/components/backstack/#single-top This should be quick to change. Alternatively, you could also use a
Spotlight
instead of a
BackStack
on the top level altogether, which keeps all of its children alive as a default. It’s only a minor layout detail whether it looks like a carousel or more like a full screen, so you could definitely use it in place of a back stack; https://bumble-tech.github.io/appyx/components/spotlight/
j
As more general advice, I believe each Backstack nav model instance has its own state, right @Zsolt? So as long as each of your root tab screens is a parent node with its own Backstack you’ll be going in the right direction.
z
That’s true, each have their own state. The whole subtree would be restored after a `push`+`pop` cycle since
push
just stashes (but keeps the element alive). However, the same is not true for a `pop`+`push` cycle as a default, since
pop
actually destroys the element (and its subtree). Additionally, since it is also possible to
push
the same element multiple times into the stack, each would be resolved to a different instance (possibly different subtree), which would not fit Kyle’s case. That’s where the other options in this specific use case are more helpful.