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
This commit is contained in:
Tim Yung
2025-03-26 20:05:28 -07:00
committed by Facebook GitHub Bot
parent c9ff9570ab
commit 4a7946bef5
@@ -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;