1

I'm new to Android Navigation Component and want to understand how can I use it in my relatively simple scenario where I want to have a single activity approach. I obviously want the system to handle the back stack, also for bottom navigation.

What I need is 2 very simple cases:

1. Mixed destinations

Some of the destinations in my navigation graph have bottom navigation, and some not. Imagine that I have a login flow without a bottom navigation and then move to the "real app" where I have bottom navigation. Google says put bottom navigation, drawer, action bar outside of navigation graph, which means they are shown for all destinations.

Is this supported by Navigation Component? Without dirty hacks of hiding/showing bottom nav.

2. Full screen popups

Another question - is multiple navhosts supported? Imagine I have a UI with bottom navigation and action bar, which are outside of the nav host area. But then I need to show a full screen popup, like a dialog or a resource selection screen, which will also go over the bottom nav and action bar.

Can I do this as a destination in navigation graph?


For both questions any conceptually supported solution is good for me, including switching graphs/hosts during navigation.

frangulyan
  • 3,580
  • 4
  • 36
  • 64

1 Answers1

3

As per the Listen for navigation events documentation:

As an example, you might have common UI elements that you intend to show in some areas of your app while hiding them in others. Using your own OnDestinationChangedListener, you can selectively show or hide these UI elements based on the target destination

So yes, you can selectively show or hide elements of your activity's UI when you move to certain destinations, such as your login screen.

As per the Create a destination from a DialogFragment documentation:

If you have an existing DialogFragment, you can use the <dialog> element to add the dialog to your navigation graph

This also supports other types of DialogFragment such as a BottomSheetDialogFragment.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Thanks Ian, this is embarrassing, since I was reading all those docs under "Navigation component" section several hours ago, I guess that was too much info for me at once and I missed it. And of course want to mention the amazing times we are living in, an hour ago I was watching your talk about single activity approach and now you answer my question. – frangulyan Feb 08 '20 at 23:29
  • 1
    Best of luck! If you run into any issues or something missing from the documentation (there is a lot of it!), please feel free to [file an issue against Navigation](https://issuetracker.google.com/issues/new?component=409828). – ianhanniballake Feb 08 '20 at 23:59