Skip to content

Transitions: animate views as they appear and disappear - #45

Merged
colemancda merged 4 commits into
masterfrom
feature/transitions
Jul 23, 2026
Merged

Transitions: animate views as they appear and disappear#45
colemancda merged 4 commits into
masterfrom
feature/transitions

Conversation

@colemancda

Copy link
Copy Markdown
Member

The deferred half of the animation tier: .transition(_:) animates a view as it is inserted into or removed from a stack (typically inside withAnimation).

What's new

  • AnyTransition.opacity, .slide, .scale, .move(edge:), .identity; .transition(_:) modifier.
  • The interpreter wraps a transition-carrying child of a VStack/HStack/ZStack in an AnimatedVisibility whose enter/exit is derived from the transition kind (timing follows the active withAnimation spec, else a 300ms tween).

The interesting part

A child removed from the Swift tree is simply gone from node.children, so there's nothing left to animate out. Each stack keeps a slot per transition child (its last node + a MutableTransitionState); when the child leaves, its slot lives on with targetState = false so the exit plays, then evicts when idle. Crucially, present and exiting children render through one unified key(id)-ed loop — my first cut used two loops, and the child hopping call sites made Compose tear it down instead of animating (bug caught on-device via a state-log; the two-loop version removed instantly).

Verification

  • swift test — new emission test, 66 total passing
  • Emulator (Animation screen, new "Transition: move + fade" and "Transition: scale" examples), frame-sampled:
    • Enter: the box slides in from the leading edge (caught at x≈0–30 mid-flight before settling)
    • Exit: a mid-frame shows the box slid left and clipped off the leading edge ("…rom the leading edge and fade"), and the MutableTransitionState log shows cur animating true→false over ~400ms — a real exit, not a snap

Deferred

Asymmetric transitions (.asymmetric), .combined(with:), and perfectly in-place exit ordering when multiple siblings leave at once (exiting children are appended, which is in-place for the common single-optional-child case).

@colemancda
colemancda merged commit 12c4ac9 into master Jul 23, 2026
6 checks passed
@colemancda
colemancda deleted the feature/transitions branch July 23, 2026 20:19
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