From 4a7946bef566e52996c107cb9fd2b471ca27dd90 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Wed, 26 Mar 2025 20:05:28 -0700 Subject: [PATCH] Animated: Pass Target into `{dis,}connectAnimatedView` (#50229) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50229 Makes a few internal improvements to `AnimatedProps`: - Change `__connectAnimatedView` and `__disconnectAnimatedView` to be private methods, so that we can confidently change their type signatures. - Pass `#targetInstance` into those methods, so that the responsibility of verifying `#targetInstance`'s non-nullability is hoisted to the call sites. There should be no observable runtime behavior change. Changelog: [Internal] Reviewed By: javache Differential Revision: D71740601 fbshipit-source-id: 6abc6faf63f3c3274fd2d92baf0958d2471d4a63 --- .../Libraries/Animated/nodes/AnimatedProps.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js index 32305ee0f77..7e6de90377e 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedProps.js @@ -183,7 +183,7 @@ export default class AnimatedProps extends AnimatedNode { __detach(): void { if (this.__isNative && this.#targetInstance != null) { - this.__disconnectAnimatedView(); + this.#disconnectAnimatedView(this.#targetInstance); } this.#targetInstance = null; @@ -211,12 +211,12 @@ export default class AnimatedProps extends AnimatedNode { this.__isNative = true; // Since this does not call the super.__makeNative, we need to store the - // supplied platformConfig here, before calling __connectAnimatedView + // supplied platformConfig here, before calling #connectAnimatedView // where it will be needed to traverse the graph of attached values. super.__setPlatformConfig(platformConfig); if (this.#targetInstance != null) { - this.__connectAnimatedView(); + this.#connectAnimatedView(this.#targetInstance); } } } @@ -227,13 +227,13 @@ export default class AnimatedProps extends AnimatedNode { } this.#targetInstance = targetInstance; if (this.__isNative) { - this.__connectAnimatedView(); + this.#connectAnimatedView(this.#targetInstance); } } - __connectAnimatedView(): void { + #connectAnimatedView(targetInstance: TargetViewInstance): void { invariant(this.__isNative, 'Expected node to be marked as "native"'); - let nativeViewTag: ?number = findNodeHandle(this.#targetInstance); + let nativeViewTag: ?number = findNodeHandle(targetInstance); if (nativeViewTag == null) { if (process.env.NODE_ENV === 'test') { nativeViewTag = -1; @@ -247,9 +247,9 @@ export default class AnimatedProps extends AnimatedNode { ); } - __disconnectAnimatedView(): void { + #disconnectAnimatedView(targetInstance: TargetViewInstance): void { invariant(this.__isNative, 'Expected node to be marked as "native"'); - let nativeViewTag: ?number = findNodeHandle(this.#targetInstance); + let nativeViewTag: ?number = findNodeHandle(targetInstance); if (nativeViewTag == null) { if (process.env.NODE_ENV === 'test') { nativeViewTag = -1;