Thursday, 13 June 2019

Can I use multiple NavHostFragments in Navigation Component?

Please look at the flowchart I made if you have difficulty in understanding the following paragraph.

I'm currently making a notes app with 3 top level destinations. One of the top-level destinations(NotesList) displays a list of notes created by the user. NotesList has a filter button which brings up a bottom modal sheet with FilterMenu destination. FilterMenu has a search button, which on clicking, replaces the contents of the sheet with a Search destination and a button named tags which on clicking, replaces the contents of the sheet with a fragment containing list of the tags associated with all the notes(TagList destination).

enter image description here

Everything in blue is a top level destination. Everything in purple is present in the modal sheet.

The FilterMenu, Search and the TagList are displayed in a modal sheet. Which means that the NotesList contains these fragments and is not replaced by them. They exist in a region of screen smaller than the NotesList. If I use navigation, the fragments will replace each other.

Can I use two NavHosts? One for the top-level destinations and one for the stuff in the modal sheet? If so, how would I implement it? If not, what's the recommended thing to do in this case?



from Can I use multiple NavHostFragments in Navigation Component?

No comments:

Post a Comment