Overview
Moti has a number of powerful features that make your animations slick and simple.
#
Mount animationsYou can set the initial state with from
. Any styles passed to animate
will transition for you.
#
Animate based on React stateThis is useful for dynamic height changes, for instance.
#
Customize your animationMoti 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.
AnimatePresence
#
Import exit
prop#
Add an Wrap your animation with AnimatePresence
, and add an exit
prop.
Even though it's experimental, I think this feature is so cool.
#
Exit before enterYou 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 animationsYou can use the delay
prop
Or, pass your delay
in transition
:
You can also set a different delay per-style:
#
Sequence animationsTo 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 animationsRepeat 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:
Repetition styles can't be changed on the fly. Reanimated's withRepeat
has some limitations, so just keep that in mind.
If you're trying to change them on the fly via re-render, you may have to update the component's key
.
#
Listen to animation changesThe onDidAnimate
function prop gets called whenever an animation completes.
#
VariantsYou 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
.