Overview
Moti has a number of powerful features that make your animations slick and simple.
Mount animations#
You can set the initial state with from. Any styles passed to animate will transition for you.
Animate based on React state#
This is useful for dynamic height changes, for instance.
Customize your animation#
Moti animations are highly configurable, thanks to the transition prop. If you've used framer-motion, this will look familiar.
You can also configure different transitions per-style:
If you set type: 'spring', you can pass any options that Reanimated's withSpring accepts. Same goes for type: 'timing' & Reanimated's withTiming.
Mount/unmount animations 😎#
Framer Motion introduced the incredible AnimatePresence component to animate a component before it unmounts.
With Moti, you can now achieve the same thing in React Native.
Import AnimatePresence#
Add an exit prop#
Wrap your animation with AnimatePresence, and add an exit prop.
Even though it's experimental, I think this feature is so cool.
Exit before enter#
You can leverage the exitBeforeEnter prop to only allow one item to be visible at a time.
Make sure that its direct children have a unique key prop for this to work.
In the example above, the content won't load in until after the skeleton has faded out.
The exit prop can be inside of a nested component. However, it's important that the direct children of AnimatePresence have a unique key.
Delay animations#
You can use the delay prop
Or, pass your delay in transition:
You can also set a different delay per-style:
Sequence animations#
To create a sequence animation, similar to CSS keyframes, just pass an array to any style:
This will animate to 0.1, then 1.1, then 1.
If you want to customize each step of the animation, you can also pass an object with a value field.
Any transition settings can be passed to a sequence object.
Repeat & loop animations#
Repeat an animation 4 times.
By default, repetitions reverse, meaning they automatically animate back to where they just were.
You can disable this behavior with repeatReverse: false.
Setting repeatReverse to true is like setting animationDirection: alternate in CSS.
Infinitely loop from 0 to 1:
Sequences animations can't be used with repeat animations.
Repetition styles can't be changed on the fly. Reanimated's withRepeat has some limitations, so just keep that in mind.
Listen to animation changes#
The onDidAnimate function prop gets called whenever an animation completes.
Variants#
You can define static variants when your component mounts:
Or set custom variants and update them on the fly:
You can use this to create reusable animations, too:
Read more about useAnimationState.