Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync ReactNativeTypes from RN repo to React #21014

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function findHostInstance_DEPRECATED<TElementType: ElementType>(
// Fabric
return (hostInstance: any).canonical;
}
// $FlowFixMe
return hostInstance;
}

Expand Down
4 changes: 0 additions & 4 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
ViewConfig,
TouchedViewDataAtPoint,
} from './ReactNativeTypes';
Expand Down Expand Up @@ -186,9 +185,6 @@ class ReactFabricHostComponent {
}
}

// eslint-disable-next-line no-unused-expressions
(ReactFabricHostComponent.prototype: NativeMethods);

export * from 'react-reconciler/src/ReactFiberHostConfigWithNoMutation';
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoHydration';
export * from 'react-reconciler/src/ReactFiberHostConfigWithNoScopes';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
MeasureInWindowOnSuccessCallback,
MeasureLayoutOnSuccessCallback,
MeasureOnSuccessCallback,
NativeMethods,
ViewConfig,
} from './ReactNativeTypes';
import type {Instance} from './ReactNativeHostConfig';
Expand Down Expand Up @@ -126,7 +125,4 @@ class ReactNativeFiberHostComponent {
}
}

// eslint-disable-next-line no-unused-expressions
(ReactNativeFiberHostComponent.prototype: NativeMethods);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These casts are actually quite important. They make sure that Paper host components and Fabric host components have the same API, and that they match the flow types that products use.

If the issue is that the now exact NativeMethods no longer matches the inexact class *HostComponent does this work?

*HostComponent: {...NativeMethods, ...}

Essentially saying explicitly that it will include NativeMethods, as well as other things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work, nor does {| ... |} and a few other things I tried

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe what I said but wrapped in $ReadOnly.

$ReadOnly<{...NativeMethods, ...}>


export default ReactNativeFiberHostComponent;
1 change: 1 addition & 0 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function findHostInstance_DEPRECATED(
// Fabric
return (hostInstance: any).canonical;
}
// $FlowFixMe inexact ReactNativeFiberHostComponent is incompatible with exact $ReadOnly
return hostInstance;
}

Expand Down
5 changes: 2 additions & 3 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type PartialViewConfig = $ReadOnly<{
validAttributes?: PartialAttributeConfiguration,
}>;

export type NativeMethods = {
export type NativeMethods = {|
blur(): void,
focus(): void,
measure(callback: MeasureOnSuccessCallback): void,
Expand All @@ -105,8 +105,7 @@ export type NativeMethods = {
onFail?: () => void,
): void,
setNativeProps(nativeProps: {...}): void,
...
};
|};

export type HostComponent<T> = AbstractComponent<T, $ReadOnly<NativeMethods>>;

Expand Down