Transition

@Stable
class Transition<S>

Transition manages all the child animations on a state level. Child animations can be created in a declarative way using Transition.animateFloat, Transition.animateValue, animateColor etc. When the targetState changes, Transition will automatically start or adjust course for all its child animations to animate to the new target values defined for each animation.

After arriving at targetState, Transition will be triggered to run if any child animation changes its target value (due to their dynamic target calculation logic, such as theme-dependent values).

See also

Types

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY])
inner class DeferredAnimation<T, V : AnimationVector>

DeferredAnimation can be constructed using Transition.createDeferredAnimation during composition and initialized later. It is useful for animations, the target values for which are unknown at composition time (e.g. layout size/position, etc).

Link copied to clipboard
interface Segment<S>

Segment holds initialState and targetState, which are the beginning and end of a transition. These states will be used to obtain the animation spec that will be used for this transition from the child animations.

Link copied to clipboard
@Stable
inner class TransitionAnimationState<T, V : AnimationVector> : State<T>

Each animation created using animateFloat, etc is represented as a TransitionAnimationState in Transition.

Properties

Link copied to clipboard
Link copied to clipboard

Current state of the transition. This will always be the initialState of the transition until the transition is finished. Once the transition is finished, currentState will be set to targetState. currentState is backed by a MutableState.

Link copied to clipboard

Indicates whether there is any animation running in the transition.

Link copied to clipboard
@get:RestrictTo(value = [RestrictTo.Scope.LIBRARY])
var isSeeking: Boolean
Link copied to clipboard
val label: String? = null
Link copied to clipboard
@get:RestrictTo(value = [RestrictTo.Scope.LIBRARY])
val parentTransition: Transition<*>?
Link copied to clipboard

segment contains the initial state and the target state of the currently on-going transition.

Link copied to clipboard

Target state of the transition. This will be read by all child animations to determine their most up-to-date target values.

Link copied to clipboard

Total duration of the Transition, accounting for all the animations and child transitions defined on the Transition.

Link copied to clipboard

List of child transitions in a Transition.

Functions

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateColor(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Color> = { spring() }, label: String = "ColorAnimation", targetValueByState: @Composable (state: S) -> Color): State<Color>

Creates a Color animation as a part of the given Transition. This means the lifecycle of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateFloat(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Float> = { spring() }, label: String = "FloatAnimation", targetValueByState: @Composable (state: S) -> Float): State<Float>

Creates a Float animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateInt(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<Int> = { spring(visibilityThreshold = 1) }, label: String = "IntAnimation", targetValueByState: @Composable (state: S) -> Int): State<Int>

Creates a Int animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateIntOffset(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<IntOffset> = { spring(visibilityThreshold = IntOffset(1, 1)) }, label: String = "IntOffsetAnimation", targetValueByState: @Composable (state: S) -> IntOffset): State<IntOffset>

Creates a IntOffset animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
inline fun <S> Transition<S>.animateIntSize(noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<IntSize> = { spring(visibilityThreshold = IntSize(1, 1)) }, label: String = "IntSizeAnimation", targetValueByState: @Composable (state: S) -> IntSize): State<IntSize>

Creates a IntSize animation as a part of the given Transition. This means the states of this animation will be managed by the Transition.

Link copied to clipboard
@Composable
inline fun <S, T, V : AnimationVector> Transition<S>.animateValue(typeConverter: TwoWayConverter<T, V>, noinline transitionSpec: @Composable Transition.Segment<S>.() -> FiniteAnimationSpec<T> = { spring() }, label: String = "ValueAnimation", targetValueByState: @Composable (state: S) -> T): State<T>

Creates an animation of type T as a part of the given Transition. This means the states of this animation will be managed by the Transition. typeConverter will be used to convert between type T and AnimationVector so that the animation system knows how to animate it.

Link copied to clipboard
@Composable
inline fun <S, T> Transition<S>.createChildTransition(label: String = "ChildTransition", transformToChildState: @Composable (parentState: S) -> T): Transition<T>

createChildTransition creates a child Transition based on the mapping between parent state to child state provided in transformToChildState. This serves the following purposes:

Link copied to clipboard
@RestrictTo(value = [RestrictTo.Scope.LIBRARY])
@Composable
fun <S, T, V : AnimationVector> Transition<S>.createDeferredAnimation(typeConverter: TwoWayConverter<T, V>, label: String = "DeferredAnimation"): Transition.DeferredAnimation<T, V, S>

This creates a DeferredAnimation, which will not animate until it is set up using DeferredAnimation.animate. Once the animation is set up, it will animate from the currentState to targetState. If the Transition has already arrived at its target state at the time when the animation added, there will be no animation.

Link copied to clipboard
open override fun toString(): String