Skip to content

Commit ae0006f

Browse files
rubennortefacebook-github-bot
authored andcommitted
Move definition of public instances to ReactNativePrivateInterface (facebook#32446)
Summary: ## Summary > [!NOTE] > This only modifies types, so shouldn't have an impact at runtime. Some time ago we moved some type definitions from React to React Native in facebook#26437. This continues making progress on that so values that are created by React Native and passed to the React renderer (in this case public instances) are actually defined in React Native and not in React. This will allow us to modify the definition of some of these types without having to make changes in the React repository (in the short term, we want to refactor PublicInstance from an object to an interface, and then modify that interface to add all the new DOM methods). ## How did you test this change? Manually synced `ReactNativeTypes` on top of facebook#49602 and verified Flow passes. DiffTrain build for [9dd378ff1222335ff133bab2d61001fcc84a1c56](facebook/react@9dd378f) Differential Revision: D70091830
1 parent 9d60c70 commit ae0006f

File tree

1 file changed

+18
-78
lines changed

1 file changed

+18
-78
lines changed

packages/react-native/Libraries/Renderer/shims/ReactNativeTypes.js

Lines changed: 18 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,25 @@
77
* @noformat
88
* @nolint
99
* @flow strict
10-
* @generated SignedSource<<de5df78e34b3d51e1cc9efbc4e79c1d8>>
10+
* @generated SignedSource<<5c76b092e0c981f96ca894e381ee593b>>
1111
*/
1212

1313
import type {
1414
Component as ReactComponent,
1515
ElementRef,
1616
ElementType,
1717
MixedElement,
18-
RefSetter,
1918
} from 'react';
20-
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
21-
import {type PublicRootInstance} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
22-
23-
export type MeasureOnSuccessCallback = (
24-
x: number,
25-
y: number,
26-
width: number,
27-
height: number,
28-
pageX: number,
29-
pageY: number,
30-
) => void;
31-
32-
export type MeasureInWindowOnSuccessCallback = (
33-
x: number,
34-
y: number,
35-
width: number,
36-
height: number,
37-
) => void;
38-
39-
export type MeasureLayoutOnSuccessCallback = (
40-
left: number,
41-
top: number,
42-
width: number,
43-
height: number,
44-
) => void;
19+
import type {
20+
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
21+
MeasureOnSuccessCallback,
22+
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
23+
PublicInstance,
24+
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
25+
PublicRootInstance,
26+
// $FlowFixMe[nonstrict-import] TODO(@rubennorte)
27+
PublicTextInstance,
28+
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
4529

4630
export type AttributeType<T, V> =
4731
| true
@@ -107,45 +91,6 @@ export type PartialViewConfig = $ReadOnly<{
10791
validAttributes?: PartialAttributeConfiguration,
10892
}>;
10993

110-
/**
111-
* Current usages should migrate to this definition
112-
*/
113-
export interface INativeMethods {
114-
blur(): void;
115-
focus(): void;
116-
measure(callback: MeasureOnSuccessCallback): void;
117-
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
118-
measureLayout(
119-
relativeToNativeNode: number | HostInstance,
120-
onSuccess: MeasureLayoutOnSuccessCallback,
121-
onFail?: () => void,
122-
): void;
123-
setNativeProps(nativeProps: {...}): void;
124-
}
125-
126-
export type NativeMethods = $ReadOnly<{
127-
blur(): void,
128-
focus(): void,
129-
measure(callback: MeasureOnSuccessCallback): void,
130-
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
131-
measureLayout(
132-
relativeToNativeNode: number | HostInstance,
133-
onSuccess: MeasureLayoutOnSuccessCallback,
134-
onFail?: () => void,
135-
): void,
136-
setNativeProps(nativeProps: {...}): void,
137-
}>;
138-
139-
// This validates that INativeMethods and NativeMethods stay in sync using Flow!
140-
declare const ensureNativeMethodsAreSynced: NativeMethods;
141-
(ensureNativeMethodsAreSynced: INativeMethods);
142-
143-
export type HostInstance = NativeMethods;
144-
export type HostComponent<Config: {...}> = component(
145-
ref: RefSetter<HostInstance>,
146-
...Config
147-
);
148-
14994
type InspectorDataProps = $ReadOnly<{
15095
[propName: string]: string,
15196
...
@@ -212,20 +157,17 @@ export type RenderRootOptions = {
212157
export type ReactNativeType = {
213158
findHostInstance_DEPRECATED<TElementType: ElementType>(
214159
componentOrHandle: ?(ElementRef<TElementType> | number),
215-
): ?HostInstance,
160+
): ?PublicInstance,
216161
findNodeHandle<TElementType: ElementType>(
217162
componentOrHandle: ?(ElementRef<TElementType> | number),
218163
): ?number,
219-
isChildPublicInstance(
220-
parent: PublicInstance | HostComponent<empty>,
221-
child: PublicInstance | HostComponent<empty>,
222-
): boolean,
164+
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
223165
dispatchCommand(
224-
handle: HostInstance,
166+
handle: PublicInstance,
225167
command: string,
226168
args: Array<mixed>,
227169
): void,
228-
sendAccessibilityEvent(handle: HostInstance, eventType: string): void,
170+
sendAccessibilityEvent(handle: PublicInstance, eventType: string): void,
229171
render(
230172
element: MixedElement,
231173
containerTag: number,
@@ -240,23 +182,21 @@ export type ReactNativeType = {
240182

241183
export opaque type Node = mixed;
242184
export opaque type InternalInstanceHandle = mixed;
243-
type PublicInstance = mixed;
244-
type PublicTextInstance = mixed;
245185

246186
export type ReactFabricType = {
247187
findHostInstance_DEPRECATED<TElementType: ElementType>(
248188
componentOrHandle: ?(ElementRef<TElementType> | number),
249-
): ?HostInstance,
189+
): ?PublicInstance,
250190
findNodeHandle<TElementType: ElementType>(
251191
componentOrHandle: ?(ElementRef<TElementType> | number),
252192
): ?number,
253193
dispatchCommand(
254-
handle: HostInstance,
194+
handle: PublicInstance,
255195
command: string,
256196
args: Array<mixed>,
257197
): void,
258198
isChildPublicInstance(parent: PublicInstance, child: PublicInstance): boolean,
259-
sendAccessibilityEvent(handle: HostInstance, eventType: string): void,
199+
sendAccessibilityEvent(handle: PublicInstance, eventType: string): void,
260200
render(
261201
element: MixedElement,
262202
containerTag: number,

0 commit comments

Comments
 (0)