Skip to content

Jetpack Compose animation (Kotlin) ​

Compose animates with snapshot-state value holders that suspend on a frame clock: animate*AsState and Transition turn a changed target in composition into a coroutine that calls withFrameNanos each frame and evaluates a stateless AnimationSpec at the elapsed play time, carrying value and velocity across retargets. Layout animation is a second, built-in measure pass: inside a LookaheadScope every layout is first measured and placed at its destination, then an approach pass lets ApproachLayoutModifierNodes (animateBounds, shared elements) animate from the bounds they showed last frame toward it.

FieldValue
LanguageKotlin (Multiplatform: commonMain sources; Android, JVM desktop, iOS and web hosts)
LicenseApache-2.0 (LICENSE.txt)
Repositoryandroidx/androidx: compose/animation/animation-core, compose/animation/animation; lookahead in compose/ui/ui/.../layout; lazy items in compose/foundation/.../lazy/layout
DocumentationAnimations in Compose · Shared element transitions · Compose phases · Test animations · KDoc in the sources cited below
Categorydeclarative target values with implicit retargeting (animate*AsState, Transition) over imperative suspend-function holders (Animatable); spec objects are stateless functions of play time; lookahead/approach two-pass layout animation
Versions surveyedCompose 1.14.0-alpha02 (COMPOSE in libraryversions.toml, an atomic version for runtime, ui, foundation and animation), androidx-main commit 296313a488a0, 2026-11-21; the same pin as the reactive-programming deep-dive
Animation state lives inremembered holders in the composition slot table (Animatable, Transition and its TransitionAnimationStates), whose value and velocity are snapshot MutableState; layout animations keep theirs in Modifier.Node instances (SizeAnimationModifierNode, BoundsAnimationModifierNode) and lazy items in a key-indexed LazyLayoutItemAnimator

NOTE

This page covers animation. The snapshot system, the Recomposer's frame loop, MonotonicFrameClock dispatch and MainTestClock are described in Jetpack Compose Runtime (time and scheduling, testing) and Testing FRP and UI loops, and are only summarised here; layout itself is in Compose layout. Vocabulary follows the catalog's concepts.


Overview ​

What it solves ​

Composable functions re-run from state, so a value that should move between two states needs a holder that outlives one composition and advances between them. Compose's holders are snapshot state: an animation writes its current value into a MutableState once per frame, and only the scopes that read it are invalidated, in whichever phase read it. The phases doc states the consequence: "State reads during drawing code affect the drawing phase. […] When the state's value changes, Compose UI runs only the draw phase" (Compose phases). The same value read inside Modifier.graphicsLayer { } "will only cause the layer properties update without triggering recomposition and relayout" (GraphicsLayerModifier.kt). A single animation API therefore serves composition-, layout- and draw-phase animation; the caller picks the phase by where it reads.

Design philosophy ​

  1. Specs are stateless; holders are stateful. "[VectorizedAnimationSpec]s are stateless vector based animation specifications. […] Its stateless nature allows the same [VectorizedAnimationSpec] to be reused by a few different running animations with different starting and ending values. More importantly, it allows the system to reuse the same animation spec when the animation target changes in-flight" (VectorizedAnimationSpec.kt). An Animation "does not track the lifecycle of an animation. It merely reacts to play time change and returns the new value/velocity" (Animation.kt).
  2. Continuity is the default. Animatable.animateTo mid-flight starts "from its current value (i.e. value at the point of interruption) to the new [targetValue]. This ensures that the value change is always continuous […] If a [spring] animation (e.g. default animation) is used with [animateTo], the velocity change will guarantee to be continuous as well" (Animatable.kt). spring() is the default spec of animate*AsState, Animatable, animateContentSize, animateItem and animateBounds.
  3. Mutual exclusion through structured concurrency. "[Animatable] ensures mutual exclusiveness on its animations […] any ongoing animation will be canceled via a [CancellationException]" (Animatable.kt); the cancellation is a MutatorMutex, the same primitive scroll and gestures use.
  4. Layout animation is a layout pass, not an effect. "[LookaheadScope] creates a scope in which all layouts will first determine their destination layout through a lookahead pass, followed by an approach pass to run the measurement and placement approach defined in [approachLayout] or [ApproachLayoutModifierNode], in order to gradually reach the destination" (LookaheadScope.kt).

How it works ​

MonotonicFrameClock, withFrameNanos and duration scale ​

Every Compose animation ends in a loop over withFrameNanos, which "Suspends until a new frame is requested, immediately invokes [onFrame] with the frame time in nanoseconds […] frameTimeNanos should be used when calculating animation time deltas from frame to frame as it may be normalized to the target time for the frame" (MonotonicFrameClock.kt). The internal AnimationState.animate creates the scope on the first frame (start time = that frame's time), then loops while (isRunning) calling doAnimationFrameWithScale, which computes playTimeNanos = (frameTimeNanos - startTimeNanos) / durationScale and sets value = anim.getValueFromNanos(playTimeNanos) and velocityVector = anim.getVelocityVectorFromNanos(playTimeNanos) (SuspendAnimation.kt, doAnimationFrame). durationScale is the MotionDurationScale element of the coroutine context (default 1); a scale of 0 makes playTimeNanos = durationNanos, so "the motion will end in the next frame callback" (SuspendAnimation.kt, MotionDurationScale.kt). On Android the Recomposer's context carries a MotionDurationScaleImpl that observes Settings.Global.ANIMATOR_DURATION_SCALE (WindowRecomposer.android.kt, MotionDurationScaleImpl). How the Recomposer dispatches frames is in Compose runtime § Time and scheduling.

Animatable ​

Animatable(initialValue, typeConverter) holds value, velocityVector, targetValue, isRunning and optional bounds; TwoWayConverter maps T to an AnimationVector1D…4D so every dimension animates independently (Animatable.kt). animateTo(target, spec, initialVelocity = velocity) builds a TargetBasedAnimation(spec, value, target, initialVelocity) and runs it under mutatorMutex.mutate { … } (animateTo, runAnimation); animateDecay(initialVelocity, decaySpec) builds a DecayAnimation instead. snapTo and stop take the same mutex, so they cancel any running animation with a CancellationException before setting the value (snapTo, stop). When an animation ends, velocity resets to zero; the end state is returned in AnimationResult for chaining a fling into a spring (endAnimation).

animate*AsState ​

animateValueAsState(targetValue, converter, spec) remembers an AnimateAsState holding an Animatable and a composition CoroutineScope, and in a SideEffect (after the composition commits) calls update (source). update restarts when target != animatable.targetValue: it cancels the previous job and launches, CoroutineStart.UNDISPATCHED "to allow for continuous progress when target changes every frame", animatable.animateTo(newTarget, specToUse) (source). The KDoc: "If there is already an animation in-flight when [targetValue] changes, the on-going animation will adjust course to animate towards the new target value", and "[animateFloatAsState] cannot be canceled/stopped without removing this composable function from the tree" (AnimateAsState.kt).

kotlin
// compose/animation/animation-core/.../AnimateAsState.kt — AnimateAsState.restartAnimation
job = coroutineScope.launch(
    // undispatched to allow for continuous progress when target changes every frame
    start = CoroutineStart.UNDISPATCHED
) {
    animatable.animateTo(newTarget, specToUse)
    finishedListener?.invoke(animatable.value)
}

Transition: updateTransition, rememberTransition, SeekableTransitionState ​

A Transition<S> animates many values toward targets derived from one state. updateTransition(targetState) remembers a Transition and calls animateTo(targetState) every composition (source); rememberTransition(transitionState) takes a MutableTransitionState (an initial state different from the target, so it animates on entry) or a SeekableTransitionState. Child values come from transition.animateFloat { state -> … } / animateValue, each a TransitionAnimationState that keeps its own animation, value and velocityVector. The frame loop exists only while needed: a derivedStateOf { targetState != currentState || isRunning || updateChildrenNeeded } gates a DisposableEffect that launches while (isActive) withFrameNanos { onFrame(it, durationScale) }, and onFrame pulses playTimeNanos to every child (animateTo, onFrame). SeekableTransitionState replaces the clock with a fraction: "A [TransitionState] that can manipulate the progress of the [Transition] by seeking with [seekTo] or animating with [animateTo]" (source); seekTo(fraction, targetState) drives predictive-back and other gesture-scrubbed transitions (source).

AnimationSpec ​

SpecParametrisationSource
tween(durationMillis = 300, delay, easing)duration + Easing (FastOutSlowInEasing, CubicBezierEasing, PathEasing)tween
spring(dampingRatio, stiffness, threshold)Spring.DampingRatioNoBouncy (1) and Spring.StiffnessMedium (1500) by default; mass fixed at 1spring, Spring
keyframes { durationMillis; v at t using e }timestamped values, per-segment easing; keyframesWithSpline for monotone splineskeyframes
repeatable, infiniteRepeatable, snapwrap a duration-based spec; snap jumpsAnimationSpec.kt
DecayAnimationSpecexponentialDecay(friction), splineBasedDecay(density) (Android fling curve); has no targetDecayAnimationSpec.kt, splineBasedDecay
InterruptionAwareAnimationSpec(spec, interruptionSpec)spec from rest, interruptionSpec when a target changes mid-flightsource

The spring is solved analytically from the start value and velocity at the play time: FloatSpringSpec.getValueFromNanos calls spring.updateValuesSeconds(initialValue, initialVelocity, deltaTSeconds) on a SpringSimulation whose natural frequency is sqrt(stiffness) (FloatAnimationSpec.kt, SpringSimulation.kt).

AnimatedVisibility, AnimatedContent, Crossfade: exit by staying composed ​

AnimatedVisibility(visible) is a Transition<Boolean> mapped by createChildTransition to EnterExitState (PreEnter, Visible, PostExit). AnimatedEnterExitImpl keeps composing content while either the transition's target or current state is visible, and drops it only when currentState == PostExit && targetState == PostExit (source). The KDoc: "[content] will only be removed after all the (built-in and custom) exit animations have finished" (source). The caller keeps calling AnimatedVisibility(visible = false) { … } in its own composition, so the exiting content is live, recomposed code reading current state. Inside a lookahead pass AnimatedVisibilityImpl reports IntSize.Zero for content whose target is invisible, so the lookahead layout already has the content gone (source).

AnimatedContent(targetState) keeps currentlyVisible, a list of state values S (not of nodes or pixels), appends each new target, and composes key(contentKey(s)) { content(s) } for every entry inside its own AnimatedEnterExitImpl; a DisposableEffect removes s from the list when its exit completes (AnimatedContentImpl, content loop). The old content is re-invoked with its old state value, so a stale S must still render. SizeTransform animates the container between the content sizes (source). Crossfade is the same list with an animateFloat alpha per entry applied in graphicsLayer (source).

Modifier.animateContentSize ​

SizeAnimationModifierNode is a LayoutModifierNode. In measure it measures the child, then reports animateTo(measuredSize) instead of the child's size; animateTo relaunches anim.animateTo(targetSize, spec) when the target changes, starting from anim.value (source). Inside a lookahead scope it records the lookahead size and animates toward it in the main pass. Reading anim.value in measure makes the node re-measure each frame; the child is laid out once at its final size and clipped or aligned inside the animated box (animateContentSize).

Lazy lists: Modifier.animateItem ​

animateItem(fadeInSpec, placementSpec, fadeOutSpec) "animates the item appearance (fade in), disappearance (fade out) and placement changes (such as an item reordering)" and needs a stable key (LazyItemScope.kt). LazyLayoutItemAnimator.onMeasured runs after each list measure: it compares each item's index with previousKeyToIndexMap, and for an item whose offset changed computes delta = newTarget - currentTarget and calls animatePlacementDelta(delta), which animates an offset back to zero (FLIP) (onMeasured, startPlacementAnimationsIfNeeded). Placement adds animation.placementDelta to the item's target offset and places it placeWithLayer (LazyListMeasuredItem.kt). A removed item (newIndex == -1) is not recomposed: its last GraphicsLayer is put in disappearingItems and drawn by the list in onDrawDisappearingItems at its last placement offset until the fade finishes (removal, draw).

Lookahead: LookaheadScope, approachLayout, animateBounds ​

Inside a LookaheadScope, each invalidated node is measured twice per frame. DepthSortedSetsForDifferentPasses.popEach drains, in order, "lookaheadAndAncestorMeasureSet, lookaheadAndAncestorPlaceSet, approachSet" (DepthSortedSet.kt); remeasureAndRelayoutIfNeeded runs doLookaheadRemeasure and lookaheadReplace for lookahead entries and doRemeasure/replace for approach entries (MeasureAndLayoutDelegate.kt). During the lookahead pass a modifier's ordinary measure runs (isLookingAhead == true) and produces the destination; during the approach pass an ApproachLayoutModifierNode's approachMeasure runs with lookaheadSize available, and isPlacementApproachInProgress(lookaheadCoordinates) sees the destination position (ApproachLayoutModifierNode.kt). LayoutModifierNodeCoordinator.measure asks isMeasurementApproachInProgress(lookaheadSize) first and, once both predicates are false, forces the child to the lookahead constraints and snaps the result to the lookahead size (source):

kotlin
// compose/ui/ui/.../node/LayoutModifierNodeCoordinator.kt — measure (approach pass)
scope.approachMeasureRequired =
    isMeasurementApproachInProgress(scope.lookaheadSize) ||
        constraints != lookaheadConstraints
if (!scope.approachMeasureRequired) {
    wrappedNonNull.forceMeasureWithLookaheadConstraints = true
}
val result = scope.approachMeasure(wrappedNonNull, constraints)

Modifier.animateBounds(lookaheadScope, boundsTransform) is the general client. BoundsAnimationModifierNode.isMeasurementApproachInProgress records the lookahead size as target; isPlacementApproachInProgress records the lookahead position (localLookaheadPositionOf) and, if the target changed, launches Animatable<Rect>.animateTo(target, boundsTransform(currentBounds, target)); approachMeasure measures and places the child at the animated rect (node, BoundsTransformDeferredAnimation, animate). The start of every bounds animation is currentBounds, the rect the node itself produced in the previous approach pass; the target is this frame's lookahead result. Positions under a LayoutCoordinates.introducesMotionFrameOfReference parent (scroll) are excluded by default (animateBounds).

Shared elements: SharedTransitionLayout, sharedElement, sharedBounds ​

SharedTransitionScope { } is a LookaheadScope plus a root modifier that records both the lookahead root and the approach root coordinates and draws an overlay (source, root node). Modifier.sharedElement(state, animatedVisibilityScope) and sharedBounds(…) tag layouts with a key; an entry in an exiting AnimatedVisibility/AnimatedContent and one in an entering one match, and "The bounds will be animated from the initial bounds defined by the exiting shared element to the target bounds calculated based on the incoming shared element" (sharedElement). Both are still composed and laid out, because both sit inside an AnimatedVisibilityScope that keeps them composed through the transition. While the bounds transform runs, "it will be rendered into the overlay of the [SharedTransitionScope] in order to avoid being faded in/out along with its parents or clipped by its parent": SharedContentNode.draw records its content into a GraphicsLayer instead of drawing in place, and the root's drawInOverlay draws every recorded layer at the animated bounds (SharedContentNode.kt, SharedTransitionScope.kt). sharedElement remeasures the child to the animated size; sharedBounds defaults to scaleToBounds, which "avoids frame-by-frame remeasurement" (sharedBounds).

Testing: mainClock.autoAdvance = false ​

MainTestClock "is ultimately responsible for driving all recompositions, all subscribers to [withFrameNanos] (all compose animations) and all coroutines launched with [LaunchedEffect]" (MainTestClock.kt). With autoAdvance = false, advanceTimeByFrame(), advanceTimeBy(ms) and advanceTimeUntil { } step it; the KDoc documents the one-frame start latency: "Because animations receive their [frame time] before recomposition, an animation will not get its start time in the first frame after kicking it off by toggling a state variable" (source). MotionDurationScale is injectable through the test rule's effectContext (MotionDurationScale.kt). Details and a worked example are in Compose runtime § Testing and Testing FRP and UI loops.


Analysis ​

Where animation state lives ​

In remembered objects in the composition slot table, keyed by call-site position (and key()), with snapshot MutableState for the observable parts: Animatable.value, TransitionAnimationState.value, velocityVector. Layout animations put theirs in Modifier.Nodes attached to the layout node (SizeAnimationModifierNode.animData, BoundsAnimationModifierNode.boundsAnimation), so they live exactly as long as the node. Lazy lists key it by item key in LazyLayoutItemAnimator.keyToItemInfoMap (source). There is no global store; the snapshot system is what lets any phase observe these values without a store.

Declaring an animation ​

Implicit and declarative is the default surface: animateDpAsState(if (expanded) 200.dp else 80.dp), updateTransition(state).animateColor { … }, AnimatedVisibility(visible), AnimatedContent(target), Modifier.animateContentSize(), animateItem(), animateBounds(scope). A target computed in composition is the whole declaration; the holder animates when it differs. Explicit and imperative is Animatable: suspend calls (animateTo, animateDecay, snapTo, stop) in a LaunchedEffect or gesture coroutine, needed for gesture-driven motion and sequencing. SeekableTransitionState is a third mode, a declarative transition whose progress the app supplies.

Time and the clock ​

The host owns the clock; animations only ask for it. The frame time arrives through the MonotonicFrameClock in the Recomposer's coroutine context (Choreographer on Android), is normalised to the frame's target time, and is converted to play time relative to the animation's first frame (MonotonicFrameClock.kt, SuspendAnimation.kt). Specs are evaluated in closed form at that play time, so a dropped frame does not change where the animation is. MotionDurationScale divides elapsed time globally per context. There is no document or scroll timeline; scroll-linked motion reads scroll state, and SeekableTransitionState.seekTo(fraction) is the only "timeline" whose position is not time (source). Within a frame the order is fixed: frame-clock subscribers first, then recomposition, then measure/layout (lookahead then approach), then draw (MainTestClock.kt, DepthSortedSet.kt).

Interruption and retargeting ​

Retargeting is continuous in value and, for springs, in velocity. Animatable.animateTo defaults initialVelocity = velocity, so the new TargetBasedAnimation starts from the in-flight value and velocity (source); runAnimation reuses the interrupted animation's lastFrameTimeNanos as the new start so no frame is lost (source). Transition goes further for non-spring specs: on interruption "use the default spring, unless the spec is also a spring or specifies its own interruption spec", so a tween interrupted mid-flight becomes a velocity-preserving spring to the new target (TransitionAnimationState.updateAnimation); InterruptionAwareAnimationSpec lets an author choose the interruption spec for Transition, animate*AsState and Animatable alike (source). A tween driven through Animatable ignores the carried velocity (duration specs have no velocity input), so only springs and the Transition fallback are velocity-continuous. Composition is exclusive, not additive: a new animateTo cancels the old one through the MutatorMutex (source). AnimatedContent is interruptible by design: currentlyVisible can hold several states at once, each with its own enter/exit progress (source).

Curves and springs ​

Both are first-class, and springs are the default. spring(dampingRatio, stiffness) with named constants (DampingRatioNoBouncy/LowBouncy/MediumBouncy/HighBouncy, StiffnessHigh…VeryLow) and an implicit unit mass (Spring, SpringSimulation.kt); the duration is estimated from the parameters, not given. Duration-based motion is tween with an Easing and keyframes. Decay (exponentialDecay, splineBasedDecay) handles flings with no target (source). Enter/exit and item animations default to StiffnessMediumLow springs (animateItem, DefaultBoundsTransform).

Layout animation ​

Compose has three layout-animation mechanisms, all of which run in the layout phase and none in user code:

MechanismPhaseStart geometry (previous)Target geometrySource
animateContentSizemeasure of a LayoutModifierNodethe node's own Animatable value (last reported size)the child's size measured this passSizeAnimationModifierNode
animateItem (placement)lazy-list measure (onMeasured) computes deltas; placement applies them through placeWithLayerthe item's previous target offset, by keythis measure's offsetstartPlacementAnimationsIfNeeded
animateBounds, shared elementslookahead pre-pass computes destination; approach measure/placement animates toward itthe node's currentBounds from the previous approach passthis frame's lookahead size/positionBoundsAnimationModifierNode

All three need the previous frame's geometry, and all three keep it themselves, inside the node or the item animator; none reads a shared "last frame" store. Lookahead removes the classic FLIP problem of measuring the destination: the pre-pass lays out the whole scope at its final state (with exiting AnimatedVisibility content already reporting zero size, source) in the same frame, so the approach pass can animate from last frame's displayed bounds toward a destination computed this frame. The approach result for a parent is the animated size, so ancestors outside the animating node see in-flight sizes; sharedBounds' scaleToBounds and animateBounds' modifier parameter exist to choose between re-measuring children at each animated size and scaling a stable layout. Draw-only animation (alpha, translation, scale via graphicsLayer { }) skips layout entirely (graphicsLayer); the compositor is not involved beyond replaying layers.

Enter and exit ​

Compose uses two different mechanisms for keeping removed content on screen:

  • Keep composing it (AnimatedVisibility, AnimatedContent, Crossfade, shared elements). The removal is expressed as a target state; the container keeps calling the content lambda, with the old state value for AnimatedContent, until the exit transition reaches PostExit, then drops it from composition (AnimatedEnterExitImpl, AnimatedContentImpl). The exiting subtree stays live: it recomposes, lays out, and can participate in shared-element matching.
  • Keep drawing its last layer (lazy animateItem). A removed item is not composed or measured again; its last recorded GraphicsLayer (a display list) is drawn by the list at its last offset, faded through the layer's alpha, and released when the animation finishes (removal, draw).

Enter is symmetric: EnterTransition (fadeIn, slideIn, expandIn, scaleIn) from PreEnter, MutableTransitionState(false) with target true to animate on first composition, and fadeInSpec for new lazy items when the item was absent from the previous key map (source).

Scheduling, reduced motion and testing ​

Frames are requested only by suspended withFrameNanos callers: an idle Animatable has no coroutine, and Transition's frame loop is composed only while targetState != currentState || isRunning (source). withInfiniteAnimationFrameNanos marks infinite animations so tests and policies can treat them separately (callWithFrameNanos). Reduced motion is the system animator duration scale: Android's "Remove animations" sets it to 0, every animation in that Recomposer finishes on its next frame, and there is no separate reduce-motion flag in the framework (WindowRecomposer.android.kt). That is all-or-nothing and per window, with no notion of essential motion. Tests own a virtual frame clock (mainClock.autoAdvance = false) and can inject MotionDurationScale; Android draw is not driven by the test clock (MainTestClock.kt).

Lessons for sparkles:ui ​

  • Stateless specs plus (start, from, velocity) in the store is the right split. Compose's VectorizedAnimationSpec takes start value, start velocity, target and play time and holds nothing else; that is exactly a @safe pure nothrow @nogc function a sparkles host can evaluate at FrameStart.target over store-held numbers (baseline).
  • The interruption policy is small and copyable. Retarget from the current value with the current velocity; if the spec cannot take velocity (a tween), fall back to a spring, as Transition does (source). That gives continuity without additive bookkeeping.
  • For UI-Q9, lookahead answers "which geometry does a layout animation need": last frame's displayed bounds as start, this frame's layout as target, both owned by the animating element. Compose computes the target in a pre-pass and animates in the approach pass, never in user code. A sparkles host can do the same after its single layout: target = this frame's laid-out rect, start = the store's committed rect for that identity, interpolated at paint, with no component reading geometry. Only the lookahead property that ancestors see the animated size needs a second layout pass; scaling a stable layout (scaleToBounds) does not. See UI-Q9 (PR #775).
  • For UI-Q10, Compose ships both answers. AnimatedVisibility keeps the subtree composed (a closing state, driven by a transition the container owns); lazy lists replay the item's last display list. The first needs the old input retained (AnimatedContent keeps old S values); the second needs only a retained draw range. For a sparkles store whose components cannot be re-run without their data, a retained op range from the last committed frame is the cheap default and a closing state the opt-in. See UI-Q10 (PR #775).
  • Phase-scoped reads are the performance model, and sparkles gets it for free. Compose works hard (snapshot read tracking per phase) so that an animated value read in draw skips composition and layout. A host that interpolates store values at paint never re-runs components for paint-only animation at all.
  • Reduced motion as a duration scale is too coarse. A single scale-to-zero cannot distinguish essential motion (progress, scroll) from decoration; the sparkles vocabulary can carry the distinction.

Strengths ​

  • Value- and velocity-continuous retargeting by default, including the tween-to-spring fallback in Transition.
  • Stateless specs evaluated in closed form at play time: seekable (SeekableTransitionState), scalable (MotionDurationScale) and frame-drop-proof.
  • One animation API serves composition, layout and draw; the read site picks the phase.
  • Lookahead gives layout animation a correct destination in the same frame, generalised to animateBounds and shared elements.
  • Lazy-list item animations (appear, move, disappear) with a cheap retained-layer exit.
  • A fully virtual test clock with documented frame ordering.

Weaknesses ​

  • Many overlapping APIs (animate*AsState, Animatable, Transition, AnimatedVisibility, AnimatedContent, Crossfade, animateContentSize, animateBounds, sharedElement/sharedBounds) with different interruption and lifecycle rules.
  • animate*AsState cannot be stopped without leaving composition (source); a tween through Animatable drops velocity.
  • Lookahead doubles measure work for every invalidated node in scope, and approach code must agree with lookahead when settled or the snap is visible (ApproachLayoutModifierNode.kt).
  • Exiting AnimatedContent content is re-run with a stale state value, which every content lambda must tolerate.
  • Reduced motion is only the global animator duration scale.
  • One-frame start latency: an animation kicked off by a state change gets its start time a frame later (MainTestClock.kt).

Key design decisions and trade-offs ​

DecisionRationaleTrade-off
Animated values are snapshot stateany phase can read them; only readers are invalidatedcorrectness and cost depend on where app code reads
Specs stateless, holders statefulone spec reused across retargets and instances; closed-form evaluationholders are remembered objects tied to composition position
Springs by default, velocity carriedcontinuous motion under rapid retargetingdurations are emergent, harder to coordinate
MutatorMutex exclusion per Animatablestructured cancellation shared with gestures and scrollno additive animation; cancelled coroutines need try/catch for cleanup
Exit by keeping content composed (AnimatedVisibility)exiting content stays live, laid out and shareablecontainers must retain old state values; content recomposes while leaving
Exit by retained GraphicsLayer (lazy lists)no composition or measure for removed itemsfrozen content; only layer properties (alpha, offset) can animate
Lookahead pre-pass + approach passdestination known in the same frame; ancestors can see animated sizesdouble measure in scope; approach/lookahead must converge exactly
Shared elements drawn in a root overlayescape parent clip and fadeclipping and fading must be re-specified explicitly on the element
Reduced motion = MotionDurationScale 0one switch, honoured by every animation automaticallyno essential-motion distinction; per-window, not per-subtree

Sources ​