# Inertia > Declarative animation primitives for React Native, built on react-native-reanimated. The API takes ideas from Framer Motion (web) and react-spring (cross-platform). DX-first: an animation is a prop on a component, not shared values, worklets, and `useAnimatedStyle` boilerplate. ## Install ```sh pnpm add @rootnative/inertia react-native-reanimated ``` Enable the Reanimated Babel plugin as its install guide shows. ## Requirements Platforms: iOS and Android are supported. Web (react-native-web 0.21, through Expo) is supported. For web, run `npx expo install react-dom react-native-web`. macOS, Windows, and Electron are not tested. Expo doesn't supply an Electron target. Runtime: 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`. `@rootnative/inertia-gradients` needs the Expo modules runtime. One release line supports one Expo SDK band. SDK 58 takes `0.0.20` and later. SDK 57 takes `0.0.11` to `0.0.19` (`npm install @rootnative/inertia@0.0.19`). SDK 54 takes `0.0.10` and earlier, with a lockfile that already resolved. On SDK 57, install Reanimated 4.5.3 or later in a native build. Reanimated 4.5.0 to 4.5.2 can write the `initial` value back after a JS stall of more than 1 s, so an entrance from `opacity: 0` goes blank (software-mansion/react-native-reanimated#9987). Expo Go 57 runs 4.5.1 and keeps the defect. The SDK 58 band starts at 4.7, which has the fix. Web differences: `gesture.hovered` works on web only. `layoutId` reads `getBoundingClientRect()` on web. A static web export needs the entrance guard from `@rootnative/inertia/static-export`. Details: https://rootnative.github.io/inertia/installation#platforms ## Which package has what The core package doesn't contain the gesture hooks, the gradient primitive, or the SVG primitives. Each one is a separate install. `useSwipe` and `useDrag` are **not** in core. A swipe deck needs `@rootnative/inertia-gestures`. | You want | Package | Extra peer dependency | | --- | --- | --- | | `Motion.*`, `Presence`, `Stagger`, `MotionConfig`, every value-layer hook | `@rootnative/inertia` | — (core, 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: a drag hook in **core**, under the `@rootnative/inertia/touch` subpath, because PanResponder is part of React Native. Use it for drag without `react-native-gesture-handler`, or when the drag needs keyboard accessibility. All four packages ship in **lockstep**: the same version, released together. Install the same version of every `@rootnative/inertia*` package that you use. Other packages in the `@rootnative` scope are different libraries with their own versions, so a different version there is not a mismatch. ## Imports ```ts import { Motion, Presence, Stagger, MotionConfig, useGesture, useVariants, useMotionValue, useAnimation, useSpring, useBooleanSpring, useTransform, useShadow, useColorTransition, useColorCascade, useInterpolatedStyle, useInView, useScroll, useHideOnScroll, useValueChange, } from '@rootnative/inertia' // Opt-in MD3 / iOS state-layer overlay helper: import { useGestureLayer } from '@rootnative/inertia/gesture-layer' // Render-layer Reanimated interop for custom animated components: import { Animated, useAnimatedStyle } from '@rootnative/inertia/reanimated' // or for tree-shaking the primitives. NOTE: these subpaths export a // differently NAMED symbol — `MotionScrollView`, not `Motion.ScrollView`. // `Motion` itself is only exported from the package root above, and there // is no '@rootnative/inertia/motion' subpath. 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' import { MotionFlatList } from '@rootnative/inertia/flat-list' ``` ## Public API - `Motion.View` / `Motion.Text` / `Motion.Image` / `Motion.Pressable` / `Motion.ScrollView` / `Motion.FlatList` — animatable primitives. Per-primitive style inference (no shared `ViewStyle & TextStyle & ImageStyle` fallback). `Motion.FlatList` is the **virtualized** animated scroller: it takes `useScroll`'s `onScroll` handler and keeps `data` / `renderItem` item-type inference, so a long list can virtualize and animate at once. Animation props apply to the scroll container; animate rows with a `Motion.*` inside `renderItem`. - `` — mount / unmount transitions; children need explicit `key`s. Exiting children get `pointerEvents: 'none'` automatically. An exiting child stays mounted until every `Motion.*` inside it has finished its exit. A nested `Motion.*` with no `exit` is finished at once, so it does not cut the parent's exit. A custom `usePresence()` consumer that calls `safeToRemove()` removes the child at once. A departing child with no `Motion.*` and no `usePresence()` consumer is removed at once, with no exit animation. - `` — assigns each child a delay of `delay + position * interval` (ms), applied to the declarative animations (`initial` → `animate`, later `animate` changes) of every `Motion.*` primitive in that child's subtree. `from='last'` reverses the cascade; `enabled={false}` zeroes every delay (the "cascade in, snap out" switch). Composes with the child's own `transition.delay`; never delays `gesture` feedback, `` exits, or reduced-motion snaps. Renders no host view. Custom animated components read the slot's delay with `useStaggerDelay()`. `` and `` each read their own direct children, so neither can wrap the other around one list. For rows that cascade in and also exit, give each `` child its own keyed, one-child ``. A removed row then exits with no delay, and the rows that stay don't replay. - `` — gates motion against the OS reduce-motion setting (default `"user"`) and registers named transitions for the subtree. A registered name is accepted anywhere a `TransitionConfig` is: the `transition` prop (top-level and per-property/per-layer), the `layout` prop, and the value-layer hooks (`transition="selection"`, `useBooleanSpring(checked, 'selection')`). Nested providers merge (child overrides per name); unknown names warn in dev and fall back to the default spring. Names are consumer vocabulary — no presets ship with the library. Optional compile-time narrowing via `declare module '@rootnative/inertia' { interface RegisteredTransitions { ... } }`. Custom components join the registry with `useNamedTransitions()` + `resolveNamedTransition(input, registry)`. - `useGesture(transition?)` — the hook form of the `gesture` prop. Returns the progress shared values (0 to 1) `pressed`, `focused`, `focusVisible`, and `hovered`, plus **two** handler sets with the same callbacks: `handlers` (keyed for a `Pressable`: `onPressIn`/`onPressOut`/`onHoverIn`/`onHoverOut`/`onFocus`/`onBlur`) and `pointerHandlers` (keyed for a plain `View`: `onPointerEnter`/`onPointerLeave`/`onFocus`/`onBlur`, no press). Use it when one gesture must drive several animated siblings (a focus ring, an MD3 state-layer halo, a multi-element composition). **Pick the set by what the surface is.** A `Pressable` is a tab stop even with no `onPress`. Measured on react-native-web 0.21, it renders `tabindex="0"`, and it still does with `accessible={false}` *and* `focusable={false}`. So a hover-only surface on a `Pressable` adds a keyboard stop that goes nowhere, and only the built HTML shows it. A hover-only surface takes `pointerHandlers` on a `Motion.View`. A real control takes `handlers` on a `Pressable` that has an `onPress` and a role. - `useGestureLayer(states, options?)` — opt-in helper at `@rootnative/inertia/gesture-layer` for the composition where **the strongest active layer wins** (an MD3 state-layer halo, an iOS translucent overlay). Supply a target map per state (`rest` / `hovered` / `focused` / `focusVisible` / `pressed` / `disabled`). The hook owns the worklet. A numeric key composes with clamped-max, with `rest` as the floor. A color key composes with the priority cascade through `interpolateColor`. `disabled` (a JS-side flag) overrides every gesture layer. Returns `{ style, handlers, states }`. `states` holds the progress shared values (0 to 1) per state (`hovered` / `focused` / `focusVisible` / `pressed` / `disabled`) behind the composed style, so you can derive an extra style (for example `useShadow({ progress: states.hovered })`) from the same gesture wiring. Use plain `useGesture` for an additive blend or a custom rule per key. - `useVariants(variants, initial?)` — returns `{ current, transitionTo }` controller for the `controller` prop. - `useMotionValue(initial)` — thin pass-through over `useSharedValue`. Returns a `SharedValue` directly so it interops with every Reanimated API without unwrapping. The generic is **unconstrained**: it holds anything `useSharedValue` holds — a number, a color string, an array of per-item measurements, a record, a boolean — not only animatable values. Two Reanimated rules follow: a structured value must be **reassigned** to be seen (`arr.value.push(x)` updates nothing), and only numbers and color strings can be handed to `withSpring` / `withTiming`, so a structured value is something you write, never something you animate. - `useAnimation(target, transition?, options?)` — drive a `SharedValue` toward `target` with any `TransitionConfig` (spring / timing / decay / no-animation, plus `repeat`) or a registered `TransitionName`. The general-purpose value-layer hook for boolean-state progress, indeterminate loops, and anywhere the same value needs to feed multiple `useAnimatedStyle` blocks. The value starts at `target`; `options.from` starts it somewhere else on mount, which a loop needs (`useAnimation(1, loop, { from: 0 })`). - `useAnimator()` — the **imperative** counterpart of `useAnimation`. Returns a setter with a stable identity, `(value: SharedValue, to: number, transition?: TransitionConfig | TransitionName) => void`, to call from an event handler (hover-in, focus, press) instead of an effect. It resolves a registered `TransitionName` through the nearest ``, and it gates on `` (the `'no-animation'` downgrade). A hand-written `resolveTransition` write in an event handler gets both of those wrong with no warning. The default transition is the library spring. It isn't a new animation API. It's the hooks-layer form of `useMotionValue` plus `resolveTransition`, without the traps. - `useSpring(target, config?)` — the spring-only short form. Animates a `SharedValue` toward `target` with the react-spring vocabulary, or with a registered `TransitionName` of type spring. A name of another type warns and falls back to the default spring. `target` can be a plain number (an effect drives it) or a `SharedValue` (a UI-thread reaction drives it). The second form is the gesture-smoothing path. - `useBooleanSpring(active, config?)` — a short form of `useSpring` for the common shape "a spring progress from 0 to 1 from a boolean" (a checkbox check, an accordion expansion, a drawer open or closed). The mechanics equal `useSpring(active ? 1 : 0, config)`. It's the named form, so the call site reads as the boolean. - `useTransform(value, inputRange, outputRange, options?)` / `useTransform(transformer)` — interpolates a numeric shared value onto a number or color range, or derives any value from any number of shared values through a worklet. Inertia wraps a transformer that isn't a worklet. - `useShadow({ from, to, progress })` — a pure value-layer interpolator between two `ShadowConfig` values (`shadowOpacity` / `shadowRadius` / `shadowOffset` / `elevation` / `shadowColor`, plus `boxShadow` as a CSS string or `BoxShadowLayer[]`, the shadow surface on web and on the new architecture of React Native 0.76+; multi-layer, with the padding rules of a CSS transition; a malformed string throws at setup). A `SharedValue` (0 to 1) drives it. Returns an animated style fragment to spread onto `style`. It emits only the keys on either side. An absent side defaults to the natural zero. The hook doesn't animate on its own. Drive `progress` with a spring, a `useTransform` from a scroll, or any other shared value source. - `useColorTransition(progress, [from, to], options?)` — pure value-layer interpolator for a single color channel, driven by a `SharedValue` (0→1). Returns an animated style fragment with one color key (default `backgroundColor`; configurable via `options.key` to `color` / `borderColor` / `tintColor` / `shadowColor` / per-side border colors). For raw `SharedValue` output, use `useTransform(progress, [0, 1], [from, to])` instead. - `useColorCascade(rest, layers, options?)` — a pure value-layer interpolator that composites a stack of color layers, **in priority order**, over a base `rest` color. Each `layers` entry is `{ progress: SharedValue, color: string }`. A later entry wins as its progress rises. It equals the nested `interpolateColor` chain `focus(error(hover(rest)))`. `options.key` takes a `ColorStyleKey` (default `backgroundColor`). Returns an animated style fragment to spread. It's memoized on a signature of the colors and the key. It's color-only by design. Cascade a numeric key separately with `useInterpolatedStyle` and a `useTransform` max. `useColorTransition` stays the single-layer fast path. - `useInterpolatedStyle(progress, map, options?)` — a pure value-layer interpolator that maps one `SharedValue` onto **N** style props at once, and returns an animated style fragment to spread. It's the multi-key, style-fragment counterpart of the output-range form of `useTransform`. A numeric key (`opacity` / `height` / `fontSize` / …) goes through `interpolate`. A transform key (`translateX` / `scale` / `rotate` / …) goes into a `transform` array in the key order of the map (`rotate*` emits `'deg'`). A color key (`backgroundColor` / `borderColor` / …) goes through `interpolateColor`, a multi-stop `useColorTransition`. TypeScript checks the stop types. **The return type comes from the own keys of the map (`InterpolatedStyle`), so it narrows to the correct style family and needs no cast in a `style` array.** View keys satisfy `StyleProp`, text-metric keys (`fontSize` / `lineHeight` / `letterSpacing`) satisfy `StyleProp`, `tintColor` satisfies `StyleProp`, and transform keys collapse into the emitted `transform` array. (The `useAnimatedStyle` of Reanimated returns the `DefaultStyle` union, whose `TextStyle` member fails against `ViewStyle` on `cursor` inside a style array.) `options.inputRange` (default `[0,1]`, or evenly spaced) and `options.extrapolate` (default `'clamp'`) apply to every key. It's memoized on a signature that keeps the key order. For a function-valued or multi-source composition, use the worklet form of `useTransform` or a hand-written `useAnimatedStyle`. - `useScroll()` — returns `{ scrollX, scrollY, maxScrollX, maxScrollY, onScroll }` for use with `Motion.ScrollView` or `Motion.FlatList`. Scroll events fire on the UI thread. `maxScrollX` / `maxScrollY` are the largest offsets that the content can rest at (`Infinity` until the first scroll event); clamp an offset to them to ignore the iOS bounce at the end. Set `scrollEventThrottle={16}` on a `Motion.ScrollView`; `Motion.FlatList` defaults it to 1. - `useInView(ref, options?)` — returns a `SharedValue` that moves from 0 to 1 when the referenced element scrolls into view, so an entrance animation starts when the element arrives, not when the screen mounts. Options: `amount` (the fraction of the element that must show, default `0`), `once` (hold at 1 after the first sighting, default `true`), `margin` (grow or shrink the detection box, in points), `transition`. Web uses `IntersectionObserver`. **Native needs the element inside a `Motion.ScrollView` or a `Motion.FlatList`**, which publish their scroll offset. Outside one, the value is 1 from the start, and the hook warns once in dev. The `onScroll` prop of the container stays free, so `useScroll` and `useInView` can drive the same scroller. The hook measures on mount and on a container resize, not continuously. - `useHideOnScroll(offset, { distance })` — returns a `SharedValue` that rises from 0 to 1 while the content scrolls down and falls while it scrolls up, one point of scroll for one point of `distance`. Set `distance` to the height of the element that hides, and translate the element by it: the hide-on-scroll pattern of a bottom bar or a floating button. The value is 0 at or above the top of the content. It accumulates and clamps, it runs on the UI thread, and it doesn't snap when the scroll stops. Movement past the end of the content doesn't count, so the iOS bounce at the end leaves a hidden element hidden. `useScroll` records the end for its own offsets, and the optional `maxOffset` shared value gives it for any other offset. A new `offset` or `maxOffset` starts the value again. The progress returns to 0, and the next movement counts from the new position, so a bar that follows the active list of a tab screen shows on each change of tab. - `useValueChange(value, onChange)` — calls `onChange(current, previous)` on the JS thread when a `SharedValue` or a `DerivedValue` changes, once per change, not for the initial value. The reaction runs on the UI thread and schedules the callback with `scheduleOnRN`. Derive the value first (`useDerivedValue(() => Math.round(scrollX.value / PAGE_WIDTH))`), so React gets one call per step and not one per frame. The hook always calls the latest callback. A new callback doesn't rebuild the reaction. - `createMotionComponent(C)` — wraps any component with the same Motion prop surface, and infers the style type from `C`. - `buildReleaseAnimation(transition, toValue)` — a worklet-safe builder for a single-step animation (spring / timing / decay / no-animation). Use it to assign an Inertia-resolved animation to a shared value from inside a gesture worklet. The `useDrag({ onRelease })` of `@rootnative/inertia-gestures` uses it internally. - `resolveTransition(config, toValue, callback?)` — the JS-thread resolver. It bakes a `TransitionConfig` and a target into a Reanimated animation (`withSpring` / `withTiming` / `withDecay`, with `delay` and `repeat` wrapped), ready to assign to a shared value. It's the building block for a custom animated component that accepts the `transition` shape of Inertia. The gradient and SVG adapter packages use it. - `resolveAnimatableValue(value, base, factory?)` — one level up. It resolves a full per-property `animate` value (a plain target, a `{ to, ...override }` step, or a keyframe array, which becomes a `withSequence` with a sequence-level `repeat`) into one animation. It gives a custom component the complete `animate` grammar. - `transitionForKey(transition, key)` — the transition that a `transition` prop gives one key (a style property, a gesture layer, or an adapter prop): a top-level config or name as given, the key's own map entry, or the default of a mixed map. A name comes back as a string; pass the result to `resolveNamedTransition`. A custom animated component reads a map through it. - `cubicBezier(x1, y1, x2, y2)` / `cubicBezier(css)` — builds a `timing.easing` value from cubic-bezier control points: four numbers, a W3C CSS `cubic-bezier(0.2, 0, 0, 1)` string (the design-token form), or a CSS keyword (`'linear'` | `'ease'` | `'ease-in'` | `'ease-out'` | `'ease-in-out'`). So you can use a CSS-format easing token as it is. Pair it with named transitions to feed the motion tokens of a theme into the registry. Invalid input throws (`x1`/`x2` must be within [0, 1]; `step-*` and `linear(...)` are unsupported). - `ensureWorkletEasing(easing)` — normalizes any accepted easing input (a plain function, a worklet, or a Reanimated 4 `EasingFunctionFactory`) into a worklet that `withTiming` can consume. You need it only for a manual `withTiming` call. The resolvers and the primitives apply it for you. - `TRANSPARENT` — `'rgba(0, 0, 0, 0)'`, the value that seeds a color shared value when a custom component has no other source. It exists because Reanimated up to 4.4 mapped the CSS keyword `'transparent'` to `undefined` in its color table. That made it the one name that `isColor()` rejected. A slot at rest at that value couldn't animate away from it, and under `withSpring` (the default) the animation never settled. **Reanimated 4.5 fixed that.** The keyword now maps to a real packed color, so within the supported peer band (`>=4.7.0 <4.8.0`) both spellings animate. The constant stays exported as an explicit, unambiguous seed, and as the safe choice for code that can also run against an older Reanimated. - `TranslateStyle` / `ColorStyle` / `ShadowStyle` (types) — what `useTranslateStyle`, `useColorTransition` / `useColorCascade`, and `useShadow` return. They are plain style objects, **not** the branded `AnimatedStyleHandle` of Reanimated. Reanimated 4.5 brands the value that `useAnimatedStyle` returns, and a `StyleProp` array rejects a branded value. So the plain shape keeps a style-array call site free of casts. The reasoning is the same as for `InterpolatedStyle` above. The brand exists at compile time only. The value is still the animated style that Reanimated made. - `SharedValue` (type) — re-exported from the root entry, so a prop or a ref that carries a value-layer hook result has a type with no import from `react-native-reanimated`. - `@rootnative/inertia/static-export` — **read this before you ship a pre-rendered web page.** A static export (`expo export`, or any SSR) renders on a server. So every `Motion.*` with an `initial` prop goes into the HTML at its pre-animation value, `style="opacity: 0"`. A visitor whose bundle fails, or who blocks scripts, gets a **blank page**, and no build error, warning, or test can see it. The fix is one style block in the HTML shell (`app/+html.tsx` for Expo Router): `