NavigationGraph animation not working issue Android

Viewed 4940

I am using this code with NavigationGraph Fragment

 <fragment
        android:id="@+id/editProfileFragment"
        android:name="com.uvm.ui.editprofile.EditProfileFragment"
        android:label="FragmentFour"
        tools:layout="@layout/edit_fragment_profile" >
        <action
            app:popExitAnim="@anim/nav_default_pop_exit_anim"
            app:exitAnim="@anim/nav_default_exit_anim"
            app:enterAnim="@anim/nav_default_enter_anim"
            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
            android:id="@+id/action_editProfileFragment_to_profileFragment"
            app:destination="@id/profileFragment"  />
    </fragment>

and then

navController.navigate(R.id.editProfileFragment);

using for navigation of fragment. its working fine and fragment replace as well but enterAnim, exitAnim etc properties not working. fragment replacing without animation. how could i resolved this? one more query is that is NavigationGraph replace fragment or add fragment? and how could i get total count of stack?

2 Answers

As i can see you are using RID of Fragment to navigate while to apply transaction animation you are giving all the animation's in the action's.

<action
            app:popExitAnim="@anim/nav_default_pop_exit_anim"
            app:exitAnim="@anim/nav_default_exit_anim"
            app:enterAnim="@anim/nav_default_enter_anim"
            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
            android:id="@+id/action_editProfileFragment_to_profileFragment"
            app:destination="@id/profileFragment"  />

So, to apply animation's use RID of action to navigate.

navController.navigate(R.id.action_editProfileFragment_to_profileFragment);

By default Navigation Component use Replace Fragment Transaction's.

And how could i get total count of stack?

currently i have not found a way to get this count what is your use case her can you explain?

This should work.

implementation "androidx.fragment:fragment-ktx:1.5.0"

Add :
 app:enterAnim="@anim/slide_in_right"
 app:exitAnim="@anim/slide_out_left"
 app:popEnterAnim="@anim/slide_in_left"
 app:popExitAnim="@anim/slide_out_right"

    

Anim link : 
https://stackoverflow.com/questions/18147840/slide-right-to-left-android-animations
Related