State of Compose 2023 results are in! Click here to learn more

← Back to Compose Animation

Transition

Component
in
Compose Animation
. Since 0.1.0-dev15

Overview

Code Examples

Video

Deprecated: Transition has been deprecated. Please use transition instead.

Transition composable creates a state-based transition using the animation configuration defined in TransitionDefinition. This can be especially useful when animating multiple values from a predefined set of values to another. For animating a single value, consider using animatedValue, animatedFloat, animatedColor or the more light-weight animate APIs.

Transition starts a new animation or changes the on-going animation when the toState parameter is changed to a different value. It dutifully ensures that the animation will head towards new toState regardless of what state (or in-between state) it’s currently in: If the transition is not currently animating, having a new toState value will start a new animation, otherwise the in-flight animation will correct course and animate towards the new toState based on the interruption handling logic.

Transition takes a transition definition, a target state and child composables. These child composables will be receiving a TransitionState object as an argument, which captures all the current values of the animation. Child composables should read the animation values from the TransitionState object, and apply the value wherever necessary.

Overloads

Transition

@Deprecated(
    "Transition has been renamed to transition, which returns a TransitionState instead " +
        "of passing it to children",
    replaceWith = ReplaceWith(
        "transition(definition, toState, clock, initState, null, onStateChangeFinished)",
        "androidx.compose.animation.transition"
    )
)
@Composable
fun <T> Transition(
    definition: TransitionDefinition<T>,
    toState: T,
    clock: AnimationClockObservable = AmbientAnimationClock.current,
    initState: T = toState,
    onStateChangeFinished: ((T) -> Unit)? = null,
    children: @Composable (state: TransitionState) -> Unit
)

Parameters

NameDescription
definitionTransition definition that defines states and transitions
toStateNew state to transition to
clockOptional animation clock that pulses animations when time changes. By default, the system uses a choreographer based clock read from the AnimationClockAmbient. A custom implementation of the AnimationClockObservable (such as a androidx.compose.animation.core.ManualAnimationClock) can be supplied here if there’s a need to manually control the clock (for example in tests).
initStateOptional initial state for the transition. When undefined, the initial state will be set to the first toState seen in the transition.
onStateChangeFinishedAn optional listener to get notified when state change animation has completed
childrenThe children composables that will be animated @see TransitionDefinition