AnimationGroup

The per-render handle returned by useAnimationGroup and the public surface for declaring a group's animations (animateFloat, animateDimen, …).

Each call to useAnimationGroup creates a fresh AnimationGroup for that render, isolating per-render bookkeeping (slot counter, pending descriptions) from the shared, persistent AnimationGroupState — so concurrent resolves never race. Declaring a slot allocates no AnimatedValue and mutates nothing here; it records a AnimationDescriptor (committed as an AnimationGroupRecord) and returns a Value handle. It deliberately exposes no animation runtime — settled state (currentState, isRunning) lives on AnimationGroupState and is read from the main thread / effects, never during render().

val transition = useAnimationGroup(expanded)

val height = transition.animateDimen(
transitionSpec = {
when {
false.isTransitioningTo(true) -> spring(stiffness = Stiffness.Low)
else -> tween(200.ms)
}
},
) { state -> if (state) 200.dp else 56.dp }

val alpha = transition.animateFloat { state -> if (state) 1f else 0f }

Parameters

S

The type of the state that drives the transition.

See also

Properties

Link copied to clipboard
var onSettled: () -> Unit?

Optional callback invoked once when all animations in this group finish and the group settles. Runs on the main thread from within the frame loop. Register it from an effect and clear it (set to null) on cleanup. Writes through to the shared AnimationGroupState, so setting it is stable across renders.

Link copied to clipboard

The state that the transition is animating toward in this render (the render prop).

Functions

Link copied to clipboard
fun animateColor(transitionSpec: Segment<S>.() -> FiniteAnimationSpec<Color> = { spring() }, label: String = "color", targetValueByState: (S) -> Color): Value<Color>

Animates a Color property with per-channel interpolation.

Link copied to clipboard
fun animateDimen(transitionSpec: Segment<S>.() -> FiniteAnimationSpec<Dimen> = { spring() }, label: String = "dimen", targetValueByState: (S) -> Dimen): Value<Dimen>

Animates a Dimen property as part of this transition.

Link copied to clipboard
fun animateFloat(transitionSpec: Segment<S>.() -> FiniteAnimationSpec<Float> = { spring() }, label: String = "float", targetValueByState: (S) -> Float): Value<Float>

Animates a Float property as part of this transition.

Link copied to clipboard
fun animateInt(transitionSpec: Segment<S>.() -> FiniteAnimationSpec<Int> = { spring() }, label: String = "int", targetValueByState: (S) -> Int): Value<Int>

Animates an Int property as part of this transition.

Link copied to clipboard
fun <T> animateValue(typeConverter: TypeConverter<T>, transitionSpec: Segment<S>.() -> FiniteAnimationSpec<T> = { spring() }, label: String = "", targetValueByState: (S) -> T): Value<T>

Animates a value of type T as part of this transition using a custom TypeConverter.