Skip to content

Commit

Permalink
Flow: types first in react-native-renderer (#25363)
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens authored Oct 3, 2022
1 parent 9143864 commit b1f34aa
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type {HostComponent} from './ReactNativeTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {ReactPortal, ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef, Element, ElementType} from 'react';

import './ReactFabricInjection';
Expand Down Expand Up @@ -249,7 +249,7 @@ function createPortal(
children: ReactNodeList,
containerTag: number,
key: ?string = null,
) {
): ReactPortal {
return createPortalImpl(children, containerTag, null, key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* @flow
*/

import type {AnyNativeEvent} from './legacy-events/PluginModuleType';
import type {
AnyNativeEvent,
EventTypes,
} from './legacy-events/PluginModuleType';
import type {TopLevelType} from './legacy-events/TopLevelEventTypes';
import SyntheticEvent from './legacy-events/SyntheticEvent';
import type {PropagationPhases} from './legacy-events/PropagationPhases';
Expand Down Expand Up @@ -175,7 +178,7 @@ function accumulateDirectDispatches(events: ?(Array<Object> | Object)) {
// End of inline

const ReactNativeBridgeEventPlugin = {
eventTypes: {},
eventTypes: ({}: EventTypes),

extractEvents: function(
topLevelType: TopLevelType,
Expand Down
14 changes: 11 additions & 3 deletions packages/react-native-renderer/src/ReactNativeFiberInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ let createHierarchy;
let getHostNode;
let getHostProps;
let lastNonHostInstance;
let getInspectorDataForInstance;
let getInspectorDataForInstance: (
closestInstance: Fiber | null,
) => InspectorData;
let getOwnerHierarchy;
let traverseOwnerTreeUp;

Expand Down Expand Up @@ -142,8 +144,14 @@ if (__DEV__ || enableGetInspectorDataForInstanceInProduction) {
};
}

let getInspectorDataForViewTag;
let getInspectorDataForViewAtPoint;
let getInspectorDataForViewTag: (viewTag: number) => Object;
let getInspectorDataForViewAtPoint: (
findNodeHandle: (componentOrHandle: any) => ?number,
inspectedView: Object,
locationX: number,
locationY: number,
callback: (viewData: TouchedViewDataAtPoint) => mixed,
) => void;

if (__DEV__) {
getInspectorDataForViewTag = function(viewTag: number): Object {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type {HostComponent} from './ReactNativeTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {ReactPortal, ReactNodeList} from 'shared/ReactTypes';
import type {ElementRef, Element, ElementType} from 'react';

import './ReactNativeInjection';
Expand Down Expand Up @@ -248,7 +248,7 @@ function createPortal(
children: ReactNodeList,
containerTag: number,
key: ?string = null,
) {
): ReactPortal {
return createPortalImpl(children, containerTag, null, key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import type {
PluginName,
LegacyPluginModule,
} from './PluginModuleType';
import type {TopLevelType} from './TopLevelEventTypes';

type NamesToPlugins = {
[key: PluginName]: LegacyPluginModule<AnyNativeEvent>,
...,
};
type EventPluginOrder = null | Array<PluginName>;

Expand Down Expand Up @@ -166,30 +166,38 @@ function publishRegistrationName(
/**
* Ordered list of injected plugins.
*/
export const plugins = [];
export const plugins: Array<LegacyPluginModule<AnyNativeEvent>> = [];

/**
* Mapping from event name to dispatch config
*/
export const eventNameDispatchConfigs = {};
export const eventNameDispatchConfigs: {
[eventName: string]: DispatchConfig,
} = {};

/**
* Mapping from registration name to plugin module
*/
export const registrationNameModules = {};
export const registrationNameModules: {
[registrationName: string]: LegacyPluginModule<AnyNativeEvent>,
} = {};

/**
* Mapping from registration name to event name
*/
export const registrationNameDependencies = {};
export const registrationNameDependencies: {
[registrationName: string]: Array<TopLevelType> | void,
} = {};

/**
* Mapping from lowercase registration names to the properly cased version,
* used to warn in the case of missing event handlers. Available
* only in __DEV__.
* @type {Object}
*/
export const possibleRegistrationNames = __DEV__ ? {} : (null: any);
export const possibleRegistrationNames: {
[lowerCasedName: string]: string,
} = __DEV__ ? {} : (null: any);
// Trust the developer to only use possibleRegistrationNames in __DEV__

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
} from './ReactSyntheticEventType';
import type {TopLevelType} from './TopLevelEventTypes';

export type EventTypes = {[key: string]: DispatchConfig, ...};
export type EventTypes = {[key: string]: DispatchConfig};

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

Expand Down
2 changes: 1 addition & 1 deletion scripts/flow/config/flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ well_formed_exports.includes=<PROJECT_ROOT>/packages/react-fetch
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-fs
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-interactions
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-is
; well_formed_exports.includes=<PROJECT_ROOT>/packages/react-native-renderer
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-native-renderer
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-noop-renderer
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-pg
well_formed_exports.includes=<PROJECT_ROOT>/packages/react-reconciler
Expand Down

0 comments on commit b1f34aa

Please sign in to comment.