diff --git a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js index 28d259fc5d0e5..7a253304fff07 100644 --- a/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js +++ b/packages/react-native-renderer/src/ReactNativeFiberHostComponent.js @@ -7,14 +7,13 @@ * @flow */ +import type {ViewConfig} from './ReactNativeTypes'; import type { - HostInstance, + LegacyPublicInstance, + MeasureOnSuccessCallback, MeasureInWindowOnSuccessCallback, MeasureLayoutOnSuccessCallback, - MeasureOnSuccessCallback, - INativeMethods, - ViewConfig, -} from './ReactNativeTypes'; +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; import type {Instance} from './ReactFiberConfigNative'; // Modules provided by RN: @@ -29,7 +28,7 @@ import { warnForStyleProps, } from './NativeMethodsMixinUtils'; -class ReactNativeFiberHostComponent implements INativeMethods { +class ReactNativeFiberHostComponent implements LegacyPublicInstance { _children: Array; _nativeTag: number; _internalFiberInstanceHandleDEV: Object; @@ -71,7 +70,7 @@ class ReactNativeFiberHostComponent implements INativeMethods { } measureLayout( - relativeToNativeNode: number | HostInstance, + relativeToNativeNode: number | LegacyPublicInstance, onSuccess: MeasureLayoutOnSuccessCallback, onFail?: () => void /* currently unused */, ) { diff --git a/packages/react-native-renderer/src/ReactNativeFiberInspector.js b/packages/react-native-renderer/src/ReactNativeFiberInspector.js index 47d588d448a18..e8be83f9a9f41 100644 --- a/packages/react-native-renderer/src/ReactNativeFiberInspector.js +++ b/packages/react-native-renderer/src/ReactNativeFiberInspector.js @@ -236,6 +236,7 @@ function getInspectorDataForViewAtPoint( pointerY: locationY, frame: {left, top, width, height}, touchedViewTag: nativeViewTag, + // $FlowExpectedError[incompatible-call] closestPublicInstance: nativeViewTag, }); }, diff --git a/packages/react-native-renderer/src/ReactNativePublicCompat.js b/packages/react-native-renderer/src/ReactNativePublicCompat.js index c8883261f7fc4..e0193ddc37e0e 100644 --- a/packages/react-native-renderer/src/ReactNativePublicCompat.js +++ b/packages/react-native-renderer/src/ReactNativePublicCompat.js @@ -7,8 +7,9 @@ * @flow */ -import type {Node, HostComponent} from './ReactNativeTypes'; +import type {Node} from './ReactNativeTypes'; import type {ElementRef, ElementType} from 'react'; +import type {PublicInstance} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; // Modules provided by RN: import { @@ -32,7 +33,7 @@ import { export function findHostInstance_DEPRECATED( componentOrHandle: ?(ElementRef | number), -): ?ElementRef> { +): ?PublicInstance { if (__DEV__) { const owner = currentOwner; if (owner !== null && isRendering && owner.stateNode !== null) { @@ -222,15 +223,10 @@ export function getNodeFromInternalInstanceHandle( ); } -// Should have been PublicInstance from ReactFiberConfigFabric -type FabricPublicInstance = mixed; -// Should have been PublicInstance from ReactFiberConfigNative -type PaperPublicInstance = HostComponent; - // Remove this once Paper is no longer supported and DOM Node API are enabled by default in RN. export function isChildPublicInstance( - parentInstance: FabricPublicInstance | PaperPublicInstance, - childInstance: FabricPublicInstance | PaperPublicInstance, + parentInstance: PublicInstance, + childInstance: PublicInstance, ): boolean { if (__DEV__) { // Paper diff --git a/packages/react-native-renderer/src/ReactNativeTypes.js b/packages/react-native-renderer/src/ReactNativeTypes.js index 1aa11cb3be0d7..4fdf4ea09e0f1 100644 --- a/packages/react-native-renderer/src/ReactNativeTypes.js +++ b/packages/react-native-renderer/src/ReactNativeTypes.js @@ -14,33 +14,17 @@ import type { ElementRef, ElementType, MixedElement, - RefSetter, } from 'react'; -// $FlowFixMe[nonstrict-import] TODO(@rubennorte) -import {type PublicRootInstance} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; - -export type MeasureOnSuccessCallback = ( - x: number, - y: number, - width: number, - height: number, - pageX: number, - pageY: number, -) => void; - -export type MeasureInWindowOnSuccessCallback = ( - x: number, - y: number, - width: number, - height: number, -) => void; - -export type MeasureLayoutOnSuccessCallback = ( - left: number, - top: number, - width: number, - height: number, -) => void; +import type { + // $FlowFixMe[nonstrict-import] TODO(@rubennorte) + MeasureOnSuccessCallback, + // $FlowFixMe[nonstrict-import] TODO(@rubennorte) + PublicInstance, + // $FlowFixMe[nonstrict-import] TODO(@rubennorte) + PublicRootInstance, + // $FlowFixMe[nonstrict-import] TODO(@rubennorte) + PublicTextInstance, +} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; export type AttributeType = | true @@ -106,45 +90,6 @@ export type PartialViewConfig = $ReadOnly<{ validAttributes?: PartialAttributeConfiguration, }>; -/** - * Current usages should migrate to this definition - */ -export interface INativeMethods { - blur(): void; - focus(): void; - measure(callback: MeasureOnSuccessCallback): void; - measureInWindow(callback: MeasureInWindowOnSuccessCallback): void; - measureLayout( - relativeToNativeNode: number | HostInstance, - onSuccess: MeasureLayoutOnSuccessCallback, - onFail?: () => void, - ): void; - setNativeProps(nativeProps: {...}): void; -} - -export type NativeMethods = $ReadOnly<{ - blur(): void, - focus(): void, - measure(callback: MeasureOnSuccessCallback): void, - measureInWindow(callback: MeasureInWindowOnSuccessCallback): void, - measureLayout( - relativeToNativeNode: number | HostInstance, - onSuccess: MeasureLayoutOnSuccessCallback, - onFail?: () => void, - ): void, - setNativeProps(nativeProps: {...}): void, -}>; - -// This validates that INativeMethods and NativeMethods stay in sync using Flow! -declare const ensureNativeMethodsAreSynced: NativeMethods; -(ensureNativeMethodsAreSynced: INativeMethods); - -export type HostInstance = NativeMethods; -export type HostComponent = component( - ref: RefSetter, - ...Config -); - type InspectorDataProps = $ReadOnly<{ [propName: string]: string, ... @@ -211,20 +156,17 @@ export type RenderRootOptions = { export type ReactNativeType = { findHostInstance_DEPRECATED( componentOrHandle: ?(ElementRef | number), - ): ?HostInstance, + ): ?PublicInstance, findNodeHandle( componentOrHandle: ?(ElementRef | number), ): ?number, - isChildPublicInstance( - parent: PublicInstance | HostComponent, - child: PublicInstance | HostComponent, - ): boolean, + isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean, dispatchCommand( - handle: HostInstance, + handle: PublicInstance, command: string, args: Array, ): void, - sendAccessibilityEvent(handle: HostInstance, eventType: string): void, + sendAccessibilityEvent(handle: PublicInstance, eventType: string): void, render( element: MixedElement, containerTag: number, @@ -239,23 +181,21 @@ export type ReactNativeType = { export opaque type Node = mixed; export opaque type InternalInstanceHandle = mixed; -type PublicInstance = mixed; -type PublicTextInstance = mixed; export type ReactFabricType = { findHostInstance_DEPRECATED( componentOrHandle: ?(ElementRef | number), - ): ?HostInstance, + ): ?PublicInstance, findNodeHandle( componentOrHandle: ?(ElementRef | number), ): ?number, dispatchCommand( - handle: HostInstance, + handle: PublicInstance, command: string, args: Array, ): void, isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean, - sendAccessibilityEvent(handle: HostInstance, eventType: string): void, + sendAccessibilityEvent(handle: PublicInstance, eventType: string): void, render( element: MixedElement, containerTag: number, diff --git a/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js index bbc2df595cea6..5800e445dd30b 100644 --- a/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js +++ b/packages/react-native-renderer/src/__mocks__/react-native/Libraries/ReactPrivate/ReactNativePrivateInterface.js @@ -7,10 +7,6 @@ * @flow strict-local */ -export opaque type PublicInstance = mixed; -export opaque type PublicTextInstance = mixed; -export opaque type PublicRootInstance = mixed; - module.exports = { get BatchedBridge() { return require('./BatchedBridge.js'); diff --git a/scripts/flow/react-native-host-hooks.js b/scripts/flow/react-native-host-hooks.js index 2620324b21287..78fa4891c1bfb 100644 --- a/scripts/flow/react-native-host-hooks.js +++ b/scripts/flow/react-native-host-hooks.js @@ -9,9 +9,26 @@ // libdefs cannot actually import. These are supposed to be the types imported // from 'react-native-renderer/src/ReactNativeTypes' -type __MeasureOnSuccessCallback = any; -type __MeasureInWindowOnSuccessCallback = any; -type __MeasureLayoutOnSuccessCallback = any; +type __MeasureOnSuccessCallback = ( + x: number, + y: number, + width: number, + height: number, + pageX: number, + pageY: number, +) => void; +type __MeasureInWindowOnSuccessCallback = ( + x: number, + y: number, + width: number, + height: number, +) => void; +type __MeasureLayoutOnSuccessCallback = ( + left: number, + top: number, + width: number, + height: number, +) => void; type __ReactNativeBaseComponentViewConfig = any; type __ViewConfigGetter = any; type __ViewConfig = any; @@ -144,6 +161,23 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' declare export opaque type PublicInstance; declare export opaque type PublicTextInstance; declare export opaque type PublicRootInstance; + declare export type MeasureOnSuccessCallback = __MeasureOnSuccessCallback; + declare export type MeasureInWindowOnSuccessCallback = + __MeasureInWindowOnSuccessCallback; + declare export type MeasureLayoutOnSuccessCallback = + __MeasureLayoutOnSuccessCallback; + declare export interface LegacyPublicInstance { + blur(): void; + focus(): void; + measure(callback: __MeasureOnSuccessCallback): void; + measureInWindow(callback: __MeasureInWindowOnSuccessCallback): void; + measureLayout( + relativeToNativeNode: number | LegacyPublicInstance, + onSuccess: __MeasureLayoutOnSuccessCallback, + onFail?: () => void, + ): void; + setNativeProps(nativeProps: {...}): void; + } declare export function getNodeFromPublicInstance( publicInstance: PublicInstance, ): Object;