Convert Figma logo to code with AI

nandorojo logomoti

🐼 The React Native (+ Web) animation library, powered by Reanimated 3.

3,980
127
3,980
23

Top Related Projects

23,338

Open source, production-ready animation and gesture library for React

✌️ A spring physics based React animation library

A spring that solves your animation problems.

🎊 A collection of animations for inline style libraries

Declarative Animations Library for React and React Native

Quick Overview

Moti is a React Native animation library designed to simplify the process of creating smooth, performant animations. It provides a declarative API that allows developers to create complex animations with minimal code, leveraging the power of Reanimated 2 under the hood.

Pros

  • Easy-to-use, declarative API for creating animations
  • Built on top of Reanimated 2, ensuring high performance
  • Supports both iOS and Android platforms
  • Offers a wide range of pre-built animations and transitions

Cons

  • Requires Reanimated 2 as a dependency, which may increase app bundle size
  • Learning curve for developers unfamiliar with React Native animation concepts
  • Limited customization options for some complex animation scenarios
  • Documentation could be more comprehensive for advanced use cases

Code Examples

  1. Basic fade-in animation:
import { AnimatePresence, MotiView } from 'moti'

function FadeInView({ children }) {
  return (
    <MotiView
      from={{ opacity: 0 }}
      animate={{ opacity: 1 }}
      exit={{ opacity: 0 }}
    >
      {children}
    </MotiView>
  )
}
  1. Spring animation with custom configuration:
import { MotiView } from 'moti'

function SpringView() {
  return (
    <MotiView
      from={{ scale: 0.5 }}
      animate={{ scale: 1 }}
      transition={{
        type: 'spring',
        damping: 10,
        stiffness: 100
      }}
    />
  )
}
  1. Sequence animation:
import { MotiView } from 'moti'

function SequenceAnimation() {
  return (
    <MotiView
      from={{ opacity: 0, scale: 0.5 }}
      animate={{ opacity: 1, scale: 1 }}
      transition={{
        type: 'timing',
        duration: 350,
        scale: {
          type: 'spring',
          delay: 100,
        },
      }}
    />
  )
}

Getting Started

To start using Moti in your React Native project:

  1. Install the required dependencies:
npm install moti react-native-reanimated react-native-gesture-handler
  1. Add Reanimated's Babel plugin to your babel.config.js:
module.exports = {
  plugins: ['react-native-reanimated/plugin'],
};
  1. Import and use Moti components in your React Native app:
import { MotiView } from 'moti'

function App() {
  return (
    <MotiView
      from={{ opacity: 0 }}
      animate={{ opacity: 1 }}
      transition={{ type: 'timing', duration: 1000 }}
    >
      <Text>Hello, Moti!</Text>
    </MotiView>
  )
}

Competitor Comparisons

23,338

Open source, production-ready animation and gesture library for React

Pros of Motion

  • More mature and widely adopted in the React ecosystem
  • Extensive documentation and community support
  • Offers a wider range of animation capabilities and advanced features

Cons of Motion

  • Larger bundle size, which may impact performance in some applications
  • Steeper learning curve for beginners due to its extensive API
  • Not specifically designed for React Native, requiring additional setup for mobile use

Code Comparison

Motion:

<motion.div
  initial={{ opacity: 0 }}
  animate={{ opacity: 1 }}
  transition={{ duration: 0.5 }}
>
  Hello World
</motion.div>

Moti:

<MotiView
  from={{ opacity: 0 }}
  animate={{ opacity: 1 }}
  transition={{ type: 'timing', duration: 500 }}
>
  Hello World
</MotiView>

Summary

Motion is a powerful animation library for React with a rich feature set and strong community support. However, it may be overkill for simpler projects or mobile applications. Moti, on the other hand, is specifically designed for React Native and offers a more streamlined API, making it easier to use for mobile development. The choice between the two depends on the specific needs of your project and the target platform.

✌️ A spring physics based React animation library

Pros of react-spring

  • More mature and widely adopted in the React ecosystem
  • Supports a wider range of animation types and complex physics-based animations
  • Offers a more flexible API for fine-grained control over animations

Cons of react-spring

  • Steeper learning curve, especially for beginners
  • Larger bundle size, which may impact performance in smaller projects
  • More complex setup and configuration required

Code Comparison

react-spring:

import { useSpring, animated } from 'react-spring'

function AnimatedComponent() {
  const props = useSpring({ opacity: 1, from: { opacity: 0 } })
  return <animated.div style={props}>I will fade in</animated.div>
}

moti:

import { MotiView } from 'moti'

function AnimatedComponent() {
  return (
    <MotiView from={{ opacity: 0 }} animate={{ opacity: 1 }}>
      I will fade in
    </MotiView>
  )
}

Both libraries offer powerful animation capabilities, but moti provides a more straightforward API for basic animations, while react-spring excels in complex, physics-based animations. moti is better suited for React Native projects, while react-spring is more versatile across different React environments.

A spring that solves your animation problems.

Pros of react-motion

  • More mature and battle-tested library with a longer history
  • Provides a physics-based animation system for more natural-feeling animations
  • Offers fine-grained control over animation behavior

Cons of react-motion

  • Steeper learning curve due to its physics-based approach
  • Less intuitive API for simple animations
  • Limited built-in animation types compared to newer libraries

Code Comparison

react-motion:

<Motion defaultStyle={{x: 0}} style={{x: spring(10)}}>
  {({x}) => <div style={{transform: `translateX(${x}px)`}} />}
</Motion>

moti:

<MotiView
  from={{ translateX: 0 }}
  animate={{ translateX: 10 }}
/>

Summary

react-motion is a well-established animation library for React that offers physics-based animations and fine-grained control. However, it has a steeper learning curve and can be less intuitive for simple animations. moti, on the other hand, provides a more modern and user-friendly approach to animations in React Native, with an easier-to-use API and built-in support for various animation types. The code comparison shows that moti's syntax is more concise and declarative, while react-motion requires more setup and uses a render prop pattern.

🎊 A collection of animations for inline style libraries

Pros of react-animations

  • Supports a wide range of predefined animations
  • Works with any inline style library or CSS-in-JS solution
  • Lightweight and easy to integrate into existing React projects

Cons of react-animations

  • Limited to CSS-based animations, which may not be as performant as native animations
  • Requires additional setup for more complex animations or custom timing functions
  • Less suitable for React Native projects compared to moti

Code Comparison

react-animations:

import { bounce } from 'react-animations';
import styled, { keyframes } from 'styled-components';

const Bounce = styled.div`animation: 2s ${keyframes`${bounce}`} infinite`;

<Bounce>Bouncing text!</Bounce>

moti:

import { MotiView } from 'moti';

<MotiView
  from={{ opacity: 0, scale: 0.5 }}
  animate={{ opacity: 1, scale: 1 }}
  transition={{ type: 'timing', duration: 350 }}
>
  {children}
</MotiView>

react-animations focuses on providing predefined CSS animations that can be easily applied to React components, while moti offers a more flexible and performant approach to animations, especially for React Native projects. moti provides a declarative API for creating complex animations with fine-grained control over timing and easing functions.

Declarative Animations Library for React and React Native

Pros of Animated

  • More mature and established library with a longer history
  • Offers lower-level control over animations
  • Supports a wider range of animation types and interpolations

Cons of Animated

  • Steeper learning curve and more complex API
  • Requires more boilerplate code for basic animations
  • Less optimized for React Native specifically

Code Comparison

Moti:

import { View } from 'moti'

export default function MyComponent() {
  return (
    <View
      from={{ opacity: 0, scale: 0.5 }}
      animate={{ opacity: 1, scale: 1 }}
      transition={{ type: 'timing', duration: 350 }}
    />
  )
}

Animated:

import { Animated } from 'react-native'

export default function MyComponent() {
  const opacity = new Animated.Value(0)
  const scale = new Animated.Value(0.5)

  Animated.timing(opacity, { toValue: 1, duration: 350 }).start()
  Animated.timing(scale, { toValue: 1, duration: 350 }).start()

  return <Animated.View style={{ opacity, transform: [{ scale }] }} />
}

The code comparison demonstrates that Moti provides a more declarative and concise approach to animations, while Animated requires more setup and imperative code. Moti's API is designed to be more intuitive for React and React Native developers, reducing the amount of boilerplate needed for common animation scenarios. However, Animated offers more fine-grained control over the animation process, which can be beneficial for complex or highly customized animations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

The universal React Native animation library, powered by Reanimated 3.

<MotiView from={{ opacity: 0 }} animate={{ opacity: 1 }} />

Documentation & Examples

Next.js Conf

Screen Shot 2021-10-22 at 3 00 05 PM

I spoke at at Next.js Conf 2021 on October 26 about React Native + Next.js. Watch the video to see how we do it.

Highlights

  • Universal: works on all platforms
  • 60 FPS animations on the native thread
  • Mount/unmount animations, like framer-motion
  • Powered by Reanimated 3
  • Web support, out-of-the-box
  • Expo support
  • Intuitive API
  • Variants
  • Strong TypeScript support
  • Highly-configurable animations
  • Sequence animations
  • Loop & repeat animations

Preview

Follow

Follow me on Twitter to stay up to date.

Sponsor

Sponsorships via GitHub are appreciated.

Analytics by Splitbee.io

License

Moti has an MIT license. That said, a lot of free work goes into it, so if your company uses it, please sponsor, write a blog post, or tweet about it!

NPM DownloadsLast 30 Days