Search code examples
androidkotlinandroid-transitions

Fragment transition using androidx.transition.Slide seems to reorder view z index


When using Slide transition to enter/exit a Frament, it seems views are reordered when exiting animation is played. There no much code to talk about just this simple line to activate the transition from a Fragment, all views are inside a ConstraintLayout so not much there neither:

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        enterTransition = Slide().setDuration(1000)
}

Is there anything to manage this zindex reordering?

Here are some captures and a projet example :

enter image description here enter image description here

From first capture everything fine all inputs are in front of image. From second capture you ca see second input is behind image, this is totally random sometime more inputs are behind image. You can grab an example project from this repository, click "GO PROFILE" button and then click back. Transition is implemented in this file net.samystudio.beaver.ui.main.authenticator.AuthenticatorFragment

Thx for your help!


Solution

  • Just found out that ordering transition from a TransitionSet influence depth so workaround is to set Slide transition for image before other elements like this :

    TransitionSet()
       .addTransition(
          Slide()
             .addTarget(R.id.image)
       )
       .addTransition(
          Slide()
             .excludeTarget(R.id.image, true)
       )
       .setDuration(5000)
    

    I'm not sure this is intended so.