diff --git a/packages/react-native-renderer/src/ReactNativeTypes.js b/packages/react-native-renderer/src/ReactNativeTypes.js index 75f4a828c9077..eb5483d1b85a5 100644 --- a/packages/react-native-renderer/src/ReactNativeTypes.js +++ b/packages/react-native-renderer/src/ReactNativeTypes.js @@ -9,22 +9,18 @@ * @flow strict */ -import type { - Component as ReactComponent, - ElementRef, - ElementType, - MixedElement, -} from 'react'; import type { // $FlowFixMe[nonstrict-import] TODO(@rubennorte) - MeasureOnSuccessCallback, + HostInstance as PublicInstance, // $FlowFixMe[nonstrict-import] TODO(@rubennorte) - PublicInstance, + MeasureOnSuccessCallback, // $FlowFixMe[nonstrict-import] TODO(@rubennorte) PublicRootInstance, // $FlowFixMe[nonstrict-import] TODO(@rubennorte) PublicTextInstance, -} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; +} from 'react-native'; + +import * as React from 'react'; export type AttributeType = | true @@ -96,8 +92,8 @@ type InspectorDataProps = $ReadOnly<{ }>; type InspectorDataGetter = ( - ( - componentOrHandle: ElementRef | number, + ( + componentOrHandle: React.ElementRef | number, ) => ?number, ) => $ReadOnly<{ measure: (callback: MeasureOnSuccessCallback) => void, @@ -140,7 +136,7 @@ export type RenderRootOptions = { +componentStack?: ?string, // $FlowFixMe[unclear-type] unknown props and state. // $FlowFixMe[value-as-type] Component in react repo is any-typed, but it will be well typed externally. - +errorBoundary?: ?ReactComponent, + +errorBoundary?: ?React.Component, }, ) => void, onRecoverableError?: ( @@ -154,11 +150,11 @@ export type RenderRootOptions = { * Provide minimal Flow typing for the high-level RN API and call it a day. */ export type ReactNativeType = { - findHostInstance_DEPRECATED( - componentOrHandle: ?(ElementRef | number), + findHostInstance_DEPRECATED( + componentOrHandle: ?(React.ElementRef | number), ): ?PublicInstance, - findNodeHandle( - componentOrHandle: ?(ElementRef | number), + findNodeHandle( + componentOrHandle: ?(React.ElementRef | number), ): ?number, isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean, dispatchCommand( @@ -168,11 +164,11 @@ export type ReactNativeType = { ): void, sendAccessibilityEvent(handle: PublicInstance, eventType: string): void, render( - element: MixedElement, + element: React.MixedElement, containerTag: number, callback: ?() => void, options: ?RenderRootOptions, - ): ?ElementRef, + ): ?React.ElementRef, unmountComponentAtNode(containerTag: number): void, unmountComponentAtNodeAndRemoveContainer(containerTag: number): void, +unstable_batchedUpdates: (fn: (T) => void, bookkeeping: T) => void, @@ -183,11 +179,11 @@ export opaque type Node = mixed; export opaque type InternalInstanceHandle = mixed; export type ReactFabricType = { - findHostInstance_DEPRECATED( - componentOrHandle: ?(ElementRef | number), + findHostInstance_DEPRECATED( + componentOrHandle: ?(React.ElementRef | number), ): ?PublicInstance, - findNodeHandle( - componentOrHandle: ?(ElementRef | number), + findNodeHandle( + componentOrHandle: ?(React.ElementRef | number), ): ?number, dispatchCommand( handle: PublicInstance, @@ -197,12 +193,12 @@ export type ReactFabricType = { isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean, sendAccessibilityEvent(handle: PublicInstance, eventType: string): void, render( - element: MixedElement, + element: React.MixedElement, containerTag: number, callback: ?() => void, concurrentRoot: ?boolean, options: ?RenderRootOptions, - ): ?ElementRef, + ): ?React.ElementRef, unmountComponentAtNode(containerTag: number): void, getNodeFromInternalInstanceHandle( internalInstanceHandle: InternalInstanceHandle, diff --git a/scripts/flow/react-native-host-hooks.js b/scripts/flow/react-native-host-hooks.js index 840450b79cdb1..8eec4393eed97 100644 --- a/scripts/flow/react-native-host-hooks.js +++ b/scripts/flow/react-native-host-hooks.js @@ -50,6 +50,10 @@ type RawEventEmitterEvent = $ReadOnly<{ nativeEvent: {[string]: mixed, ...}, }>; +declare opaque type __PublicInstance; +declare opaque type __PublicTextInstance; +declare opaque type __PublicRootInstance; + declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' { declare export function deepDiffer( one: any, @@ -158,9 +162,9 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' emit: (channel: string, event: RawEventEmitterEvent) => string, ... }; - declare export opaque type PublicInstance; - declare export opaque type PublicTextInstance; - declare export opaque type PublicRootInstance; + declare export type PublicInstance = __PublicInstance; + declare export type PublicTextInstance = __PublicTextInstance; + declare export type PublicRootInstance = __PublicRootInstance; declare export type MeasureOnSuccessCallback = __MeasureOnSuccessCallback; declare export type MeasureInWindowOnSuccessCallback = __MeasureInWindowOnSuccessCallback; @@ -204,6 +208,13 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore' { } +declare module 'react-native' { + declare export type HostInstance = __PublicInstance; + declare export type PublicTextInstance = __PublicTextInstance; + declare export type PublicRootInstance = __PublicRootInstance; + declare export type MeasureOnSuccessCallback = __MeasureOnSuccessCallback; +} + // eslint-disable-next-line no-unused-vars declare const RN$enableMicrotasksInReact: boolean;