diff --git a/src/components/Lottie.ts b/src/components/Lottie.ts index db7e02c..ae0fae5 100644 --- a/src/components/Lottie.ts +++ b/src/components/Lottie.ts @@ -22,6 +22,7 @@ const Lottie = (props: LottieComponentProps) => { setSubframe, getDuration, destroy, + animationContainerRef, animationLoaded, animationItem, } = useLottie(lottieProps, style); @@ -43,6 +44,7 @@ const Lottie = (props: LottieComponentProps) => { setSubframe, getDuration, destroy, + animationContainerRef, animationLoaded, animationItem, }; @@ -50,7 +52,7 @@ const Lottie = (props: LottieComponentProps) => { }, [props.lottieRef?.current]); if (interactivity) { - const EnhancedView = useLottieInteractivity({ + return useLottieInteractivity({ lottieObj: { View, play, @@ -64,13 +66,12 @@ const Lottie = (props: LottieComponentProps) => { setSubframe, getDuration, destroy, + animationContainerRef, animationLoaded, animationItem, }, ...interactivity, }); - - return EnhancedView; } return View; diff --git a/src/hooks/useLottie.tsx b/src/hooks/useLottie.tsx index 12184c6..efd93dd 100644 --- a/src/hooks/useLottie.tsx +++ b/src/hooks/useLottie.tsx @@ -335,6 +335,7 @@ const useLottie = ( setSubframe, getDuration, destroy, + animationContainerRef: animationContainer, animationLoaded, animationItem: animationInstanceRef.current, }; diff --git a/src/hooks/useLottieInteractivity.tsx b/src/hooks/useLottieInteractivity.tsx index e706e32..b72dfea 100644 --- a/src/hooks/useLottieInteractivity.tsx +++ b/src/hooks/useLottieInteractivity.tsx @@ -1,5 +1,5 @@ import { AnimationSegment } from "lottie-web"; -import React, { useEffect, ReactElement, useRef } from "react"; +import React, { useEffect, ReactElement } from "react"; import { InteractivityProps } from "../types"; // helpers @@ -256,10 +256,9 @@ const useLottieInteractivity = ({ }: InteractivityProps): ReactElement => { const { animationItem, View } = lottieObj; - const wrapperRef = useRef(null); - useInitInteractivity({ actions, animationItem, mode, wrapperRef }); + useInitInteractivity({ actions, animationItem, mode, wrapperRef: lottieObj.animationContainerRef }); - return
{View}
; + return View; }; export default useLottieInteractivity; diff --git a/src/types.ts b/src/types.ts index 1d4641f..bec93ef 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ import React, { MutableRefObject, AnimationEventHandler, - ReactElement, + ReactElement, RefObject } from "react"; import { AnimationConfigWithData, @@ -19,13 +19,11 @@ export type LottieRefCurrentProps = { goToAndStop: (value: number, isFrame?: boolean) => void; goToAndPlay: (value: number, isFrame?: boolean) => void; setDirection: (direction: AnimationDirection) => void; - playSegments: ( - segments: AnimationSegment | AnimationSegment[], - forceFlag?: boolean, - ) => void; + playSegments: (segments: AnimationSegment | AnimationSegment[], forceFlag?: boolean) => void; setSubframe: (useSubFrames: boolean) => void; getDuration: (inFrames?: boolean) => number | undefined; destroy: () => void; + animationContainerRef: RefObject; animationLoaded: boolean; animationItem: AnimationItem | undefined; };