• Stars
    star
    685
  • Rank 65,982 (Top 2 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tour of React animation libraries with a focus on developer experience

πŸ†• 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
  • Using react-transition-group and a vanilla JavaScript animation library ended up being my favorite technique, because it offers total flexibility and control, at the cost of some additional complexity.
  • Animejs is lightweight and open source, and I find its imperative API more intuitive than the typical React approach for coordinated, complex animations.
  • my animation attempt
  • my code
  • React transition group docs
  • Anime docs
  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
  1. πŸ₯‰ react-spring
  • The library's use of the hooks API is very concise and expressiveβ€”it took only about 70 lines of code to implement the example!
  • The library is in active development and supports a wide variety of use cases.
  • I was unable to get the cards to have different animations depending on whether they were arriving as a group ("fade in down") or as an individually added card ("fade in up").
  • my animation attempt
  • my code
  • react-spring docs
  1. react-transition-group & gsap
  1. react-move
  • A lightweight library that helps D3 and React work together. It ended up not being quite flexible enough for the needs of this task, though if the demo featured more traditionally D3-like interactions it would have been great.
  • my animation attempt
  • my code
  • react-move docs
  1. velocity-react
  • A straightforward option that got me far but then ended up tripping me up when it came time to get the nested leave animations working.
  • At one point, this library might have been one of the better options for animating in React, but now with react-spring, popmotion-pose, and react-transition-group v2 there are more powerful, updated alternatives with better documentation.
  • my animation attempt
  • my code
  • velocity-react docs
  1. react-motion

Run the project locally

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

More Repositories

1

react-flip-toolkit

A lightweight magic-move library for configurable layout transitions
TypeScript
3,773
star
2

mobile-first-animation

Gesture-driven animation on the mobile web (React Conf 2019)
JavaScript
2,069
star
3

animate-css-grid

Painless transitions for CSS Grid
TypeScript
1,300
star
4

bundle-wizard

Magically easy insight into the JavaScript loaded by a web app
JavaScript
684
star
5

react-stripe-menu

A clone of Stripe's animated menu using React, Styled Components and React-Flip-Toolkit
JavaScript
458
star
6

storybook-mobile

[Deprecated] A storybook addon that helps you create truly mobile-friendly components
JavaScript
107
star
7

react-flip-toolkit-router-example

Meaningful transitions with react-router-v4 and react-flip-toolkit
JavaScript
102
star
8

aholachek.github.io

My website
JavaScript
53
star
9

redux-usage-report

A Redux Devtools monitor to audit your app's usage of the store
JavaScript
41
star
10

react-animations-from-scratch

JavaScript
20
star
11

react-2019-interactive-workbook

Learn new features of React interactively
JavaScript
18
star
12

scrollbounce

Add a subtle bounce effect on mobile when the user scrolls (WIP)
JavaScript
17
star
13

react-spring-workshop

Learn by building small animations
JavaScript
9
star
14

gif-search

Take a selfie, get a gif
CSS
8
star
15

github-actions-examples

Tiny test repo for github actions
HTML
7
star
16

review-fetch

Code exercises to help you solidify your knowledge of fetch
JavaScript
6
star
17

react-fancy-tween-circular-progress

A configurable circular progress bar with color and number animation
JavaScript
3
star
18

virgin-airlines

A prototype for a Virgin Airlines mobile ticket site redesign
JavaScript
1
star
19

overdrive-experiment

JavaScript
1
star
20

tap-demo

JavaScript
1
star
21

npm-script-starter

A basic front end development setup using npm scripts
JavaScript
1
star
22

spring-example

JavaScript
1
star
23

meaningful-layout-transitions

JavaScript
1
star
24

gif-search-backend

JavaScript
1
star
25

basic-postcss-setup

A simple npm scripts-powered set up for experimenting with Shoelace.css and postcss in general
HTML
1
star