Motion recipes and a springConfig that actually works - #7
Merged
Merged
Conversation
springConfig could not change the feel: react-spring ignores mass, tension and friction whenever duration is set, and the sheet always set it. easing, the one knob that does work in that branch, was missing from the type. Adds easing and clamp, four presets including Material 3 motion, a cubic-bezier solver and a demo to compare them. No default changes.
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.
Makes the animation configurable in the way people actually want to configure it, and documents the rule that made the old advice wrong.
The problem
springConfigcould not change the feel of the animation. react-spring runs a tween wheneverdurationis set and ignoresmass,tension,frictionandvelocityin that branch, and the sheet always passedduration: 115. The README's own example,springConfig={{mass: 0.1, tension: 370, friction: 26}}, therefore did nothing at all.Worse, the one knob that does work in a tween,
easing, was missing from theSpringConfigtype, so it could not be passed even though the underlying library honours it. The default easing is linear, which is why the sheet starts and stops abruptly.Changes
SpringConfiggainseasingandclamp, with doc comments saying which branch each field belongs to.presetsexport with four recipes.cubicBezierhelper, because react-spring ships no curve solver and Material's curves are cubic-beziers./fixtures/motiondemo that switches recipes with the sheet open, throughsiblingso the controls stay above the backdrop.lineareasedeaseOutCubicmaterialspringyNo default changes. The sheet still animates exactly as it does today unless you opt in.
Why the longer durations are not slower
An eased curve front loads the distance, so the durations are not comparable directly. Measured against the point where the motion has covered 90% of its travel, which is where the eye stops tracking it:
linear115mseased190msmaterial300msAll three feel like the same speed. The extra time is the tail settling.
Where the numbers come from
The duration and curve for
materialaremd.sys.motion.duration.medium2(300ms) andemphasized.decelerate(cubic-bezier(0.05, 0.7, 0.1, 1)), read from Google's own token repository. The Material Design site itself renders client side and could not be read directly, so the tokens repo is the source.For reference, that scale puts a surface of this size at 300ms and reserves the 100 to 150ms band the current default sits in for small controls. That is context, not a verdict: a sheet a salesperson opens fifty times a day has a fair claim to being faster than the spec.
Two hard limits, read from the react-spring source rather than assumed:
Test plan
npm test: lint, 32 unit tests, library build, docs build