aholachek / react-animation-comparison

A tour of React animation libraries with a focus on developer experience
https://alex.holachek.com/react-animation-comparison
686 stars 38 forks source link
animation animation-library animejs beginner-friendly comparison popmotion react react-spring

πŸ†• Updated for 2019

What's the most powerful and developer-friendly React animation library?

The goal: replicate this animation in React

example animation

Here's a rundown of what should happen (it's more complex than it appears at first glance!)

  1. When it's first rendered in React, the grid component should animate in from the left, followed by the staggered animation of its child, a list of cards, with each card fading in from above.
  2. New cards can be added individually to the cards array, and should be animated in with a "fade up" animation.
  3. Individual cards can also be removed from the cards array, and should be animated out with a "fade up" animation as they leave.
  4. When the grid component is unmounted, it should wait for its children to animate out before animating itself and leaving the DOM in the opposite direction from where it arrived.
  5. In-progress animations should be appropriately cancelled if the enter/exit state is toggled rapidly.
  6. If the cards were shuffled, they should still animate out with the expected staggered order.

Why it's hard

  1. The sequenced "enter" and "exit" animations of both a parent and its child requires coordination between different components.
  2. The enter and exit animations are not simple mirrors of each other, as some libraries expect.
  3. The positions of the grid and cards should be animated with a spring (or, failing that, with an elastic easing), while opacity changes should have a linear easing.
  4. The cards animating in and out are initially staggered, but adding or removing cards one-by-one should result in a fluid animation with no delay.
  5. The initial staggered entry of cards should have them animating in from the top, but an individual card being added should have its own animation — fading in from the bottom.
  6. Toggling the example rapidly should not create a broken view— cancelled animations should be cleaned up and there shouldn't be any straggler DOM elements left behind.

The results, ordered by preference

  1. πŸ₯‡ react-transition-group & animejs
  1. πŸ₯ˆ framer-motion

    • Of the react-specific animation libraries, I found this one to have the most intuitive API.
    • I do wish it was possible to minimize the wait time between the parent and child animations.
    • my animation attempt
    • my code
    • Framer motion docs
  2. πŸ₯‰ react-spring

  1. react-transition-group & gsap
  1. react-move
  1. velocity-react
  1. react-motion

Run the project locally

  1. yarn or npm install
  2. yarn start or npm start