Skip to content

Commit 1a1a705

Browse files
committed
fix: useInteractivity adds another wrapping div that is not accessible to the consumer #42
1 parent e4f228a commit 1a1a705

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/components/Lottie.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const Lottie = (props: LottieComponentProps) => {
2222
setSubframe,
2323
getDuration,
2424
destroy,
25+
animationContainerRef,
2526
animationLoaded,
2627
animationItem,
2728
} = useLottie(lottieProps, style);
@@ -43,14 +44,15 @@ const Lottie = (props: LottieComponentProps) => {
4344
setSubframe,
4445
getDuration,
4546
destroy,
47+
animationContainerRef,
4648
animationLoaded,
4749
animationItem,
4850
};
4951
}
5052
}, [props.lottieRef?.current]);
5153

5254
if (interactivity) {
53-
const EnhancedView = useLottieInteractivity({
55+
return useLottieInteractivity({
5456
lottieObj: {
5557
View,
5658
play,
@@ -64,13 +66,12 @@ const Lottie = (props: LottieComponentProps) => {
6466
setSubframe,
6567
getDuration,
6668
destroy,
69+
animationContainerRef,
6770
animationLoaded,
6871
animationItem,
6972
},
7073
...interactivity,
7174
});
72-
73-
return EnhancedView;
7475
}
7576

7677
return View;

src/hooks/useLottie.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ const useLottie = (
335335
setSubframe,
336336
getDuration,
337337
destroy,
338+
animationContainerRef: animationContainer,
338339
animationLoaded,
339340
animationItem: animationInstanceRef.current,
340341
};

src/hooks/useLottieInteractivity.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AnimationSegment } from "lottie-web";
2-
import React, { useEffect, ReactElement, useRef } from "react";
2+
import React, { useEffect, ReactElement } from "react";
33
import { InteractivityProps } from "../types";
44

55
// helpers
@@ -256,10 +256,9 @@ const useLottieInteractivity = ({
256256
}: InteractivityProps): ReactElement => {
257257
const { animationItem, View } = lottieObj;
258258

259-
const wrapperRef = useRef<HTMLDivElement>(null);
260-
useInitInteractivity({ actions, animationItem, mode, wrapperRef });
259+
useInitInteractivity({ actions, animationItem, mode, wrapperRef: lottieObj.animationContainerRef });
261260

262-
return <div ref={wrapperRef}>{View}</div>;
261+
return View;
263262
};
264263

265264
export default useLottieInteractivity;

src/types.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {
22
MutableRefObject,
33
AnimationEventHandler,
4-
ReactElement,
4+
ReactElement, RefObject
55
} from "react";
66
import {
77
AnimationConfigWithData,
@@ -19,13 +19,11 @@ export type LottieRefCurrentProps = {
1919
goToAndStop: (value: number, isFrame?: boolean) => void;
2020
goToAndPlay: (value: number, isFrame?: boolean) => void;
2121
setDirection: (direction: AnimationDirection) => void;
22-
playSegments: (
23-
segments: AnimationSegment | AnimationSegment[],
24-
forceFlag?: boolean,
25-
) => void;
22+
playSegments: (segments: AnimationSegment | AnimationSegment[], forceFlag?: boolean) => void;
2623
setSubframe: (useSubFrames: boolean) => void;
2724
getDuration: (inFrames?: boolean) => number | undefined;
2825
destroy: () => void;
26+
animationContainerRef: RefObject<HTMLDivElement>;
2927
animationLoaded: boolean;
3028
animationItem: AnimationItem | undefined;
3129
};

0 commit comments

Comments
 (0)