Wondering if there is a way to create a reusable set of the animations for the nav graph. Something like a style that contains all of the animation properties rather than repeating the same ones over and over.
What I have:
<action
android:id="@+id/toFragmentA"
app:destination="@id/fragmentA"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/toFragmentB"
app:destination="@id/fragmentB"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/toFragmentC"
app:destination="@id/fragmentC"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/toFragmentD"
app:destination="@id/fragmentD"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/toFragmentE"
app:destination="@id/fragmentE"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
What I would like to have
<action
android:id="@+id/toFragmentA"
app:destination="@id/fragmentA"
app:anim="@anim/slideInOut" />
<action
android:id="@+id/toFragmentB"
app:destination="@id/fragmentB"
app:anim="@anim/slideInOut" />
<action
android:id="@+id/toFragmentC"
app:destination="@id/fragmentC"
app:anim="@anim/slideInOut" />
<action
android:id="@+id/toFragmentD"
app:destination="@id/fragmentD"
app:anim="@anim/slideInOut" />
<action
android:id="@+id/toFragmentE"
app:destination="@id/fragmentE"
app:anim="@anim/slideInOut" />
With a large nav graph reducing this repeated animation setup would make it much more manageable.
One way to do this will be to change the default nav animations and set the animations you want as the default navigations for your fragments. For that purpose, you will have to update the nav options Process:
to:
Now, Create your own nav host fragment to be used instead of the original nav host.
In here, just change the anim value in navoptions and you are good to go