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.transitionDefinition

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
            duration = 75
        }
        Alpha using keyframes {
            duration = 375
            0f at 0 // ms  // Optional
            0.4f at 75 // ms
            0.4f at 225 // ms
            0f at 375 // ms  // Optional
        }
        Background using physics {
            dampingRatio = 1.0f
        }
        interruptionHandling = InterruptionHandling.UNINTERRUPTIBLE
    }
}

Summary

Public methods
KeyframesBuilder<T>
keyframes(init: KeyframesBuilder<T>.() -> Unit)

Creates a KeyframesSpec animation, initialized with init

AnimationBuilder<T>
physics(init: PhysicsBuilder<T>.() -> Unit)

Creates a FloatSpringSpec animation, initialized with init

AnimationBuilder<T>
repeatable(init: RepeatableBuilder<T>.() -> Unit)

Creates a RepeatableSpec animation, initialized with init

AnimationBuilder<T>

Creates a Snap animation for immediately switching the animating value to the end value.

DurationBasedAnimationBuilder<T>
tween(init: TweenBuilder<T>.() -> Unit)

Creates a FloatTweenSpec animation, initialized with init

infix Unit
PropKey<T, V>.using(builder: AnimationBuilder<T>)

Associates a property with a AnimationBuilder

Properties
InterruptionHandling

The interruption handling mechanism.

S?

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

Public methods

keyframes

fun <T> keyframes(init: KeyframesBuilder<T>.() -> Unit): KeyframesBuilder<T>

Creates a KeyframesSpec animation, initialized with init

Parameters
init: KeyframesBuilder<T>.() -> Unit Initialization function for the KeyframesSpec animation

physics

fun <T> physics(init: PhysicsBuilder<T>.() -> Unit): AnimationBuilder<T>

Creates a FloatSpringSpec animation, initialized with init

Parameters
init: PhysicsBuilder<T>.() -> Unit Initialization function for the FloatSpringSpec animation

repeatable

fun <T> repeatable(init: RepeatableBuilder<T>.() -> Unit): AnimationBuilder<T>

Creates a RepeatableSpec animation, initialized with init

Parameters
init: RepeatableBuilder<T>.() -> Unit Initialization function for the RepeatableSpec animation

snap

fun <T> snap(): AnimationBuilder<T>

Creates a Snap animation for immediately switching the animating value to the end value.

tween

fun <T> tween(init: TweenBuilder<T>.() -> Unit): DurationBasedAnimationBuilder<T>

Creates a FloatTweenSpec animation, initialized with init

Parameters
init: TweenBuilder<T>.() -> Unit Initialization function for the FloatTweenSpec animation

using

infix fun <T, V : AnimationVector> PropKey<T, V>.using(builder: AnimationBuilder<T>): Unit

Associates a property with a AnimationBuilder

Parameters
builder: AnimationBuilder<T> : AnimationBuilder 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.