11
11
*/
12
12
'use strict' ;
13
13
14
- var EventPropagators = require ( 'EventPropagators' ) ;
15
- var SyntheticEvent = require ( 'SyntheticEvent' ) ;
16
- var ReactNativeEventTypes = require ( 'ReactNativeEventTypes' ) ;
17
- var invariant = require ( 'fbjs/lib/invariant' ) ;
14
+ const EventPropagators = require ( 'EventPropagators' ) ;
15
+ const SyntheticEvent = require ( 'SyntheticEvent' ) ;
16
+ const invariant = require ( 'fbjs/lib/invariant' ) ;
18
17
19
- var customBubblingEventTypes = ReactNativeEventTypes . customBubblingEventTypes ;
20
- var customDirectEventTypes = ReactNativeEventTypes . customDirectEventTypes ;
18
+ const customBubblingEventTypes = { } ;
19
+ const customDirectEventTypes = { } ;
21
20
22
- if ( __DEV__ ) {
23
- var warning = require ( 'fbjs/lib/warning' ) ;
21
+ import type { ReactNativeBaseComponentViewConfig } from 'ReactNativeTypes' ;
24
22
25
- for ( var directTypeName in customDirectEventTypes ) {
26
- warning (
27
- ! customBubblingEventTypes [ directTypeName ] ,
28
- 'Event cannot be both direct and bubbling: %s' ,
29
- directTypeName ,
30
- ) ;
31
- }
32
- }
33
-
34
- var ReactNativeBridgeEventPlugin = {
35
- eventTypes : { ...customBubblingEventTypes , ...customDirectEventTypes } ,
23
+ const ReactNativeBridgeEventPlugin = {
24
+ eventTypes : { } ,
36
25
37
26
/**
38
27
* @see {EventPluginHub.extractEvents}
@@ -43,14 +32,14 @@ var ReactNativeBridgeEventPlugin = {
43
32
nativeEvent : Event ,
44
33
nativeEventTarget : Object ,
45
34
) : ?Object {
46
- var bubbleDispatchConfig = customBubblingEventTypes [ topLevelType ] ;
47
- var directDispatchConfig = customDirectEventTypes [ topLevelType ] ;
35
+ const bubbleDispatchConfig = customBubblingEventTypes [ topLevelType ] ;
36
+ const directDispatchConfig = customDirectEventTypes [ topLevelType ] ;
48
37
invariant (
49
38
bubbleDispatchConfig || directDispatchConfig ,
50
39
'Unsupported top level event type "%s" dispatched' ,
51
40
topLevelType,
52
41
) ;
53
- var event = SyntheticEvent . getPooled (
42
+ const event = SyntheticEvent . getPooled (
54
43
bubbleDispatchConfig || directDispatchConfig ,
55
44
targetInst,
56
45
nativeEvent,
@@ -65,6 +54,46 @@ var ReactNativeBridgeEventPlugin = {
65
54
}
66
55
return event ;
67
56
} ,
57
+
58
+ processEventTypes: function (
59
+ viewConfig : ReactNativeBaseComponentViewConfig ,
60
+ ) : void {
61
+ const { bubblingEventTypes, directEventTypes} = viewConfig ;
62
+
63
+ if ( __DEV__ ) {
64
+ if ( bubblingEventTypes != null && directEventTypes != null ) {
65
+ for ( const topLevelType in directEventTypes ) {
66
+ invariant (
67
+ bubblingEventTypes [ topLevelType ] == null ,
68
+ 'Event cannot be both direct and bubbling: %s' ,
69
+ topLevelType ,
70
+ ) ;
71
+ }
72
+ }
73
+ }
74
+
75
+ if ( bubblingEventTypes != null ) {
76
+ for ( const topLevelType in bubblingEventTypes ) {
77
+ if ( customBubblingEventTypes [ topLevelType ] == null ) {
78
+ ReactNativeBridgeEventPlugin . eventTypes [
79
+ topLevelType
80
+ ] = customBubblingEventTypes [ topLevelType ] =
81
+ bubblingEventTypes [ topLevelType ] ;
82
+ }
83
+ }
84
+ }
85
+
86
+ if ( directEventTypes != null ) {
87
+ for ( const topLevelType in directEventTypes ) {
88
+ if ( customDirectEventTypes [ topLevelType ] == null ) {
89
+ ReactNativeBridgeEventPlugin . eventTypes [
90
+ topLevelType
91
+ ] = customDirectEventTypes [ topLevelType ] =
92
+ directEventTypes [ topLevelType ] ;
93
+ }
94
+ }
95
+ }
96
+ } ,
68
97
} ;
69
98
70
99
module . exports = ReactNativeBridgeEventPlugin ;
0 commit comments