Skip to main content

Installation

Inertia is a thin wrapper around react-native-reanimated. Install Reanimated first: Inertia is a peer of Reanimated, not a replacement.

Prerequisites​

  • Expo SDK 58 (React Native 0.88.x, React 19.3.0), or a bare React Native app with no Expo on the same versions
  • react-native-reanimated >=4.7.0 <4.8.0
  • react-native-worklets >=0.13.0 <0.14.0, the worklet runtime of Reanimated 4. It's a peer of both Reanimated and Inertia, so Yarn and pnpm won't install it for you.

Each release of @rootnative/inertia is bundled in an Expo app and in a bare React Native app with no Expo before it's published. Of the adapters, only @rootnative/inertia-gradients needs Expo: it runs on the Expo modules runtime. See Gradients.

Each release line supports one Expo SDK band. Install the line that matches the SDK of the app.

Expo SDK@rootnative/inertia and the adapters
580.0.20 and later
570.0.11 to 0.0.19 (npm install @rootnative/inertia@0.0.19)
540.0.10 and earlier, with a lockfile that already resolved

On SDK 57 with 0.0.19, install Reanimated 4.5.3 or later in a development build or a store build. Reanimated 4.5.0 to 4.5.2 can show a view at its initial value after its animation ends. The cause: native keeps a settled value for 2 s only, and React holds the first-render value. When the JS thread doesn't read the settled value in that window (a stall of more than 1 s, a paused app, a native dialog), the next React commit writes the initial value back. An entrance from opacity: 0 then goes blank with no error. Reanimated 4.5.3 keeps the value until React has it (software-mansion/react-native-reanimated#9987). The fix is native, so it needs a new build, not an over-the-air update. Expo SDK 57 pins 4.5.1: add react-native-reanimated to expo.install.exclude in package.json, or expo install --check moves it back. Expo Go 57 runs 4.5.1 and can't change, so a project in Expo Go keeps the defect. The SDK 58 band starts at Reanimated 4.7, which has the fix.

Inertia targets one SDK band, not a floor, so SDK 58+ is not correct. The peer ranges stop below React Native 0.89 and below Reanimated 4.8, which the next SDK will carry.

The upper bounds are deliberate. Reanimated and react-native-worklets are version-locked to each other, and each pair works with one React Native band. Reanimated 4.7 needs worklets 0.13.x and React Native 0.86 to 0.88. A wider range would let a package manager pair a new Reanimated with an old worklets, and that pair can't install at all. A second SDK needs a second release line, not a wider range.

Platforms​

PlatformStatus
iOSSupported
AndroidSupported
Web (react-native-web 0.21, through Expo)Supported. The example app and the docs demo run on web. Tests ran in Chromium only. Safari and Firefox are not tested.
macOS (react-native-macos)Not tested
Windows (react-native-windows)Not tested
ElectronNot tested. Expo does not supply an Electron target.

Inertia uses the same API on every supported platform. For web, add the web dependencies to an Expo app:

npx expo install react-dom react-native-web

Some behavior is different on web:

  • gesture.hovered works on web only. On iOS and Android it does nothing. See Gestures.
  • layoutId measures the DOM rect with getBoundingClientRect() on web. See Layout.
  • A static web export writes each element at its initial values. Without the entrance guard, the page stays blank when the JavaScript bundle doesn't run. See Static export.

The adapter packages use the web support of their peer dependency:

  • @rootnative/inertia-gestures works on web through the web support of react-native-gesture-handler.
  • @rootnative/inertia-svg works on web through the web support of react-native-svg.
  • @rootnative/inertia-gradients works on web through the web component of expo-linear-gradient. On web, Reanimated can log a console error on each frame for this component. The gradient renders and animates correctly.

Which package has what​

Read this before you install. The core package doesn't contain the gesture hooks, the gradient primitive, or the SVG primitives. Each one is a separate install. A swipe deck is a common reason to use this library, and useSwipe is not in the core package.

You wantPackageInstall
Motion.* primitives, Presence, MotionConfig, every value-layer hook@rootnative/inertiacore, always required
useDrag, useSwipe, usePan@rootnative/inertia-gestures+ react-native-gesture-handler
Animatable linear gradients@rootnative/inertia-gradients+ expo-linear-gradient
Animatable SVG paths and shapes@rootnative/inertia-svg+ react-native-svg

useTouchDrag is the exception. It's a drag hook in core, under the @rootnative/inertia/touch subpath, because PanResponder is part of React Native and needs no extra peer dependency. Use it when you want drag without react-native-gesture-handler, or when the drag needs keyboard accessibility.

Versions​

All four packages ship in lockstep: the same version number, released together. Install the same version of every @rootnative/inertia* package you use. Each adapter requires a core version at or above its own.

Other packages in the @rootnative scope are different libraries with their own versions. A different version there isn't a mismatch.

Install​

Yarn is the default. Switch tabs for npm, pnpm, or Bun. Your choice applies to every install snippet in the docs.

yarn add @rootnative/inertia react-native-reanimated react-native-worklets

Then enable the worklets Babel plugin as the Reanimated install guide shows. The plugin transforms each 'worklet' function into UI-thread code. Without the plugin, every animation crashes at runtime.

A typical babel.config.js for a managed Expo app:

module.exports = function (api) {
api.cache(true)
return {
presets: ['babel-preset-expo'],
plugins: ['react-native-worklets/plugin'],
}
}

The worklets plugin must be last in the plugins array. react-native-reanimated/plugin still works in Reanimated 4: it's a one-line shim that forwards to react-native-worklets/plugin. The worklets name is the canonical one, and Inertia's own install check tells you to add that name.

The plugin must run on node_modules too​

@rootnative/inertia, react-native-reanimated, and react-native-worklets all ship their 'worklet' directives untransformed. The plugin in your build turns them into UI-thread code. Metro runs Babel on node_modules, so an Expo or bare React Native app needs only the config above.

A web bundler without Metro (Vite, webpack, Electron, Tauri) skips node_modules by default. The build then succeeds, and no animation plays: every animated style stays at its first frame, and a production build shows no error. In that case Inertia logs one console.error at the first Motion render, in production too. Add the three packages to the include list of the plugin. A Vite example with @rolldown/plugin-babel:

babel({
include: [
/src\/.*\.tsx?$/,
/node_modules\/(@rootnative|react-native-reanimated|react-native-worklets)\/.*\.m?js$/,
],
plugins: ['react-native-worklets/plugin'],
})

The equivalent for babel-loader in webpack is an include array with the same paths.

First animation​

import { Motion } from '@rootnative/inertia'

export function FadeIn() {
return (
<Motion.View
initial={{ opacity: 0, translateY: 20 }}
animate={{ opacity: 1, translateY: 0 }}
transition={{
opacity: { type: 'timing', duration: 200 },
translateY: { type: 'spring', tension: 180, friction: 12 },
}}
/>
)
}

Try it live​

The example app runs in the iframe below. Tap a screen to try the same primitives that you ship in your app.

example / view

Subpath imports​

Each primitive has its own import path, so an app that animates one element doesn't pull in the rest:

import { MotionView } from '@rootnative/inertia/view'
import { MotionText } from '@rootnative/inertia/text'
import { MotionImage } from '@rootnative/inertia/image'
import { MotionPressable } from '@rootnative/inertia/pressable'
import { MotionScrollView } from '@rootnative/inertia/scroll-view'

@rootnative/inertia is sideEffects: false, so a bundler with tree-shaking (Metro 0.79+, Webpack, Rollup) drops the primitives that you don't import. The named imports above tree-shake to within about 0.1 kB of the subpath imports. CI checks this for each primitive.

One caveat: the Motion namespace object can't tree-shake. import { Motion } from '@rootnative/inertia' followed by Motion.View keeps the whole namespace in the bundle, because a bundler can't remove a property access on a literal object. Use the namespace for comfort. Use import { MotionView } from '@rootnative/inertia' (or the subpath) when bundle size matters.

Optional adapter packages​

Three sibling packages extend Inertia with features that need extra peer dependencies. The core library doesn't depend on any of them. Install only what you need.

Gestures (@rootnative/inertia-gestures)​

Drag, pan, and swipe hooks on react-native-gesture-handler. Compose them with any Motion.* primitive through <GestureDetector>.

yarn add @rootnative/inertia-gestures react-native-gesture-handler

Then follow the react-native-gesture-handler install guide. It needs <GestureHandlerRootView> near the root of your app. See Gestures adapter for the hooks.

Gradients (@rootnative/inertia-gradients)​

MotionLinearGradient wraps expo-linear-gradient with animatable colors, start, end, and locations. It works in bare React Native and in Expo, but expo-linear-gradient is an Expo Module. A bare project needs the Expo modules runtime. See Installing Expo modules.

yarn add @rootnative/inertia-gradients expo-linear-gradient

See Gradients for the primitive.

SVG (@rootnative/inertia-svg)​

MotionPath wraps the <Path> of react-native-svg with animatable d (path morphing between paths with the same structure), fill, stroke, strokeWidth, opacities, and strokeDashoffset. It works in bare React Native and in Expo.

yarn add @rootnative/inertia-svg react-native-svg

See SVG for the primitive.

Reduced motion​

Inertia follows the reduce-motion accessibility setting of the OS by default. You need no extra setup. To override the default for the whole app or a subtree, see MotionConfig.