Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandra Cynk committed Oct 19, 2023
2 parents 7b5f66f + 4801045 commit 3a27ddd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
14 changes: 5 additions & 9 deletions src/reanimated2/animation/spring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
criticallyDampedSpringCalculations,
isAnimationTerminatingCalculation,
scaleZetaToMatchClamps,
isConfigValid,
checkIfConfigIsValid,
} from './springUtils';

// TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.
Expand Down Expand Up @@ -60,7 +60,7 @@ export const withSpring = ((
skipAnimation: false,
};

config.skipAnimation = !isConfigValid(config);
config.skipAnimation = !checkIfConfigIsValid(config);

if (config.duration === 0) {
config.skipAnimation = true;
Expand All @@ -82,13 +82,9 @@ export const withSpring = ((
}

if (config.skipAnimation) {
// If we use duration we want to wait the provided time before stopping
if (config.useDuration) return false;
else {
animation.current = toValue;
animation.lastTimestamp = 0;
return true;
}
animation.current = toValue;
animation.lastTimestamp = 0;
return true;
}
const { lastTimestamp, velocity } = animation;

Expand Down
23 changes: 4 additions & 19 deletions src/reanimated2/animation/springUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export interface InnerSpringAnimation
toValue: number;
current: number;
}
export function isConfigValid(config: DefaultSpringConfig): boolean {
export function checkIfConfigIsValid(config: DefaultSpringConfig): boolean {
'worklet';
let errorMessage: string | null = null;
let errorMessage = '';

(
[
Expand All @@ -77,34 +77,19 @@ export function isConfigValid(config: DefaultSpringConfig): boolean {
).forEach((prop) => {
const value = config[prop];
if (value <= 0) {
if (errorMessage === null) {
errorMessage = '';
}
errorMessage += `, ${prop} must be grater than zero but got ${value}`;
}
});

if (config.duration < 0) {
if (errorMessage === null) {
errorMessage = '';
}

errorMessage += `, duration can't be negative, got ${config.duration}`;
}

if (config.clamp && config.clamp[0] > config.clamp[1]) {
if (errorMessage === null) {
errorMessage = '';
}
errorMessage +=
'clamp is incorrect, lower bound should not be greater than the upper band';
}

if (errorMessage !== null) {
if (errorMessage !== '') {
console.warn('[Reanimated] Invalid spring config' + errorMessage);
}

return errorMessage === null;
return errorMessage === '';
}

function bisectRoot({
Expand Down

0 comments on commit 3a27ddd

Please sign in to comment.