|
| 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 IOSNativeBridgeEventPlugin |
| 10 | + * @flow |
| 11 | + */ |
| 12 | +'use strict'; |
| 13 | + |
| 14 | +var EventPropagators = require('EventPropagators'); |
| 15 | +var SyntheticEvent = require('SyntheticEvent'); |
| 16 | +var UIManager = require('UIManager'); |
| 17 | + |
| 18 | +var merge = require('merge'); |
| 19 | +var warning = require('warning'); |
| 20 | + |
| 21 | +var customBubblingEventTypes = UIManager.customBubblingEventTypes; |
| 22 | +var customDirectEventTypes = UIManager.customDirectEventTypes; |
| 23 | + |
| 24 | +var allTypesByEventName = {}; |
| 25 | + |
| 26 | +for (var bubblingTypeName in customBubblingEventTypes) { |
| 27 | + allTypesByEventName[bubblingTypeName] = customBubblingEventTypes[bubblingTypeName]; |
| 28 | +} |
| 29 | + |
| 30 | +for (var directTypeName in customDirectEventTypes) { |
| 31 | + warning( |
| 32 | + !customBubblingEventTypes[directTypeName], |
| 33 | + 'Event cannot be both direct and bubbling: %s', |
| 34 | + directTypeName |
| 35 | + ); |
| 36 | + allTypesByEventName[directTypeName] = customDirectEventTypes[directTypeName]; |
| 37 | +} |
| 38 | + |
| 39 | +var IOSNativeBridgeEventPlugin = { |
| 40 | + |
| 41 | + eventTypes: merge(customBubblingEventTypes, customDirectEventTypes), |
| 42 | + |
| 43 | + /** |
| 44 | + * @see {EventPluginHub.extractEvents} |
| 45 | + */ |
| 46 | + extractEvents: function( |
| 47 | + topLevelType, |
| 48 | + targetInst, |
| 49 | + nativeEvent, |
| 50 | + nativeEventTarget |
| 51 | + ): ?Object { |
| 52 | + var bubbleDispatchConfig = customBubblingEventTypes[topLevelType]; |
| 53 | + var directDispatchConfig = customDirectEventTypes[topLevelType]; |
| 54 | + var event = SyntheticEvent.getPooled( |
| 55 | + bubbleDispatchConfig || directDispatchConfig, |
| 56 | + targetInst, |
| 57 | + nativeEvent, |
| 58 | + nativeEventTarget |
| 59 | + ); |
| 60 | + if (bubbleDispatchConfig) { |
| 61 | + EventPropagators.accumulateTwoPhaseDispatches(event); |
| 62 | + } else if (directDispatchConfig) { |
| 63 | + EventPropagators.accumulateDirectDispatches(event); |
| 64 | + } else { |
| 65 | + return null; |
| 66 | + } |
| 67 | + return event; |
| 68 | + }, |
| 69 | +}; |
| 70 | + |
| 71 | +module.exports = IOSNativeBridgeEventPlugin; |
0 commit comments