Animation: withAnimation and the animation modifier - #34
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withanimationCurve/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().animate*AsStateunconditionally — spec is a tween/spring while an animated tree (or the node's own.animation) applies,snapotherwise — so eachAnimatablepersists 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 rememberedAnimatable, 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 passingDeferred
AnimatedVisibilityfor 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).