Skip to content

Commit 80c96e3

Browse files
committed
feat(reanimated): Add placeholder withSequence function to prevent errors
Also a bit of cleanup of withRepeat and withDelay functions
1 parent 94fc91c commit 80c96e3

5 files changed

Lines changed: 52 additions & 38 deletions

File tree

.changeset/icy-ways-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plextv/react-lightning-plugin-reanimated": patch
3+
---
4+
5+
feat: Add a placeholder withSequence
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
import type {
2-
AnimationObject,
3-
withDelay as withDelayRN,
4-
} from 'react-native-reanimated-original';
1+
import type { AnimatedValue } from '../animation/AnimatedValue';
52

63
export type WithDelayFn = (
7-
...args: Parameters<typeof withDelayRN>
8-
) => AnimationObject;
4+
delayMs: number,
5+
animation: AnimatedValue,
6+
reduceMotion?: string,
7+
) => AnimatedValue;
98

10-
export const withDelay: WithDelayFn = (
11-
_delayMs,
12-
nextAnimation,
13-
_reduceMotion,
14-
): AnimationObject => {
15-
// withTiming and withSpring supports `delay`. The client should pass it directly
16-
return typeof nextAnimation === 'function'
17-
? (nextAnimation as () => AnimationObject)()
18-
: (nextAnimation as AnimationObject);
9+
export const withDelay: WithDelayFn = (delayMs, animation) => {
10+
animation.lngAnimation.delay = delayMs;
11+
12+
return animation;
1913
};
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
11
import type { AnimatedValue } from '../animation/AnimatedValue';
2-
import type { AnimationType } from '../types/AnimationType';
32

4-
export function withRepeat(
3+
export type WithRepeatFn = (
4+
animation: AnimatedValue,
5+
repeatCount?: number,
6+
reverse?: boolean,
7+
) => AnimatedValue;
8+
9+
export const withRepeat: WithRepeatFn = (
510
animation: AnimatedValue,
611
repeatCount = 2,
712
reverse = false,
8-
): {
9-
isHigherOrder: boolean;
10-
onFrame: () => void;
11-
onStart: () => void;
12-
reps: number;
13-
current: AnimatedValue<AnimationType>;
14-
callback: () => void;
15-
startValue: number;
16-
reduceMotion: boolean;
17-
} {
13+
) => {
14+
animation.lngAnimation.loop = repeatCount === -1;
1815
animation.lngAnimation.repeat = repeatCount;
1916
animation.lngAnimation.stopMethod = reverse ? 'reverse' : false;
2017

21-
return {
22-
isHigherOrder: true,
23-
onFrame: (): void => {},
24-
onStart: (): void => {},
25-
reps: 0,
26-
current: animation,
27-
callback: (): void => {},
28-
startValue: 0,
29-
reduceMotion: false,
30-
};
31-
}
18+
return animation;
19+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type {
2+
AnimatableValue,
3+
AnimationObject,
4+
withSequence as withSequenceRN,
5+
} from 'react-native-reanimated-original';
6+
7+
export function withSequence(
8+
_reduceMotion: string,
9+
...animations: AnimatableValue[]
10+
): ReturnType<typeof withSequenceRN> {
11+
console.error(
12+
'[Reanimated] withSequence is unsupported. Consider building a custom animation in lightning directly instead. Returning just the first animation.',
13+
);
14+
15+
const returnAnimation = animations[0];
16+
17+
if (!returnAnimation) {
18+
throw new Error(
19+
'[Reanimated] withSequence requires at least one animation.',
20+
);
21+
}
22+
23+
return typeof returnAnimation === 'function'
24+
? (returnAnimation as () => AnimationObject)()
25+
: (returnAnimation as AnimationObject);
26+
}

packages/plugin-reanimated/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export { useAnimatedStyle } from './exports/useAnimatedStyle';
5252
export { useComposedEventHandler } from './exports/useComposedEventHandler';
5353
export { withDelay } from './exports/withDelay';
5454
export { withRepeat } from './exports/withRepeat';
55+
export { withSequence } from './exports/withSequence';
5556
export { withSpring } from './exports/withSpring';
5657
export { withTiming } from './exports/withTiming';
5758

0 commit comments

Comments
 (0)