TransitionDefinition

class TransitionDefinition<T>
kotlin.Any
   ↳ androidx.animation.TransitionDefinition

Static definitions of states and transitions.

Summary

Public constructors

Static definitions of states and transitions.

Public methods

TransitionState
getStateFor(name: T)

Returns a state holder for the specific state name.

Unit
snapTransition(vararg fromToPairs: Pair<T?, T?>, nextState: T? = null)

With this transition definition we are saying that every time we reach the state 'from' we should immediately snap to 'to' state instead.

Unit
state(name: T, init: MutableTransitionState.() -> Unit)

Defines all the properties and their values associated with the state with the name: name The first state defined in the transition definition will be the default state, whose property values will be used as its initial values to createAnimation from.

Unit
transition(fromState: T? = null, toState: T? = null, init: TransitionSpec<T>.() -> Unit)

Defines a transition from state fromState to toState.

Unit
transition(vararg fromToPairs: Pair<T?, T?>, init: TransitionSpec<T>.() -> Unit)

Defines a transition from state first value to the second value of the fromToPairs.

Extension functions

From androidx.animation
TransitionAnimation<T>

Creates a transition animation using the transition definition.

TransitionAnimation<T>

Creates a transition animation using the transition definition and the given clock.

Public constructors

<init>

TransitionDefinition()

Static definitions of states and transitions.

Public methods

getStateFor

fun getStateFor(name: T): TransitionState

Returns a state holder for the specific state name. Useful for the cases where we don't need actual animation to be happening like in tests.

snapTransition

fun snapTransition(
    vararg fromToPairs: Pair<T?, T?>,
    nextState: T? = null
): Unit

With this transition definition we are saying that every time we reach the state 'from' we should immediately snap to 'to' state instead.

Sample of usage with Pairs infix extension to: snapTransition(State.Released to State.Pressed)

Parameters
vararg fromToPairs: Pair<T?, T?> The pairs of states for this transition
nextState: T? = null Optional state where should we start switching after snap

state

fun state(
    name: T,
    init: MutableTransitionState.() -> Unit
): Unit

Defines all the properties and their values associated with the state with the name: name The first state defined in the transition definition will be the default state, whose property values will be used as its initial values to createAnimation from.

Note that the first MutableTransitionState created with state in a TransitionDefinition will be used as the initial state.

Parameters
name: T The name of the state, which can be used to createAnimation from or to this state
init: MutableTransitionState.() -> Unit Lambda to initialize a state

transition

fun transition(
    fromState: T? = null,
    toState: T? = null,
    init: TransitionSpec<T>.() -> Unit
): Unit

Defines a transition from state fromState to toState. When animating from one state to another, TransitionAnimation will find the most specific matching transition, and use the animations defined in it for the state transition. Both fromState and toState are optional. When undefined, it means a wildcard transition going from/to any state.

Parameters
fromState: T? = null The state that the transition will be animated from
toState: T? = null The state that the transition will be animated to
init: TransitionSpec<T>.() -> Unit Lambda to initialize the transition

transition

fun transition(
    vararg fromToPairs: Pair<T?, T?>,
    init: TransitionSpec<T>.() -> Unit
): Unit

Defines a transition from state first value to the second value of the fromToPairs. When animating from one state to another, TransitionAnimation will find the most specific matching transition, and use the animations defined in it for the state transition. Both values in the pair can be null. When they are null, it means a wildcard transition going from/to any state.

Sample of usage with Pairs infix extension to:


//Unresolved: androidx.animation.samples.TransitionSpecWithPairs
Parameters
vararg fromToPairs: Pair<T?, T?> The pairs of from and to states for this transition
init: TransitionSpec<T>.() -> Unit Lambda to initialize the transition