Skip to content

Commit

Permalink
Embed ReactNative event types in JavaScript (#10567)
Browse files Browse the repository at this point in the history
* ReactNative doesn't query UIManager for native event types
This is a pre-req to unblock Prepack optimiations for ReactNative apps
* Replaced mock ReactNativeEventTypes with mock Platform
* Added Platform.OS to RN host hooks Flow types
  • Loading branch information
bvaughn authored Aug 31, 2017
1 parent 8bd5b48 commit e34ac7c
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 49 deletions.
3 changes: 3 additions & 0 deletions flow/react-native-host-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ declare module 'ExceptionsManager' {
isFatal: boolean,
) : void;
}
declare module 'Platform' {
declare var OS : string;
}
declare module 'UIManager' {
declare var customBubblingEventTypes : Object;
declare var customDirectEventTypes : Object;
Expand Down
1 change: 1 addition & 0 deletions scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ const bundles = [
externals: [
'ExceptionsManager',
'InitializeCore',
'Platform',
'RCTEventEmitter',
'TextInputState',
'UIManager',
Expand Down
13 changes: 13 additions & 0 deletions src/__mocks__/Platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

module.exports = {
OS: 'ios',
};
46 changes: 0 additions & 46 deletions src/__mocks__/UIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,52 +155,6 @@ var RCTUIManager = {
}),
replaceExistingNonRootView: jest.fn(),
__takeSnapshot: jest.fn(),
customBubblingEventTypes: {
topBlur: {
phasedRegistrationNames: {
bubbled: 'onBlur',
captured: 'onBlurCapture',
},
},
topFocus: {
phasedRegistrationNames: {
bubbled: 'onFocus',
captured: 'onFocusCapture',
},
},
topTouchCancel: {
phasedRegistrationNames: {
bubbled: 'onTouchCancel',
captured: 'onTouchCancelCapture',
},
},
topTouchEnd: {
phasedRegistrationNames: {
bubbled: 'onTouchEnd',
captured: 'onTouchEndCapture',
},
},
topTouchMove: {
phasedRegistrationNames: {
bubbled: 'onTouchMove',
captured: 'onTouchMoveCapture',
},
},
topTouchStart: {
phasedRegistrationNames: {
bubbled: 'onTouchStart',
captured: 'onTouchStartCapture',
},
},
},
customDirectEventTypes: {
topAccessibilityTap: {
registrationName: 'onAccessibilityTap',
},
topTextLayout: {
registrationName: 'onTextLayout',
},
},
};

module.exports = RCTUIManager;
6 changes: 3 additions & 3 deletions src/renderers/native/ReactNativeBridgeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

var EventPropagators = require('EventPropagators');
var SyntheticEvent = require('SyntheticEvent');
var UIManager = require('UIManager');
var ReactNativeEventTypes = require('ReactNativeEventTypes');

var customBubblingEventTypes = UIManager.customBubblingEventTypes;
var customDirectEventTypes = UIManager.customDirectEventTypes;
var customBubblingEventTypes = ReactNativeEventTypes.customBubblingEventTypes;
var customDirectEventTypes = ReactNativeEventTypes.customDirectEventTypes;

if (__DEV__) {
var warning = require('fbjs/lib/warning');
Expand Down
Loading

0 comments on commit e34ac7c

Please sign in to comment.