Skip to content

Commit e4d650a

Browse files
rubennortefacebook-github-bot
authored andcommitted
Create specific module in RN to define the types for host instances and host components that ReactNativeTypes defines
Differential Revision: D69996010
1 parent b6c0b7a commit e4d650a

File tree

8 files changed

+105
-18
lines changed

8 files changed

+105
-18
lines changed

packages/react-native/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
*/
1010

1111
import type {AccessibilityRole} from '../../Components/View/ViewAccessibility';
12+
import type {ColorValue, ViewStyleProp} from '../../StyleSheet/StyleSheet';
13+
import type {DirectEventHandler} from '../../Types/CodegenTypes';
1214
import type {
1315
MeasureInWindowOnSuccessCallback,
1416
MeasureLayoutOnSuccessCallback,
1517
MeasureOnSuccessCallback,
16-
} from '../../Renderer/shims/ReactNativeTypes';
17-
import type {ColorValue, ViewStyleProp} from '../../StyleSheet/StyleSheet';
18-
import type {DirectEventHandler} from '../../Types/CodegenTypes';
18+
} from '../../Types/HostInstance';
1919

2020
import StyleSheet from '../../StyleSheet/StyleSheet';
2121
import dismissKeyboard from '../../Utilities/dismissKeyboard';

packages/react-native/Libraries/ReactNative/FabricUIManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import type {NativeElementReference} from '../../src/private/webapis/dom/nodes/s
1414
import type {
1515
InternalInstanceHandle,
1616
LayoutAnimationConfig,
17+
Node,
18+
} from '../Renderer/shims/ReactNativeTypes';
19+
import type {
1720
MeasureInWindowOnSuccessCallback,
1821
MeasureLayoutOnSuccessCallback,
1922
MeasureOnSuccessCallback,
20-
Node,
21-
} from '../Renderer/shims/ReactNativeTypes';
23+
} from '../Types/HostInstance';
2224
import type {RootTag} from '../Types/RootTagTypes';
2325

2426
import defineLazyObjectProperty from '../Utilities/defineLazyObjectProperty';

packages/react-native/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
import type {HostInstance} from '../../..';
1212
import type {
13-
INativeMethods,
1413
InternalInstanceHandle,
14+
ViewConfig,
15+
} from '../../Renderer/shims/ReactNativeTypes';
16+
import type {
17+
INativeMethods,
1518
MeasureInWindowOnSuccessCallback,
1619
MeasureLayoutOnSuccessCallback,
1720
MeasureOnSuccessCallback,
18-
ViewConfig,
19-
} from '../../Renderer/shims/ReactNativeTypes';
21+
} from '../../Types/HostInstance';
2022

2123
import TextInputState from '../../Components/TextInput/TextInputState';
2224
import {getNodeFromInternalInstanceHandle} from '../../ReactNative/RendererProxy';

packages/react-native/Libraries/Types/CoreEventTypes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @format
99
*/
1010

11-
import type {HostInstance} from '../Renderer/shims/ReactNativeTypes';
11+
import type {HostInstance} from './HostInstance';
1212

1313
export type NativeSyntheticEvent<+T> = $ReadOnly<{
1414
bubbles: ?boolean,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict
8+
* @format
9+
*/
10+
11+
import type {HostInstance} from './HostInstance';
12+
13+
export type HostComponent<Config: {...}> = component(
14+
ref: React$RefSetter<HostInstance>,
15+
...Config
16+
);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow strict
9+
*/
10+
11+
export type MeasureOnSuccessCallback = (
12+
x: number,
13+
y: number,
14+
width: number,
15+
height: number,
16+
pageX: number,
17+
pageY: number,
18+
) => void;
19+
20+
export type MeasureInWindowOnSuccessCallback = (
21+
x: number,
22+
y: number,
23+
width: number,
24+
height: number,
25+
) => void;
26+
27+
export type MeasureLayoutOnSuccessCallback = (
28+
left: number,
29+
top: number,
30+
width: number,
31+
height: number,
32+
) => void;
33+
34+
/**
35+
* Current usages should migrate to this definition
36+
*/
37+
export interface INativeMethods {
38+
blur(): void;
39+
focus(): void;
40+
measure(callback: MeasureOnSuccessCallback): void;
41+
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
42+
measureLayout(
43+
relativeToNativeNode: number | HostInstance,
44+
onSuccess: MeasureLayoutOnSuccessCallback,
45+
onFail?: () => void,
46+
): void;
47+
setNativeProps(nativeProps: {...}): void;
48+
}
49+
50+
export type NativeMethods = $ReadOnly<{
51+
blur(): void,
52+
focus(): void,
53+
measure(callback: MeasureOnSuccessCallback): void,
54+
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void,
55+
measureLayout(
56+
relativeToNativeNode: number | HostInstance,
57+
onSuccess: MeasureLayoutOnSuccessCallback,
58+
onFail?: () => void,
59+
): void,
60+
setNativeProps(nativeProps: {...}): void,
61+
}>;
62+
63+
// This validates that INativeMethods and NativeMethods stay in sync using Flow!
64+
declare const ensureNativeMethodsAreSynced: NativeMethods;
65+
(ensureNativeMethodsAreSynced: INativeMethods);
66+
67+
export type HostInstance = NativeMethods;

packages/react-native/index.js.flow

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
// TODO(T215317597): Reconsider the pre-existing grouping of these APIs
1919

20-
export type {
21-
HostComponent,
22-
HostInstance,
23-
} from './Libraries/Renderer/shims/ReactNativeTypes';
20+
export type {HostInstance} from './Libraries/Types/HostInstance';
21+
export type {HostComponent} from './Libraries/Types/HostComponent';
2422
export {default as registerCallableModule} from './Libraries/Core/registerCallableModule';
2523

2624
// #region Components

packages/react-native/src/private/webapis/dom/nodes/ReactNativeElement.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010

1111
// flowlint unsafe-getters-setters:off
1212

13-
import type {HostInstance} from '../../../../..';
1413
import type {
15-
INativeMethods,
1614
InternalInstanceHandle,
17-
MeasureInWindowOnSuccessCallback,
18-
MeasureLayoutOnSuccessCallback,
19-
MeasureOnSuccessCallback,
2015
Node as ShadowNode,
2116
ViewConfig,
2217
} from '../../../../../Libraries/Renderer/shims/ReactNativeTypes';
18+
import type {
19+
HostInstance,
20+
INativeMethods,
21+
MeasureInWindowOnSuccessCallback,
22+
MeasureLayoutOnSuccessCallback,
23+
MeasureOnSuccessCallback,
24+
} from '../../../../../Libraries/Types/HostInstance';
2325
import type {InstanceHandle} from './internals/NodeInternals';
2426
import type ReactNativeDocument from './ReactNativeDocument';
2527

0 commit comments

Comments
 (0)