Hi Guys, how do you check whether NavController ha...
# compose
a
Hi Guys, how do you check whether NavController have something in the backstack?
i
This isn't something you should be doing. What are you trying to do?
a
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
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
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
@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
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
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
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?