Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/hooks/useLottieInteractivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const useInitInteractivity = ({
}: InitInteractivity) => {
useEffect(() => {
const wrapper = wrapperRef.current;
let playCount = 0;

if (!wrapper || !animationItem || !actions.length) {
return;
Expand Down Expand Up @@ -117,6 +118,12 @@ export const useInitInteractivity = ({
animationItem.resetSegments(true);
animationItem.play();
}
if (action.type === "playOnce" && playCount === 0) {
// Play: Reset segments and continue playing full animation from current position
animationItem.resetSegments(true);
animationItem.play();
playCount++;
}

if (action.type === "stop") {
// Stop: Stop playback
Expand Down Expand Up @@ -218,6 +225,14 @@ export const useInitInteractivity = ({
animationItem.playSegments(action.frames as AnimationSegment);
}

if (action.type === "playOnce" && playCount === 0) {
if (animationItem.isPaused) {
animationItem.resetSegments(false);
}
animationItem.playSegments(action.frames as AnimationSegment);
playCount++;
}

if (action.type === "stop") {
animationItem.goToAndStop(action.frames[0], true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export type Axis = "x" | "y";
export type Position = { [key in Axis]: number | [number, number] };

export type Action = {
type: "seek" | "play" | "stop" | "loop";

type: "seek" | "play" | "stop" | "loop" | "playOnce";
frames: [number] | [number, number];
visibility?: [number, number];
position?: Position;
Expand Down