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: readme.md
+52-28Lines changed: 52 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,26 +5,27 @@
5
5
npm install react-spring
6
6
7
7
# Table of Contents 👇
8
-
*[Installation](#installation-)
9
-
*[Why](#why-)
10
-
*[Overview](#overview-)
11
-
*[API Overview](#api-overview-)
12
-
*[Springs and Interpolation](#springs-and-interpolation)
13
-
*[Render Props](#render-props)
14
-
*[Native rendering](#native-rendering-demo)
15
-
*[Transitions](#transitions)
16
-
*[Parallax and page transitions](#parallax-and-page-transitions)
17
-
*[License](#license-)
8
+
9
+
*[Installation](#installation-)
10
+
*[Why](#why-)
11
+
*[Overview](#overview-)
12
+
*[API Overview](#api-overview-)
13
+
*[Springs and Interpolation](#springs-and-interpolation)
14
+
*[Render Props](#render-props)
15
+
*[Native rendering](#native-rendering-demo)
16
+
*[Transitions](#transitions)
17
+
*[Parallax and page transitions](#parallax-and-page-transitions)
18
+
*[License](#license-)
18
19
19
20
# Why 🤔
20
21
21
22
react-spring is a cooked down fork of Christopher Chedeau's [animated](https://github.com/animatedjs/animated) (which is used in react-native by default). It is trying to bridge it with Cheng Lou's [react-motion](https://github.com/chenglou/react-motion). Although both are similar in that they are spring-physics based, they have their pros and cons and could definitively benefit from one another:
react-spring inherits react-motions api (and simplifies it), has lots of primitives (springs, trails, transitions, reveals, parallax), can interpolate mostly everything (colors, gradients, percentages, degrees, svg-paths, arrays, etc.) and last but not least, can animate by committing directly to the dom instead of re-rendering a component frame-by-frame.
30
31
@@ -76,10 +77,7 @@ A `Spring` will move data from one state to another. It remembers the current st
76
77
Given a single child instead of a list you can reveal components with it.
@@ -127,6 +129,8 @@ You can interpolate almost everything, from numbers, colors, svg-paths, percenta
127
129
}}>
128
130
```
129
131
132
+
A couple of extra props you might be interested in are `onRest`, which fires once the animations stops, `onFrame`, which fires on every frame and gives you the animation value, `reset`, which literally resets the spring so that it goes through `from` to `to` again, `immediate` which can enforce values to spring to their to-values immediatelly (can be `true` for a zero-time spring or an array where you can pass the key-names individually).
Et voilà! `Header` animates on prop changes! Props that `Spring` doesn't recognize will be spread over the receiving component, in this example `bold`, but it also includes `children` if you use `render` to refer to the render-child.
@@ -153,7 +156,7 @@ By default we'll render the receiving component every frame as it gives you more
153
156
154
157
Just be aware of the following conditions:
155
158
156
-
1. It only animates element styles and attributes, the values you receive *are opaque objects, not regular values*
159
+
1. It only animates element styles and attributes, the values you receive _are opaque objects, not regular values_
157
160
2. Receiving elements must be `animated.[elementName]`, for instance `div` becomes `animated.div`
158
161
3. If you need to interpolate styles use the `template` string literal
You have several interpolation options, not just `template`. `interpolate` can be called on the value itself or as a stand-alone function which can read multiple values. It accepts either a function which receives the animation value(/s), or a range.
Animates children as they mount and unmount. `from` denotes base styles, `enter` styles are applied when objects appear, `leave` styles are applied when objects disappear. Keys and children have to match in their order! The keys are the same that you would provide in any other looping situation.
@@ -190,14 +203,25 @@ import { Transition } from 'react-spring'
190
203
You can use this prototype for two-state reveals, simply render a single child that you can switch out for another. You don't have to pass keys for this one.
For more complex animations you can return per-object styles individually. Let Transition know the actual data by passing it raw to `items`, either pass your keys like always or give it an accessor. And for more control, there's `update` which fires for nodes that are neither entering nor leaving.
`Trail` animates the first child of the list you pass, the others will follow in a trailing motion. The api is similar to `Transition` though it will assume your list is fixed.
@@ -230,8 +254,8 @@ import { Parallax } from 'react-spring'
0 commit comments