question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inertia/momentum incorrect behavior, and unexpected value jumping

See original GitHub issue

šŸ› Bug Report

This is a bug for tracking the overall not-quite-right behavior of 1:1 animation with momentum at the end. I started thinking about this after my issue on react-use-gesture last weekend. Here are some earlier reports and discussions from react-spring and react-use-gesture:

https://github.com/react-spring/react-spring/issues/887 https://github.com/react-spring/react-spring/issues/1010 https://github.com/react-spring/react-use-gesture/issues/132

This is a problem that comes up most commonly with gestures, but I believe the solution lies in the animation primitives. Mapping gestures 1:1 with the animation requires using the immediate parameter, but doing so ends up breaking the expected velocity/momentum for the end of the animation/gesture. You can get kind of close to the desired behavior by using a stiff spring config without the immediate parameter, but this isn’t ideal. HCI research has shown that the desired behavior for these types of gestures is a 1:1 correspondence.

The previous suggested solutions for building this behavior have been custom hooks outside the library, but hopefully we can all agree that this is something that should be covered by the library. Previous solutions added a concept of decay, but I think the library already has all of the concepts/APIs we need, it’s just a matter of fixing how velocity is calculated when using immediate.

Expected behavior with reproduction

This is a demo of some horizontal scroll areas nested in a vertical scrolling area. Both of them have ā€œtouchā€ scrolling enabled; the scrollLeft and scrollTop are being animated, in order to co-exist with native browser scrolling.

https://codesandbox.io/s/react-spring-inertial-scroll-challenge-qh4wr

The desired behavior is exemplified by the native scrolling behavior on macOS with a trackpad – 1:1 mapping of scroll gesture to position, with momentum proportional to the spring config when ending the gesture with velocity. The animated value should not overshoot its target.

The touch scrolling demo implementation does have some momentum, but only a tiny bit; not at all like you’d expect. Here’s a gif showing how much momentum I could get when trying my hardest to ā€œslingā€ it

missing inertia

Environment

  • react-spring v9.0.0-rc.3
  • react v16.8.12

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lourdcommented, Apr 29, 2021

That works brilliantly, thanks @joshuaellis!!!

I played around with your tweaks a little more, and it looks like the vxvy Vector2 parameter to onDrag is already scaled with the direction, so that can be used instead of having to scale the velocity Vector2. I updated my 9.2.0 beta sandbox with that change. I also converted it to TypeScript and added a Leva range control for the decay config to play around with.

0reactions
ian-rafaelcommented, Jun 14, 2021

is there any way to know where spring will rest, the final value, with decay and velocity?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which specific law of physics is broken by the "double jump"?
So, to repeat, the core of the problem isn't Newton's laws. ... In the case of a double-jump the body's velocity/inertia changes without...
Read more >
Inertial Tail Effects during Righting of Squirrels in Unexpected ...
Interestingly, many animals could use their tail to support righting behavior. By actively moving their tail, which has a given mass and shape,Ā ......
Read more >
Unexpected behaviour when calculating power from moment ...
I can get the torque via a moment report and the value matches an ... even forces seem to work, the only problem...
Read more >
Jumping onto a merry go round (PhysCasts) - YouTube
This PhysCast will look at a problem involving a merry go round with some people jumping onto it.
Read more >
Scroll Bouncing On Your Websites - Smashing Magazine
The CSS property, overscroll-behavior, which was implemented in Chrome on December 2017 and in Firefox on March 2018, is also described inĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found