Skip to content

Commit f5861bd

Browse files
sebmarkbagerhagigi
authored andcommitted
Consolidate eventTypes registry with view configs (facebook#12556)
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 725cdb8 commit f5861bd

File tree

7 files changed

+50
-76
lines changed

7 files changed

+50
-76
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import * as ReactGenericBatching from 'events/ReactGenericBatching';
1717
import ReactVersion from 'shared/ReactVersion';
1818

1919
import NativeMethodsMixin from './NativeMethodsMixin';
20-
import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
2120
import ReactNativeComponent from './ReactNativeComponent';
2221
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
2322
import ReactFabricRenderer from './ReactFabricRenderer';
@@ -73,7 +72,6 @@ const ReactFabric: ReactFabricType = {
7372
// Used as a mixin in many createClass-based components
7473
NativeMethodsMixin,
7574
// Used by react-native-github/Libraries/ components
76-
ReactNativeBridgeEventPlugin, // requireNativeComponent
7775
ReactNativeComponentTree, // ScrollResponder
7876
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
7977
},

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
@@ -21,7 +21,6 @@ import UIManager from 'UIManager';
2121
import {getStackAddendumByWorkInProgressFiber} from 'shared/ReactFiberComponentTreeHook';
2222

2323
import NativeMethodsMixin from './NativeMethodsMixin';
24-
import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
2524
import ReactNativeComponent from './ReactNativeComponent';
2625
import * as ReactNativeComponentTree from './ReactNativeComponentTree';
2726
import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
@@ -98,7 +97,6 @@ const ReactNativeRenderer: ReactNativeType = {
9897
// Used as a mixin in many createClass-based components
9998
NativeMethodsMixin,
10099
// Used by react-native-github/Libraries/ components
101-
ReactNativeBridgeEventPlugin, // requireNativeComponent
102100
ReactNativeComponentTree, // ScrollResponder
103101
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
104102
computeComponentStackForErrorReporting,

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
// TODO (bvaughn) Decide which additional types to expose here?
8580
// And how much information to fill in for the above types.

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')

scripts/rollup/shims/react-native/ReactNativeBridgeEventPlugin.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)