# animate*AsState vs Animatable: Animation Is Just an Interpolated Value

> animate*AsState and Animatable look like two separate animation APIs, but they're two faces of the same idea. An animation in Compose isn't an action you trigger, it's a value that keeps interpolating toward whatever target you last gave it.

**Date:** 2026-10-10T00:00:00.000Z
**Tags:** Animation, State

## The intuition

Coming from View-based Android, or from most imperative UI toolkits,
"animating something" feels like an action you perform. You grab an
object, an `ObjectAnimator`, a `UIViewPropertyAnimator`, hand it a
duration and a target, and call `.start()`. The animation is a thing that
runs *on* a view, separately from the rest of your code, and you have to
remember to `.cancel()` it yourself if a new one fires before the old one
finishes.

`animate*AsState` and [`Animatable`](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/Animatable)
look like that same kind of API from the outside: a duration, an easing
curve, a target value. The mental model underneath is different, though:

* There's no animation object attached to a composable the way an
  `ObjectAnimator` is attached to a `View`. What exists is a *value*, and
  the current reading of that value on any given frame is just "wherever
  the
  interpolation (Blending between a start and an end value by how far along a transition you are: 0% gives the start value, 100% gives the end value, and every point between is some mix of the two, the same idea as lerp.)
  currently sits" on its way toward the latest target.
* You never call `.start()` or `.cancel()` yourself for the common case.
  You change the target, by changing a plain `mutableStateOf`, and the
  animation notices the target moved and retargets itself.
* If the target changes again mid-flight (the user taps twice fast),
  nothing needs to be stopped and restarted. The value just bends toward
  the new target from wherever it currently is.

- [Recomposition, Layout, and DrawScope: One Idea, Three Phases](/phase-aware-compose-tips) — Which phase a state read happens in decides whether an animated value triggers a full recomposition or just a cheap layout/draw pass on every frame.

## Concrete example: a value that jumps vs a value that's animated

```kotlin
// jump: expanded flips instantly, size flips with it, no animation at all
var expanded by remember { mutableStateOf(false) }
val size = if (expanded) 200.dp else 100.dp

Box(Modifier.size(size).background(Color.Blue))
```

```kotlin
// animated: same boolean, same target expression, but size is now a read
// of an interpolated value instead of the raw target
var expanded by remember { mutableStateOf(false) }
val size by animateDpAsState(targetValue = if (expanded) 200.dp else 100.dp)

Box(Modifier.size(size).background(Color.Blue))
```

The only thing that changed is where `size` gets read from. `expanded`
still flips instantly in both versions, there's no such thing as an
"animated boolean." `animateDpAsState` just sits between that target and
the `size` you read, smoothing out what you see on screen every frame
without you touching `expanded` at all.

## More cases: Animatable is the same mechanism, by hand

`animate*AsState` is the convenience wrapper. `Animatable` is the same
idea with the wrapper peeled off, so you can see what it's actually doing:

```kotlin
var target by remember { mutableStateOf(0f) }
val offset = remember { Animatable(0f) }

LaunchedEffect(target) {
    // retargets automatically: if offset is already mid-flight toward an
    // older target, this cancels that run and continues from wherever
    // offset currently sits, toward the new target
    offset.animateTo(target, animationSpec = spring())
}

Row {
    Button(onClick = { target = 0f }) { Text("0f") }
    Button(onClick = { target = 120f }) { Text("120f") }
}
```

That's doing, by hand, exactly what this one-liner does for you:

```kotlin
val offset by animateFloatAsState(targetValue = target, animationSpec = spring())
```

Tap the two buttons below like the ones in that code, including fast,
mid-flight taps. The curve is the same
critically damped (A spring tuned so it settles exactly at its target without ever overshooting and bouncing back, the fastest it can arrive without any bounce.)
`spring()` Compose defaults to (`Spring.StiffnessMedium`,
`Spring.DampingRatioNoBouncy`), not a generic easing curve standing in
for it:

*\[Interactive demo: AnimatableRetargetDemo — view this post in a browser for the live version.]*

Internally, `animateFloatAsState` remembers an `Animatable` and launches a
`LaunchedEffect` (A composable function that launches a coroutine tied to the composition it's called from. The coroutine is cancelled and relaunched whenever the key(s) passed to LaunchedEffect change.)
keyed on the target, whose body is that same `animateTo` call. The reason
to reach for `Animatable` directly instead of the `*AsState` wrapper is
control: `animateTo` is a suspend function, so you can `await` it and run
code after the animation actually settles; `snapTo` jumps to a value with
no interpolation at all, useful for resetting state without a visible
animation; and `animateDecay` lets a fling continue under its own
momentum instead of chasing a fixed target.

> **The fundamental**
>
> This is **value-based animation**. The "animation" is just an
> `Animatable` value plus a running
> coroutine (A unit of suspendable work that can pause at a suspension point and resume later without blocking a thread. Compose animations run inside one so they can keep writing new interpolated values across many frames.)
> that keeps writing new interpolated values into it, frame by frame,
> toward whatever target it was last given, following the curve described
> by an
> AnimationSpec (A description of how a value should move from its current position to a target: a fixed-duration tween with an easing curve, a physical spring with stiffness and damping, or a few other shapes.).
> `animate*AsState` is a managed instance of exactly that: a remembered
> `Animatable` plus a `LaunchedEffect` that calls `animateTo(target)` every
> time the target changes. There's no separate "player" object sitting
> outside the value itself, the value *is* the animation.

## The whole `animate*AsState` family

Every typed `animate*AsState` function is the exact same `Animatable` +
`LaunchedEffect` wrapper from the last section, just pre-filled with a
`TwoWayConverter` for one specific type, the piece that knows how to turn
that type into a vector of floats and back so a spring or tween has
something to interpolate.

| Function | Animates | Notes |
|---|---|---|
| `animateFloatAsState` | `Float` | the base case; most of the others are this with a type wrapped around it |
| `animateDpAsState` | `Dp` | same as `Float`, just unit-wrapped |
| `animateIntAsState` | `Int` | rounds to a whole number every frame |
| `animateIntOffsetAsState` | `IntOffset` | whole-pixel x/y, e.g. `Modifier.offset { }` |
| `animateIntSizeAsState` | `IntSize` | whole-pixel width/height |
| `animateOffsetAsState` | `Offset` | float x/y, e.g. a dragged position |
| `animateSizeAsState` | `Size` | float width/height |
| `animateRectAsState` | `Rect` | all four edges, animated together |
| `animateColorAsState` | `Color` | lives in a separate `animation` artifact from the rest, since `Color` pulls in the graphics module that `animation-core` otherwise avoids depending on |
| `animateValueAsState` | any `T` | the generic form underneath all of the above; hand it your own `TwoWayConverter<T, V>` and it'll animate a type none of the named functions cover |

There's no `animateBooleanAsState`, and that's not an oversight: a
`Boolean` has nothing to interpolate *between*, it's one of two values
with nothing in the middle. Animating "between" `true` and `false`
always actually means animating some other type that represents the two
states, a `Float` alpha, a `Color`, a `Dp` size, with the boolean only
deciding which target that value should move toward.

## Where you'd actually reach for these

* **Press feedback.** `animateFloatAsState` driving a `scale` or `alpha`
  off `interactionSource.collectIsPressedAsState()`, so a button visibly
  compresses or dims the instant it's pressed, then springs back on
  release.
* **Expand/collapse.** `animateDpAsState` on a card's `height` (or a
  `Modifier.size`), toggled by the same boolean that swaps the content,
  so the container resizes instead of jump-cutting between two heights.
* **Selection highlight.** `animateColorAsState` on a list item's
  `background`, toggled by a selected flag, so switching selection
  crossfades the highlight color instead of flashing it on and off.
* **Drag-to-dismiss.** `Animatable` driven directly inside
  `Modifier.pointerInput`: `snapTo` on every drag delta for exact 1:1
  tracking under the finger, then either `animateTo(0f)` to snap back or
  `animateDecay` to let it fly off screen, depending on whether the drag
  crossed a dismiss threshold on release.
* **Progress that doesn't tick in discrete jumps.** `animateFloatAsState`
  on a progress bar's fraction, with the backing state only updated at
  whatever granularity the real work reports, so the bar itself supplies
  the smoothness instead of the data source needing to.
* **Running code only once motion actually finishes.** `Animatable`
  awaited with `animateTo` inside a coroutine, so a snackbar's dismiss
  callback, or a button re-enabling, fires when the slide-out has visibly
  completed, not the instant the target state flipped.

## Elsewhere: same fundamental, different framework

* **Flutter**: the exact same split exists, just under different names.
  `AnimatedContainer`, `AnimatedOpacity`, and the rest of the
  `ImplicitlyAnimatedWidget` family work like `animate*AsState`, you
  change a target property and the widget rebuilds toward it on its own.
  `AnimationController` paired with a `Tween` is the `Animatable`
  equivalent: the same underlying interpolation, with direct control over
  starting, stopping, and reading the value mid-flight.
* **CSS transitions**: `transition: width 0.3s ease` on an element means
  you never call anything to "start" an animation. You just change the
  `width` (by toggling a class, say), and the browser interpolates from
  whatever the old computed value was to the new one, the same retargeting
  behavior as `animateDpAsState` reacting to a new `targetValue`.
* **SwiftUI**: `.animation(_:value:)` is the implicit, `animate*AsState`-
  shaped half, wire it to a `@State` property and every change to that
  property animates automatically. `withAnimation { }` wrapped around an
  explicit state mutation is the `Animatable`-shaped half: you're still
  animating a value, just triggering and scoping it yourself instead of
  letting a modifier watch for changes.

## Where this actually trips people up

### Keying the `LaunchedEffect` on the wrong thing

```kotlin
// wrong: Unit never changes, so this effect runs once on first
// composition and never again. offset.animateTo runs exactly once,
// toward whatever target happened to be at that moment.
LaunchedEffect(Unit) {
    offset.animateTo(target)
}
```

```kotlin
// right: keyed on target, so the effect relaunches, and retargets,
// every time target actually changes
LaunchedEffect(target) {
    offset.animateTo(target)
}
```

Every later change to `target` is silently ignored in the first version,
because nothing re-triggers the block. `Animatable` doesn't know your
value changed; only a `LaunchedEffect` keyed on that value does.

### Forgetting `remember` around the `Animatable`

```kotlin
// wrong: a brand-new Animatable(0f), reset to 0f, on every recomposition
val offset = Animatable(0f)
```

```kotlin
// right: the same instance survives recomposition, so it can actually
// finish animating instead of restarting from 0f each time
val offset = remember { Animatable(0f) }
```

Without `remember`, the value never actually finishes animating to its
target. It keeps getting recreated from scratch and restarting, which
looks like jitter or a value that's stuck near its starting point.

### Mixing an animated read with a raw read of the same target

```kotlin
// mismatch: color crossfades, but size jumps instantly, even though
// both are supposedly animating off the same `selected` boolean
val color by animateColorAsState(if (selected) Color.Blue else Color.Gray)
val size = if (selected) 56.dp else 48.dp
```

This is the same bug as the very first example in this post, just
reintroduced by accident once a composable has more than one property
driven off the same target. Fixing it is the same move as that example:
run `size` through `animateDpAsState` too.

## Mental model to actually use

**You're not telling Compose to play an animation; you're handing it a
new target value, and the `Animatable` underneath keeps interpolating
toward whatever target you handed it most recently.**


---

Canonical page: https://recomposed.blog/compose-value-based-animation