The <doc example> for multiple back stacks &amp; bottom navigation causes the bottom icon to highlig...
r
The doc example for multiple back stacks & bottom navigation causes the bottom icon to highlight when you are exactly at that destination. Shouldn't it also highlight if your stack is rooted at that destination? In other words, if the bottom nav items are A,B,C,D; and you go from B to E, so your back stack is [B,E], shouldn't the bottom nav show B as selected/highlighted?
i
Is B a nested graph that contains E? If so, it will continue to appear as highlighted when on E
r
No, I have only one graph so far. I can get to E through A or B, but I would like to see the highlight, to see what context I'm in. I guess that's not supported currently.
i
You can write whatever logic you want; it is your code
but the intent is that only when you're on graph B does the item associated with B highlight. If you had a Settings composable that wasn't part of A, B, C, or D that is equally not part of any of those graphs, then A, B, C, or D shouldn't be highlighted
r
Can I see the full stack from the navController? That doc example shows
navController.currentBackStackEntryAsState()
. That will point to E if my stack is [B, E]. But how to test to see if B is the root of the current stack?
I'm poking around the API and I don't see it.
i
No, that's purposefully not part of the API surface
I think if you want your selected item to be 'whatever the last selected item was', I think you'll want to track that yourself in a
mutableStateOf
and change it whenever an item is selected
s
@robnik You can check Chris Tivi app example for the NestedGraph approach.
r
Thanks. I'll experiment with both of these ways.
t
One of the samples uses
backStackEntry.destination.hierarchy
to check the selected route. That returns a
Sequence
of parent destinations in the graph.