Repository navigation
cherry-pick(4.5-stable): Stop taking over UIManagerAnimationDelegate (#9901) - #10404
Conversation
…te (#9901) ## Summary We register `LayoutAnimationsProxy_Legacy` as the `UIManagerAnimationDelegate` only to receive `stopSurface` callback. Occupying that slot overwrites the `LayoutAnimationDriver` that RN installs there, which silently kills `LayoutAnimation.configureNext` for the whole app. The proxy now detects teardown itself: it registers a commit hook and marks a surface in `surfacesToRemove_` whenever a commit's root has no children. This could be a false positive if everything actually gets unmounted. As one of the next steps we should add a callback on the RN side that we can use the same way RN's `LayoutAnimation` api does. The check deliberately doesn't read the `ShadowTreeRegistry` as `pullTransaction`/commit hooks can run under the registry's shared lock, and re-locking there deadlocks with a pending writer (#8579 is that exact bug elsewhere). Freeing the slot restores `configureNext` to stock RN behavior per platform: it animates on iOS (`enableLayoutAnimationsOnIOS` defaults to true) and on Android when the app enables `enableLayoutAnimationsOnAndroid` (off by default in RN core - without it `configureNext` snaps in stock RN too). The `MountingCoordinator` chains RN's driver and our override delegate; the driver's own `stopSurface` flushes its withheld removals into the teardown transaction, so the consume condition always holds there. ## Test plan Run both our and RN LA's in the same app <details> <summary>Minimal testing example</summary> Paste into a Fabric app built with `ENABLE_SHARED_ELEMENT_TRANSITIONS=false` (legacy proxy). On Android, RN's `enableLayoutAnimationsOnAndroid` feature flag must be force-enabled — it's off by default in RN core, and without it `configureNext` snaps in stock RN too. ```tsx import React, { useState } from 'react'; import { Button, LayoutAnimation, View } from 'react-native'; import Animated, { FadeIn, FadeOut } from 'react-native-reanimated'; export default function ConfigureNextExample() { const [rows, setRows] = useState([0, 1, 2]); const [visible, setVisible] = useState(true); return ( <View style={{ flex: 1, padding: 32 }}> <Button title="configureNext: toggle rows" onPress={() => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); setRows(rows.length ? [] : [0, 1, 2]); }} /> <Button title="reanimated: toggle box" onPress={() => setVisible(!visible)} /> {rows.map((i) => ( <View key={i} style={{ height: 40, margin: 4, backgroundColor: 'skyblue' }} /> ))} {visible && ( <Animated.View entering={FadeIn} exiting={FadeOut} style={{ height: 80, margin: 4, backgroundColor: 'plum' }} /> )} </View> ); } ``` Expected: - "configureNext: toggle rows" animates the rows in and out (before this PR the transition snapped; the removal direction crashed when the driver replayed the withheld delete together with a final keyframe update) - "reanimated: toggle box" runs the entering/exiting animations as before — both systems coexist in the same app </details> <details> <summary> AI gibberish </summary> fabric-example with `ENABLE_SHARED_ELEMENT_TRANSITIONS=false` (legacy proxy), iOS sim + Android emulator (with `enableLayoutAnimationsOnAndroid` force-enabled on Android): - `configureNext` animates: video frame measurements show full easeInEaseOut interpolation on both platforms (iOS: 119 frames, 180→720px; Android: 158→275→388→468→514→630px) - `configureNext` delete animations (transitions that remove views): the driver replays withheld Remove/Delete together with a final keyframe update; our reordering used to mount that update after the delete and abort (found in the Bluesky app, deterministic). Fixed in the second commit; covered by the bench's remove-views button on both platforms - Reanimated entering/exiting/layout animations unchanged - Reload teardown: exit animations skipped (single-frame removal), clean registry teardown, animations work on the fresh surface - Adversarial pass: reloads fired at 0/60/150/350ms into exit animations, mount/unmount storms, concurrent reload requests, background/foreground with exits in flight, LogBox surface churn, `configureNext` mid-flight at teardown — 11/11 teardowns skipped exits with zero false positives on live surfaces, no crashes/ANRs/ghost views - Rendering `null` at the app root: exits animate normally (surface alive), UI recovers </details> (cherry picked from commit 27823cb) Co-authored-by: Tomasz Żelawski <tzelawski@gmail.com>
📝 WalkthroughWalkthroughLayout animation proxies now receive Merge Risk: 🟡 Moderate · up to This change updates legacy layout-animation delegate and cleanup behavior, but the current head may fail to compile with supported React Native versions and may leave removed views mounted during certain animation sequences. Merge should wait for these bounded correctness and build issues to be addressed. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp (1)
8-8: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd
<algorithm>forstd::ranges::any_of.Bruce found the real smoking gun here: the call at line 69 uses
std::ranges::any_of, which requires the direct<algorithm>include.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fd942da8-9754-4cee-bf10-a1788398e248
📒 Files selected for processing (5)
packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.hpackages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.hpackages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpppackages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.hpackages/react-native-reanimated/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Cherry-picking #9901