Fixed
Status Update
Comments
so...@gmail.com <so...@gmail.com> #2
Yes, we need better control over Nested NavHost. Also, nested NavHostFragment is recreating and it can't hold it's last state.
Suppose:
- Main Activity has a NavHostFragment and it is set up with bottomNavigationView
- Each Fragment has multiple fragments.
Then what's the proper way of handling these types of situations?
Suppose:
- Main Activity has a NavHostFragment and it is set up with bottomNavigationView
- Each Fragment has multiple fragments.
Then what's the proper way of handling these types of situations?
il...@google.com <il...@google.com> #3
Re #2 - supporting multiple back stacks for cases like bottom nav is being tracked in https://issuetracker.google.com/issues/80029773 - please star that issue for updates.
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #4
This allows you to solve your problem by:
- Adding your Toolbar to Fragment B
- Call:
toolbar.setupWithNavController(innerNavController, AppBarConfiguration(setOf()) {
findNavController().navigateUp()
})
By using an empty set of top level destinations, the Up button will always appear. When the innerNavController is on its own start destination, the fallback will be called, allowing you to pass the navigateUp() call to the outer NavController. The reason the Toolbar in your FragmentB is the right place to do this is so that it has a reference to both your inner NavController and a reference to your outer NavController.
This will be available in 1.0.0-alpha09.
See also the related issue for activities:
ka...@gmail.com <ka...@gmail.com> #5
Re #4 - In my use case I have single activity and single (global) toolbar setup with it. So it doesn't make sense for my application to add additional toolbar for my nested fragments. I just want to work them with existing activity's toolbar. I would like to use nested fragments to use ViewModels shared with parentFragment. Can you consider supporting my use case?
Description
Version used: 1.0.0-alpha08
Devices/Android versions reproduced on:
Assuming:
- Main Activity has a NavHostFragment, which navigates between Fragment A & Fragment B
- Main activity handles going back with onSupportNavigateUp
- Fragment B has it's own NavHostFragment, which navigated between InnerFragmentB1 & InnerFragmentB2
- Parent NavHostFragment navigates from A -> B (which starts with B1)
- Sub NavHostFragment navigates from B1 -> B2
- Press up: Sub NavHostFragment returns to B1
- Press up: Parent NavHostFragment returns from B to A
What's the proper way of handling these types of situations where we'd like the back button to handle backing out of Inner Fragments first and then Outer Fragments after?
Details here:
Sample Code: