React native event type fixes (#10627)
* Added invariant check for native dispatching an unsupported event type This prevents a case of a silent failure when native dispatches an event that JavaScript does not know how to handle. * Added iOS direct event type 'onSnapshotReady' This is used for snapshot testing.
Brian Vaughn committed
Sep 6, 2017 at 15:34 UTC
abce30f771e07670b3efac6ffdcab1a7139556a9
2 files changed
+9
src/renderers/native/ReactNativeBridgeEventPlugin.js
+6
@@ -14,6 +14,7 @@
14
var EventPropagators = require('EventPropagators');
15
var SyntheticEvent = require('SyntheticEvent');
16
var ReactNativeEventTypes = require('ReactNativeEventTypes');
17
+var invariant = require('fbjs/lib/invariant');
18
19
var customBubblingEventTypes = ReactNativeEventTypes.customBubblingEventTypes;
20
var customDirectEventTypes = ReactNativeEventTypes.customDirectEventTypes;
@@ -44,6 +45,11 @@ var ReactNativeBridgeEventPlugin = {
45
): ?Object {
46
var bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
47
var directDispatchConfig = customDirectEventTypes[topLevelType];
48
+ invariant(
49
+ bubbleDispatchConfig || directDispatchConfig,
50
+ 'Unsupported top level event type "%s" dispatched',
51
+ topLevelType,
52
+ );
53
var event = SyntheticEvent.getPooled(
54
bubbleDispatchConfig || directDispatchConfig,
55
targetInst,
src/renderers/native/ReactNativeEventTypes.js
+3
@@ -284,6 +284,9 @@ const IOS_DIRECT_EVENT_TYPES = {
284
topShouldStartLoadWithRequest: {
285
registrationName: 'onShouldStartLoadWithRequest',
286
},
287
+ topSnapshotReady: {
288
+ registrationName: 'onSnapshotReady',
289
+ },
290
topStateChange: {
291
registrationName: 'onStateChange',
292
},