A lightweight magic-move library for configurable layout transitions
A lightweight magic-move library for configurable layout transitions
| Feature | react-flip-move |
react-overdrive |
react-flip-toolkit |
|---|---|---|---|
| Animate position | ✅ | ✅ | ✅ |
| Animate scale | ❌ | ✅ | ✅ |
| Animate opacity | ❌ | ✅ | ✅ |
| Animate parent's size without warping children | ❌ | ❌ | ✅ |
| Use real FLIP instead of cloning & crossfading | ✅ | ❌ | ✅ |
| Use springs for animations | ❌ | ❌ | ✅ |
| Support spring-based stagger effects | ❌ | ❌ | ✅ |
| Usable with frameworks other than React | ❌ | ❌ | ✅ |
npm install react-flip-toolkit or yarn add react-flip-toolkit
Wrap all animated children with a single Flipper component that has a flipKey prop that changes every time animations should happen.
Wrap elements that should be animated with Flipped components that have a flipId prop matching them across renders.
Fork this example on Code Sandbox
import React, { useState } from 'react'
import { Flipper, Flipped } from 'react-flip-toolkit'
const AnimatedSquare = () => {
const [fullScreen, setFullScreen] = useState(false)
const toggleFullScreen = () => setFullScreen(prevState => !prevState)
return (
<Flipper flipKey={fullScreen}>
<Flipped flipId="square">
</Flipped>
</div>
</Flipped>By default, both the scale and the translation transforms of the parent will be counteracted (this allows children components to make their own FLIP animations without being affected by the parent).
But for many use cases, you'll want to additionally specify the scale prop to limit the adjustment to the scale and allow the positioning to move with the parent.
Note: the DOM element with the inverse transform should lie flush against its parent container for the most seamless animation.
That means any layout styles — padding, flexbox, etc—should be applied to the inverted container (the element wrapped with a Flipped component with an inverseFlipId) rather than the parent Flipped container.
react-flip-toolkit works great with client-side routers to provide route-driven transitions:
<Route
render={({ location, search }) => {
return (
<Flipper
flipKey={`${location.pathname}-${location.search}`}
>
{/* Child routes that contain Flipped components go here...*/}
</Flipper>
)
}}
/>FlipperThe parent wrapper component that contains all the elements to be animated. You'll often need only one of these per page, but sometimes it will be more convenient to have multiple Flipper regions of your page concerned with different transitions.
<Flipper flipKey={someKeyThatChanges}>{/* children */}</Flipper>| prop | default | type | details |
|---|---|---|---|
| flipKey (required) | - | string, number, bool |
Changing this tells react-flip-toolkit to transition child elements wrapped in Flipped components. |
| children (required) | - | node |
One or more element children |
| spring | noWobble |
string or object |
Provide a string referencing one of the spring presets — noWobble (default), veryGentle, gentle, wobbly, or stiff, OR provide an object with stiffness and damping parameters. Explore the spring setting options here. The prop provided here will be the spring default that can be overrided on a per-element basis on the Flipped component. |
| applyTransformOrigin | true |
bool |
Whether or not react-flip-toolkit should apply a transform-origin of "0 0" to animating children (this is generally, but not always, desirable for FLIP animations) |
| element | div |
string |
If you'd like the wrapper element created by the Flipped container to be something other than a div, you can specify that here. |
| className | - | string |
A class applied to the wrapper element, helpful for styling. |
| staggerConfig | - | object |
Provide configuration for staggered Flipped children. The config object might look something like the code snippet below: |
staggerConfig={{
// the "default" config will apply to staggered elements without explicit keys
default: {
// default direction is forwards
reverse: true,
// default is .1, 0 < n < 1
speed: .5
},
// this will apply to Flipped elements with the prop stagger='namedStagger'
namedStagger : { speed: .2 }
}}| prop | default | type | details
No open issues yet, or sync has not completed.