react 15.3.2 → 15.4.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/dist/react-with-addons.js +3898 -21383
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2672 -19494
  4. package/dist/react.min.js +2 -6
  5. package/lib/LinkedStateMixin.js +1 -2
  6. package/lib/PooledClass.js +3 -0
  7. package/lib/ReactAddonsDOMDependencies.js +36 -0
  8. package/lib/ReactAddonsDOMDependenciesUMDShim.js +32 -0
  9. package/lib/ReactCSSTransitionGroup.js +60 -42
  10. package/lib/ReactCSSTransitionGroupChild.js +2 -2
  11. package/lib/ReactClass.js +38 -53
  12. package/lib/ReactComponentTreeHook.js +84 -100
  13. package/lib/{DOMNamespaces.js → ReactComponentTreeHookUMDShim.js} +5 -7
  14. package/lib/ReactCurrentOwner.js +1 -1
  15. package/lib/{renderSubtreeIntoContainer.js → ReactCurrentOwnerUMDShim.js} +6 -4
  16. package/lib/ReactElement.js +6 -13
  17. package/lib/ReactElementSymbol.js +20 -0
  18. package/lib/{ReactDOMComponentFlags.js → ReactElementType.js} +4 -9
  19. package/lib/ReactElementValidator.js +1 -2
  20. package/lib/ReactPropTypeLocationNames.js +1 -0
  21. package/lib/ReactPropTypeLocations.js +2 -11
  22. package/lib/ReactPropTypes.js +5 -2
  23. package/lib/ReactPropTypesSecret.js +1 -0
  24. package/lib/ReactTransitionEvents.js +1 -1
  25. package/lib/ReactTransitionGroup.js +145 -141
  26. package/lib/ReactUMDEntry.js +11 -5
  27. package/lib/{ReactDOMFeatureFlags.js → ReactUMDShim.js} +4 -6
  28. package/lib/ReactVersion.js +1 -1
  29. package/lib/ReactWithAddons.js +15 -2
  30. package/lib/ReactWithAddonsUMDEntry.js +11 -5
  31. package/lib/canDefineProperty.js +2 -0
  32. package/lib/traverseAllChildren.js +11 -2
  33. package/lib/update.js +6 -7
  34. package/package.json +1 -1
  35. package/lib/AutoFocusUtils.js +0 -24
  36. package/lib/BeforeInputEventPlugin.js +0 -390
  37. package/lib/CSSProperty.js +0 -148
  38. package/lib/CSSPropertyOperations.js +0 -205
  39. package/lib/CallbackQueue.js +0 -106
  40. package/lib/ChangeEventPlugin.js +0 -325
  41. package/lib/DOMChildrenOperations.js +0 -194
  42. package/lib/DOMLazyTree.js +0 -118
  43. package/lib/DOMProperty.js +0 -206
  44. package/lib/DOMPropertyOperations.js +0 -221
  45. package/lib/Danger.js +0 -48
  46. package/lib/DefaultEventPluginOrder.js +0 -27
  47. package/lib/DisabledInputUtils.js +0 -50
  48. package/lib/EnterLeaveEventPlugin.js +0 -105
  49. package/lib/EventConstants.js +0 -97
  50. package/lib/EventPluginHub.js +0 -251
  51. package/lib/EventPluginRegistry.js +0 -247
  52. package/lib/EventPluginUtils.js +0 -229
  53. package/lib/EventPropagators.js +0 -137
  54. package/lib/FallbackCompositionState.js +0 -95
  55. package/lib/HTMLDOMPropertyConfig.js +0 -212
  56. package/lib/LinkedValueUtils.js +0 -136
  57. package/lib/NativeMethodsMixin.js +0 -167
  58. package/lib/ReactBrowserEventEmitter.js +0 -330
  59. package/lib/ReactChildReconciler.js +0 -154
  60. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  61. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  62. package/lib/ReactComponentEnvironment.js +0 -45
  63. package/lib/ReactComponentTreeTestUtils.js +0 -87
  64. package/lib/ReactCompositeComponent.js +0 -904
  65. package/lib/ReactDOM.js +0 -110
  66. package/lib/ReactDOMButton.js +0 -24
  67. package/lib/ReactDOMComponent.js +0 -1006
  68. package/lib/ReactDOMComponentTree.js +0 -188
  69. package/lib/ReactDOMContainerInfo.js +0 -33
  70. package/lib/ReactDOMEmptyComponent.js +0 -60
  71. package/lib/ReactDOMFiber.js +0 -76
  72. package/lib/ReactDOMIDOperations.js +0 -34
  73. package/lib/ReactDOMInput.js +0 -269
  74. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  75. package/lib/ReactDOMOption.js +0 -123
  76. package/lib/ReactDOMSelect.js +0 -201
  77. package/lib/ReactDOMSelection.js +0 -212
  78. package/lib/ReactDOMServer.js +0 -26
  79. package/lib/ReactDOMTextComponent.js +0 -164
  80. package/lib/ReactDOMTextarea.js +0 -155
  81. package/lib/ReactDOMTreeTraversal.js +0 -136
  82. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  83. package/lib/ReactDebugTool.js +0 -301
  84. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  85. package/lib/ReactDefaultInjection.js +0 -84
  86. package/lib/ReactEmptyComponent.js +0 -30
  87. package/lib/ReactErrorUtils.js +0 -76
  88. package/lib/ReactEventEmitterMixin.js +0 -33
  89. package/lib/ReactEventListener.js +0 -157
  90. package/lib/ReactFeatureFlags.js +0 -22
  91. package/lib/ReactHostComponent.js +0 -76
  92. package/lib/ReactHostOperationHistoryHook.js +0 -37
  93. package/lib/ReactInjection.js +0 -36
  94. package/lib/ReactInputSelection.js +0 -124
  95. package/lib/ReactInstanceHandles.js +0 -302
  96. package/lib/ReactInstanceMap.js +0 -48
  97. package/lib/ReactInstrumentation.js +0 -21
  98. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  99. package/lib/ReactMarkupChecksum.js +0 -50
  100. package/lib/ReactMount.js +0 -534
  101. package/lib/ReactMultiChild.js +0 -451
  102. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  103. package/lib/ReactNative.js +0 -71
  104. package/lib/ReactNativeAttributePayload.js +0 -371
  105. package/lib/ReactNativeBaseComponent.js +0 -198
  106. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  107. package/lib/ReactNativeComponentEnvironment.js +0 -31
  108. package/lib/ReactNativeComponentTree.js +0 -68
  109. package/lib/ReactNativeContainerInfo.js +0 -21
  110. package/lib/ReactNativeDOMIDOperations.js +0 -79
  111. package/lib/ReactNativeDefaultInjection.js +0 -101
  112. package/lib/ReactNativeEventEmitter.js +0 -191
  113. package/lib/ReactNativeEventPluginOrder.js +0 -16
  114. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  115. package/lib/ReactNativeMount.js +0 -193
  116. package/lib/ReactNativePropRegistry.js +0 -52
  117. package/lib/ReactNativeReconcileTransaction.js +0 -129
  118. package/lib/ReactNativeTagHandles.js +0 -56
  119. package/lib/ReactNativeTextComponent.js +0 -71
  120. package/lib/ReactNativeTreeTraversal.js +0 -127
  121. package/lib/ReactNodeTypes.js +0 -40
  122. package/lib/ReactNoop.js +0 -173
  123. package/lib/ReactOwner.js +0 -94
  124. package/lib/ReactPerf.js +0 -494
  125. package/lib/ReactReconcileTransaction.js +0 -178
  126. package/lib/ReactReconciler.js +0 -168
  127. package/lib/ReactRef.js +0 -80
  128. package/lib/ReactServerBatchingStrategy.js +0 -22
  129. package/lib/ReactServerRendering.js +0 -90
  130. package/lib/ReactServerRenderingTransaction.js +0 -90
  131. package/lib/ReactServerUpdateQueue.js +0 -141
  132. package/lib/ReactSimpleEmptyComponent.js +0 -37
  133. package/lib/ReactTestMount.js +0 -126
  134. package/lib/ReactTestReconcileTransaction.js +0 -121
  135. package/lib/ReactTestRenderer.js +0 -144
  136. package/lib/ReactTestUtils.js +0 -518
  137. package/lib/ReactUpdateQueue.js +0 -226
  138. package/lib/ReactUpdates.js +0 -251
  139. package/lib/ResponderEventPlugin.js +0 -510
  140. package/lib/ResponderSyntheticEvent.js +0 -39
  141. package/lib/ResponderTouchHistoryStore.js +0 -184
  142. package/lib/SVGDOMPropertyConfig.js +0 -302
  143. package/lib/SelectEventPlugin.js +0 -196
  144. package/lib/SimpleEventPlugin.js +0 -635
  145. package/lib/SyntheticAnimationEvent.js +0 -39
  146. package/lib/SyntheticClipboardEvent.js +0 -38
  147. package/lib/SyntheticCompositionEvent.js +0 -36
  148. package/lib/SyntheticDragEvent.js +0 -36
  149. package/lib/SyntheticEvent.js +0 -268
  150. package/lib/SyntheticFocusEvent.js +0 -36
  151. package/lib/SyntheticInputEvent.js +0 -37
  152. package/lib/SyntheticKeyboardEvent.js +0 -84
  153. package/lib/SyntheticMouseEvent.js +0 -72
  154. package/lib/SyntheticTouchEvent.js +0 -45
  155. package/lib/SyntheticTransitionEvent.js +0 -39
  156. package/lib/SyntheticUIEvent.js +0 -59
  157. package/lib/SyntheticWheelEvent.js +0 -54
  158. package/lib/TapEventPlugin.js +0 -110
  159. package/lib/TouchHistoryMath.js +0 -99
  160. package/lib/Transaction.js +0 -233
  161. package/lib/ViewportMetrics.js +0 -27
  162. package/lib/accumulate.js +0 -46
  163. package/lib/accumulateInto.js +0 -58
  164. package/lib/adler32.js +0 -44
  165. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  166. package/lib/createReactNativeComponentClass.js +0 -42
  167. package/lib/dangerousStyleValue.js +0 -79
  168. package/lib/escapeTextContentForBrowser.js +0 -123
  169. package/lib/findDOMNode.js +0 -60
  170. package/lib/findNodeHandle.js +0 -91
  171. package/lib/forEachAccumulated.js +0 -31
  172. package/lib/getEventCharCode.js +0 -50
  173. package/lib/getEventKey.js +0 -102
  174. package/lib/getEventModifierState.js +0 -43
  175. package/lib/getEventTarget.js +0 -35
  176. package/lib/getHostComponentFromComposite.js +0 -30
  177. package/lib/getNodeForCharacterOffset.js +0 -74
  178. package/lib/getTestDocument.js +0 -21
  179. package/lib/getTextContentAccessor.js +0 -33
  180. package/lib/getVendorPrefixedEventName.js +0 -101
  181. package/lib/instantiateReactComponent.js +0 -119
  182. package/lib/isEventSupported.js +0 -60
  183. package/lib/isTextInputElement.js +0 -51
  184. package/lib/quoteAttributeValueForBrowser.js +0 -26
  185. package/lib/reactComponentExpect.js +0 -217
  186. package/lib/setInnerHTML.js +0 -98
  187. package/lib/setTextContent.js +0 -48
  188. package/lib/shouldUpdateReactComponent.js +0 -42
  189. package/lib/validateDOMNesting.js +0 -382
@@ -1,510 +0,0 @@
1
- /**
2
- * Copyright 2013-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 ResponderEventPlugin
10
- */
11
-
12
- 'use strict';
13
-
14
- var EventConstants = require('./EventConstants');
15
- var EventPluginUtils = require('./EventPluginUtils');
16
- var EventPropagators = require('./EventPropagators');
17
- var ResponderSyntheticEvent = require('./ResponderSyntheticEvent');
18
- var ResponderTouchHistoryStore = require('./ResponderTouchHistoryStore');
19
-
20
- var accumulate = require('./accumulate');
21
- var keyOf = require('fbjs/lib/keyOf');
22
-
23
- var isStartish = EventPluginUtils.isStartish;
24
- var isMoveish = EventPluginUtils.isMoveish;
25
- var isEndish = EventPluginUtils.isEndish;
26
- var executeDirectDispatch = EventPluginUtils.executeDirectDispatch;
27
- var hasDispatches = EventPluginUtils.hasDispatches;
28
- var executeDispatchesInOrderStopAtTrue = EventPluginUtils.executeDispatchesInOrderStopAtTrue;
29
-
30
- /**
31
- * Instance of element that should respond to touch/move types of interactions,
32
- * as indicated explicitly by relevant callbacks.
33
- */
34
- var responderInst = null;
35
-
36
- /**
37
- * Count of current touches. A textInput should become responder iff the
38
- * selection changes while there is a touch on the screen.
39
- */
40
- var trackedTouchCount = 0;
41
-
42
- /**
43
- * Last reported number of active touches.
44
- */
45
- var previousActiveTouches = 0;
46
-
47
- var changeResponder = function (nextResponderInst, blockHostResponder) {
48
- var oldResponderInst = responderInst;
49
- responderInst = nextResponderInst;
50
- if (ResponderEventPlugin.GlobalResponderHandler !== null) {
51
- ResponderEventPlugin.GlobalResponderHandler.onChange(oldResponderInst, nextResponderInst, blockHostResponder);
52
- }
53
- };
54
-
55
- var eventTypes = {
56
- /**
57
- * On a `touchStart`/`mouseDown`, is it desired that this element become the
58
- * responder?
59
- */
60
- startShouldSetResponder: {
61
- phasedRegistrationNames: {
62
- bubbled: keyOf({ onStartShouldSetResponder: null }),
63
- captured: keyOf({ onStartShouldSetResponderCapture: null })
64
- }
65
- },
66
-
67
- /**
68
- * On a `scroll`, is it desired that this element become the responder? This
69
- * is usually not needed, but should be used to retroactively infer that a
70
- * `touchStart` had occurred during momentum scroll. During a momentum scroll,
71
- * a touch start will be immediately followed by a scroll event if the view is
72
- * currently scrolling.
73
- *
74
- * TODO: This shouldn't bubble.
75
- */
76
- scrollShouldSetResponder: {
77
- phasedRegistrationNames: {
78
- bubbled: keyOf({ onScrollShouldSetResponder: null }),
79
- captured: keyOf({ onScrollShouldSetResponderCapture: null })
80
- }
81
- },
82
-
83
- /**
84
- * On text selection change, should this element become the responder? This
85
- * is needed for text inputs or other views with native selection, so the
86
- * JS view can claim the responder.
87
- *
88
- * TODO: This shouldn't bubble.
89
- */
90
- selectionChangeShouldSetResponder: {
91
- phasedRegistrationNames: {
92
- bubbled: keyOf({ onSelectionChangeShouldSetResponder: null }),
93
- captured: keyOf({ onSelectionChangeShouldSetResponderCapture: null })
94
- }
95
- },
96
-
97
- /**
98
- * On a `touchMove`/`mouseMove`, is it desired that this element become the
99
- * responder?
100
- */
101
- moveShouldSetResponder: {
102
- phasedRegistrationNames: {
103
- bubbled: keyOf({ onMoveShouldSetResponder: null }),
104
- captured: keyOf({ onMoveShouldSetResponderCapture: null })
105
- }
106
- },
107
-
108
- /**
109
- * Direct responder events dispatched directly to responder. Do not bubble.
110
- */
111
- responderStart: { registrationName: keyOf({ onResponderStart: null }) },
112
- responderMove: { registrationName: keyOf({ onResponderMove: null }) },
113
- responderEnd: { registrationName: keyOf({ onResponderEnd: null }) },
114
- responderRelease: { registrationName: keyOf({ onResponderRelease: null }) },
115
- responderTerminationRequest: {
116
- registrationName: keyOf({ onResponderTerminationRequest: null })
117
- },
118
- responderGrant: { registrationName: keyOf({ onResponderGrant: null }) },
119
- responderReject: { registrationName: keyOf({ onResponderReject: null }) },
120
- responderTerminate: { registrationName: keyOf({ onResponderTerminate: null }) }
121
- };
122
-
123
- /**
124
- *
125
- * Responder System:
126
- * ----------------
127
- *
128
- * - A global, solitary "interaction lock" on a view.
129
- * - If a node becomes the responder, it should convey visual feedback
130
- * immediately to indicate so, either by highlighting or moving accordingly.
131
- * - To be the responder means, that touches are exclusively important to that
132
- * responder view, and no other view.
133
- * - While touches are still occurring, the responder lock can be transferred to
134
- * a new view, but only to increasingly "higher" views (meaning ancestors of
135
- * the current responder).
136
- *
137
- * Responder being granted:
138
- * ------------------------
139
- *
140
- * - Touch starts, moves, and scrolls can cause an ID to become the responder.
141
- * - We capture/bubble `startShouldSetResponder`/`moveShouldSetResponder` to
142
- * the "appropriate place".
143
- * - If nothing is currently the responder, the "appropriate place" is the
144
- * initiating event's `targetID`.
145
- * - If something *is* already the responder, the "appropriate place" is the
146
- * first common ancestor of the event target and the current `responderInst`.
147
- * - Some negotiation happens: See the timing diagram below.
148
- * - Scrolled views automatically become responder. The reasoning is that a
149
- * platform scroll view that isn't built on top of the responder system has
150
- * began scrolling, and the active responder must now be notified that the
151
- * interaction is no longer locked to it - the system has taken over.
152
- *
153
- * - Responder being released:
154
- * As soon as no more touches that *started* inside of descendants of the
155
- * *current* responderInst, an `onResponderRelease` event is dispatched to the
156
- * current responder, and the responder lock is released.
157
- *
158
- * TODO:
159
- * - on "end", a callback hook for `onResponderEndShouldRemainResponder` that
160
- * determines if the responder lock should remain.
161
- * - If a view shouldn't "remain" the responder, any active touches should by
162
- * default be considered "dead" and do not influence future negotiations or
163
- * bubble paths. It should be as if those touches do not exist.
164
- * -- For multitouch: Usually a translate-z will choose to "remain" responder
165
- * after one out of many touches ended. For translate-y, usually the view
166
- * doesn't wish to "remain" responder after one of many touches end.
167
- * - Consider building this on top of a `stopPropagation` model similar to
168
- * `W3C` events.
169
- * - Ensure that `onResponderTerminate` is called on touch cancels, whether or
170
- * not `onResponderTerminationRequest` returns `true` or `false`.
171
- *
172
- */
173
-
174
- /* Negotiation Performed
175
- +-----------------------+
176
- / \
177
- Process low level events to + Current Responder + wantsResponderID
178
- determine who to perform negot-| (if any exists at all) |
179
- iation/transition | Otherwise just pass through|
180
- -------------------------------+----------------------------+------------------+
181
- Bubble to find first ID | |
182
- to return true:wantsResponderID| |
183
- | |
184
- +-------------+ | |
185
- | onTouchStart| | |
186
- +------+------+ none | |
187
- | return| |
188
- +-----------v-------------+true| +------------------------+ |
189
- |onStartShouldSetResponder|----->|onResponderStart (cur) |<-----------+
190
- +-----------+-------------+ | +------------------------+ | |
191
- | | | +--------+-------+
192
- | returned true for| false:REJECT +-------->|onResponderReject
193
- | wantsResponderID | | | +----------------+
194
- | (now attempt | +------------------+-----+ |
195
- | handoff) | | onResponder | |
196
- +------------------->| TerminationRequest| |
197
- | +------------------+-----+ |
198
- | | | +----------------+
199
- | true:GRANT +-------->|onResponderGrant|
200
- | | +--------+-------+
201
- | +------------------------+ | |
202
- | | onResponderTerminate |<-----------+
203
- | +------------------+-----+ |
204
- | | | +----------------+
205
- | +-------->|onResponderStart|
206
- | | +----------------+
207
- Bubble to find first ID | |
208
- to return true:wantsResponderID| |
209
- | |
210
- +-------------+ | |
211
- | onTouchMove | | |
212
- +------+------+ none | |
213
- | return| |
214
- +-----------v-------------+true| +------------------------+ |
215
- |onMoveShouldSetResponder |----->|onResponderMove (cur) |<-----------+
216
- +-----------+-------------+ | +------------------------+ | |
217
- | | | +--------+-------+
218
- | returned true for| false:REJECT +-------->|onResponderRejec|
219
- | wantsResponderID | | | +----------------+
220
- | (now attempt | +------------------+-----+ |
221
- | handoff) | | onResponder | |
222
- +------------------->| TerminationRequest| |
223
- | +------------------+-----+ |
224
- | | | +----------------+
225
- | true:GRANT +-------->|onResponderGrant|
226
- | | +--------+-------+
227
- | +------------------------+ | |
228
- | | onResponderTerminate |<-----------+
229
- | +------------------+-----+ |
230
- | | | +----------------+
231
- | +-------->|onResponderMove |
232
- | | +----------------+
233
- | |
234
- | |
235
- Some active touch started| |
236
- inside current responder | +------------------------+ |
237
- +------------------------->| onResponderEnd | |
238
- | | +------------------------+ |
239
- +---+---------+ | |
240
- | onTouchEnd | | |
241
- +---+---------+ | |
242
- | | +------------------------+ |
243
- +------------------------->| onResponderEnd | |
244
- No active touches started| +-----------+------------+ |
245
- inside current responder | | |
246
- | v |
247
- | +------------------------+ |
248
- | | onResponderRelease | |
249
- | +------------------------+ |
250
- | |
251
- + + */
252
-
253
- /**
254
- * A note about event ordering in the `EventPluginHub`.
255
- *
256
- * Suppose plugins are injected in the following order:
257
- *
258
- * `[R, S, C]`
259
- *
260
- * To help illustrate the example, assume `S` is `SimpleEventPlugin` (for
261
- * `onClick` etc) and `R` is `ResponderEventPlugin`.
262
- *
263
- * "Deferred-Dispatched Events":
264
- *
265
- * - The current event plugin system will traverse the list of injected plugins,
266
- * in order, and extract events by collecting the plugin's return value of
267
- * `extractEvents()`.
268
- * - These events that are returned from `extractEvents` are "deferred
269
- * dispatched events".
270
- * - When returned from `extractEvents`, deferred-dispatched events contain an
271
- * "accumulation" of deferred dispatches.
272
- * - These deferred dispatches are accumulated/collected before they are
273
- * returned, but processed at a later time by the `EventPluginHub` (hence the
274
- * name deferred).
275
- *
276
- * In the process of returning their deferred-dispatched events, event plugins
277
- * themselves can dispatch events on-demand without returning them from
278
- * `extractEvents`. Plugins might want to do this, so that they can use event
279
- * dispatching as a tool that helps them decide which events should be extracted
280
- * in the first place.
281
- *
282
- * "On-Demand-Dispatched Events":
283
- *
284
- * - On-demand-dispatched events are not returned from `extractEvents`.
285
- * - On-demand-dispatched events are dispatched during the process of returning
286
- * the deferred-dispatched events.
287
- * - They should not have side effects.
288
- * - They should be avoided, and/or eventually be replaced with another
289
- * abstraction that allows event plugins to perform multiple "rounds" of event
290
- * extraction.
291
- *
292
- * Therefore, the sequence of event dispatches becomes:
293
- *
294
- * - `R`s on-demand events (if any) (dispatched by `R` on-demand)
295
- * - `S`s on-demand events (if any) (dispatched by `S` on-demand)
296
- * - `C`s on-demand events (if any) (dispatched by `C` on-demand)
297
- * - `R`s extracted events (if any) (dispatched by `EventPluginHub`)
298
- * - `S`s extracted events (if any) (dispatched by `EventPluginHub`)
299
- * - `C`s extracted events (if any) (dispatched by `EventPluginHub`)
300
- *
301
- * In the case of `ResponderEventPlugin`: If the `startShouldSetResponder`
302
- * on-demand dispatch returns `true` (and some other details are satisfied) the
303
- * `onResponderGrant` deferred dispatched event is returned from
304
- * `extractEvents`. The sequence of dispatch executions in this case
305
- * will appear as follows:
306
- *
307
- * - `startShouldSetResponder` (`ResponderEventPlugin` dispatches on-demand)
308
- * - `touchStartCapture` (`EventPluginHub` dispatches as usual)
309
- * - `touchStart` (`EventPluginHub` dispatches as usual)
310
- * - `responderGrant/Reject` (`EventPluginHub` dispatches as usual)
311
- */
312
-
313
- function setResponderAndExtractTransfer(topLevelType, targetInst, nativeEvent, nativeEventTarget) {
314
- var shouldSetEventType = isStartish(topLevelType) ? eventTypes.startShouldSetResponder : isMoveish(topLevelType) ? eventTypes.moveShouldSetResponder : topLevelType === EventConstants.topLevelTypes.topSelectionChange ? eventTypes.selectionChangeShouldSetResponder : eventTypes.scrollShouldSetResponder;
315
-
316
- // TODO: stop one short of the current responder.
317
- var bubbleShouldSetFrom = !responderInst ? targetInst : EventPluginUtils.getLowestCommonAncestor(responderInst, targetInst);
318
-
319
- // When capturing/bubbling the "shouldSet" event, we want to skip the target
320
- // (deepest ID) if it happens to be the current responder. The reasoning:
321
- // It's strange to get an `onMoveShouldSetResponder` when you're *already*
322
- // the responder.
323
- var skipOverBubbleShouldSetFrom = bubbleShouldSetFrom === responderInst;
324
- var shouldSetEvent = ResponderSyntheticEvent.getPooled(shouldSetEventType, bubbleShouldSetFrom, nativeEvent, nativeEventTarget);
325
- shouldSetEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
326
- if (skipOverBubbleShouldSetFrom) {
327
- EventPropagators.accumulateTwoPhaseDispatchesSkipTarget(shouldSetEvent);
328
- } else {
329
- EventPropagators.accumulateTwoPhaseDispatches(shouldSetEvent);
330
- }
331
- var wantsResponderInst = executeDispatchesInOrderStopAtTrue(shouldSetEvent);
332
- if (!shouldSetEvent.isPersistent()) {
333
- shouldSetEvent.constructor.release(shouldSetEvent);
334
- }
335
-
336
- if (!wantsResponderInst || wantsResponderInst === responderInst) {
337
- return null;
338
- }
339
- var extracted;
340
- var grantEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderGrant, wantsResponderInst, nativeEvent, nativeEventTarget);
341
- grantEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
342
-
343
- EventPropagators.accumulateDirectDispatches(grantEvent);
344
- var blockHostResponder = executeDirectDispatch(grantEvent) === true;
345
- if (responderInst) {
346
-
347
- var terminationRequestEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderTerminationRequest, responderInst, nativeEvent, nativeEventTarget);
348
- terminationRequestEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
349
- EventPropagators.accumulateDirectDispatches(terminationRequestEvent);
350
- var shouldSwitch = !hasDispatches(terminationRequestEvent) || executeDirectDispatch(terminationRequestEvent);
351
- if (!terminationRequestEvent.isPersistent()) {
352
- terminationRequestEvent.constructor.release(terminationRequestEvent);
353
- }
354
-
355
- if (shouldSwitch) {
356
- var terminateEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderTerminate, responderInst, nativeEvent, nativeEventTarget);
357
- terminateEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
358
- EventPropagators.accumulateDirectDispatches(terminateEvent);
359
- extracted = accumulate(extracted, [grantEvent, terminateEvent]);
360
- changeResponder(wantsResponderInst, blockHostResponder);
361
- } else {
362
- var rejectEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderReject, wantsResponderInst, nativeEvent, nativeEventTarget);
363
- rejectEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
364
- EventPropagators.accumulateDirectDispatches(rejectEvent);
365
- extracted = accumulate(extracted, rejectEvent);
366
- }
367
- } else {
368
- extracted = accumulate(extracted, grantEvent);
369
- changeResponder(wantsResponderInst, blockHostResponder);
370
- }
371
- return extracted;
372
- }
373
-
374
- /**
375
- * A transfer is a negotiation between a currently set responder and the next
376
- * element to claim responder status. Any start event could trigger a transfer
377
- * of responderInst. Any move event could trigger a transfer.
378
- *
379
- * @param {string} topLevelType Record from `EventConstants`.
380
- * @return {boolean} True if a transfer of responder could possibly occur.
381
- */
382
- function canTriggerTransfer(topLevelType, topLevelInst, nativeEvent) {
383
- return topLevelInst && (
384
- // responderIgnoreScroll: We are trying to migrate away from specifically
385
- // tracking native scroll events here and responderIgnoreScroll indicates we
386
- // will send topTouchCancel to handle canceling touch events instead
387
- topLevelType === EventConstants.topLevelTypes.topScroll && !nativeEvent.responderIgnoreScroll || trackedTouchCount > 0 && topLevelType === EventConstants.topLevelTypes.topSelectionChange || isStartish(topLevelType) || isMoveish(topLevelType));
388
- }
389
-
390
- /**
391
- * Returns whether or not this touch end event makes it such that there are no
392
- * longer any touches that started inside of the current `responderInst`.
393
- *
394
- * @param {NativeEvent} nativeEvent Native touch end event.
395
- * @return {boolean} Whether or not this touch end event ends the responder.
396
- */
397
- function noResponderTouches(nativeEvent) {
398
- var touches = nativeEvent.touches;
399
- if (!touches || touches.length === 0) {
400
- return true;
401
- }
402
- for (var i = 0; i < touches.length; i++) {
403
- var activeTouch = touches[i];
404
- var target = activeTouch.target;
405
- if (target !== null && target !== undefined && target !== 0) {
406
- // Is the original touch location inside of the current responder?
407
- var targetInst = EventPluginUtils.getInstanceFromNode(target);
408
- if (EventPluginUtils.isAncestor(responderInst, targetInst)) {
409
- return false;
410
- }
411
- }
412
- }
413
- return true;
414
- }
415
-
416
- var ResponderEventPlugin = {
417
-
418
- /* For unit testing only */
419
- _getResponderID: function () {
420
- return responderInst ? responderInst._rootNodeID : null;
421
- },
422
-
423
- eventTypes: eventTypes,
424
-
425
- /**
426
- * We must be resilient to `targetInst` being `null` on `touchMove` or
427
- * `touchEnd`. On certain platforms, this means that a native scroll has
428
- * assumed control and the original touch targets are destroyed.
429
- */
430
- extractEvents: function (topLevelType, targetInst, nativeEvent, nativeEventTarget) {
431
- if (isStartish(topLevelType)) {
432
- trackedTouchCount += 1;
433
- } else if (isEndish(topLevelType)) {
434
- if (trackedTouchCount >= 0) {
435
- trackedTouchCount -= 1;
436
- } else {
437
- console.error('Ended a touch event which was not counted in `trackedTouchCount`.');
438
- return null;
439
- }
440
- }
441
-
442
- ResponderTouchHistoryStore.recordTouchTrack(topLevelType, nativeEvent);
443
-
444
- var extracted = canTriggerTransfer(topLevelType, targetInst, nativeEvent) ? setResponderAndExtractTransfer(topLevelType, targetInst, nativeEvent, nativeEventTarget) : null;
445
- // Responder may or may not have transferred on a new touch start/move.
446
- // Regardless, whoever is the responder after any potential transfer, we
447
- // direct all touch start/move/ends to them in the form of
448
- // `onResponderMove/Start/End`. These will be called for *every* additional
449
- // finger that move/start/end, dispatched directly to whoever is the
450
- // current responder at that moment, until the responder is "released".
451
- //
452
- // These multiple individual change touch events are are always bookended
453
- // by `onResponderGrant`, and one of
454
- // (`onResponderRelease/onResponderTerminate`).
455
- var isResponderTouchStart = responderInst && isStartish(topLevelType);
456
- var isResponderTouchMove = responderInst && isMoveish(topLevelType);
457
- var isResponderTouchEnd = responderInst && isEndish(topLevelType);
458
- var incrementalTouch = isResponderTouchStart ? eventTypes.responderStart : isResponderTouchMove ? eventTypes.responderMove : isResponderTouchEnd ? eventTypes.responderEnd : null;
459
-
460
- if (incrementalTouch) {
461
- var gesture = ResponderSyntheticEvent.getPooled(incrementalTouch, responderInst, nativeEvent, nativeEventTarget);
462
- gesture.touchHistory = ResponderTouchHistoryStore.touchHistory;
463
- EventPropagators.accumulateDirectDispatches(gesture);
464
- extracted = accumulate(extracted, gesture);
465
- }
466
-
467
- var isResponderTerminate = responderInst && topLevelType === EventConstants.topLevelTypes.topTouchCancel;
468
- var isResponderRelease = responderInst && !isResponderTerminate && isEndish(topLevelType) && noResponderTouches(nativeEvent);
469
- var finalTouch = isResponderTerminate ? eventTypes.responderTerminate : isResponderRelease ? eventTypes.responderRelease : null;
470
- if (finalTouch) {
471
- var finalEvent = ResponderSyntheticEvent.getPooled(finalTouch, responderInst, nativeEvent, nativeEventTarget);
472
- finalEvent.touchHistory = ResponderTouchHistoryStore.touchHistory;
473
- EventPropagators.accumulateDirectDispatches(finalEvent);
474
- extracted = accumulate(extracted, finalEvent);
475
- changeResponder(null);
476
- }
477
-
478
- var numberActiveTouches = ResponderTouchHistoryStore.touchHistory.numberActiveTouches;
479
- if (ResponderEventPlugin.GlobalInteractionHandler && numberActiveTouches !== previousActiveTouches) {
480
- ResponderEventPlugin.GlobalInteractionHandler.onChange(numberActiveTouches);
481
- }
482
- previousActiveTouches = numberActiveTouches;
483
-
484
- return extracted;
485
- },
486
-
487
- GlobalResponderHandler: null,
488
- GlobalInteractionHandler: null,
489
-
490
- injection: {
491
- /**
492
- * @param {{onChange: (ReactID, ReactID) => void} GlobalResponderHandler
493
- * Object that handles any change in responder. Use this to inject
494
- * integration with an existing touch handling system etc.
495
- */
496
- injectGlobalResponderHandler: function (GlobalResponderHandler) {
497
- ResponderEventPlugin.GlobalResponderHandler = GlobalResponderHandler;
498
- },
499
-
500
- /**
501
- * @param {{onChange: (numberActiveTouches) => void} GlobalInteractionHandler
502
- * Object that handles any change in the number of active touches.
503
- */
504
- injectGlobalInteractionHandler: function (GlobalInteractionHandler) {
505
- ResponderEventPlugin.GlobalInteractionHandler = GlobalInteractionHandler;
506
- }
507
- }
508
- };
509
-
510
- module.exports = ResponderEventPlugin;