@samitouri / QOS-React-2 / commits / b6e0512a81

Consolidate eventTypes registry with view configs (#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.

Sebastian Markbåge committed Apr 9, 2018 at 19:42 UTC b6e0512a81524d397ff4fbfb892372ecc84c6b02
7 files changed +50 -76
packages/react-native-renderer/src/ReactFabric.js
-2
@@ -17,7 +17,6 @@ import * as ReactGenericBatching from 'events/ReactGenericBatching';
17 import ReactVersion from 'shared/ReactVersion';
18
19 import NativeMethodsMixin from './NativeMethodsMixin';
20 -import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
20 import ReactNativeComponent from './ReactNativeComponent';
21 import * as ReactNativeComponentTree from './ReactNativeComponentTree';
22 import ReactFabricRenderer from './ReactFabricRenderer';
@@ -73,7 +72,6 @@ const ReactFabric: ReactFabricType = {
72 // Used as a mixin in many createClass-based components
73 NativeMethodsMixin,
74 // Used by react-native-github/Libraries/ components
76 - ReactNativeBridgeEventPlugin, // requireNativeComponent
75 ReactNativeComponentTree, // ScrollResponder
76 createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
77 },
packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js
+7 -44
@@ -7,20 +7,23 @@
7 * @flow
8 */
9
10 -import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
10 import type {AnyNativeEvent} from 'events/PluginModuleType';
11 import {
12 accumulateTwoPhaseDispatches,
13 accumulateDirectDispatches,
14 } from 'events/EventPropagators';
15 +import * as ReactNativeViewConfigRegistry from './ReactNativeViewConfigRegistry';
16 import SyntheticEvent from 'events/SyntheticEvent';
17 import invariant from 'fbjs/lib/invariant';
18
19 -const customBubblingEventTypes = {};
20 -const customDirectEventTypes = {};
19 +const {
20 + customBubblingEventTypes,
21 + customDirectEventTypes,
22 + eventTypes,
23 +} = ReactNativeViewConfigRegistry;
24
25 const ReactNativeBridgeEventPlugin = {
23 - eventTypes: {},
26 + eventTypes: eventTypes,
27
28 /**
29 * @see {EventPluginHub.extractEvents}
@@ -57,46 +60,6 @@ const ReactNativeBridgeEventPlugin = {
60 }
61 return event;
62 },
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 - },
63 };
64
65 export default ReactNativeBridgeEventPlugin;
packages/react-native-renderer/src/ReactNativeRenderer.js
-2
@@ -21,7 +21,6 @@ import UIManager from 'UIManager';
21 import {getStackAddendumByWorkInProgressFiber} from 'shared/ReactFiberComponentTreeHook';
22
23 import NativeMethodsMixin from './NativeMethodsMixin';
24 -import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin';
24 import ReactNativeComponent from './ReactNativeComponent';
25 import * as ReactNativeComponentTree from './ReactNativeComponentTree';
26 import ReactNativeFiberRenderer from './ReactNativeFiberRenderer';
@@ -98,7 +97,6 @@ const ReactNativeRenderer: ReactNativeType = {
97 // Used as a mixin in many createClass-based components
98 NativeMethodsMixin,
99 // Used by react-native-github/Libraries/ components
101 - ReactNativeBridgeEventPlugin, // requireNativeComponent
100 ReactNativeComponentTree, // ScrollResponder
101 createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
102 computeComponentStackForErrorReporting,
packages/react-native-renderer/src/ReactNativeTypes.js
-5
@@ -69,17 +69,12 @@ export type NativeMethodsMixinType = {
69 setNativeProps(nativeProps: Object): void,
70 };
71
72 -type ReactNativeBridgeEventPlugin = {
73 - processEventTypes(viewConfig: ReactNativeBaseComponentViewConfig): void,
74 -};
75 -
72 type SecretInternalsType = {
73 NativeMethodsMixin: NativeMethodsMixinType,
74 createReactNativeComponentClass(
75 name: string,
76 callback: ViewConfigGetter,
77 ): any,
82 - ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin,
78 ReactNativeComponentTree: any,
79 // TODO (bvaughn) Decide which additional types to expose here?
80 // And how much information to fill in for the above types.
packages/react-native-renderer/src/ReactNativeViewConfigRegistry.js
+42
@@ -14,9 +14,50 @@ import type {
14
15 import invariant from 'fbjs/lib/invariant';
16
17 +// Event configs
18 +export const customBubblingEventTypes = {};
19 +export const customDirectEventTypes = {};
20 +export const eventTypes = {};
21 +
22 const viewConfigCallbacks = new Map();
23 const viewConfigs = new Map();
24
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 +
61 /**
62 * Registers a native view/component by name.
63 * A callback is provided to load the view config from UIManager.
@@ -49,6 +90,7 @@ export function get(name: string): ReactNativeBaseComponentViewConfig {
90 );
91 viewConfigCallbacks.set(name, null);
92 viewConfig = callback();
93 + processEventTypes(viewConfig);
94 viewConfigs.set(name, viewConfig);
95 } else {
96 viewConfig = viewConfigs.get(name);
packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js
+1 -6
@@ -14,13 +14,12 @@ let PropTypes;
14 let RCTEventEmitter;
15 let React;
16 let ReactNative;
17 -let ReactNativeBridgeEventPlugin;
17 let ResponderEventPlugin;
18 let UIManager;
19 let createReactNativeComponentClass;
20
21 // 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.
23 const fakeRequireNativeComponent = (uiViewClassName, validAttributes) => {
24 const getViewConfig = () => {
25 const viewConfig = {
@@ -55,8 +54,6 @@ const fakeRequireNativeComponent = (uiViewClassName, validAttributes) => {
54 directEventTypes: {},
55 };
56
58 - ReactNativeBridgeEventPlugin.processEventTypes(viewConfig);
59 -
57 return viewConfig;
58 };
59
@@ -70,8 +67,6 @@ beforeEach(() => {
67 RCTEventEmitter = require('RCTEventEmitter');
68 React = require('react');
69 ReactNative = require('react-native-renderer');
73 - ReactNativeBridgeEventPlugin = require('../ReactNativeBridgeEventPlugin')
74 - .default;
70 ResponderEventPlugin = require('events/ResponderEventPlugin').default;
71 UIManager = require('UIManager');
72 createReactNativeComponentClass = require('../createReactNativeComponentClass')
scripts/rollup/shims/react-native/ReactNativeBridgeEventPlugin.js deleted
-17
@@ -1,17 +0,0 @@
1 -/**
2 - * Copyright (c) 2013-present, Facebook, Inc.
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 - * @providesModule ReactNativeBridgeEventPlugin
8 - */
9 -
10 -'use strict';
11 -
12 -const {
13 - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
14 -} = require('ReactNative');
15 -
16 -module.exports =
17 - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactNativeBridgeEventPlugin;