|
1 | | -# What's the most developer-friendly React animation library? |
| 1 | +### 🚨 Updated for 2019 |
2 | 2 |
|
3 | | -### The Goal: to replicate this animation on entering and exiting react components: |
| 3 | +# What's the most powerful and developer-friendly React animation library? |
4 | 4 |
|
5 | | - |
| 5 | +### The Task: Replicate this animation in React |
6 | 6 |
|
7 | | -1. Initially, when it is first rendered in React, the grid should animate in, followed by the staggered animation of its children cards. |
8 | | -2. New cards can be added individually to the cards array and should be animated in. |
9 | | -3. Cards can be removed from the cards array and should be animated out as they leave. |
10 | | -4. When the grid is removed from the DOM, it should wait for its children to animate out before animating itself and leaving the DOM |
| 7 | + |
| 8 | + |
| 9 | +Here's a rundown of what should happen (it's more complex than it appears at first glance!) |
| 10 | + |
| 11 | +1. When it's first rendered in React, the grid component should animate in, followed by the staggered animation of its child, a list of cards. |
| 12 | +2. New cards can be added individually to the cards array, and should be animated in. |
| 13 | +3. Individual cards can also be removed from the cards array, and should be animated out as they leave. |
| 14 | +4. When the grid component is unmounted, it should wait for its children to animate out before animating itself and leaving the DOM. |
11 | 15 | 5. In-progress animations should be appropriately cancelled if the enter/exit state is toggled rapidly. |
12 | | -6. _Stretch goal_: When shuffled, the cards should smoothly transition to their new positions. |
| 16 | +6. If the cards were shuffled, they should still animate out with the expected staggered order. |
13 | 17 |
|
14 | 18 | ### Why It's Hard |
15 | | -The example sequences the "enter" and "exit" animations of both a parent and its child elements, requiring coordination between different components. Not only that, but the enter and exit animations are not simple mirrors of each other (as many libraries expect). The positions of the grid and cards should be animated with a slightly gooey-feeling elastic easing, but opacity changes should have a linear easing. The cards animating in and out are initially staggered, but adding or removing cards one-by-one should also result in a fluid animation with no delay. |
16 | 19 |
|
17 | | -### The Arbitrary Limit: |
18 | | -Spend as little time as possible learning a library's API and trying to implement the animation. |
| 20 | +1. The sequenced "enter" and "exit" animations of both a parent and its child requires coordination between different components. |
| 21 | +2. The enter and exit animations are not simple mirrors of each other, as some libraries expect. |
| 22 | +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 |
| 23 | +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. |
| 24 | +5. 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. |
19 | 25 |
|
20 | 26 | ### The Results, Ordered by Preference |
21 | 27 |
|
22 | | -1. 🥇 **react-transition-group & animejs** |
23 | | - |
24 | | -* Using `react-transition-group` and a JavaScript animation library ended up being my favorite technique, because it offered the flexibility to make custom, sequenced transitions. |
25 | | -* `Animejs` is lightweight and open source, and I find the imperative API more intuitive than the typical React approach for multiple complex animations. |
26 | | -* [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Transition-Group%20%2B%20animejs&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
27 | | -* [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-transition-group-anime-example.js) |
28 | | -* [React transition group docs](http://reactcommunity.org/react-transition-group/) |
29 | | -* [Anime docs](https://github.com/juliangarnier/anime) |
30 | | - |
31 | | -2. 🥈 **react-pose** |
32 | | -* This was the easiest example to get up and running. |
33 | | -* The automatic FLIP animations are pretty cool (try shuffling the cards to see it in action), and the default easings made the animations look great. |
34 | | -* I liked how the library automatically applies transitions to DOM elements for you instead of just tweening values and making you handle the style updates yourself. |
35 | | -* The docs are good. |
36 | | -* 🐛 **Bug** Interrupted repeat animations are implemented incorrectly (extra ghost elements are animated in if the previous animation did not fully complete). Try toggling the example multiple times fairly quickly to see what I mean. |
37 | | -* 🐛 **Bug** Shuffling the cards will result in an out-of-order staggered exit transition. |
38 | | -* This would have been my #1 choice were it not for the bugs. |
39 | | -* [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=Popmotion%20Pose&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
40 | | -* [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/popmotion-pose-example.js) |
41 | | -* [Popmotion Pose docs](https://popmotion.io/pose/) |
42 | | - |
43 | | -3. 🥉 **react-transition-group & gsap** |
44 | | - |
45 | | -* Basically the same as the `animejs` example, just with the animation library swapped out. `GSAP` has a less permissive license and it's older and heavier than `animejs`, but it's battle-tested and powerful. |
46 | | -* [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Transition-Group%20%2B%20GSAP&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
47 | | -* [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-transition-group-gsap-example.js) |
48 | | -* [React transition group docs](http://reactcommunity.org/react-transition-group/) |
49 | | -* [GSAP docs](https://greensock.com/docs) |
50 | | - |
51 | | -4. **react-spring** |
52 | | - |
53 | | -* This newcomer melds the powers of `react-motion` and `react-animated` into one library (and the docs have tons of cool examples). |
54 | | -* `React-spring`'s keyframes API, which I used in my example to sequence animations makes great use of async/await but is marked as experimental in the docs. |
55 | | -* 🐛 **Bug** There is a serious, window-crashing memory leak created when adding new cards, though this could be something I'm doing incorrectly. |
56 | | -* I couldn't quite get the whole thing working the way I wanted to. |
57 | | -* [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Spring&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
58 | | -* [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-spring-example.js) |
59 | | -* [react-spring docs](https://github.com/drcmda/react-spring) |
| 28 | +1. 🥇 **react-transition-group & animejs** |
| 29 | + |
| 30 | +- Using `react-transition-group` and a JavaScript animation library ended up being my favorite technique, because it offers total flexibility and control, at the cost of additional complexity. |
| 31 | +- `Animejs` is lightweight and open source, and I find the imperative API more intuitive than the typical React approach for coordinated, complex animations. |
| 32 | +- [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Transition-Group%20%2B%20animejs&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
| 33 | +- [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-transition-group-anime-example.js) |
| 34 | +- [React transition group docs](http://reactcommunity.org/react-transition-group/) |
| 35 | +- [Anime docs](https://github.com/juliangarnier/anime) |
| 36 | + |
| 37 | +1. 🥈 **react-spring** |
| 38 | + |
| 39 | +- If you'd prefer to use a React-specific library, I recommend `react-spring`. |
| 40 | +- 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! |
| 41 | +- The library is in active development and supports a wide variety of use cases. |
| 42 | +- I was unable to get the cards to animate in and out in opposite directions, but that is a minor limitation. |
| 43 | +- [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Spring&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
| 44 | +- [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-spring-example.js) |
| 45 | +- [react-spring docs](https://react-spring.surge.sh/) |
| 46 | + |
| 47 | +1. 🥉 **react-pose** |
| 48 | + |
| 49 | +- A year ago, this was my favorite option, but now the number of bugs make me hesitant to recommend it. |
| 50 | +- The good: |
| 51 | + - the library API is very user friendly. |
| 52 | + - I liked how the library automatically applies transitions to DOM elements for you instead of just tweening values and making you handle the style updates yourself. |
| 53 | +- The bad (bugs): |
| 54 | + - Interrupted repeat animations are implemented incorrectly (extra ghost elements are animated in if the previous animation did not fully complete). Try toggling the example multiple times fairly quickly to see what I mean. [Link to issue](https://github.com/Popmotion/popmotion/issues/318) |
| 55 | + - Shuffling the cards will result in an out-of-order staggered exit transition. [Link to issue](https://github.com/Popmotion/popmotion/issues/319) |
| 56 | + - (Introduced in v4): Individual card animations no longer work correctly. |
| 57 | + |
| 58 | +- [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=Popmotion%20Pose&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
| 59 | +- [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/popmotion-pose-example.js) |
| 60 | +- [Popmotion Pose docs](https://popmotion.io/pose/) |
| 61 | + |
| 62 | +4. 🥉 **react-transition-group & gsap** |
| 63 | + |
| 64 | +- Basically the same as the `animejs` example, just with the animation library swapped out. `GSAP` has a less permissive license and it's older and heavier than `animejs`, but it's battle-tested and powerful. |
| 65 | +- [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Transition-Group%20%2B%20GSAP&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
| 66 | +- [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-transition-group-gsap-example.js) |
| 67 | +- [React transition group docs](http://reactcommunity.org/react-transition-group/) |
| 68 | +- [GSAP docs](https://greensock.com/docs) |
60 | 69 |
|
61 | 70 | 5. **react-move** |
62 | 71 |
|
63 | | -* 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. |
64 | | -* [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Move&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
65 | | -* [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-move-example.js) |
66 | | -* [react-move docs](https://react-move-example.js.org/#/) |
| 72 | +- 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. |
| 73 | +- [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Move&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
| 74 | +- [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-move-example.js) |
| 75 | +- [react-move docs](https://react-move-example.js.org/#/) |
67 | 76 |
|
68 | 77 | 6. **velocity-react** |
69 | 78 |
|
70 | | -* 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. |
71 | | -* At one point, this library might have been one of the better options for animating in React, but now with `popmotion-pose`, `react-spring`, and `react-transition-group v2` there are more powerful, updated alternatives with better documentation. |
72 | | -* [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=Velocity-React&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
73 | | -* [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/velocity-react-example.js) |
74 | | -* [velocity-react docs](https://github.com/google-fabric/velocity-react) |
75 | | - |
76 | | -7. **react-motion** |
| 79 | +- 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. |
| 80 | +- 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. |
| 81 | +- [my animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=Velocity-React&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
| 82 | +- [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/velocity-react-example.js) |
| 83 | +- [velocity-react docs](https://github.com/google-fabric/velocity-react) |
77 | 84 |
|
78 | | -* An hour and a half wasn't enough time for me to understand the intricacies of this physics-based animation library and to create the example animation. |
79 | | -* [my sad animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Motion&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
80 | | -* [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-motion-example.js) |
81 | | -* [react motion docs](https://github.com/chenglou/react-motion) |
| 85 | +1. **react-motion** |
82 | 86 |
|
| 87 | +- I found this library very difficult to use when implementing the example. |
| 88 | +- [my sad animation attempt](https://alex.holachek.com/react-animation-comparison/?selectedKind=Animation%20Examples&selectedStory=React-Motion&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel) |
| 89 | +- [my code](https://github.com/aholachek/react-animation-comparison/blob/master/src/react-motion-example.js) |
| 90 | +- [react motion docs](https://github.com/chenglou/react-motion) |
83 | 91 |
|
84 | 92 | ## Run the project locally |
85 | 93 |
|
86 | 94 | 1. `yarn` or `npm install` |
87 | 95 | 2. `yarn start` or `npm start` |
88 | | - |
|
0 commit comments