6

I would like to know what is the best practice of using Navigation Component + BottomNavigationView + NavigationDrawer.

I have tried google's advanced sample for Navigation component. It worked very well for multiple back stack modules. Because it has a workaround extension. When using this approach, each bottom tab has its own graph and the graphs change as you select one of the tabs.

But when NavigationView is integrated, it needs to know the navigation graph in advance. But in advanced sample the navGraph attribute is not used, graphs added programmatically for bottomNavigation.

So how do we manage graphs when both Bottom Navigation View and Navigation Drawer View are used together?

wang willway
  • 415
  • 1
  • 3
  • 16
Azamat Mahkamov
  • 912
  • 14
  • 18
  • Have you solved it? I am facing the same dilemma. Here comes a solution that uses FragmentTransition: https://github.com/mreek/NavigationDrawer – Aliton Oliveira Mar 25 '20 at 01:15
  • I did some workaround. But my approach still lacks. 1.I Used google's bottom navigation extension to keep the back stack. 2.But to keep the link for Navigation Drawer, added the drawers destinations Fragments to each bottom Navigation graphs. Overall It seemed to be good. But I believe, there is a better approach)) – Azamat Mahkamov Apr 05 '20 at 20:08

1 Answers1

0

After experimenting with different approaches, I have come to the conclusion, when using both BottomNavigationView and NavigationDrawer, It's best practice to keep your navigation graph single. When having multiple navigation graphs, it will be hard to manage logical connections between screen.

To have a control over the toolbar and bottomNavigationView's visibility, I use addOnDestinationChangedListener

navController.addOnDestinationChangedListener { controller, destination, arguments ->
        when(destination.id){ //check with destination ids,  }

it may not be best practice. If you have any better ways, please share it

Azamat Mahkamov
  • 912
  • 14
  • 18