Skip to main content

Gradients

@rootnative/inertia-gradients adds an animatable linear gradient built on expo-linear-gradient. It's an optional sibling package. Install it only when you need to animate gradient stops. The core library doesn't depend on expo-linear-gradient.

MotionLinearGradient accepts the same initial, animate, and transition shape as the core Motion.* primitives, with the animatable keys colors, start, end, and locations.

When to pick which​

You wantReach for
Animate a flat background colorMotion.View with animate={{ backgroundColor }} from core — no gradient package needed
Animate gradient stop colors, direction, or stop positionsMotionLinearGradient (this package)
Change the number of stopsA remount via key={...} — the slot count is locked at mount
A radial or conic gradientNot covered — linear only; radial / conic are backlog, unscheduled
A gradient fill inside an SVG<Defs> + <LinearGradient> from react-native-svg, referenced by url(#id) — see the SVG page

Install​

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

expo-linear-gradient works in a bare React Native project and in Expo, but it's an Expo Module. A bare project needs the Expo modules runtime. See Installing Expo modules.

Usage​

import { MotionLinearGradient } from '@rootnative/inertia-gradients'

function Hero() {
return (
<MotionLinearGradient
colors={['#0f172a', '#1e293b']}
animate={{ colors: ['#7c3aed', '#0ea5e9'] }}
transition={{ type: 'timing', duration: 600 }}
style={StyleSheet.absoluteFill}
/>
)
}

The static colors prop is required. It sets the visual on the first render and locks the slot count for the lifetime of the component. To resize the gradient (for example, from 2 stops to 3 stops), remount it with key={...}. The component throws in dev if colors.length changes between renders.

Animatable props​

KeyShapeNotes
colorsreadonly string[]Element-wise color interpolation via Reanimated's color setter. Length must match the static colors prop.
start{ x: number, y: number }Normalized [0, 1] coordinates. x and y animate independently — useful for rotating gradient direction.
end{ x: number, y: number }Same shape as start.
locationsreadonly number[]Optional stop positions. If supplied at mount, must remain supplied and same-length as colors for the component's lifetime.

Per-property transitions work the same as in the core primitives:

<MotionLinearGradient
colors={['#000', '#000']}
animate={{
colors: ['#7c3aed', '#0ea5e9'],
start: { x: 0, y: 0 },
end: { x: 1, y: 1 },
}}
transition={{
colors: { type: 'timing', duration: 600 },
start: { type: 'spring', tension: 80, friction: 14 },
end: { type: 'spring', tension: 80, friction: 14 },
}}
/>

initial​

Pass initial to override the values of the mount frame, so the component starts somewhere other than the static props. Pass initial={false} to start at the animate target with no mount animation.

<MotionLinearGradient
colors={['#111', '#222']}
initial={{ colors: ['#000', '#000'] }} // fade up from black
animate={{ colors: ['#7c3aed', '#0ea5e9'] }}
/>

<MotionLinearGradient
colors={['#111', '#222']}
initial={false} // skip the mount animation
animate={{ colors: ['#7c3aed', '#0ea5e9'] }}
/>

Reduced motion​

MotionLinearGradient follows <MotionConfig reducedMotion> the same as the core primitives. When the reduce-motion setting of the OS is on, or you pass reducedMotion="always", a transition resolves as a direct assignment instead of withSpring or withTiming.

What this primitive doesn't do​

  • Radial or conic gradients. The primitive is linear only. Radial and conic are in the backlog, not scheduled. They need their own prop shape, and the linear API must prove itself first.
  • A slot-count resize. The length of the colors array is locked at mount. To change it, remount with key={...}.
  • Sequence keyframes per stop. animate.colors accepts one target array, not a nested array of arrays. For chained gradient transitions, drive the target through state and let React re-render.