Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RN] Consolidate eventTypes registry with view configs #12556

Merged
merged 1 commit into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/react-native-renderer/src/ReactFabric.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -80,7 +79,6 @@ const ReactFabric: ReactNativeType = {
// Used as a mixin in many createClass-based components
NativeMethodsMixin,
// Used by react-native-github/Libraries/ components
ReactNativeBridgeEventPlugin, // requireNativeComponent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also delete the forwarding scripts/rollup/shims/react-native/ReactNativeBridgeEventPlugin.js now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just get rid of the ReactNativeBridgeEventPlugin entirely now and just move extractEvents over into the view config registry as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the shim. I'll delete it.

ReactNativeComponentTree, // ScrollResponder
ReactNativePropRegistry, // flattenStyle, Stylesheet
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
Expand Down
51 changes: 7 additions & 44 deletions packages/react-native-renderer/src/ReactNativeBridgeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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;
2 changes: 0 additions & 2 deletions packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -99,7 +98,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
ReactNativePropRegistry, // flattenStyle, Stylesheet
createReactNativeComponentClass, // RCTText, RCTView, ReactNativeART
Expand Down
5 changes: 0 additions & 5 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
ReactNativePropRegistry: any,
// TODO (bvaughn) Decide which additional types to expose here?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -49,6 +90,7 @@ export function get(name: string): ReactNativeBaseComponentViewConfig {
);
viewConfigCallbacks.set(name, null);
viewConfig = callback();
processEventTypes(viewConfig);
Copy link
Collaborator Author

@sebmarkbage sebmarkbage Apr 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what lets us avoid exposing ReactNativeBridgeEventPlugin.

viewConfigs.set(name, viewConfig);
} else {
viewConfig = viewConfigs.get(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -55,8 +54,6 @@ const fakeRequireNativeComponent = (uiViewClassName, validAttributes) => {
directEventTypes: {},
};

ReactNativeBridgeEventPlugin.processEventTypes(viewConfig);

return viewConfig;
};

Expand All @@ -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')
Expand Down
17 changes: 0 additions & 17 deletions scripts/rollup/shims/react-native/ReactNativeBridgeEventPlugin.js

This file was deleted.