Skip to content
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

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const withDecay = function (
onFrame: decay,
onStart,
callback,
forceRunAnimation: true,
velocity: config.velocity ?? 0,
initialVelocity: 0,
current: 0,
patrycjakalinska marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@ const IS_WEB = isWeb();
export const VELOCITY_EPS = IS_WEB ? 1 / 20 : 1;
export const SLOPE_FACTOR = 0.1;

/*
* The `forceRunAnimation` prop is necessary to run withDecay animation when
* related sharedValue stays as `0`. It allows to skip animation check and start
* animation immediately
*/

export interface DecayAnimation extends Animation<DecayAnimation> {
lastTimestamp: Timestamp;
startTimestamp: Timestamp;
initialVelocity: number;
velocity: number;
current: AnimatableValue;
forceRunAnimation: boolean;
}

export interface InnerDecayAnimation
extends Omit<DecayAnimation, 'current'>,
extends Omit<DecayAnimation, 'current' | 'forceRunAnimation'>,
AnimationObject {
current: number;
springActive?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/src/valueSetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
patrycjakalinska marked this conversation as resolved.
Show resolved Hide resolved
!animation.isHigherOrder &&
!forceUpdate
) {
Expand Down
Loading