Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/playground updates #221

Merged
merged 14 commits into from
Sep 6, 2023
Merged
7 changes: 5 additions & 2 deletions packages/react-player/src/hooks/use-dotlottie-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const useDotLottiePlayer = (
config?: DotLottieConfig<RendererType> & {
lottieRef?: MutableRefObject<DotLottieRefProps | undefined>;
},
): DotLottiePlayer => {
): { dotLottiePlayer: DotLottiePlayer; setDotLottiePlayer: (player: DotLottiePlayer) => void } => {
const [dotLottiePlayer, setDotLottiePlayer] = useState<DotLottiePlayer>(() => {
return new DotLottiePlayer(src, container.current, config);
});
Expand Down Expand Up @@ -234,5 +234,8 @@ export const useDotLottiePlayer = (
};
});

return dotLottiePlayer;
return {
dotLottiePlayer,
setDotLottiePlayer,
};
};
14 changes: 9 additions & 5 deletions packages/react-player/src/react-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import type { RendererSettings, PlayMode } from '@dotlottie/common';
import { PlayerState, PlayerEvents } from '@dotlottie/common';
import { DotLottiePlayer as DotLottiePlayerCommon, PlayerState, PlayerEvents } from '@dotlottie/common';
import React, { useEffect, useRef } from 'react';
import type { MutableRefObject } from 'react';
import { useUpdateEffect } from 'react-use';
Expand Down Expand Up @@ -59,8 +59,7 @@ export const DotLottiePlayer: React.FC<DotLottiePlayerProps> = ({
...props
}) => {
const container = useRef(null);

const dotLottiePlayer = useDotLottiePlayer(src, container, {
const config = {
lottieRef,
renderer,
activeAnimationId,
Expand All @@ -82,7 +81,9 @@ export const DotLottiePlayer: React.FC<DotLottiePlayerProps> = ({
defaultTheme,
light,
activeStateId,
});
};

const { dotLottiePlayer, setDotLottiePlayer } = useDotLottiePlayer(src, container, config);

const currentState = useSelectDotLottieState(dotLottiePlayer, (state) => state.currentState);
const frame = useSelectDotLottieState(dotLottiePlayer, (state) => state.frame);
Expand Down Expand Up @@ -182,7 +183,10 @@ export const DotLottiePlayer: React.FC<DotLottiePlayerProps> = ({

useUpdateEffect(() => {
if (typeof src !== 'undefined') {
dotLottiePlayer.updateSrc(src);
const dl = new DotLottiePlayerCommon(src, container.current, config);

dl.load();
setDotLottiePlayer(dl);
afsalz marked this conversation as resolved.
Show resolved Hide resolved
}
}, [src]);

Expand Down