Repository navigation
cherry-pick(4.4-stable): 30fps layout animations on iOS release builds (#9616) - #9724
Merged
Merged
Conversation
## Summary Fixes #9591. Layout animations (`entering` / `exiting` / `layout`) run at 30 FPS on iOS **Release** builds while staying smooth at 60 FPS in Debug. This is a regression from #9431. On the non-backend path, every `progressLayoutAnimation` scheduled the commit through `requestRenderForLayoutAnimations()`, which posts a render request on `REANodesManager`'s display link, deduped by a single-in-flight flag (`layoutAnimationRenderRequested_`) that the commit clears. The catch is that progress and the commit run on **two independent `CADisplayLink`s** — progress on the worklets `AnimationFrameQueue`, the commit (`performOperations`) on `REANodesManager` — and the two links are registered at different times, so their firing order within a frame isn't pinned. When the progress link fires first, it checks the flag before the commit has cleared it that frame, the render request is dropped, and the commit only runs every other frame → 30 FPS. Release happens to settle on progress-before-commit; Debug gets the opposite order and stays at 60 FPS. Android isn't affected because both frame sources go through a single `ReactChoreographer` callback queue. Instead of that gated cross-display-link request, we now flush layout-animation progress the same way animated-prop updates already do: once per frame from the worklet runtime's `requestAnimationFrameFinalizer` (which runs after all `requestAnimationFrame` callbacks), calling `_maybeFlushUIUpdatesQueue`. That's independent of display-link ordering, so the commit lands every frame. This also lets us drop `requestRenderForLayoutAnimations` and the gate flag entirely. The animation-backend path already drives its own flush from `runGrandCallback`, so it's untouched — `progressLayoutAnimation` / `endLayoutAnimation` just record the surface in `layoutAnimationFlushRequests_`. ## Test plan Run the example below on iOS in **Release** and hold the **Spam** button (it adds / removes / shuffles tiles on an interval, driving continuous `LinearTransition` layout animations). Before: the tiles step every other frame (30 FPS). After: smooth 60 FPS, matching Debug. <details> <summary>Example</summary> ```tsx import React, { useEffect, useRef, useState } from 'react'; import { Pressable, ScrollView, StyleSheet, Text, View } from 'react-native'; import Animated, { LinearTransition, ZoomIn, ZoomOut, } from 'react-native-reanimated'; const COLORS = [ '#ef4444', '#f97316', '#f59e0b', '#eab308', '#84cc16', '#22c55e', '#10b981', '#14b8a6', '#06b6d4', '#0ea5e9', '#3b82f6', '#6366f1', '#8b5cf6', '#a855f7', '#d946ef', '#ec4899', ]; type Tile = { id: string; color: string }; let nextId = 0; const makeTile = (): Tile => ({ id: `t-${nextId++}`, color: COLORS[Math.floor(Math.random() * COLORS.length)], }); const initialTiles = () => Array.from({ length: 100 }, makeTile); export default function StressDemo() { const [tiles, setTiles] = useState<Tile[]>(initialTiles); const [spam, setSpam] = useState(false); const tickRef = useRef(0); const add = (n: number) => setTiles((prev) => [...prev, ...Array.from({ length: n }, makeTile)]); const remove = (n: number) => setTiles((prev) => prev.slice(0, Math.max(0, prev.length - n))); const shuffle = () => setTiles((prev) => [...prev].sort(() => Math.random() - 0.5)); const reset = () => setTiles(initialTiles()); useEffect(() => { if (!spam) return; const id = setInterval(() => { const phase = tickRef.current++ % 3; if (phase === 0) add(20); else if (phase === 1) remove(20); else shuffle(); }, 500); return () => clearInterval(id); }, [spam]); return ( <View style={styles.container}> <View style={styles.toolbar}> <Pressable style={styles.button} onPress={() => add(20)}> <Text style={styles.buttonText}>+20</Text> </Pressable> <Pressable style={styles.button} onPress={() => remove(20)}> <Text style={styles.buttonText}>-20</Text> </Pressable> <Pressable style={styles.button} onPress={shuffle}> <Text style={styles.buttonText}>Shuffle</Text> </Pressable> <Pressable style={[styles.button, spam && styles.buttonActive]} onPress={() => setSpam((s) => !s)}> <Text style={styles.buttonText}>{spam ? 'Stop' : 'Spam'}</Text> </Pressable> <Pressable style={styles.button} onPress={reset}> <Text style={styles.buttonText}>Reset</Text> </Pressable> </View> <Text style={styles.count}> Tiles: {tiles.length} · ZoomIn / ZoomOut / LinearTransition </Text> <ScrollView contentContainerStyle={styles.grid}> {tiles.map((tile) => ( <Animated.View key={tile.id} entering={ZoomIn.duration(250)} exiting={ZoomOut.duration(250)} layout={LinearTransition.duration(250)} style={[styles.tile, { backgroundColor: tile.color }]} /> ))} </ScrollView> </View> ); } const styles = StyleSheet.create({ container: { flex: 1 }, toolbar: { flexDirection: 'row', flexWrap: 'wrap', padding: 8, gap: 8, backgroundColor: '#f3f4f6', }, button: { paddingHorizontal: 12, paddingVertical: 8, backgroundColor: '#1f2937', borderRadius: 6, }, buttonActive: { backgroundColor: '#dc2626' }, buttonText: { color: 'white', fontWeight: '600' }, count: { paddingHorizontal: 12, paddingVertical: 4, fontWeight: '600', color: '#374151', }, grid: { flexDirection: 'row', flexWrap: 'wrap', padding: 8, gap: 6, }, tile: { width: 50, height: 50, borderRadius: 6, }, }); ``` </details>
tjzel
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cherry-picking for Reanimated 4.4.2 release