I have 3 tabs A, B, C in BottomNavigationView
and each has a nav graph.
I can do what I want perfectly in navigation 2.3.3 by a complicated navigation extension, just like the old architecture-components-samples. This sample is now upgrade to 2.4.0. which use less code.
What I want is:
Step: Graph A' s start destination fragment A1 navigate to A2.
Step: Tap tab B or C.
- B or C' s
navigateUp
action is back to A. (works fine) - When back to tab A, it shows A2. (in 2.4.0' s sample, shows A1)
- The BottomNavigationView' s ItemReselected action is
popBackStack
to current graph' sstartDestination
. (how to setsetOnItemReselectedListener
if thenavController
does not change?) - The three
startDestination
fragment A1, B1, C1 are top level destinations, so B1 and C1' s toolbar do not show back icon. (works fine, because the sample set a set of these 3 fragments instead ofnavController.graph
toAppBarConfiguration
)
2.4.0 said it support Multiple back stacks. What does it mean? Can I make my BottomNavigationView in 2.4.0?
Here is how I do "3. The BottomNavigationView' s ItemReselected action..." in 2.3.3:
private fun BottomNavigationView.setupItemReselected(
graphIdToTagMap: SparseArray<String>,
fragmentManager: FragmentManager
) {
setOnNavigationItemReselectedListener { item ->
... // get the item' s navController
navController.popBackStack(
navController.graph.startDestination, false
)
}
}
What I do in 2.4.0: just copy the sample code.