Skip to content

Commit

Permalink
fix: loop by default
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed May 6, 2024
1 parent b588d5c commit 858c5c0
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions package/src/SkottieView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type SkottieViewProps = NativeSkiaViewProps & {

/**
* A boolean flag indicating whether or not the animation should loop.
* @default false
* @default true
*/
loop?: boolean;

Expand Down Expand Up @@ -71,6 +71,7 @@ export type SkottieViewRef = {
export const Skottie = React.forwardRef<SkottieViewRef, SkottieViewProps>(
(props, ref) => {
const nativeId = useRef(SkiaViewNativeId.current++).current;
const loop = props.loop ?? true;

const skottieAnimation = useMemo(() => {
if (typeof props.source === 'object' && 'fps' in props.source) {
Expand Down Expand Up @@ -168,22 +169,13 @@ export const Skottie = React.forwardRef<SkottieViewRef, SkottieViewProps>(
const initialShouldPlayRef = useRef(shouldPlay);
useEffect(() => {
if (shouldPlay) {
start(props.loop ? undefined : props.onAnimationFinish);
start(loop ? undefined : props.onAnimationFinish);
}

// TODO: support speed prop
// const speed = props.speed ?? 1;
// const duration = (skottieAnimation.duration * 1000) / speed;
}, [
progress,
props.loop,
props.autoPlay,
props.onAnimationFinish,
props.speed,
shouldPlay,
skottieAnimation.duration,
start,
]);
}, [loop, props.onAnimationFinish, shouldPlay, start]);

// Pause the animation
const shouldPause = progress == null && !props.autoPlay;
Expand All @@ -196,8 +188,8 @@ export const Skottie = React.forwardRef<SkottieViewRef, SkottieViewProps>(
// Toggle loop mode
useEffect(() => {
assertSkiaViewApi();
SkiaViewApi.setJsiProperty(nativeId, 'loop', Boolean(props.loop));
}, [nativeId, props.loop]);
SkiaViewApi.setJsiProperty(nativeId, 'loop', loop);
}, [nativeId, loop]);
//#endregion

const { debug = false, ...viewProps } = props;
Expand Down

0 comments on commit 858c5c0

Please sign in to comment.