I have 2 modules in my app (app module and splash module). I'm trying to leverage the <include>
tag in an effort to make the FTUE self contained and not a part of the main nav graph as the docs suggest.
My main nav graph is defined in the app module and looks like this:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/home">
<include app:graph="@navigation/splash_nav_graph"/>
<fragment
android:id="@+id/home"
android:name="com.example.Home"
android:label="fragment_home"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_home_to_splash_nav_graph"
app:destination="@id/splash_nav_graph"/>
</fragment>
</navigation>
splash_nav_graph
is defined in the splash module (app module obviously has a dependency on it):
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash_nav_graph"
app:startDestination="@id/splashFragment">
<fragment
android:id="@+id/splashFragment"
android:name="com.example.splash.SplashFragment"
android:label="example"
tools:layout="@layout/fragment_splash">
<action
android:id="@+id/action_splashFragment_to_signInFragment"
app:destination="@id/signInFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"/>
</fragment>
<fragment
android:id="@+id/signInFragment"
android:name="com.example.splash.signin.ui.SignInFragment"
android:label="fragment_sign_in"
tools:layout="@layout/fragment_sign_in">
<action
android:id="@+id/action_signInFragment_pop"
app:popUpTo="@id/splash_nav_graph"/>
</fragment>
</navigation>
Finally, here's the layout where the main nav graph is tied to the NavHostFragment back in the app module:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph"
/>
</LinearLayout>
This will run and navigating through the flow (home-> splash -> sign in -> home) yields the expected behavior. However, the following lint error is present at the top of splash_nav_graph
:
This navigation graph is not referenced from any layout files (expected to find it in at least one layout file with a NavHostFragment with app:navGraph="@navigation/splash_nav_graph" attribute). more... (⌘F1)
What the lint error says is true (I don't have another NavHostFragment
that has app:navGraph="@navigation/splash_nav_graph"
) , however:
NavHostFragment
because I only have a single activity in the app module.Do I actually need to add another NavHostFragment
somewhere or is this a bug in lint?
Looks like this will be fixed in AS 3.6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With