Google is committed to advancing racial equity for Black communities. See how.

TransitionSpec

class TransitionSpec<S>
kotlin.Any
   ↳ androidx.animation.TransitionSpec

Static specification for the transition from one state to another.

Each property involved in the states that the transition is from and to can have an animation associated with it. When such an animation is defined, the animation system will be using it instead of the default FloatSpringSpec animation to animate the value change for that property.

import androidx.animation.FloatPropKey
import androidx.animation.keyframes
import androidx.animation.spring
import androidx.animation.transitionDefinition
import androidx.animation.tween

val Radius = FloatPropKey()
val Alpha = FloatPropKey()
val Background = FloatPropKey()

transitionDefinition {
    // This defines animations for 3 properties: Radius, Alpha, and Background.
    transition(fromState = ButtonState.Released, toState = ButtonState.Pressed) {
        Radius using tween(
            easing = LinearEasing,
            durationMillis = 75
        )
        Alpha using keyframes {
            durationMillis = 375
            0f at 0 // ms  // Optional
            0.4f at 75 // ms
            0.4f at 225 // ms
            0f at 375 // ms  // Optional
        }
        Background using spring(
            dampingRatio = 1.0f
        )
        interruptionHandling = InterruptionHandling.UNINTERRUPTIBLE
    }
}

Summary

Public methods
infix Unit
PropKey<T, V>.using(animationSpec: AnimationSpec<T>)

Associates a property with an AnimationSpec

Properties
InterruptionHandling

The interruption handling mechanism.

S?

Optional state where should we start switching after this transition finishing.

Public methods

using

infix fun <T, V : AnimationVector> PropKey<T, V>.using(animationSpec: AnimationSpec<T>): Unit

Associates a property with an AnimationSpec

Parameters
animationSpec: AnimationSpec<T> : AnimationSpec for animating this property value changes

Properties

interruptionHandling

var interruptionHandling: InterruptionHandling

The interruption handling mechanism. The default interruption handling is InterruptionHandling.PHYSICS. Meaning both value and velocity of the property will be preserved as the target state (and therefore target animation value) changes. InterruptionHandling.TWEEN, which only ensures the continuity of current animation value. InterruptionHandling.UNINTERRUPTIBLE defines a scenario where an animation is so important that it cannot be interrupted, so the new state request has to be queued. InterruptionHandling.SNAP_TO_END can be used for cases where higher priority events (such as user gesture) come in and the on-going animation needs to finish immediately to give way to the user events.

nextState

var nextState: S?

Optional state where should we start switching after this transition finishing.