-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix:withDecay
animation not starting if inital value is set to 0
#6769
base: main
Are you sure you want to change the base?
fix:withDecay
animation not starting if inital value is set to 0
#6769
Conversation
@@ -31,6 +31,7 @@ export function valueSetter<Value>( | |||
// built in animations that are not higher order(withTiming, withSpring) hold target value in .current | |||
if ( | |||
mutable._value === animation.current && | |||
!animation.forceRunAnimation && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like this check has a purpose (explained above), does introducing this flag not defeat that purpose? i think this needs to be rethought more holistically with the above comment in mind
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear i'm not a maintainer, just thinking based on the code
@@ -113,6 +113,7 @@ export const withDecay = function ( | |||
onFrame: decay, | |||
onStart, | |||
callback, | |||
forceRunAnimation: true, | |||
velocity: config.velocity ?? 0, | |||
initialVelocity: 0, | |||
current: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding that artificial prop, we should calculate the finish position like we do for withTiming
, for example. You can see how it's done here: https://github.com/software-mansion/react-native-reanimated/blob/main/packages/react-native-reanimated/src/animation/timing.ts#L154. This solution should be clearer and simpler
Summary
This PR introduces a new property
forceRunAnimation
to ourDecayAnimation
object. It allows us to skip conditional check that preventedwithDecay
from running if the initial value was set to0
.Fixes #6680.
Test plan
Run code snippet in React Native Paper example 🚀
Code snippet used in issue