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

[CHORE] use UNSAFE_ #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jarretmoses
Copy link

Remove warning pertaining to React 17.x

@BrOrlandi
Copy link

This PR updates fix it: #109

@dubzzz
Copy link

dubzzz commented Dec 8, 2020

Great change 👍 Any plan to merge it soon?

@multivoltage
Copy link

Why this is not merged?

@mikejdegroot
Copy link

  • 1

@perrmadiafrrian
Copy link

Bumping

@jarretmoses
Copy link
Author

jarretmoses commented Aug 6, 2021

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants