https://kotlinlang.org logo
#compose
Title
# compose
a

AN

03/28/2023, 1:27 PM
Question: I have a navigation bar setup that works except when navigating to a destination that has it's own navigation graph. When navigating to that destination the navigation bar selected item goes blank?
s

Stylianos Gakis

03/28/2023, 2:55 PM
Might wanna look into this https://kotlinlang.slack.com/archives/CJLTWPH7S/p1627592231186200?thread_ts=1627558176.121600&cid=CJLTWPH7S None are selected since you may not be in that destination exactly. So you either want to hide the bottom bar, or check the backstack, and see if any of the parent destinations are one of those destinations that make the bottom bar light up, and if that’s the case pick that bottom bar item to be highlighted. With that said, how do you currently select which item will be highlighted in the bottom bar? By looking at that it may be easy to suggest something
a

AN

03/28/2023, 9:39 PM
Thanks for the reply! Currently, this is how I'm handling which item of the bottom navigation bar is selected
Copy code
navBackStackEntry?.destination?.hierarchy?.any {
    it.route == item.getRoute()
} == true
Shouldn't that check if the given destination is present in the backstack?
s

Stylianos Gakis

03/28/2023, 10:32 PM
Oh hmm yeah this looks correct, since you are looking at the entire hierarchy. Not sure about the
item.getRoute()
and what that returns, but I’ll just assume it’s the right thing. Now the next question would be, how are you getting
navBackStackEntry
? Any chance you’re somehow referring to stale information by calling
currentBackStackEntry
and not listening to the
currentBackStackEntryAsState
or something like that? Scouring this sub there’s plenty of examples where they do this exact same thing as you are trying to do, so it should work? A quick search in this channel for “hierarchy?.any” brings some results https://kotlinlang.slack.com/archives/CJLTWPH7S/p1655344229608759?thread_ts=1655344206.778579&cid=CJLTWPH7S https://kotlinlang.slack.com/archives/CJLTWPH7S/p1654796984543839?thread_ts=1654793995.106589&cid=CJLTWPH7S https://kotlinlang.slack.com/archives/CJLTWPH7S/p1654794017709439?thread_ts=1654793995.106589&cid=CJLTWPH7S https://kotlinlang.slack.com/archives/CJLTWPH7S/p1646298469736739 Maybe scour some more yourself too and see if any one of them can help you figure it out? 😄
2 Views