Skip to content

Root import types from react-native in ReactNativeTypes #33063

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

Merged
merged 11 commits into from
May 8, 2025
Merged
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
44 changes: 20 additions & 24 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, V> =
| true
Expand Down Expand Up @@ -96,8 +92,8 @@ type InspectorDataProps = $ReadOnly<{
}>;

type InspectorDataGetter = (
<TElementType: ElementType>(
componentOrHandle: ElementRef<TElementType> | number,
<TElementType: React.ElementType>(
componentOrHandle: React.ElementRef<TElementType> | number,
) => ?number,
) => $ReadOnly<{
measure: (callback: MeasureOnSuccessCallback) => void,
Expand Down Expand Up @@ -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<any, any>,
+errorBoundary?: ?React.Component<any, any>,
},
) => void,
onRecoverableError?: (
Expand All @@ -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<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
findHostInstance_DEPRECATED<TElementType: React.ElementType>(
componentOrHandle: ?(React.ElementRef<TElementType> | number),
): ?PublicInstance,
findNodeHandle<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
findNodeHandle<TElementType: React.ElementType>(
componentOrHandle: ?(React.ElementRef<TElementType> | number),
): ?number,
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
dispatchCommand(
Expand All @@ -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<ElementType>,
): ?React.ElementRef<React.ElementType>,
unmountComponentAtNode(containerTag: number): void,
unmountComponentAtNodeAndRemoveContainer(containerTag: number): void,
+unstable_batchedUpdates: <T>(fn: (T) => void, bookkeeping: T) => void,
Expand All @@ -183,11 +179,11 @@ export opaque type Node = mixed;
export opaque type InternalInstanceHandle = mixed;

export type ReactFabricType = {
findHostInstance_DEPRECATED<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
findHostInstance_DEPRECATED<TElementType: React.ElementType>(
componentOrHandle: ?(React.ElementRef<TElementType> | number),
): ?PublicInstance,
findNodeHandle<TElementType: ElementType>(
componentOrHandle: ?(ElementRef<TElementType> | number),
findNodeHandle<TElementType: React.ElementType>(
componentOrHandle: ?(React.ElementRef<TElementType> | number),
): ?number,
dispatchCommand(
handle: PublicInstance,
Expand All @@ -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<ElementType>,
): ?React.ElementRef<React.ElementType>,
unmountComponentAtNode(containerTag: number): void,
getNodeFromInternalInstanceHandle(
internalInstanceHandle: InternalInstanceHandle,
Expand Down
17 changes: 14 additions & 3 deletions scripts/flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Loading