Index of every page on this site: llms.txt
All skills
Run it yourself

Production animation patterns for React Native using Reanimated 4, Skia, WebGPU, and TypeGPU. Covers CSS transitions, CSS animations, CSS pseudo-selectors, CSS callbacks, shared value animations, canvas animations with react-native-skia, GPU shader animations, layout animations, scroll-driven animations, particle systems, procedural noise, SDF rendering, performance tuning, and accessibility. Trigger on: Reanimated, useSharedValue, useAnimatedStyle, withSpring, withTiming, withDecay, withRepeat, withSequence, CSS transition, CSS animation, layout animation, FadeIn, SlideIn, ZoomIn, LinearTransition, keyframe, interpolate, scrollTo, useFrameCallback, react-native-skia, Skia Canvas, Atlas, usePathInterpolation, usePathValue, useClock, useTexture, SKSL, interpolateColors, Picture API, canvas animation, sprite animation, WebGPU, react-native-wgpu, TypeGPU, GPU shader, WGSL, particle system, Perlin noise, SDF, Three.js, react-three-fiber, animation performance, or any request to animate UI in React Native.

Use this Skill: https://skilld.dev/gh/software-mansion-labs/skills/animations

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

animation-functions.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Animation Functions and Core Hooks

Gotchas, rules, and patterns for Reanimated 4 core hooks, animation functions, and modifiers.

For API signatures and config options, webfetch the linked documentation pages below.

For choosing between animation approaches (CSS vs shared value), see animations.md.


Worklet Directive

Do not add 'worklet'; to callbacks passed to Reanimated and Worklets APIs (useAnimatedStyle, useAnimatedProps, useDerivedValue, useAnimatedReaction, useAnimatedScrollHandler, useFrameCallback, gesture callbacks, animation callbacks). The Reanimated Babel plugin auto-workletizes these. The 'worklet'; directive is only needed for standalone functions you define yourself and want to run on the UI thread.


Core Hooks

useSharedValue

Gotchas:

  • Never destructure: const { value } = sv breaks reactivity.
  • For objects, reassign the entire value: sv.value = { ...sv.value, x: 50 }. Direct mutation (sv.value.x = 50) loses reactivity.
  • For large arrays/objects, use .modify() to mutate in place: sv.modify(arr => { arr.push(item); return arr; }).
  • Reading .value on the JS thread blocks until the UI thread syncs. Minimize cross-thread reads.
  • Never read/modify during component render. Access only in callbacks (useAnimatedStyle, event handlers, useEffect). Reanimated will warn: "Reading from value during component render" / "Writing to value during component render".
  • Use .get()/.set() methods instead of .value for React Compiler compatibility.
  • Avoid using a shared value exclusively on the JS thread. If you only need the value on the JS thread, use useState instead. Reading a shared value on the JS thread is slow (requires thread synchronization) and may return a stale value. A common mistake is reading or updating a shared value in the component body (during render):
// BAD: reading/writing shared values during render
function Counter() {
  const count = useSharedValue(0);

  // Triggers "Reading from value during component render" warning
  const doubled = count.value * 2;

  return (
    <Animated.View>
      {/* Triggers "Writing to value during component render" warning */}
      <Button onPress={() => { count.value += 1; }} title={`Count: ${count.value}`} />
    </Animated.View>
  );
}

// GOOD: shared value used for UI-thread animations
function AnimatedCounter() {
  const offset = useSharedValue(0);

  const animatedStyle = useAnimatedStyle(() => ({
    transform: [{ translateX: offset.value }],
  }));

  return (
    <Animated.View style={animatedStyle}>
      <Button onPress={() => { offset.value = withSpring(offset.value + 50); }} title="Move" />
    </Animated.View>
  );
}

useAnimatedStyle

const animatedStyle = useAnimatedStyle(() => ({
  transform: [{ translateX: withSpring(offset.value) }],
}));

<Animated.View style={[styles.box, animatedStyle]} />

Rules:

  • Keep static styles in StyleSheet.create(). Only put dynamic parts in useAnimatedStyle.
  • Animated styles override static styles in the style array.
  • Removing an animated style does not unset its values. Manually set properties to undefined to clear them.
  • Never mutate shared values inside the updater (e.g., sv.value = withTiming(1) in the callback). This causes infinite loops.
  • The callback runs on the JS thread first, then immediately on the UI thread. Use global._WORKLET to guard thread-specific code.

useAnimatedProps

For animating component properties (not styles). Do all value conversions directly inside the useAnimatedProps callback instead of using adapters like SVGAdapter:

const animatedProps = useAnimatedProps(() => ({
  cx: x.value,
  r: radius.value,
}));

Custom color properties require manual processColor() wrapping inside the callback.

useDerivedValue

Creates a read-only shared value that recomputes when its dependencies change. Runs on the UI thread automatically. The .set() method is deprecated and will be removed.

If you need access to the previous value, use useAnimatedReaction instead.

createAnimatedComponent

Function components can accept a ref prop directly (React 19+). For older React versions, wrap with React.forwardRef(). Class components work directly.

Built-in animated components: Animated.View, Animated.Text, Animated.Image, Animated.ScrollView, Animated.FlatList.

useAnimatedRef

The ref value (current) is null until the component mounts. It is only accessible from the JS thread, so do not read it inside worklets.


Animation Functions

withSpring

Two configuration modes (cannot mix):

  • Physics-based (stiffness/damping)
  • Duration-based (duration/dampingRatio)

dampingRatio values: < 1 = underdamped (bouncy), 1 = critically damped (no bounce, fastest settle), > 1 = overdamped (slow, no bounce).

If both physics-based and duration-based configs are provided, duration-based overrides.

withDecay

clamp is required when rubberBandEffect is true. The rubber band effect makes the animation bounce at clamp boundaries instead of stopping.


Animation Modifiers

withRepeat

  • Non-positive values (0, -1) repeat infinitely until cancelled or unmounted.
  • reverse: true creates a ping-pong effect (plays forward, then backward).
  • reverse only works with animation functions (withSpring, withTiming). It does not work with animation modifiers like withSequence.

withClamp

Limits the animated value range. Designed for withSpring to prevent overshoot beyond boundaries. When the spring hits a clamped boundary, its dampingRatio is automatically reduced.


Composition Patterns

Modifiers nest freely:

// Staggered entrance
items.forEach((_, i) => {
  sv[i].value = withDelay(i * 100, withSpring(1));
});

// Infinite ping-pong
sv.value = withRepeat(withTiming(1, { duration: 800 }), -1, true);

// Multi-step sequence
sv.value = withSequence(
  withTiming(50, { duration: 200 }),
  withSpring(0),
  withDelay(300, withTiming(100))
);

// Clamped spring
sv.value = withClamp({ min: 0, max: 200 }, withSpring(scrollTarget));

Callback behavior

Callbacks on withTiming, withSpring, withDecay, and withRepeat are automatically workletized and run on the UI thread. They receive (finished: boolean, current: AnimatableValue) where finished is true if the animation completed normally, false if cancelled.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides comprehensive documentation and production patterns for React Native animations using Reanimated 4, Skia, and WebGPU. It includes instructions for environment setup, package installation, and configuration for the New Architecture. All referenced resources, including Node.js packages and external documentation, belong to the vendor (Software Mansion) or established community libraries. No malicious patterns or security risks were identified.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: MEDIUM · 1 issue

Signed by skilld at 43cde80. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 months ago

README badge

README badge for software-mansion-labs/skills/animations