-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Canary 808.14 - spring and decay don't play well together when spring has a velocity set in config #887
Comments
Don't know when I'll get to this. I tried writing a test in I created the |
@aleclarson I think I've somewhat narrowed down the bug: it has to do with the velocity of the spring. // before
if(down) set({ y: my, config: { decay: false } })
else set({ y: my, config: { decay: true, velocity: vy } })
// after
if(down) set({ y: my, config: { decay: false, velocity: 0 } }) // <-- add velocity: 0
else set({ y: my, config: { decay: true, velocity: vy } }) This solves my use case but I believe it still remains a bug since the jump shouldn't happen even with a velocity set in config. As a side note, I think that this is a bit counterintuitive having to reset the last config but we can discuss this separately. |
@aleclarson sorry for the previous message I deleted. This time I think I've isolated the issue. Here is the code I'm using to trigger the bug: const [{ y }, set] = useSpring(() => ({ y: 0 }))
const bind = useDrag(
({ down, movement: [, my], vxvy: [, vy] }) => {
if (down) set({ y: my, config: { decay: false } })
else set({ to: my, config: { decay: true, velocity: vy } })
},
{ initial: () => [0, y.get()] }
) What happensSo what the code does is while the mouse is down follow it with a spring, then when it's released, decay with the last velocity of the gesture. The bug occurs when you interrupt the decay gesture by pressing the mouse. From the capture below, it seems like the spring animates with an erroneous Looking at the codeLooking at This function is called from the When a spring gets interrupted, it seems like Here is how My observation is that things happen L604: Then there is the second check occurring on L609 where So there's hardly a chance both can be different. I'm not sure what should be the right check, but I think this is where the problem is. Side observation about decayDecay shouldn't even need a Also there is this line in the decay loop which I'm not sure of the effect since |
This should fix #887, because changing of the "config.decay" prop now affects the "started" variable. Also, a new variable named "finished" detects if the current value equals the latest goal value.
I think the goal value of your spring animation is missing an offset based off the
Yup, this one was on my radar. It should be fixed in the next canary (releasing today after I verify this issue is not react-spring's fault). I think 10e5e93 is what fixed it. |
Oh nevermind my first sentence. Just noticed the edit: Hmm, in my tests, it seems like the |
@aleclarson hey Alec thanks for taking the time. Actually the initial array gets updated every time the gesture starts. Again, this works with v8, I think you can reproduce the issue by following these steps:
The spring animation should start from the current position of the value (so the current value of decay should be the implicit |
The |
I'll have another look as well, I just tried to reproduce the issue and can't do it steadily. But I still think my observation is valid in the Looking at the code section especially line 609! |
Be sure to pull the |
This should fix #887, because changing of the "config.decay" prop now affects the "started" variable. Also, a new variable named "finished" detects if the current value equals the latest goal value.
Wow, this looks like it's also fixed! Updated sandbox: https://codesandbox.io/s/decay-v9-mtkwn |
Nice, I didn't even try to fix this one :) edit: I mean.. I did with 874897d, but I don't think that worked at the time.. 😋 |
I am facing this problem in the latest version (9.1.0). This probably got reintroduced here. According to the discussion above decay animations shouldn't worry about |
🐛 Bug Report
When a spring take over a decay, the animated value jumps erratically for a short time.
To Reproduce
The sandbox allows you to drag the viewport and "fake scroll" its content. When the mouse is down, the content should scroll along your pointer. When you release the mouse, the content decays.
If you interrupt the decay movement, here's a weird jump as shown in the following gif.
Expected behavior
See v8 sandbox.
Link to repro
Environment
react-spring
v9.0.0-canary.808.14react
v16.9.0The text was updated successfully, but these errors were encountered: