fix(core): preserve velocity across retargets for decay animations#2516
Merged
Conversation
🦋 Changeset detectedLatest commit: 71ca974 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Docs preview: https://pr-2516---react-spring-204644970562.europe-west1.run.app Deployed at |
Decay animations integrate an initial velocity; the previous `_update` logic unconditionally reset `config.velocity` to `0` whenever `to` or `from` was provided, silently breaking gesture-driven decay flows that retarget mid-throw. Skip the reset when `config.decay` is set. Also clarifies the JSDoc and docs-site reference for `decay` to explain that it decelerates from an initial velocity and does not ease toward `to` — the root cause of the user-facing confusion in #1843. Closes #1843.
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.
Summary
Decay animations integrate an initial velocity —
position = from + (v0 / (1 - decay)) * (1 - e^(-(1-decay)t)). The previous_updatelogic unconditionally resetconfig.velocity = 0whenevertoorfromwas provided, which silently breaks gesture-driven decay flows that retarget mid-throw (mouse-flick decay, drag-throw, etc.). The fix is a one-condition tweak: skip the velocity reset whenconfig.decayis set.The bug report (#1843) was filed because
useSpring({ xys, config: { decay: 0.48 } })"doesn't work". That repro never sets a velocity at all, so even after this fix it won't animate — decay needs a velocity to decelerate. The user-facing confusion is that the existing docs don't say so. This PR also updates thedecayJSDoc and docs-site reference to make that explicit, including a@use-gesture/reactsnippet that mirrors therocket-decaydemo.Closes #1843.