From 7b17dea0cf08bf943d41bbc1d23c6965a51f505d Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Mon, 16 Sep 2024 12:29:56 -0700 Subject: [PATCH] Call __makeNative on children before __getNativeTag (#46524) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46524 There's an interesting behavior in Animated where we effectively perform an O(N + M) traversal of the Animated graph, calling `__makeNative` on each "input", which in turn tends to call `__makeNative` on each "output" (so we revisit the current node M times when calling `__makeNative` on the M inputs). In practice, the behavior is still O(N), because M is small and finite (most Animated nodes have 1 or 2 inputs). All that said, some platforms (e.g., react-native-windows) rely on this revisiting behavior, where on the first visit, we recurse the node to its inputs, and on the subsequent visit, we update the `_platformConfig` value without recursion (see https://github.com/facebook/react-native/pull/32736 for the original change adding platformConfig). A recent change to AnimatedWithChildren (https://github.com/facebook/react-native/pull/46286) eagerly invokes `__getNativeTag` on AnimatedWithChildren in the initial recursion step, which forces materialization of the NativeAnimated node *before* it's `_platformConfig` is set. There is certainly some refactoring that needs to be done to improve all this, but for now, this change reverts to delay the call to `__getNativeTag` until after at least one `__makeNative` occurs on an input. ## Changelog [General][Fixed]: Order of operations related to platformConfig propagation in NativeAnimated Reviewed By: yungsters Differential Revision: D62768179 --- .../Libraries/Animated/nodes/AnimatedWithChildren.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js b/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js index 21de142464d9f6..9d4469e33c44c9 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js @@ -28,12 +28,10 @@ export default class AnimatedWithChildren extends AnimatedNode { const children = this._children; let length = children.length; if (length > 0) { - const nativeTag = this.__getNativeTag(); - for (let ii = 0; ii < length; ii++) { const child = children[ii]; child.__makeNative(platformConfig); - connectAnimatedNodes(nativeTag, child.__getNativeTag()); + connectAnimatedNodes(this.__getNativeTag(), child.__getNativeTag()); } } }