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.

scroll-and-events.md

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

Scroll, Events, and Utilities

Patterns for scroll-driven animations, event-based reactions, frame callbacks, and measurement in Reanimated 4.

For API signatures and parameter details, webfetch the linked documentation pages below.


Scroll-Driven Animations

useAnimatedScrollHandler

Respond to scroll events with multiple handlers:

const scrollHandler = useAnimatedScrollHandler({
  onScroll: (event, context) => {
    offset.value = event.contentOffset.y;
  },
  onBeginDrag: (event, context) => {
    context.startY = event.contentOffset.y;
  },
  onEndDrag: (event, context) => {
    if (event.contentOffset.y - context.startY > 100) {
      offset.value = withSpring(200);
    }
  },
});

<Animated.ScrollView onScroll={scrollHandler}>
  {children}
</Animated.ScrollView>

Available handlers: onScroll, onBeginDrag, onEndDrag, onMomentumBegin, onMomentumEnd.

The context object is shared between all handlers for the same component, letting you pass state across events (e.g., save drag start position in onBeginDrag, read it in onEndDrag).

Passing a single function instead of an object is treated as onScroll.

Gotchas:

  • Must use Animated.ScrollView, not plain ScrollView.
  • On Web, only onScroll fires. Other events are iOS/Android only.

useScrollOffset

Simpler alternative when you only need the scroll position as a shared value:

const animatedRef = useAnimatedRef<Animated.ScrollView>();
const scrollOffset = useScrollOffset(animatedRef);

const headerStyle = useAnimatedStyle(() => ({
  opacity: interpolate(scrollOffset.value, [0, 100], [1, 0]),
}));

Automatically detects horizontal or vertical scroll. Works with ScrollView, FlatList, and FlashList. The ref can be changed at runtime.

scrollTo

Programmatic scrolling from the UI thread:

const animatedRef = useAnimatedRef<Animated.ScrollView>();

// In a worklet or useDerivedValue
scrollTo(animatedRef, 0, targetY, true); // (ref, x, y, animated)

Can only be called from the UI thread. Wrap with scheduleOnUI() when calling from RN-thread event handlers.


Value Mapping Utilities

interpolate

Maps a numeric value from one range to another:

const opacity = interpolate(scrollOffset.value, [0, 100, 200], [1, 0.5, 0]);

Input values must be in increasing order.

interpolateColor

Maps a numeric value to a color, producing smooth color transitions:

const color = interpolateColor(progress.value, [0, 1], ['#ff0000', '#0000ff'], 'RGB');

Color spaces: 'RGB' (default), 'HSV', 'LAB' (Oklab, perceptually uniform).


Event Reactions

useAnimatedReaction

React to shared value changes with access to both current and previous values:

useAnimatedReaction(
  () => Math.floor(scrollOffset.value / PAGE_HEIGHT),
  (currentPage, previousPage) => {
    if (previousPage !== null && currentPage !== previousPage) {
      scheduleOnRN(onPageChanged, currentPage);
    }
  }
);

The prepare function transforms/filters shared values before comparison. The react function fires when the prepared value changes.

Critical: Do not mutate the same shared value in react that you track in prepare. This causes an infinite loop.

Use prepare to reduce callback frequency (e.g., Math.floor() to react only on whole page changes instead of every pixel).


Frame Callbacks

useFrameCallback

Run logic on every frame (60Hz or 120Hz depending on the device):

const frameCallback = useFrameCallback((frameInfo) => {
  progress.value += (frameInfo.timeSincePreviousFrame ?? 0) * speed;
});

// Pause/resume
frameCallback.setActive(false);
frameCallback.setActive(true);
  • autostart (second parameter, default true) controls whether the callback begins immediately.
  • Always memoize the callback with useCallback to avoid recreation on every render.
  • Use time deltas (timeSincePreviousFrame) for frame-rate-independent animations.

Measurement

measure

Synchronously get a view's dimensions and position on the UI thread:

const animatedRef = useAnimatedRef<Animated.View>();

const animatedStyle = useAnimatedStyle(() => {
  if (!_WORKLET) return {}; // Guard: first evaluation runs on JS thread

  const measurements = measure(animatedRef);
  if (measurements === null) return {};

  return {
    transform: [{ translateY: -measurements.height }],
  };
});

Returns { x, y, width, height, pageX, pageY } or null if the component is unmounted or off-screen (e.g., recycled FlatList items).

Rules:

  • Always check for null before using measurements.
  • In useAnimatedStyle, guard with if (!_WORKLET) return {} because the first evaluation runs on the JS thread where measure is unavailable.
  • Wrap with scheduleOnUI() when calling from RN-thread event handlers.
  • Not available with Remote JS Debugger (use Chrome DevTools).

Device Sensors

useAnimatedSensor tracks device motion (accelerometer, gyroscope, rotation) for parallax and tilt animations. iOS requires location services enabled. Web requires HTTPS.


Keyboard (Deprecated)

useAnimatedKeyboard is deprecated in Reanimated 4. Use react-native-keyboard-controller for keyboard-aware animations.

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