Search code examples
androidandroid-motionlayout

How to use MotionLayout like TransitionManager?


Tutoiral I see with MotionLayout have things in common and that is it focused on either an onClick or onSwipe to trigger MotionLayout Transition. I was wondering how to Transition from something like State A to State B with other trigger like instead of onClick it would trigger onNavDestinationChanged something like:

navController.addNavigationChangeListener { motionLayout.transtionToAnotherState() }

Something similar to TransitionManager where if I want to go from Scene A to Scene B I just do:

TransitionManager.beginDelayedTransition(rootLayout)
// Do someLayout changes

1) Is something similar doable with MotionLayout? 2) If yes can anyone guide me?

Thank you very much.


Solution

  • So apparently, it was really easy to do this and for anyone else who needs to know simply call:

    motionLayout.transitionToState(constraintSetId)