Skip to content

Commit b1f34aa

Browse files
authored
Flow: types first in react-native-renderer (#25363)
1 parent 9143864 commit b1f34aa

File tree

7 files changed

+36
-17
lines changed

7 files changed

+36
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {HostComponent} from './ReactNativeTypes';
11-
import type {ReactNodeList} from 'shared/ReactTypes';
11+
import type {ReactPortal, ReactNodeList} from 'shared/ReactTypes';
1212
import type {ElementRef, Element, ElementType} from 'react';
1313

1414
import './ReactFabricInjection';
@@ -249,7 +249,7 @@ function createPortal(
249249
children: ReactNodeList,
250250
containerTag: number,
251251
key: ?string = null,
252-
) {
252+
): ReactPortal {
253253
return createPortalImpl(children, containerTag, null, key);
254254
}
255255

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
* @flow
88
*/
99

10-
import type {AnyNativeEvent} from './legacy-events/PluginModuleType';
10+
import type {
11+
AnyNativeEvent,
12+
EventTypes,
13+
} from './legacy-events/PluginModuleType';
1114
import type {TopLevelType} from './legacy-events/TopLevelEventTypes';
1215
import SyntheticEvent from './legacy-events/SyntheticEvent';
1316
import type {PropagationPhases} from './legacy-events/PropagationPhases';
@@ -175,7 +178,7 @@ function accumulateDirectDispatches(events: ?(Array<Object> | Object)) {
175178
// End of inline
176179

177180
const ReactNativeBridgeEventPlugin = {
178-
eventTypes: {},
181+
eventTypes: ({}: EventTypes),
179182

180183
extractEvents: function(
181184
topLevelType: TopLevelType,

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ let createHierarchy;
3030
let getHostNode;
3131
let getHostProps;
3232
let lastNonHostInstance;
33-
let getInspectorDataForInstance;
33+
let getInspectorDataForInstance: (
34+
closestInstance: Fiber | null,
35+
) => InspectorData;
3436
let getOwnerHierarchy;
3537
let traverseOwnerTreeUp;
3638

@@ -142,8 +144,14 @@ if (__DEV__ || enableGetInspectorDataForInstanceInProduction) {
142144
};
143145
}
144146

145-
let getInspectorDataForViewTag;
146-
let getInspectorDataForViewAtPoint;
147+
let getInspectorDataForViewTag: (viewTag: number) => Object;
148+
let getInspectorDataForViewAtPoint: (
149+
findNodeHandle: (componentOrHandle: any) => ?number,
150+
inspectedView: Object,
151+
locationX: number,
152+
locationY: number,
153+
callback: (viewData: TouchedViewDataAtPoint) => mixed,
154+
) => void;
147155

148156
if (__DEV__) {
149157
getInspectorDataForViewTag = function(viewTag: number): Object {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {HostComponent} from './ReactNativeTypes';
11-
import type {ReactNodeList} from 'shared/ReactTypes';
11+
import type {ReactPortal, ReactNodeList} from 'shared/ReactTypes';
1212
import type {ElementRef, Element, ElementType} from 'react';
1313

1414
import './ReactNativeInjection';
@@ -248,7 +248,7 @@ function createPortal(
248248
children: ReactNodeList,
249249
containerTag: number,
250250
key: ?string = null,
251-
) {
251+
): ReactPortal {
252252
return createPortalImpl(children, containerTag, null, key);
253253
}
254254

packages/react-native-renderer/src/legacy-events/EventPluginRegistry.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import type {
1313
PluginName,
1414
LegacyPluginModule,
1515
} from './PluginModuleType';
16+
import type {TopLevelType} from './TopLevelEventTypes';
1617

1718
type NamesToPlugins = {
1819
[key: PluginName]: LegacyPluginModule<AnyNativeEvent>,
19-
...,
2020
};
2121
type EventPluginOrder = null | Array<PluginName>;
2222

@@ -166,30 +166,38 @@ function publishRegistrationName(
166166
/**
167167
* Ordered list of injected plugins.
168168
*/
169-
export const plugins = [];
169+
export const plugins: Array<LegacyPluginModule<AnyNativeEvent>> = [];
170170

171171
/**
172172
* Mapping from event name to dispatch config
173173
*/
174-
export const eventNameDispatchConfigs = {};
174+
export const eventNameDispatchConfigs: {
175+
[eventName: string]: DispatchConfig,
176+
} = {};
175177

176178
/**
177179
* Mapping from registration name to plugin module
178180
*/
179-
export const registrationNameModules = {};
181+
export const registrationNameModules: {
182+
[registrationName: string]: LegacyPluginModule<AnyNativeEvent>,
183+
} = {};
180184

181185
/**
182186
* Mapping from registration name to event name
183187
*/
184-
export const registrationNameDependencies = {};
188+
export const registrationNameDependencies: {
189+
[registrationName: string]: Array<TopLevelType> | void,
190+
} = {};
185191

186192
/**
187193
* Mapping from lowercase registration names to the properly cased version,
188194
* used to warn in the case of missing event handlers. Available
189195
* only in __DEV__.
190196
* @type {Object}
191197
*/
192-
export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
198+
export const possibleRegistrationNames: {
199+
[lowerCasedName: string]: string,
200+
} = __DEV__ ? {} : (null: any);
193201
// Trust the developer to only use possibleRegistrationNames in __DEV__
194202

195203
/**

packages/react-native-renderer/src/legacy-events/PluginModuleType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
} from './ReactSyntheticEventType';
1515
import type {TopLevelType} from './TopLevelEventTypes';
1616

17-
export type EventTypes = {[key: string]: DispatchConfig, ...};
17+
export type EventTypes = {[key: string]: DispatchConfig};
1818

1919
export type AnyNativeEvent = Event | KeyboardEvent | MouseEvent | TouchEvent;
2020

scripts/flow/config/flowconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ well_formed_exports.includes=<PROJECT_ROOT>/packages/react-fetch
7070
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-fs
7171
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-interactions
7272
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-is
73-
; well_formed_exports.includes=<PROJECT_ROOT>/packages/react-native-renderer
73+
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-native-renderer
7474
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-noop-renderer
7575
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-pg
7676
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-reconciler

0 commit comments

Comments
 (0)