Skip to content

Commit

Permalink
fix: useInteractivity adds another wrapping div that is not acces…
Browse files Browse the repository at this point in the history
…sible to the consumer #42
  • Loading branch information
Gamote committed Jan 18, 2022
1 parent e4f228a commit 1a1a705
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/components/Lottie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Lottie = (props: LottieComponentProps) => {
setSubframe,
getDuration,
destroy,
animationContainerRef,
animationLoaded,
animationItem,
} = useLottie(lottieProps, style);
Expand All @@ -43,14 +44,15 @@ const Lottie = (props: LottieComponentProps) => {
setSubframe,
getDuration,
destroy,
animationContainerRef,
animationLoaded,
animationItem,
};
}
}, [props.lottieRef?.current]);

if (interactivity) {
const EnhancedView = useLottieInteractivity({
return useLottieInteractivity({
lottieObj: {
View,
play,
Expand All @@ -64,13 +66,12 @@ const Lottie = (props: LottieComponentProps) => {
setSubframe,
getDuration,
destroy,
animationContainerRef,
animationLoaded,
animationItem,
},
...interactivity,
});

return EnhancedView;
}

return View;
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useLottie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ const useLottie = (
setSubframe,
getDuration,
destroy,
animationContainerRef: animationContainer,
animationLoaded,
animationItem: animationInstanceRef.current,
};
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/useLottieInteractivity.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -256,10 +256,9 @@ const useLottieInteractivity = ({
}: InteractivityProps): ReactElement => {
const { animationItem, View } = lottieObj;

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

return <div ref={wrapperRef}>{View}</div>;
return View;
};

export default useLottieInteractivity;
8 changes: 3 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {
MutableRefObject,
AnimationEventHandler,
ReactElement,
ReactElement, RefObject
} from "react";
import {
AnimationConfigWithData,
Expand All @@ -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<HTMLDivElement>;
animationLoaded: boolean;
animationItem: AnimationItem | undefined;
};
Expand Down

0 comments on commit 1a1a705

Please sign in to comment.