react-lottie icon indicating copy to clipboard operation
react-lottie copied to clipboard

[CHORE] use UNSAFE_

Open jarretmoses opened this issue 4 years ago • 6 comments

Remove warning pertaining to React 17.x

jarretmoses avatar Aug 12 '20 19:08 jarretmoses

This PR updates fix it: https://github.com/chenqingspring/react-lottie/pull/109

BrOrlandi avatar Oct 18 '20 15:10 BrOrlandi

Great change 👍 Any plan to merge it soon?

dubzzz avatar Dec 08 '20 11:12 dubzzz

Why this is not merged?

multivoltage avatar Apr 08 '21 13:04 multivoltage

  • 1

mikejdegroot avatar Apr 14 '21 13:04 mikejdegroot

Bumping

perrmadiafrrian avatar Aug 06 '21 07:08 perrmadiafrrian

This repo seems to no longer be maintained. Id suggest moving to https://github.com/airbnb/lottie-web as I did. I can give an example of how I used it here

import {
  useRef,
  useEffect,
  forwardRef,
  useImperativeHandle,
} from 'react';
import lottie, { AnimationConfigWithPath, AnimationItem } from 'lottie-web';

const Lottie = ({
  path,
  className = '',
  animationClassName = '',
  loop = false,
  renderer = 'svg',
  onComplete,
  speed,
  viewBoxOnly,
  testId = 'dk-lottie',
}: Props, ref: Ref) => {
  const containerRef = useRef(null);
  const animationRef = useRef<AnimationItem | null>(null);

  useEffect(() => {
    const rendererSettings = { viewBoxOnly, className: animationClassName.trim() };
    const loadAnimationConfig = {
      container: containerRef.current!,
      renderer,
      path,
      loop,
      autoplay: false,
      rendererSettings,
    };

    const animationCallback = () => {
      if (onComplete) {
        onComplete();
      }
    };

    animationRef.current = lottie.loadAnimation(loadAnimationConfig);

    /*
      If you want to be able to stop/play the instance through the animation ref, autoplay has to be set to false
      the animationRef.current.play() below is starting the animation on componentDidMount
      the equivalent of setting autoplay = true
    */

    animationRef.current!.play();

    if (speed) {
      animationRef.current!.setSpeed(speed);
    }

    animationRef.current!.addEventListener('complete', animationCallback);

    return () => {
      animationRef.current!.removeEventListener('complete', animationCallback);
      animationRef.current!.destroy();
    };
  });

  useImperativeHandle(ref, () => ({
    play: (name?: string) => {
      animationRef.current!.play(name);
    },
    stop: (name?: string) => {
      animationRef.current!.stop(name);
    },
  }));

  return (
    <div
      ref={containerRef}
      className={`dk-lottie ${className.trim()}`.trim()}
      data-testid={testId}
    />
  );
};

export const DKLottie = forwardRef(Lottie);

jarretmoses avatar Aug 06 '21 16:08 jarretmoses