@samitouri / QOS-React / commits / e34ac7c066

Embed ReactNative event types in JavaScript (#10567)

* 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

Brian Vaughn committed Aug 31, 2017 at 15:27 UTC e34ac7c0668906f588883e1ec8b936495bf0a9d9
6 files changed +336 -49
flow/react-native-host-hooks.js
+3
@@ -32,6 +32,9 @@ declare module 'ExceptionsManager' {
32 isFatal: boolean,
33 ) : void;
34 }
35 +declare module 'Platform' {
36 + declare var OS : string;
37 +}
38 declare module 'UIManager' {
39 declare var customBubblingEventTypes : Object;
40 declare var customDirectEventTypes : Object;
scripts/rollup/bundles.js
+1
@@ -263,6 +263,7 @@ const bundles = [
263 externals: [
264 'ExceptionsManager',
265 'InitializeCore',
266 + 'Platform',
267 'RCTEventEmitter',
268 'TextInputState',
269 'UIManager',
src/__mocks__/Platform.js new
+13
@@ -0,0 +1,13 @@
1 +/**
2 + * Copyright (c) 2015-present, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + */
9 +'use strict';
10 +
11 +module.exports = {
12 + OS: 'ios',
13 +};
src/__mocks__/UIManager.js
-46
@@ -155,52 +155,6 @@ var RCTUIManager = {
155 }),
156 replaceExistingNonRootView: jest.fn(),
157 __takeSnapshot: jest.fn(),
158 - customBubblingEventTypes: {
159 - topBlur: {
160 - phasedRegistrationNames: {
161 - bubbled: 'onBlur',
162 - captured: 'onBlurCapture',
163 - },
164 - },
165 - topFocus: {
166 - phasedRegistrationNames: {
167 - bubbled: 'onFocus',
168 - captured: 'onFocusCapture',
169 - },
170 - },
171 - topTouchCancel: {
172 - phasedRegistrationNames: {
173 - bubbled: 'onTouchCancel',
174 - captured: 'onTouchCancelCapture',
175 - },
176 - },
177 - topTouchEnd: {
178 - phasedRegistrationNames: {
179 - bubbled: 'onTouchEnd',
180 - captured: 'onTouchEndCapture',
181 - },
182 - },
183 - topTouchMove: {
184 - phasedRegistrationNames: {
185 - bubbled: 'onTouchMove',
186 - captured: 'onTouchMoveCapture',
187 - },
188 - },
189 - topTouchStart: {
190 - phasedRegistrationNames: {
191 - bubbled: 'onTouchStart',
192 - captured: 'onTouchStartCapture',
193 - },
194 - },
195 - },
196 - customDirectEventTypes: {
197 - topAccessibilityTap: {
198 - registrationName: 'onAccessibilityTap',
199 - },
200 - topTextLayout: {
201 - registrationName: 'onTextLayout',
202 - },
203 - },
158 };
159
160 module.exports = RCTUIManager;
src/renderers/native/ReactNativeBridgeEventPlugin.js
+3 -3
@@ -13,10 +13,10 @@
13
14 var EventPropagators = require('EventPropagators');
15 var SyntheticEvent = require('SyntheticEvent');
16 -var UIManager = require('UIManager');
16 +var ReactNativeEventTypes = require('ReactNativeEventTypes');
17
18 -var customBubblingEventTypes = UIManager.customBubblingEventTypes;
19 -var customDirectEventTypes = UIManager.customDirectEventTypes;
18 +var customBubblingEventTypes = ReactNativeEventTypes.customBubblingEventTypes;
19 +var customDirectEventTypes = ReactNativeEventTypes.customDirectEventTypes;
20
21 if (__DEV__) {
22 var warning = require('fbjs/lib/warning');
src/renderers/native/ReactNativeEventTypes.js new
+316
@@ -0,0 +1,316 @@
1 +/**
2 + * Copyright (c) 2015-present, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + * @providesModule ReactNativeEventTypes
10 + * @flow
11 + */
12 +'use strict';
13 +
14 +const Platform = require('Platform');
15 +
16 +const emptyObject = require('fbjs/lib/emptyObject');
17 +
18 +const COMMON_BUBBLING_EVENT_TYPES = {
19 + topBlur: {
20 + phasedRegistrationNames: {
21 + captured: 'onBlurCapture',
22 + bubbled: 'onBlur',
23 + },
24 + },
25 + topChange: {
26 + phasedRegistrationNames: {
27 + captured: 'onChangeCapture',
28 + bubbled: 'onChange',
29 + },
30 + },
31 + topEndEditing: {
32 + phasedRegistrationNames: {
33 + captured: 'onEndEditingCapture',
34 + bubbled: 'onEndEditing',
35 + },
36 + },
37 + topFocus: {
38 + phasedRegistrationNames: {
39 + captured: 'onFocusCapture',
40 + bubbled: 'onFocus',
41 + },
42 + },
43 + topSubmitEditing: {
44 + phasedRegistrationNames: {
45 + captured: 'onSubmitEditingCapture',
46 + bubbled: 'onSubmitEditing',
47 + },
48 + },
49 + topTouchEnd: {
50 + phasedRegistrationNames: {
51 + captured: 'onTouchEndCapture',
52 + bubbled: 'onTouchEnd',
53 + },
54 + },
55 + topTouchMove: {
56 + phasedRegistrationNames: {
57 + captured: 'onTouchMoveCapture',
58 + bubbled: 'onTouchMove',
59 + },
60 + },
61 + topTouchStart: {
62 + phasedRegistrationNames: {
63 + captured: 'onTouchStartCapture',
64 + bubbled: 'onTouchStart',
65 + },
66 + },
67 +};
68 +
69 +const COMMON_DIRECT_EVENT_TYPES = {
70 + topError: {
71 + registrationName: 'onError',
72 + },
73 + topLayout: {
74 + registrationName: 'onLayout',
75 + },
76 + topLoad: {
77 + registrationName: 'onLoad',
78 + },
79 + topLoadEnd: {
80 + registrationName: 'onLoadEnd',
81 + },
82 + topLoadStart: {
83 + registrationName: 'onLoadStart',
84 + },
85 + topLoadingError: {
86 + registrationName: 'onLoadingError',
87 + },
88 + topLoadingFinish: {
89 + registrationName: 'onLoadingFinish',
90 + },
91 + topLoadingStart: {
92 + registrationName: 'onLoadingStart',
93 + },
94 + topMessage: {
95 + registrationName: 'onMessage',
96 + },
97 + topMomentumScrollBegin: {
98 + registrationName: 'onMomentumScrollBegin',
99 + },
100 + topMomentumScrollEnd: {
101 + registrationName: 'onMomentumScrollEnd',
102 + },
103 + topRefresh: {
104 + registrationName: 'onRefresh',
105 + },
106 + topScroll: {
107 + registrationName: 'onScroll',
108 + },
109 + topScrollAnimationEnd: {
110 + registrationName: 'onScrollAnimationEnd',
111 + },
112 + topScrollBeginDrag: {
113 + registrationName: 'onScrollBeginDrag',
114 + },
115 + topScrollEndDrag: {
116 + registrationName: 'onScrollEndDrag',
117 + },
118 + topSelectionChange: {
119 + registrationName: 'onSelectionChange',
120 + },
121 + topShow: {
122 + registrationName: 'onShow',
123 + },
124 +};
125 +
126 +const ANDROID_BUBBLING_EVENT_TYPES = {
127 + ...COMMON_BUBBLING_EVENT_TYPES,
128 + topSelect: {
129 + phasedRegistrationNames: {
130 + bubbled: 'onSelect',
131 + captured: 'onSelectCapture',
132 + },
133 + },
134 + topTextInput: {
135 + phasedRegistrationNames: {
136 + bubbled: 'onTextInput',
137 + captured: 'onTextInputCapture',
138 + },
139 + },
140 +};
141 +
142 +const ANDROID_DIRECT_EVENT_TYPES = {
143 + ...COMMON_DIRECT_EVENT_TYPES,
144 + topContentSizeChange: {
145 + registrationName: 'onContentSizeChange',
146 + },
147 + topDrawerClosed: {
148 + registrationName: 'onDrawerClose',
149 + },
150 + topDrawerOpened: {
151 + registrationName: 'onDrawerOpen',
152 + },
153 + topDrawerSlide: {
154 + registrationName: 'onDrawerSlide',
155 + },
156 + topDrawerStateChanged: {
157 + registrationName: 'onDrawerStateChanged',
158 + },
159 + topPageScroll: {
160 + registrationName: 'onPageScroll',
161 + },
162 + topPageScrollStateChanged: {
163 + registrationName: 'onPageScrollStateChanged',
164 + },
165 + topPageSelected: {
166 + registrationName: 'onPageSelected',
167 + },
168 + topRequestClose: {
169 + registrationName: 'onRequestClose',
170 + },
171 + topSlidingComplete: {
172 + registrationName: 'onSlidingComplete',
173 + },
174 + topVideoProgress: {
175 + registrationName: 'onProgress',
176 + },
177 + topVideoSizeDetected: {
178 + registrationName: 'onVideoSizeDetected',
179 + },
180 + topVideoStateChange: {
181 + registrationName: 'onStateChange',
182 + },
183 + topZoom: {
184 + registrationName: 'onZoom',
185 + },
186 +};
187 +
188 +const IOS_BUBBLING_EVENT_TYPES = {
189 + ...COMMON_BUBBLING_EVENT_TYPES,
190 + topAnnotationBlur: {
191 + phasedRegistrationNames: {
192 + captured: 'onAnnotationBlurCapture',
193 + bubbled: 'onAnnotationBlur',
194 + },
195 + },
196 + topAnnotationDragStateChange: {
197 + phasedRegistrationNames: {
198 + captured: 'onAnnotationDragStateChangeCapture',
199 + bubbled: 'onAnnotationDragStateChange',
200 + },
201 + },
202 + topAnnotationFocus: {
203 + phasedRegistrationNames: {
204 + captured: 'onAnnotationFocusCapture',
205 + bubbled: 'onAnnotationFocus',
206 + },
207 + },
208 + topContentSizeChange: {
209 + phasedRegistrationNames: {
210 + captured: 'onContentSizeChangeCapture',
211 + bubbled: 'onContentSizeChange',
212 + },
213 + },
214 + topKeyPress: {
215 + phasedRegistrationNames: {
216 + captured: 'onKeyPressCapture',
217 + bubbled: 'onKeyPress',
218 + },
219 + },
220 + topLeftButtonPress: {
221 + phasedRegistrationNames: {
222 + captured: 'onLeftButtonPressCapture',
223 + bubbled: 'onLeftButtonPress',
224 + },
225 + },
226 + topNavigationComplete: {
227 + phasedRegistrationNames: {
228 + captured: 'onNavigationCompleteCapture',
229 + bubbled: 'onNavigationComplete',
230 + },
231 + },
232 + topPress: {
233 + phasedRegistrationNames: {
234 + captured: 'onPressCapture',
235 + bubbled: 'onPress',
236 + },
237 + },
238 + topRightButtonPress: {
239 + phasedRegistrationNames: {
240 + captured: 'onRightButtonPressCapture',
241 + bubbled: 'onRightButtonPress',
242 + },
243 + },
244 + topSlidingComplete: {
245 + phasedRegistrationNames: {
246 + captured: 'onSlidingCompleteCapture',
247 + bubbled: 'onSlidingComplete',
248 + },
249 + },
250 + topTouchCancel: {
251 + phasedRegistrationNames: {
252 + captured: 'onTouchCancelCapture',
253 + bubbled: 'onTouchCancel',
254 + },
255 + },
256 + topValueChange: {
257 + phasedRegistrationNames: {
258 + captured: 'onValueChangeCapture',
259 + bubbled: 'onValueChange',
260 + },
261 + },
262 +};
263 +
264 +const IOS_DIRECT_EVENT_TYPES = {
265 + ...COMMON_DIRECT_EVENT_TYPES,
266 + topAccessibilityTap: {
267 + registrationName: 'onAccessibilityTap',
268 + },
269 + topMagicTap: {
270 + registrationName: 'onMagicTap',
271 + },
272 + topNavigationProgress: {
273 + registrationName: 'onNavigationProgress',
274 + },
275 + topOrientationChange: {
276 + registrationName: 'onOrientationChange',
277 + },
278 + topPartialLoad: {
279 + registrationName: 'onPartialLoad',
280 + },
281 + topProgress: {
282 + registrationName: 'onProgress',
283 + },
284 + topShouldStartLoadWithRequest: {
285 + registrationName: 'onShouldStartLoadWithRequest',
286 + },
287 + topStateChange: {
288 + registrationName: 'onStateChange',
289 + },
290 + topTextInput: {
291 + registrationName: 'onTextInput',
292 + },
293 + topTextLayout: {
294 + registrationName: 'onTextLayout',
295 + },
296 +};
297 +
298 +let ReactNativeEventTypes;
299 +if (Platform.OS === 'ios') {
300 + ReactNativeEventTypes = {
301 + customBubblingEventTypes: IOS_BUBBLING_EVENT_TYPES,
302 + customDirectEventTypes: IOS_DIRECT_EVENT_TYPES,
303 + };
304 +} else if (Platform.OS === 'android') {
305 + ReactNativeEventTypes = {
306 + customBubblingEventTypes: ANDROID_BUBBLING_EVENT_TYPES,
307 + customDirectEventTypes: ANDROID_DIRECT_EVENT_TYPES,
308 + };
309 +} else {
310 + ReactNativeEventTypes = {
311 + customBubblingEventTypes: emptyObject,
312 + customDirectEventTypes: emptyObject,
313 + };
314 +}
315 +
316 +module.exports = ReactNativeEventTypes;