Files
stack/packages/mosaic/framework/skills/vercel-react-native-skills/rules/animation-gpu-properties.md
T
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05:00

2.0 KiB

title, impact, impactDescription, tags
title impact impactDescription tags
Animate Transform and Opacity Instead of Layout Properties HIGH GPU-accelerated animations, no layout recalculation animation, performance, reanimated, transform, opacity

Animate Transform and Opacity Instead of Layout Properties

Avoid animating width, height, top, left, margin, or padding. These trigger layout recalculation on every frame. Instead, use transform (scale, translate) and opacity which run on the GPU without triggering layout.

Incorrect (animates height, triggers layout every frame):

import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated';

function CollapsiblePanel({ expanded }: { expanded: boolean }) {
  const animatedStyle = useAnimatedStyle(() => ({
    height: withTiming(expanded ? 200 : 0), // triggers layout on every frame
    overflow: 'hidden',
  }));

  return <Animated.View style={animatedStyle}>{children}</Animated.View>;
}

Correct (animates scaleY, GPU-accelerated):

import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated';

function CollapsiblePanel({ expanded }: { expanded: boolean }) {
  const animatedStyle = useAnimatedStyle(() => ({
    transform: [{ scaleY: withTiming(expanded ? 1 : 0) }],
    opacity: withTiming(expanded ? 1 : 0),
  }));

  return (
    <Animated.View style={[{ height: 200, transformOrigin: 'top' }, animatedStyle]}>
      {children}
    </Animated.View>
  );
}

Correct (animates translateY for slide animations):

import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated';

function SlideIn({ visible }: { visible: boolean }) {
  const animatedStyle = useAnimatedStyle(() => ({
    transform: [{ translateY: withTiming(visible ? 0 : 100) }],
    opacity: withTiming(visible ? 1 : 0),
  }));

  return <Animated.View style={animatedStyle}>{children}</Animated.View>;
}

GPU-accelerated properties: transform (translate, scale, rotate), opacity. Everything else triggers layout.