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

Archie

03/02/2021, 1:28 PM
Hi Guys, how do you check whether NavController have something in the backstack?
i

Ian Lake

03/02/2021, 3:03 PM
This isn't something you should be doing. What are you trying to do?
a

Archie

03/02/2021, 3:19 PM
Hi @Ian Lake, I was trying to hide or show a back button on the AppBar if there is an item in the backstack. Do you have any recommendation?
b

Bryan Herbst

03/02/2021, 3:33 PM
It sounds like you are trying to have a global AppBar that is shared across different screens, is that correct? IMO, each individual screen should have its own AppBar. The content in the app bar (the title, actions, etc.) is going to be screen-specific so each individual screen should own its app bar. You can make a shared Composable to provide consistent styling. Then you also don’t need to worry about conditionally showing a back button if there are items on the back stack- for any given instance of a screen the back button should always be in the same state.
i

Ian Lake

03/02/2021, 3:39 PM
Here's the previous thread on this topic with how you should be doing it: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1605978856011300?thread_ts=1605978856.011300&cid=CJLTWPH7S
a

Archie

03/02/2021, 4:10 PM
@Bryan Herbst, I agree but you'll be pretty limited on how you present your screen such as how you define animation as your screen goes in and out. Unless you could fake all of those with animation? but currently I believe faking it with animation isn't possible.
b

Bryan Herbst

03/02/2021, 4:11 PM
Haven’t played around with transition animations in Compose much yet, but in the View framework you could just exclude the Toolbar from the transition animations and it worked as expected. I’m assuming Compose will offer similar functionality
a

Archie

03/02/2021, 4:19 PM
Honestly I do understand your point. Having a shared Ui brings its own problem.. I created this sample project to demonstrate my issues: https://github.com/qrezet/SharedUiSample/blob/master/app/src/main/java/com/sample/sampleapp/MainActivity.kt Being able to define the SharedUi for each screen solves almost all of the issue I stated there. But I also do not want my AppBar to go in and out everytime I navigate from screen to screen.
👀 1
j

Jason Ankers

03/02/2021, 6:27 PM
On this topic, what would be the best way to check the “closest” parent graph to the destination you’re currently on? Say I have a bottom tab bar, each tab has their own nested graph. For any given destination in any of the graphs, how could you determine what tab to show as selected?
2 Views