mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Animated: Type #animatedView in AnimatedProps (#50228)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50228 Properly annotate the type of `#animatedView` in `AnimatedProps` and rename it to `#targetInstance`. Otherwise, no runtime behavior change. Changelog: [Internal] Reviewed By: javache Differential Revision: D71739606 fbshipit-source-id: c97e4bd323ad9b1c08fd4976f13b6b20e8fe4793
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f3a5d1957a
commit
c9ff9570ab
+11
-10
@@ -25,6 +25,8 @@ export type AnimatedPropsAllowlist = $ReadOnly<{
|
||||
[string]: true,
|
||||
}>;
|
||||
|
||||
type TargetViewInstance = React.ElementRef<React.ElementType>;
|
||||
|
||||
function createAnimatedProps(
|
||||
inputProps: {[string]: mixed},
|
||||
allowlist: ?AnimatedPropsAllowlist,
|
||||
@@ -75,11 +77,11 @@ function createAnimatedProps(
|
||||
}
|
||||
|
||||
export default class AnimatedProps extends AnimatedNode {
|
||||
#animatedView: any;
|
||||
#callback: () => void;
|
||||
#nodeKeys: $ReadOnlyArray<string>;
|
||||
#nodes: $ReadOnlyArray<AnimatedNode>;
|
||||
#props: {[string]: mixed};
|
||||
#targetInstance: ?TargetViewInstance = null;
|
||||
|
||||
constructor(
|
||||
inputProps: {[string]: mixed},
|
||||
@@ -89,7 +91,6 @@ export default class AnimatedProps extends AnimatedNode {
|
||||
) {
|
||||
super(config);
|
||||
const [nodeKeys, nodes, props] = createAnimatedProps(inputProps, allowlist);
|
||||
this.#animatedView = null;
|
||||
this.#nodeKeys = nodeKeys;
|
||||
this.#nodes = nodes;
|
||||
this.#props = props;
|
||||
@@ -181,10 +182,10 @@ export default class AnimatedProps extends AnimatedNode {
|
||||
}
|
||||
|
||||
__detach(): void {
|
||||
if (this.__isNative && this.#animatedView) {
|
||||
if (this.__isNative && this.#targetInstance != null) {
|
||||
this.__disconnectAnimatedView();
|
||||
}
|
||||
this.#animatedView = null;
|
||||
this.#targetInstance = null;
|
||||
|
||||
const nodes = this.#nodes;
|
||||
for (let ii = 0, length = nodes.length; ii < length; ii++) {
|
||||
@@ -214,17 +215,17 @@ export default class AnimatedProps extends AnimatedNode {
|
||||
// where it will be needed to traverse the graph of attached values.
|
||||
super.__setPlatformConfig(platformConfig);
|
||||
|
||||
if (this.#animatedView) {
|
||||
if (this.#targetInstance != null) {
|
||||
this.__connectAnimatedView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setNativeView(animatedView: any): void {
|
||||
if (this.#animatedView === animatedView) {
|
||||
setNativeView(targetInstance: TargetViewInstance): void {
|
||||
if (this.#targetInstance === targetInstance) {
|
||||
return;
|
||||
}
|
||||
this.#animatedView = animatedView;
|
||||
this.#targetInstance = targetInstance;
|
||||
if (this.__isNative) {
|
||||
this.__connectAnimatedView();
|
||||
}
|
||||
@@ -232,7 +233,7 @@ export default class AnimatedProps extends AnimatedNode {
|
||||
|
||||
__connectAnimatedView(): void {
|
||||
invariant(this.__isNative, 'Expected node to be marked as "native"');
|
||||
let nativeViewTag: ?number = findNodeHandle(this.#animatedView);
|
||||
let nativeViewTag: ?number = findNodeHandle(this.#targetInstance);
|
||||
if (nativeViewTag == null) {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
nativeViewTag = -1;
|
||||
@@ -248,7 +249,7 @@ export default class AnimatedProps extends AnimatedNode {
|
||||
|
||||
__disconnectAnimatedView(): void {
|
||||
invariant(this.__isNative, 'Expected node to be marked as "native"');
|
||||
let nativeViewTag: ?number = findNodeHandle(this.#animatedView);
|
||||
let nativeViewTag: ?number = findNodeHandle(this.#targetInstance);
|
||||
if (nativeViewTag == null) {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
nativeViewTag = -1;
|
||||
|
||||
@@ -890,6 +890,7 @@ exports[`public API should not change unintentionally Libraries/Animated/nodes/A
|
||||
style?: ?AnimatedStyleAllowlist,
|
||||
[string]: true,
|
||||
}>;
|
||||
type TargetViewInstance = React.ElementRef<React.ElementType>;
|
||||
declare export default class AnimatedProps extends AnimatedNode {
|
||||
constructor(
|
||||
inputProps: { [string]: mixed },
|
||||
@@ -898,7 +899,7 @@ declare export default class AnimatedProps extends AnimatedNode {
|
||||
config?: ?AnimatedNodeConfig
|
||||
): void;
|
||||
update(): void;
|
||||
setNativeView(animatedView: any): void;
|
||||
setNativeView(targetInstance: TargetViewInstance): void;
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user