yanggwangseong / family-social

1 stars 0 forks source link

[FEAT-FE] lottie-react 'requestanimationframe' handler took #59

Closed yanggwangseong closed 1 year ago

yanggwangseong commented 1 year ago

๐Ÿ’ก ์ด์Šˆ ์ œ๋ชฉ

lottie-react 'requestanimationframe' handler took. animation์„ ๋ฌดํ•œ์ • ํ˜ธ์ถœํ•˜๋ฉด์„œ ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜

โœจ ์ด์Šˆ ์„ค๋ช…

import Lottie, { LottieRefCurrentProps } from 'lottie-react';

...

const lottieRef = useRef<LottieRefCurrentProps>(null);

const handleLike = () => {
        if (lottieRef.current) {
            lottieRef.current.play();
            if (lottieRef.current?.animationContainerRef.current) {
                lottieRef.current.animationContainerRef.current.style.visibility =
                    'visible';
            }
        }

};
useEffect(() => {
    if (lottieRef.current?.animationContainerRef.current) {
        lottieRef.current.animationContainerRef.current.style.visibility =
                'hidden';
    }
});

const handleLottieComplete = () => {
        if (lottieRef.current) {
            lottieRef.current.stop();
            if (lottieRef.current?.animationContainerRef.current) {
                lottieRef.current.animationContainerRef.current.style.visibility =
                    'hidden';
            }

        }
};

return(
     ...
     <Lottie
        className={styles.lottie_container}
        animationData={heartAnimation}
        loop={false}
        lottieRef={lottieRef}
        onComplete={handleLottieComplete}
    />
     ...
)

๐ŸŽฏ ์ด์Šˆ ์ƒ์„ฑ ํ›„ ํ™•์ธ ๋‚ด์šฉ