Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build performant React Native and Expo apps with best practices for lists, animations, and navigation
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/animation-gpu-properties.md
1---2title: Animate Transform and Opacity Instead of Layout Properties3impact: HIGH4impactDescription: GPU-accelerated animations, no layout recalculation5tags: animation, performance, reanimated, transform, opacity6---78## Animate Transform and Opacity Instead of Layout Properties910Avoid 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.1112**Incorrect (animates height, triggers layout every frame):**1314```tsx15import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'1617function CollapsiblePanel({ expanded }: { expanded: boolean }) {18const animatedStyle = useAnimatedStyle(() => ({19height: withTiming(expanded ? 200 : 0), // triggers layout on every frame20overflow: 'hidden',21}))2223return <Animated.View style={animatedStyle}>{children}</Animated.View>24}25```2627**Correct (animates scaleY, GPU-accelerated):**2829```tsx30import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'3132function CollapsiblePanel({ expanded }: { expanded: boolean }) {33const animatedStyle = useAnimatedStyle(() => ({34transform: [35{ scaleY: withTiming(expanded ? 1 : 0) },36],37opacity: withTiming(expanded ? 1 : 0),38}))3940return (41<Animated.View style={[{ height: 200, transformOrigin: 'top' }, animatedStyle]}>42{children}43</Animated.View>44)45}46```4748**Correct (animates translateY for slide animations):**4950```tsx51import Animated, { useAnimatedStyle, withTiming } from 'react-native-reanimated'5253function SlideIn({ visible }: { visible: boolean }) {54const animatedStyle = useAnimatedStyle(() => ({55transform: [56{ translateY: withTiming(visible ? 0 : 100) },57],58opacity: withTiming(visible ? 1 : 0),59}))6061return <Animated.View style={animatedStyle}>{children}</Animated.View>62}63```6465GPU-accelerated properties: `transform` (translate, scale, rotate), `opacity`. Everything else triggers layout.66