diff --git a/packages/react-native-renderer/src/ReactFabric.js b/packages/react-native-renderer/src/ReactFabric.js index 6bd03432c430..fa406703fce7 100644 --- a/packages/react-native-renderer/src/ReactFabric.js +++ b/packages/react-native-renderer/src/ReactFabric.js @@ -17,7 +17,6 @@ import * as ReactGenericBatching from 'events/ReactGenericBatching'; import ReactVersion from 'shared/ReactVersion'; import NativeMethodsMixin from './NativeMethodsMixin'; -import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin'; import ReactNativeComponent from './ReactNativeComponent'; import * as ReactNativeComponentTree from './ReactNativeComponentTree'; import ReactFabricRenderer from './ReactFabricRenderer'; @@ -73,7 +72,6 @@ const ReactFabric: ReactFabricType = { // Used as a mixin in many createClass-based components NativeMethodsMixin, // Used by react-native-github/Libraries/ components - ReactNativeBridgeEventPlugin, // requireNativeComponent ReactNativeComponentTree, // ScrollResponder createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART }, diff --git a/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js b/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js index 4721b6a51e17..19f6938d5264 100644 --- a/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js +++ b/packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js @@ -7,20 +7,23 @@ * @flow */ -import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes'; import type {AnyNativeEvent} from 'events/PluginModuleType'; import { accumulateTwoPhaseDispatches, accumulateDirectDispatches, } from 'events/EventPropagators'; +import * as ReactNativeViewConfigRegistry from './ReactNativeViewConfigRegistry'; import SyntheticEvent from 'events/SyntheticEvent'; import invariant from 'fbjs/lib/invariant'; -const customBubblingEventTypes = {}; -const customDirectEventTypes = {}; +const { + customBubblingEventTypes, + customDirectEventTypes, + eventTypes, +} = ReactNativeViewConfigRegistry; const ReactNativeBridgeEventPlugin = { - eventTypes: {}, + eventTypes: eventTypes, /** * @see {EventPluginHub.extractEvents} @@ -57,46 +60,6 @@ const ReactNativeBridgeEventPlugin = { } return event; }, - - processEventTypes: function( - viewConfig: ReactNativeBaseComponentViewConfig, - ): void { - const {bubblingEventTypes, directEventTypes} = viewConfig; - - if (__DEV__) { - if (bubblingEventTypes != null && directEventTypes != null) { - for (const topLevelType in directEventTypes) { - invariant( - bubblingEventTypes[topLevelType] == null, - 'Event cannot be both direct and bubbling: %s', - topLevelType, - ); - } - } - } - - if (bubblingEventTypes != null) { - for (const topLevelType in bubblingEventTypes) { - if (customBubblingEventTypes[topLevelType] == null) { - ReactNativeBridgeEventPlugin.eventTypes[ - topLevelType - ] = customBubblingEventTypes[topLevelType] = - bubblingEventTypes[topLevelType]; - } - } - } - - if (directEventTypes != null) { - for (const topLevelType in directEventTypes) { - if (customDirectEventTypes[topLevelType] == null) { - ReactNativeBridgeEventPlugin.eventTypes[ - topLevelType - ] = customDirectEventTypes[topLevelType] = - directEventTypes[topLevelType]; - } - } - } - }, }; export default ReactNativeBridgeEventPlugin; diff --git a/packages/react-native-renderer/src/ReactNativeRenderer.js b/packages/react-native-renderer/src/ReactNativeRenderer.js index 8c1c8c348b44..6419ef9ca1d9 100644 --- a/packages/react-native-renderer/src/ReactNativeRenderer.js +++ b/packages/react-native-renderer/src/ReactNativeRenderer.js @@ -21,7 +21,6 @@ import UIManager from 'UIManager'; import {getStackAddendumByWorkInProgressFiber} from 'shared/ReactFiberComponentTreeHook'; import NativeMethodsMixin from './NativeMethodsMixin'; -import ReactNativeBridgeEventPlugin from './ReactNativeBridgeEventPlugin'; import ReactNativeComponent from './ReactNativeComponent'; import * as ReactNativeComponentTree from './ReactNativeComponentTree'; import ReactNativeFiberRenderer from './ReactNativeFiberRenderer'; @@ -98,7 +97,6 @@ const ReactNativeRenderer: ReactNativeType = { // Used as a mixin in many createClass-based components NativeMethodsMixin, // Used by react-native-github/Libraries/ components - ReactNativeBridgeEventPlugin, // requireNativeComponent ReactNativeComponentTree, // ScrollResponder createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART computeComponentStackForErrorReporting, diff --git a/packages/react-native-renderer/src/ReactNativeTypes.js b/packages/react-native-renderer/src/ReactNativeTypes.js index f967c06b1671..8f9305d0358a 100644 --- a/packages/react-native-renderer/src/ReactNativeTypes.js +++ b/packages/react-native-renderer/src/ReactNativeTypes.js @@ -69,17 +69,12 @@ export type NativeMethodsMixinType = { setNativeProps(nativeProps: Object): void, }; -type ReactNativeBridgeEventPlugin = { - processEventTypes(viewConfig: ReactNativeBaseComponentViewConfig): void, -}; - type SecretInternalsType = { NativeMethodsMixin: NativeMethodsMixinType, createReactNativeComponentClass( name: string, callback: ViewConfigGetter, ): any, - ReactNativeBridgeEventPlugin: ReactNativeBridgeEventPlugin, ReactNativeComponentTree: any, // TODO (bvaughn) Decide which additional types to expose here? // And how much information to fill in for the above types. diff --git a/packages/react-native-renderer/src/ReactNativeViewConfigRegistry.js b/packages/react-native-renderer/src/ReactNativeViewConfigRegistry.js index 589ad30e753d..929bd8d4e52d 100644 --- a/packages/react-native-renderer/src/ReactNativeViewConfigRegistry.js +++ b/packages/react-native-renderer/src/ReactNativeViewConfigRegistry.js @@ -14,9 +14,50 @@ import type { import invariant from 'fbjs/lib/invariant'; +// Event configs +export const customBubblingEventTypes = {}; +export const customDirectEventTypes = {}; +export const eventTypes = {}; + const viewConfigCallbacks = new Map(); const viewConfigs = new Map(); +function processEventTypes( + viewConfig: ReactNativeBaseComponentViewConfig, +): void { + const {bubblingEventTypes, directEventTypes} = viewConfig; + + if (__DEV__) { + if (bubblingEventTypes != null && directEventTypes != null) { + for (const topLevelType in directEventTypes) { + invariant( + bubblingEventTypes[topLevelType] == null, + 'Event cannot be both direct and bubbling: %s', + topLevelType, + ); + } + } + } + + if (bubblingEventTypes != null) { + for (const topLevelType in bubblingEventTypes) { + if (customBubblingEventTypes[topLevelType] == null) { + eventTypes[topLevelType] = customBubblingEventTypes[topLevelType] = + bubblingEventTypes[topLevelType]; + } + } + } + + if (directEventTypes != null) { + for (const topLevelType in directEventTypes) { + if (customDirectEventTypes[topLevelType] == null) { + eventTypes[topLevelType] = customDirectEventTypes[topLevelType] = + directEventTypes[topLevelType]; + } + } + } +} + /** * Registers a native view/component by name. * A callback is provided to load the view config from UIManager. @@ -49,6 +90,7 @@ export function get(name: string): ReactNativeBaseComponentViewConfig { ); viewConfigCallbacks.set(name, null); viewConfig = callback(); + processEventTypes(viewConfig); viewConfigs.set(name, viewConfig); } else { viewConfig = viewConfigs.get(name); diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js index b3a867ca14a4..e61f1c2d29d5 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeEvents-test.internal.js @@ -14,13 +14,12 @@ let PropTypes; let RCTEventEmitter; let React; let ReactNative; -let ReactNativeBridgeEventPlugin; let ResponderEventPlugin; let UIManager; let createReactNativeComponentClass; // Parallels requireNativeComponent() in that it lazily constructs a view config, -// And registers view manager event types with ReactNativeBridgeEventPlugin. +// And registers view manager event types with ReactNativeViewConfigRegistry. const fakeRequireNativeComponent = (uiViewClassName, validAttributes) => { const getViewConfig = () => { const viewConfig = { @@ -55,8 +54,6 @@ const fakeRequireNativeComponent = (uiViewClassName, validAttributes) => { directEventTypes: {}, }; - ReactNativeBridgeEventPlugin.processEventTypes(viewConfig); - return viewConfig; }; @@ -70,8 +67,6 @@ beforeEach(() => { RCTEventEmitter = require('RCTEventEmitter'); React = require('react'); ReactNative = require('react-native-renderer'); - ReactNativeBridgeEventPlugin = require('../ReactNativeBridgeEventPlugin') - .default; ResponderEventPlugin = require('events/ResponderEventPlugin').default; UIManager = require('UIManager'); createReactNativeComponentClass = require('../createReactNativeComponentClass') diff --git a/scripts/rollup/shims/react-native/ReactNativeBridgeEventPlugin.js b/scripts/rollup/shims/react-native/ReactNativeBridgeEventPlugin.js deleted file mode 100644 index 3170faedbad7..000000000000 --- a/scripts/rollup/shims/react-native/ReactNativeBridgeEventPlugin.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @providesModule ReactNativeBridgeEventPlugin - */ - -'use strict'; - -const { - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, -} = require('ReactNative'); - -module.exports = - __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactNativeBridgeEventPlugin;