You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/09.1-animation.md
+37-15Lines changed: 37 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,20 @@ prev: addons.html
7
7
next: two-way-binding-helpers.html
8
8
---
9
9
10
-
`ReactTransitions` is an easy way to perform CSS transitions and animations when a React component enters or leaves the DOM. It's inspired by the excellent [ng-animate](http://www.nganimate.org/) library.
10
+
React provides a `ReactTransitionGroup` addon component as a low-level API for animation, and a `ReactCSSTransitionGroup` for easily implementing basic CSS animations and transitions.
11
11
12
-
## Getting Started
12
+
## High-level API: `ReactCSSTransitionGroup`
13
13
14
-
`ReactTransitionGroup` is the interface to `ReactTransitions`. This is a simple element that wraps all of the components you are interested in animating. Here's an example where we fade list items in and out.
14
+
`ReactCSSTransitionGroup` is based on `ReactTransitionGroup` and is an easy way to perform CSS transitions and animations when a React component enters or leaves the DOM. It's inspired by the excellent [ng-animate](http://www.nganimate.org/) library.
15
+
16
+
### Getting Started
17
+
18
+
`ReactCSSTransitionGroup` is the interface to `ReactTransitions`. This is a simple element that wraps all of the components you are interested in animating. Here's an example where we fade list items in and out.
15
19
16
20
```javascript{22-24}
17
21
/** @jsx React.DOM */
18
22
19
-
var ReactTransitionGroup = React.addons.TransitionGroup;
23
+
var ReactCSSTransitionGroup = React.addons.TransitionGroup;
20
24
21
25
var TodoList = React.createClass({
22
26
getInitialState: function() {
@@ -43,16 +47,16 @@ var TodoList = React.createClass({
In this component, when a new item is added to `ReactTransitionGroup` it will get the `example-enter` CSS class and the `example-enter-active` CSS class added in the next tick. This is a convention based on the `transitionName` prop.
59
+
In this component, when a new item is added to `ReactCSSTransitionGroup` it will get the `example-enter` CSS class and the `example-enter-active` CSS class added in the next tick. This is a convention based on the `transitionName` prop.
56
60
57
61
You can use these classes to trigger a CSS animation or transition. For example, try adding this CSS and adding a new list item:
58
62
@@ -67,7 +71,7 @@ You can use these classes to trigger a CSS animation or transition. For example,
67
71
}
68
72
```
69
73
70
-
You'll notice that when you try to remove an item `ReactTransitionGroup` keeps it in the DOM. If you're using an unminified build of React with add-ons you'll see a warning that React was expecting an animation or transition to occur. That's because `ReactTransitionGroup` keeps your DOM elements on the page until the animation completes. Try adding this CSS:
74
+
You'll notice that when you try to remove an item `ReactCSSTransitionGroup` keeps it in the DOM. If you're using an unminified build of React with add-ons you'll see a warning that React was expecting an animation or transition to occur. That's because `ReactCSSTransitionGroup` keeps your DOM elements on the page until the animation completes. Try adding this CSS:
71
75
72
76
```css
73
77
.example-leave {
@@ -80,18 +84,36 @@ You'll notice that when you try to remove an item `ReactTransitionGroup` keeps i
80
84
}
81
85
```
82
86
83
-
## Disabling Animations
87
+
### Disabling Animations
88
+
89
+
You can disable animating `enter` or `leave` animations if you want. For example, sometimes you may want an `enter` animation and no `leave` animation, but `ReactCSSTransitionGroup` waits for an animation to complete before removing your DOM node. You can add `transitionEnter={false}` or `transitionLeave={false}` props to `ReactCSSTransitionGroup` to disable these animations.
90
+
91
+
## Low-level API: `ReactTransitionGroup`
92
+
93
+
`ReactTransitionGroup` is the basis for animations. When children are declaratively added or removed from it (as in the example above) special lifecycle hooks are called on them.
94
+
95
+
### `componentWillEnter(callback)`
96
+
97
+
This is called at the same time as `componentDidMount()` for components added to an existing `TransitionGroup`. It will block other animations from occurring until `callback` is called. It will not be called on the initial render of a `TransitionGroup`.
98
+
99
+
### `componentDidEnter()`
100
+
101
+
This is called after the `callback` function that was passed to `componentWillEnter` is called.
102
+
103
+
### `componentWillLeave(callback)`
104
+
105
+
This is called when the child has been removed from the `ReactTransitionGroup`. Though the child has been removed, `ReactTransitionGroup` will keep it in the DOM until `callback` is called.
106
+
107
+
### `componentDidLeave()`
84
108
85
-
You can disable animating `enter` or `leave` animations if you want. For example, sometimes you may want an `enter` animation and no `leave` animation, but `ReactTransitionGroup` waits for an animation to complete before removing your DOM node. You can add `transitionEnter={false}` or `transitionLeave={false}` props to `ReactTransitionGroup` to disable these animations.
109
+
This is called when the `willLeave``callback` is called (at the same time as `componentWillUnmount`).
86
110
87
-
## Rendering a Different Component
111
+
###Rendering a Different Component
88
112
89
113
By default `ReactTransitionGroup` renders as a `span`. You can change this behavior by providing a `component` prop. For example, here's how you would render a `<ul>`:
0 commit comments