Skip to content

Commit

Permalink
React native event type fixes (#10627)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
bvaughn authored Sep 6, 2017
1 parent 7ff922c commit abce30f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/renderers/native/ReactNativeBridgeEventPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var EventPropagators = require('EventPropagators');
var SyntheticEvent = require('SyntheticEvent');
var ReactNativeEventTypes = require('ReactNativeEventTypes');
var invariant = require('fbjs/lib/invariant');

var customBubblingEventTypes = ReactNativeEventTypes.customBubblingEventTypes;
var customDirectEventTypes = ReactNativeEventTypes.customDirectEventTypes;
Expand Down Expand Up @@ -44,6 +45,11 @@ var ReactNativeBridgeEventPlugin = {
): ?Object {
var bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
var directDispatchConfig = customDirectEventTypes[topLevelType];
invariant(
bubbleDispatchConfig || directDispatchConfig,
'Unsupported top level event type "%s" dispatched',
topLevelType,
);
var event = SyntheticEvent.getPooled(
bubbleDispatchConfig || directDispatchConfig,
targetInst,
Expand Down
3 changes: 3 additions & 0 deletions src/renderers/native/ReactNativeEventTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ const IOS_DIRECT_EVENT_TYPES = {
topShouldStartLoadWithRequest: {
registrationName: 'onShouldStartLoadWithRequest',
},
topSnapshotReady: {
registrationName: 'onSnapshotReady',
},
topStateChange: {
registrationName: 'onStateChange',
},
Expand Down

0 comments on commit abce30f

Please sign in to comment.