2015-01-30 01:10:49 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* 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.
|
2015-01-30 01:10:49 +00:00
|
|
|
*
|
|
|
|
* @providesModule IOSNativeBridgeEventPlugin
|
2015-03-26 01:19:28 +00:00
|
|
|
* @flow
|
2015-01-30 01:10:49 +00:00
|
|
|
*/
|
2015-05-19 20:43:46 +00:00
|
|
|
'use strict';
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
var EventPropagators = require('EventPropagators');
|
|
|
|
var SyntheticEvent = require('SyntheticEvent');
|
2015-11-27 13:39:00 +00:00
|
|
|
var UIManager = require('UIManager');
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
var merge = require('merge');
|
2016-03-02 12:27:13 +00:00
|
|
|
var warning = require('fbjs/lib/warning');
|
2015-01-30 01:10:49 +00:00
|
|
|
|
2015-11-27 13:39:00 +00:00
|
|
|
var customBubblingEventTypes = UIManager.customBubblingEventTypes;
|
|
|
|
var customDirectEventTypes = UIManager.customDirectEventTypes;
|
2015-01-30 01:10:49 +00:00
|
|
|
|
|
|
|
var allTypesByEventName = {};
|
|
|
|
|
|
|
|
for (var bubblingTypeName in customBubblingEventTypes) {
|
|
|
|
allTypesByEventName[bubblingTypeName] = customBubblingEventTypes[bubblingTypeName];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var directTypeName in customDirectEventTypes) {
|
|
|
|
warning(
|
|
|
|
!customBubblingEventTypes[directTypeName],
|
2015-05-19 20:43:46 +00:00
|
|
|
'Event cannot be both direct and bubbling: %s',
|
2015-01-30 01:10:49 +00:00
|
|
|
directTypeName
|
|
|
|
);
|
|
|
|
allTypesByEventName[directTypeName] = customDirectEventTypes[directTypeName];
|
|
|
|
}
|
|
|
|
|
|
|
|
var IOSNativeBridgeEventPlugin = {
|
|
|
|
|
|
|
|
eventTypes: merge(customBubblingEventTypes, customDirectEventTypes),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} topLevelType Record from `EventConstants`.
|
|
|
|
* @param {DOMEventTarget} topLevelTarget The listening component root node.
|
|
|
|
* @param {string} topLevelTargetID ID of `topLevelTarget`.
|
|
|
|
* @param {object} nativeEvent Native browser event.
|
|
|
|
* @return {*} An accumulation of synthetic events.
|
|
|
|
* @see {EventPluginHub.extractEvents}
|
|
|
|
*/
|
|
|
|
extractEvents: function(
|
2015-03-26 01:19:28 +00:00
|
|
|
topLevelType: string,
|
|
|
|
topLevelTarget: EventTarget,
|
|
|
|
topLevelTargetID: string,
|
|
|
|
nativeEvent: Event
|
|
|
|
): ?Object {
|
2015-01-30 01:10:49 +00:00
|
|
|
var bubbleDispatchConfig = customBubblingEventTypes[topLevelType];
|
|
|
|
var directDispatchConfig = customDirectEventTypes[topLevelType];
|
|
|
|
var event = SyntheticEvent.getPooled(
|
|
|
|
bubbleDispatchConfig || directDispatchConfig,
|
|
|
|
topLevelTargetID,
|
|
|
|
nativeEvent
|
|
|
|
);
|
|
|
|
if (bubbleDispatchConfig) {
|
|
|
|
EventPropagators.accumulateTwoPhaseDispatches(event);
|
|
|
|
} else if (directDispatchConfig) {
|
|
|
|
EventPropagators.accumulateDirectDispatches(event);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = IOSNativeBridgeEventPlugin;
|