https://kotlinlang.org logo
Title
a

Alexander Maryanovsky

05/28/2022, 9:56 AM
How do I specify “no-animation”
transitionSpec
in
AnimatedContent
. Before you ask why I would need that, the animation I’m doing is conditional - in one case I want slideInFromRight with slideOutToLeft, in another case I want slideInFromLeft with slideOutToRight, and in a third case I just want the content to be replaced with no animation. The transitionSpec is defined by a separate function, so in the third case I want it to return “no-animation”. Is there a built-in function for that, or do I need to do something silly like a fadeIn/Out with 0 duration tween?
a

Albert Chang

05/28/2022, 12:46 PM
EnterTransition.None with ExitTransition.None
👍 3
d

Doris Liu

05/28/2022, 5:49 PM
Seems like it would be useful to mention that in the docs here as an option: https://developer.android.com/reference/kotlin/androidx/compose/animation/EnterTransition Please feel free to file a bug on updating the docs. 🙂
z

Zoltan Demant

05/29/2022, 6:20 AM
Whenever the target state changes, you might see additional recompositions even if you specify no animation (as mentioned above). Just something to keep in mind, I had a lot of trouble with debugging this so I thought I'd mention it! Best solution I've found is simply wrapping the relevant parts of the state in another class, this solves the no animation portion of it as well.