https://kotlinlang.org logo
#compose-android
Title
# compose-android
c

Colton Idle

03/26/2024, 12:36 PM
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

Stylianos Gakis

03/26/2024, 2:47 PM
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

Colton Idle

03/26/2024, 5:34 PM
I'll try that when I'm back at my machine. Thank you!
s

Stylianos Gakis

03/26/2024, 6:19 PM
Lmk how it goes 😊
c

Colton Idle

03/27/2024, 10:53 AM
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

Stylianos Gakis

03/27/2024, 11:36 AM
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

Colton Idle

03/27/2024, 5:17 PM
Will look. thank you. been a crazy week at work 🙃
😵 1
f

Filip Wiesner

03/28/2024, 2:56 PM
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

Colton Idle

03/28/2024, 3:11 PM
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

Stylianos Gakis

03/28/2024, 5:20 PM
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
2 Views