Android Navigation Component: PopEnterAnim not working

Viewed 1185

When navigating through fragments all the animations are working properly except for popenteranim, which does not work at all, and there's no obvious reason why. For example, LoginFragment to Register1AccountFragment (all on the same activity):

Nav graph:

<action
            android:id="@+id/action_loginFragment_to_register1AccountFragment"
            app:destination="@id/nav_register"
            app:enterAnim="@anim/slide_in_from_right"
            app:exitAnim="@anim/slide_out_to_left"
            app:popEnterAnim="@anim/slide_in_from_left"
            app:popExitAnim="@anim/slide_out_to_right" />

Note the destination is a new nav graph, where the startDestination is register1AccountFragment. I did this simply to split the register fragments from the rest of the navigation, and there is only one activity in the app.

LoginFragment

registerButton.setOnClickListener(v -> {
            view.clearFocus();
            NavDirections action = LoginFragmentDirections.actionLoginFragmentToRegister1AccountFragment();
            Navigation.findNavController(v).navigate(action);
        });

anim/slide_in_from_left

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXDelta="-100%" android:toXDelta="0%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="300" />

So all the other animations work, including popExitAnim, which is just the opposite of slide_in_from_left, i.e.

anim/slide_out_to_right

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:fromXDelta="0%" android:toXDelta="100%"
    android:fromYDelta="0%" android:toYDelta="0%"
    android:duration="300" />

This is the same on all fragments, regardless of their popEnterAnim. I have tried multiple different animations too, like popEnterAnim = fade from 0 alpha to 1 alpha.

I have also tried navigating using the action's ID instead of NavDirections, which still does not show the animation;

LoginFragment

registerButton.setOnClickListener(v -> {
            view.clearFocus();
            Navigation.findNavController(v).navigate(R.id.action_loginFragment_to_register1AccountFragment);
        });
2 Answers

Apparently there is a bug in androidx.fragment:fragment-ktx:1.3.2 that makes some animations stop working If you have that dependency change it to version 1.3.1. That error has been reported and will be fixed in version 1.3.3

I am facing with the exact same problem in Kotlin.

All animation works but only PopEnterAnim is not working.

My anim files are totally correct. My navigation dependency is:

implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'

implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

I don't have dependency androidx.fragment:fragment-ktx

I am using Safe Args for access the nav actions. There is no problem.

Related