react-test-renderer 15.5.0 → 15.5.4

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