useAnimatedValue

fun <T> ComponentScope.useAnimatedValue(targetValue: T, typeConverter: TypeConverter<T>, spec: FiniteAnimationSpec<T> = spring(), trigger: AnimationTrigger = AnimationTrigger.Immediate, label: String = ""): Value<T>

Animates a value of type T, automatically starting a new animation whenever targetValue changes.

This is the foundation hook for all declarative animations. It creates an AnimatedValue internally and drives it via useEffect whenever the target or spec changes. The returned Value integrates with Litho's state read tracking for automatic phase-skipping.

Prefer the typed convenience hooks (useAnimatedFloat, useAnimatedInt, useAnimatedColor, useAnimatedDimen) over calling this directly.

val alpha = useAnimatedValue(
targetValue = if (visible) 1f else 0f,
typeConverter = FloatTypeConverter,
)
Style.alpha(alpha)

Return

A Value containing the current animated value.

Parameters

targetValue

The value to animate toward. Changes trigger new animations.

typeConverter

Converts between T and Float for animation computation.

spec

The animation specification. Defaults to spring.

trigger

Controls when the animation begins receiving frame callbacks. Defaults to AnimationTrigger.Immediate.

label

Optional label for debugging and tracing attribution.