title: Navigating multi-module App with nested fragments
body: <p>I'm trying to implement a multi-module app structure with navigation between modules. The challenge Im having is doing this with a structure that contains nested fragment containers.</p>
  <p>Background:
  <a href="https://i.stack.imgur.com/O5TqB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O5TqB.png" alt="Module Structure" /></a>
  The design uses a single activity.The main activity layout comprises of an actionbar and fragment container. This container is used to host the different 'main' module fragment.</p>
  <pre><code>&lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/frg_main_container&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          app:defaultNavHost=&quot;true&quot;
          app:navGraph=&quot;@navigation/nav_graph_app&quot; /&gt;
  </code></pre>
  <p>Each module has a single 'parent' like fragment with a fragment container and bottomNavbar. This fragment container is used to host the detail fragments of each module and is the home fragment in the modules nav graph.</p>
  <pre><code>&lt;androidx.fragment.app.FragmentContainerView
          android:id=&quot;@+id/frg_home_contacts_container&quot;
          android:name=&quot;androidx.navigation.fragment.NavHostFragment&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          app:defaultNavHost=&quot;false&quot;
          app:navGraph=&quot;@navigation/nav_graph_contacts&quot; /&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/APwUu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/APwUu.png" alt="Layout Example" /></a>
  The app module contains a top level nav graph linking each modules parent fragment (these are not nested graphs or the modules nav graph, as the module's detail fragments are not used in the apps container view).
  Each module has a bottom level nav graph linking the detail fragments of that module. This is used in conjunction with the bottomNavbar to navigate between module fragments [works].</p>
  <p>For example, the goal is to have a button, on the home screen of the home module, that when clicked moves the user to a screen within another module, such as the contacts list screen in the Contact module.</p>
  <p>There are two actions:</p>
  <ol>
  <li>Navigate the Main container to the new module home fragment. (managed by the navContorller in the App)</li>
  <li>Navigate the module container to the new details fragment. (managed by the navController in the module)</li>
  </ol>
  <p>Presently I'm working with interfaces and trying to inject (hilt) into the main activity to achieve no.1. However, I'm always running into issues that the home module cant see the apps nav_graph or there are missing dependencies (i.e. it wants the dependency to get the nav_graph). I believe a simlar process should work between fragments for no.2</p>
  <p>Concept reference: <a href="https://itnext.io/multi-module-navigation-in-android-63cb9924ffbd" rel="nofollow noreferrer">https://itnext.io/multi-module-navigation-in-android-63cb9924ffbd</a></p>
  <p>This following code is functional when R.id.nav_graph_home but for links outside the module i.e. R.id.nav_graph_contacts it isnt.</p>
  <pre><code>interface HomeModuleNavInterface {
      fun gotoContacts(navController: NavController)
  }
  </code></pre>
  <pre><code>class HomeModuleNavContract : HomeModuleNavInterface {
      override fun gotoContacts(navController: NavController) {
          navController.navigate(R.id.nav_graph_contacts)
      }
  }
  </code></pre>
  <pre><code>@Module
  @InstallIn(SingletonComponent::class)
  class HomeNavigator  {
     @Singleton
     @Provides
     fun providesHomeNavInterface(): HomeModuleNavContract = HomeModuleNavContract()
  }
  </code></pre>
  <pre><code>class FragmentHomeNavigation : Fragment(R.layout.fragment_home_navigation) {
  ...
     @Inject
     lateinit var homeModuleNavigation: HomeModuleNavContract
  ...
     btnContact.setOnCLickListener{
        homeModuleNavigation.gotoContacts(findNavController())
     }
  }
  </code></pre>
  <p>Any suggestions or direction is appreciated. Thanks.</p>