I'm using the SupportFragmentManager to navigate between different fragments (let's call them A, B, C, D for simplicity). The navigation itself works correctly. The animation works only correctly considering the entering fragments. My code is basically the same for navigating between all fragments:
activity?.supportFragmentManager?.commit {
setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
replace(R.id.myNavHostFragment, BFragment())
}
The navigation is only linear, so I navigate from A -> B, B -> C, and C -> D.
The problem is: only the animation of A -> B works correctly. For all others, during the animation, the wrong 'old' (exit) fragment A is shown in background, while the new one slides in.
So this means:
- animation A -> B works fine.
- animation B -> C does not work correctly. Fragment C slides in correctly. But while the animation plays, not Fragment B is shown in the background. Instead, somehow Fragment A is shown again.
- the same for C -> D. Fragment A is shown, while C should be seen during the animation.
As you can see, I do not add fragments to the backstack. I really can't figure out why Fragment A is always shown during the animation, even if it should be a different one.
In a nutshell: the animation shows always the first fragment (A) as exit fragment, while it should be the previous one instead.