Skip to content

cherry-pick(4.5-stable): Stop taking over UIManagerAnimationDelegate (#9901) - #10404

Merged
tjzel merged 1 commit into
4.5-stablefrom
@tjzel/4.5-stable/cherry-pick-#9901
Aug 25, 2026
Merged

tjzel merged 1 commit into
4.5-stablefrom
@tjzel/4.5-stable/cherry-pick-#9901

Conversation

@tjzel

@tjzel tjzel commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Cherry-picking #9901

…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>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Layout animation proxies now receive uiManager on all platforms. The legacy proxy uses UIManagerCommitHook for surface registration and commit tracking. Transaction processing detects dropped surfaces, filters updates for deleted views, and controls dead-node cleanup. Android can defer cleanup pulls when mutation ordering requires it. Animation paths record the UI thread ID, and cancelled exit animations preserve layout configuration for reused tags.

Merge Risk: 🟡 Moderate · up to 3ab2b

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)
Check name Status Explanation
Description check ✅ Passed The description states that the pull request cherry-picks issue #9901, which matches the stated objective and changeset.
Title check ✅ Passed The title clearly identifies the cherry-pick target, branch, and primary change: stopping UIManagerAnimationDelegate takeover.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Add <algorithm> for std::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

📥 Commits

Reviewing files that changed from the base of the PR and between 00917d0 and 3ab2b1e.

📒 Files selected for processing (5)
  • packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h
  • packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h
  • packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp
  • packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h
  • packages/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.

@tjzel
tjzel merged commit dd29cdb into 4.5-stable Aug 25, 2026
20 checks passed
@tjzel
tjzel deleted the @tjzel/4.5-stable/cherry-pick-#9901 branch August 25, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants