I'm using BottomNavigation with androidx navigatio...
# compose-android
c
I'm using BottomNavigation with androidx navigation-compose. I currently have each tab maintaining it's own backstack (like my designer wants)... but my designer also wants that if you click the tab that you're already on/selected, that it reloads that tabs/clears the stack. Any idea how to do that? Tried googling but all I get is results for how to support multiple backstacks with bottomNav.
s
When you click that button, first check if that nav graph is in the hierarchy of the current destination already. If it's not, do what you were doing already. If it is, popBackStack to the nav graph not inclusive
😍 1
c
I'll try that when I'm back at my machine. Thank you!
s
Lmk how it goes 😊
c
Gave it a shot yesterday and no dice. I think I'm doing something with "first check if that nav graph is in the hierarchy of the current destination already" wrong. Will have more time to debug later today 🤞
s
Show the code and it'll probably be a simple fix. I do this here https://github.com/HedvigInsurance/android/blob/develop/app%2Fapp%2Fsrc%2Fmain%2Fkotlin%2Fcom%2Fhedvig%2Fandroid%2Fapp%2Fui%2FIsTopLevelGraphInHierarchy.kt#L13-L28 where I use the result of this to know which of the bottom bar tabs should look "selected".
c
Will look. thank you. been a crazy week at work 🙃
😵 1
f
if you click the tab that you're already on/selected, that it reloads that tabs/clears the stack
Isn't that normal/expected behavior?
Huh, I guess it's just scroll that should be reset? But I swear I saw it in some documentation that you should reset stack.
c
I was able to get this mostly working. The only thing that doesn't work is that once you click away to a different tab, then that tab doesn't load the first time. and you have to click it again 🤷 Someone wrote a custom wrapper around navigation-compose on this current project, so I will likely try to tear that out (it provides no value) and then try again.
s
isn't that normal/expected behavior?
Not really, if you're doing singleTop, which I think you do want to do in the nav tabs if you click it again it just does nothing actually.
☝️ 1