Home > Net >  How to achieve different animation while navigating to the same fragment with BottomNavigationView a
How to achieve different animation while navigating to the same fragment with BottomNavigationView a

Time:12-06

I have the below screens:

Bottom Navigation stack:       [A]               [B]
Root fragments:           [HomeFragment], [SettingsFragment]
Nested fragments:                         [ProfileFragment]

I want to achieve different animation while navigating to ProfileFragment:

  1. From SettingsFragment
  2. From BottomNavigationView going from ProfileFragment to [A] (HomeFragment) and then back to [B] (ProfileFragment)

I am using navigation component alongside bottomNavigationView which supports multiple backstack. While navigating to ProfileFragment from SettingsFragment, I am using the below transition animations in the navigation graph:

app:enterAnim="@anim/slide_right"
app:exitAnim="@anim/slide_left"

Everything is working fine, but I don't want to use slide_right animation when the user goes to HomeFragment and then goes back to the ProfileFragment via bottomNavigationView.

I am setting up the navController like so:

bottomNavigationView.setupWithNavController(navController)

Is there any way to have a different animation (e.g fade in, fade out) while navigating to ProfileFragment via bottomNavigationView but use my custom slide_right animation while navigating from SettingsFragment?

CodePudding user response:

After a lot of trial and error, downgrading navigation component version from 2.5.3 to 2.5.0 did the trick for me. Without any further change, it started to work as expected.

  • Related