Skip to content

Animation: withAnimation and the animation modifier - #34

Merged
colemancda merged 6 commits into
masterfrom
feature/animation
Jul 23, 2026
Merged

Animation: withAnimation and the animation modifier#34
colemancda merged 6 commits into
masterfrom
feature/animation

Conversation

@colemancda

Copy link
Copy Markdown
Member

Final parity tier: animation. Swift describes intent; Compose animates.

How it works

  • withAnimation(_:_:) sets the animation on a transaction while its body runs; a state write inside captures it, and the next (coalesced) evaluation stamps the root node with animationCurve/animationDurationMs.
  • .animation(_:value:) marks a single view: its modifier carries the curve, duration, and a token of the observed value.
  • Animation.default, .linear/.easeIn/.easeOut/.easeInOut(duration:), .spring().
  • The interpreter folds numeric modifier values (offset, opacity, scale, rotation, frame, background color, corner radius) through animate*AsState unconditionally — spec is a tween/spring while an animated tree (or the node's own .animation) applies, snap otherwise — so each Animatable persists across trees and eases from wherever it currently is.

The interesting bug

The first cut wrapped the tree in a conditional CompositionLocalProvider — and an animated tree arriving switched Compose branches, tearing down every remembered Animatable, so values snapped. The provider is now structurally unconditional (inheriting when a node carries no spec — only the root ever does), keeping the composition stable.

Verification

  • swift test — 3 new tests (transaction stamping + one-shot clearing, scoping/restore, implicit emission), 56 passing
  • Emulator (new Animation screen), frame-sampled with burst screencaps:
    • implicit color swap: caught a mid-blend frame between the two colors
    • explicit 2s linear offset: five distinct intermediate positions (x = 44 → 190 → 302 → 402 → 498 → 630 → 650) — genuine easing, not a snap
    • default, easeOut, and spring examples all settle at correct end states

Deferred

AnimatedVisibility for inserted/removed children; per-value curve fidelity beyond the five presets; gesture-driven/interruptible animation semantics (a mid-flight non-animated tree snaps to target).

@colemancda
colemancda merged commit 6832bb5 into master Jul 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant