Skip to content

Commit

Permalink
Call __makeNative on children before __getNativeTag (#46524)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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 #32736 for the original change adding platformConfig).

A recent change to AnimatedWithChildren (#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

fbshipit-source-id: ca9d911503e0630bc3a1309b21f9686aa77ac8b9
  • Loading branch information
rozele authored and facebook-github-bot committed Sep 16, 2024
1 parent 7aeff18 commit a64183b
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down

0 comments on commit a64183b

Please sign in to comment.