Skip to content

Commit f947cdc

Browse files
committed
Consolidate eventTypes registry with view configs
We already have one stateful module that contains all the view config. We might as well store the event types there too. That way the shared state is compartmentalized (and I can move it out in a follow up PR). The view config registry also already has an appropriate place to call processEventTypes so now we no longer have to do it in RN. Will follow up with a PR to RN to remove that call.
1 parent 7a3416f commit f947cdc

File tree

6 files changed

+50
-59
lines changed

6 files changed

+50
-59
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import TouchHistoryMath from 'events/TouchHistoryMath';
1818
import ReactVersion from 'shared/ReactVersion';
1919

2020
import NativeMethodsMixin from './NativeMethodsMixin';
21-
import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
2221
import ReactNativeComponent from './ReactNativeComponent';
2322
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
2423
import ReactFabricRenderer from './ReactFabricRenderer';
@@ -84,7 +83,6 @@ const ReactFabric: ReactNativeType = {
8483
// Used as a mixin in many createClass-based components
8584
NativeMethodsMixin,
8685
// Used by react-native-github/Libraries/ components
87-
ReactNativeBridgeEventPlugin, // requireNativeComponent
8886
ReactNativeComponentTree, // ScrollResponder
8987
ReactNativePropRegistry, // flattenStyle, Stylesheet
9088
TouchHistoryMath, // PanResponder

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

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77
* @flow
88
*/
99

10-
import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
1110
import type {AnyNativeEvent} from 'events/PluginModuleType';
1211
import {
1312
accumulateTwoPhaseDispatches,
1413
accumulateDirectDispatches,
1514
} from 'events/EventPropagators';
15+
import * as ReactNativeViewConfigRegistry from './ReactNativeViewConfigRegistry';
1616
import SyntheticEvent from 'events/SyntheticEvent';
1717
import invariant from 'fbjs/lib/invariant';
1818

19-
const customBubblingEventTypes = {};
20-
const customDirectEventTypes = {};
19+
const {
20+
customBubblingEventTypes,
21+
customDirectEventTypes,
22+
eventTypes,
23+
} = ReactNativeViewConfigRegistry;
2124

2225
const ReactNativeBridgeEventPlugin = {
23-
eventTypes: {},
26+
eventTypes: eventTypes,
2427

2528
/**
2629
* @see {EventPluginHub.extractEvents}
@@ -57,46 +60,6 @@ const ReactNativeBridgeEventPlugin = {
5760
}
5861
return event;
5962
},
60-
61-
processEventTypes: function(
62-
viewConfig: ReactNativeBaseComponentViewConfig,
63-
): void {
64-
const {bubblingEventTypes, directEventTypes} = viewConfig;
65-
66-
if (__DEV__) {
67-
if (bubblingEventTypes != null && directEventTypes != null) {
68-
for (const topLevelType in directEventTypes) {
69-
invariant(
70-
bubblingEventTypes[topLevelType] == null,
71-
'Event cannot be both direct and bubbling: %s',
72-
topLevelType,
73-
);
74-
}
75-
}
76-
}
77-
78-
if (bubblingEventTypes != null) {
79-
for (const topLevelType in bubblingEventTypes) {
80-
if (customBubblingEventTypes[topLevelType] == null) {
81-
ReactNativeBridgeEventPlugin.eventTypes[
82-
topLevelType
83-
] = customBubblingEventTypes[topLevelType] =
84-
bubblingEventTypes[topLevelType];
85-
}
86-
}
87-
}
88-
89-
if (directEventTypes != null) {
90-
for (const topLevelType in directEventTypes) {
91-
if (customDirectEventTypes[topLevelType] == null) {
92-
ReactNativeBridgeEventPlugin.eventTypes[
93-
topLevelType
94-
] = customDirectEventTypes[topLevelType] =
95-
directEventTypes[topLevelType];
96-
}
97-
}
98-
}
99-
},
10063
};
10164

10265
export default ReactNativeBridgeEventPlugin;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import UIManager from 'UIManager';
2222
import {getStackAddendumByWorkInProgressFiber} from 'shared/ReactFiberComponentTreeHook';
2323

2424
import NativeMethodsMixin from './NativeMethodsMixin';
25-
import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
2625
import ReactNativeComponent from './ReactNativeComponent';
2726
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
2827
import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
@@ -103,7 +102,6 @@ const ReactNativeRenderer: ReactNativeType = {
103102
// Used as a mixin in many createClass-based components
104103
NativeMethodsMixin,
105104
// Used by react-native-github/Libraries/ components
106-
ReactNativeBridgeEventPlugin, // requireNativeComponent
107105
ReactNativeComponentTree, // ScrollResponder
108106
ReactNativePropRegistry, // flattenStyle, Stylesheet
109107
TouchHistoryMath, // PanResponder

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,12 @@ export type NativeMethodsMixinType = {
6969
setNativeProps(nativeProps: Object): void,
7070
};
7171

72-
type ReactNativeBridgeEventPlugin = {
73-
processEventTypes(viewConfig: ReactNativeBaseComponentViewConfig): void,
74-
};
75-
7672
type SecretInternalsType = {
7773
NativeMethodsMixin: NativeMethodsMixinType,
7874
createReactNativeComponentClass(
7975
name: string,
8076
callback: ViewConfigGetter,
8177
): any,
82-
ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin,
8378
ReactNativeComponentTree: any,
8479
ReactNativePropRegistry: any,
8580
// TODO (bvaughn) Decide which additional types to expose here?

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,50 @@ import type {
1414

1515
import invariant from 'fbjs/lib/invariant';
1616

17+
// Event configs
18+
export const customBubblingEventTypes = {};
19+
export const customDirectEventTypes = {};
20+
export const eventTypes = {};
21+
1722
const viewConfigCallbacks = new Map();
1823
const viewConfigs = new Map();
1924

25+
function processEventTypes(
26+
viewConfig: ReactNativeBaseComponentViewConfig,
27+
): void {
28+
const {bubblingEventTypes, directEventTypes} = viewConfig;
29+
30+
if (__DEV__) {
31+
if (bubblingEventTypes != null && directEventTypes != null) {
32+
for (const topLevelType in directEventTypes) {
33+
invariant(
34+
bubblingEventTypes[topLevelType] == null,
35+
'Event cannot be both direct and bubbling: %s',
36+
topLevelType,
37+
);
38+
}
39+
}
40+
}
41+
42+
if (bubblingEventTypes != null) {
43+
for (const topLevelType in bubblingEventTypes) {
44+
if (customBubblingEventTypes[topLevelType] == null) {
45+
eventTypes[topLevelType] = customBubblingEventTypes[topLevelType] =
46+
bubblingEventTypes[topLevelType];
47+
}
48+
}
49+
}
50+
51+
if (directEventTypes != null) {
52+
for (const topLevelType in directEventTypes) {
53+
if (customDirectEventTypes[topLevelType] == null) {
54+
eventTypes[topLevelType] = customDirectEventTypes[topLevelType] =
55+
directEventTypes[topLevelType];
56+
}
57+
}
58+
}
59+
}
60+
2061
/**
2162
* Registers a native view/component by name.
2263
* A callback is provided to load the view config from UIManager.
@@ -49,6 +90,7 @@ export function get(name: string): ReactNativeBaseComponentViewConfig {
4990
);
5091
viewConfigCallbacks.set(name, null);
5192
viewConfig = callback();
93+
processEventTypes(viewConfig);
5294
viewConfigs.set(name, viewConfig);
5395
} else {
5496
viewConfig = viewConfigs.get(name);

packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ let PropTypes;
1414
let RCTEventEmitter;
1515
let React;
1616
let ReactNative;
17-
let ReactNativeBridgeEventPlugin;
1817
let ResponderEventPlugin;
1918
let UIManager;
2019
let createReactNativeComponentClass;
2120

2221
// Parallels requireNativeComponent() in that it lazily constructs a view config,
23-
// And registers view manager event types with ReactNativeBridgeEventPlugin.
22+
// And registers view manager event types with ReactNativeViewConfigRegistry.
2423
const fakeRequireNativeComponent = (uiViewClassName, validAttributes) => {
2524
const getViewConfig = () => {
2625
const viewConfig = {
@@ -55,8 +54,6 @@ const fakeRequireNativeComponent = (uiViewClassName, validAttributes) => {
5554
directEventTypes: {},
5655
};
5756

58-
ReactNativeBridgeEventPlugin.processEventTypes(viewConfig);
59-
6057
return viewConfig;
6158
};
6259

@@ -70,8 +67,6 @@ beforeEach(() => {
7067
RCTEventEmitter = require('RCTEventEmitter');
7168
React = require('react');
7269
ReactNative = require('react-native-renderer');
73-
ReactNativeBridgeEventPlugin = require('../ReactNativeBridgeEventPlugin')
74-
.default;
7570
ResponderEventPlugin = require('events/ResponderEventPlugin').default;
7671
UIManager = require('UIManager');
7772
createReactNativeComponentClass = require('../createReactNativeComponentClass')

0 commit comments

Comments
 (0)