Skip to content

Navigate between destinations in separate nav graphs programmatically #2

Description

@premacck

Thanks for this amazing sample. I was working on a POC of having navigation components in an existing app with millions of active users, and I found your sample to be quite informative.

However, I had a requirement which I was trying to accomplish on top of your sample.
For the sake of simplicity, I'm calling the root pages (all the containerFragments defined in main_navigation) as L0 pages, and all the pages that open inside the heirarchy as non-L0 pages.

So here's what I'm trying to accomplish:

Navigation from one L0 / Non-L0 page to another L0 page.

Let's say I want to go from tradingFragment to profileFragment.
If I directly put the destination id R.id.profileFragment in the findRootNavigator.navigate(), then the app crashes with the error:

Navigation action/destination com.hakvardanyan.navigationsample:id/profileFragment cannot be found from the current destination Destination(com.hakvardanyan.navigationsample:id/mainFragment) label=MainFragment class=com.hakvardanyan.navigationsample.main.MainFragment

The same happens when I try to navigate to R.id.profileContainerFragment:

Navigation action/destination com.hakvardanyan.navigationsample:id/profileContainerFragment cannot be found from the current destination Destination(com.hakvardanyan.navigationsample:id/mainFragment) label=MainFragment class=com.hakvardanyan.navigationsample.main.MainFragment

I tried <includeing the nav graph of TradingFragment (home_navigation), ProfileFragment (profile_navigation), and even ProfileContainerFragment (main_navigation) in that of MainFragment (app_navigation). But the same issue is still there.

Do I need to create the destination programmatically and add it in the same nav graph every time I need to navigate to an L0 page in another tab? Do you think there could be a scalable way to achieve this through non-XML ways?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions