Skip to content

Commit 9518f11

Browse files
authored
Root import types from react-native in ReactNativeTypes (#33063)
1 parent 557a647 commit 9518f11

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

packages/react-native-renderer/src/ReactNativeTypes.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@
99
* @flow strict
1010
*/
1111

12-
import type {
13-
Component as ReactComponent,
14-
ElementRef,
15-
ElementType,
16-
MixedElement,
17-
} from 'react';
1812
import type {
1913
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
20-
MeasureOnSuccessCallback,
14+
HostInstance as PublicInstance,
2115
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
22-
PublicInstance,
16+
MeasureOnSuccessCallback,
2317
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
2418
PublicRootInstance,
2519
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
2620
PublicTextInstance,
27-
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
21+
} from 'react-native';
22+
23+
import * as React from 'react';
2824

2925
export type AttributeType<T, V> =
3026
| true
@@ -96,8 +92,8 @@ type InspectorDataProps = $ReadOnly<{
9692
}>;
9793

9894
type InspectorDataGetter = (
99-
<TElementType: ElementType>(
100-
componentOrHandle: ElementRef<TElementType> | number,
95+
<TElementType: React.ElementType>(
96+
componentOrHandle: React.ElementRef<TElementType> | number,
10197
) => ?number,
10298
) => $ReadOnly<{
10399
measure: (callback: MeasureOnSuccessCallback) => void,
@@ -140,7 +136,7 @@ export type RenderRootOptions = {
140136
+componentStack?: ?string,
141137
// $FlowFixMe[unclear-type] unknown props and state.
142138
// $FlowFixMe[value-as-type] Component in react repo is any-typed, but it will be well typed externally.
143-
+errorBoundary?: ?ReactComponent<any, any>,
139+
+errorBoundary?: ?React.Component<any, any>,
144140
},
145141
) => void,
146142
onRecoverableError?: (
@@ -154,11 +150,11 @@ export type RenderRootOptions = {
154150
* Provide minimal Flow typing for the high-level RN API and call it a day.
155151
*/
156152
export type ReactNativeType = {
157-
findHostInstance_DEPRECATED<TElementType: ElementType>(
158-
componentOrHandle: ?(ElementRef<TElementType> | number),
153+
findHostInstance_DEPRECATED<TElementType: React.ElementType>(
154+
componentOrHandle: ?(React.ElementRef<TElementType> | number),
159155
): ?PublicInstance,
160-
findNodeHandle<TElementType: ElementType>(
161-
componentOrHandle: ?(ElementRef<TElementType> | number),
156+
findNodeHandle<TElementType: React.ElementType>(
157+
componentOrHandle: ?(React.ElementRef<TElementType> | number),
162158
): ?number,
163159
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
164160
dispatchCommand(
@@ -168,11 +164,11 @@ export type ReactNativeType = {
168164
): void,
169165
sendAccessibilityEvent(handle: PublicInstance, eventType: string): void,
170166
render(
171-
element: MixedElement,
167+
element: React.MixedElement,
172168
containerTag: number,
173169
callback: ?() => void,
174170
options: ?RenderRootOptions,
175-
): ?ElementRef<ElementType>,
171+
): ?React.ElementRef<React.ElementType>,
176172
unmountComponentAtNode(containerTag: number): void,
177173
unmountComponentAtNodeAndRemoveContainer(containerTag: number): void,
178174
+unstable_batchedUpdates: <T>(fn: (T) => void, bookkeeping: T) => void,
@@ -183,11 +179,11 @@ export opaque type Node = mixed;
183179
export opaque type InternalInstanceHandle = mixed;
184180

185181
export type ReactFabricType = {
186-
findHostInstance_DEPRECATED<TElementType: ElementType>(
187-
componentOrHandle: ?(ElementRef<TElementType> | number),
182+
findHostInstance_DEPRECATED<TElementType: React.ElementType>(
183+
componentOrHandle: ?(React.ElementRef<TElementType> | number),
188184
): ?PublicInstance,
189-
findNodeHandle<TElementType: ElementType>(
190-
componentOrHandle: ?(ElementRef<TElementType> | number),
185+
findNodeHandle<TElementType: React.ElementType>(
186+
componentOrHandle: ?(React.ElementRef<TElementType> | number),
191187
): ?number,
192188
dispatchCommand(
193189
handle: PublicInstance,
@@ -197,12 +193,12 @@ export type ReactFabricType = {
197193
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
198194
sendAccessibilityEvent(handle: PublicInstance, eventType: string): void,
199195
render(
200-
element: MixedElement,
196+
element: React.MixedElement,
201197
containerTag: number,
202198
callback: ?() => void,
203199
concurrentRoot: ?boolean,
204200
options: ?RenderRootOptions,
205-
): ?ElementRef<ElementType>,
201+
): ?React.ElementRef<React.ElementType>,
206202
unmountComponentAtNode(containerTag: number): void,
207203
getNodeFromInternalInstanceHandle(
208204
internalInstanceHandle: InternalInstanceHandle,

scripts/flow/react-native-host-hooks.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ type RawEventEmitterEvent = $ReadOnly<{
5050
nativeEvent: {[string]: mixed, ...},
5151
}>;
5252

53+
declare opaque type __PublicInstance;
54+
declare opaque type __PublicTextInstance;
55+
declare opaque type __PublicRootInstance;
56+
5357
declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' {
5458
declare export function deepDiffer(
5559
one: any,
@@ -158,9 +162,9 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
158162
emit: (channel: string, event: RawEventEmitterEvent) => string,
159163
...
160164
};
161-
declare export opaque type PublicInstance;
162-
declare export opaque type PublicTextInstance;
163-
declare export opaque type PublicRootInstance;
165+
declare export type PublicInstance = __PublicInstance;
166+
declare export type PublicTextInstance = __PublicTextInstance;
167+
declare export type PublicRootInstance = __PublicRootInstance;
164168
declare export type MeasureOnSuccessCallback = __MeasureOnSuccessCallback;
165169
declare export type MeasureInWindowOnSuccessCallback =
166170
__MeasureInWindowOnSuccessCallback;
@@ -204,6 +208,13 @@ declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'
204208
declare module 'react-native/Libraries/ReactPrivate/ReactNativePrivateInitializeCore' {
205209
}
206210

211+
declare module 'react-native' {
212+
declare export type HostInstance = __PublicInstance;
213+
declare export type PublicTextInstance = __PublicTextInstance;
214+
declare export type PublicRootInstance = __PublicRootInstance;
215+
declare export type MeasureOnSuccessCallback = __MeasureOnSuccessCallback;
216+
}
217+
207218
// eslint-disable-next-line no-unused-vars
208219
declare const RN$enableMicrotasksInReact: boolean;
209220

0 commit comments

Comments
 (0)