react 15.0.2-alpha.1 → 15.0.2

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.
@@ -1,362 +0,0 @@
1
- /**
2
- * @providesModule PanResponder
3
- */
4
-
5
- 'use strict';
6
-
7
- var TouchHistoryMath = require('./TouchHistoryMath');
8
-
9
- var currentCentroidXOfTouchesChangedAfter = TouchHistoryMath.currentCentroidXOfTouchesChangedAfter;
10
- var currentCentroidYOfTouchesChangedAfter = TouchHistoryMath.currentCentroidYOfTouchesChangedAfter;
11
- var previousCentroidXOfTouchesChangedAfter = TouchHistoryMath.previousCentroidXOfTouchesChangedAfter;
12
- var previousCentroidYOfTouchesChangedAfter = TouchHistoryMath.previousCentroidYOfTouchesChangedAfter;
13
- var currentCentroidX = TouchHistoryMath.currentCentroidX;
14
- var currentCentroidY = TouchHistoryMath.currentCentroidY;
15
-
16
- /**
17
- * `PanResponder` reconciles several touches into a single gesture. It makes
18
- * single-touch gestures resilient to extra touches, and can be used to
19
- * recognize simple multi-touch gestures.
20
- *
21
- * It provides a predictable wrapper of the responder handlers provided by the
22
- * [gesture responder system](docs/gesture-responder-system.html).
23
- * For each handler, it provides a new `gestureState` object alongside the
24
- * native event object:
25
- *
26
- * ```
27
- * onPanResponderMove: (event, gestureState) => {}
28
- * ```
29
- *
30
- * A native event is a synthetic touch event with the following form:
31
- *
32
- * - `nativeEvent`
33
- * + `changedTouches` - Array of all touch events that have changed since the last event
34
- * + `identifier` - The ID of the touch
35
- * + `locationX` - The X position of the touch, relative to the element
36
- * + `locationY` - The Y position of the touch, relative to the element
37
- * + `pageX` - The X position of the touch, relative to the root element
38
- * + `pageY` - The Y position of the touch, relative to the root element
39
- * + `target` - The node id of the element receiving the touch event
40
- * + `timestamp` - A time identifier for the touch, useful for velocity calculation
41
- * + `touches` - Array of all current touches on the screen
42
- *
43
- * A `gestureState` object has the following:
44
- *
45
- * - `stateID` - ID of the gestureState- persisted as long as there at least
46
- * one touch on screen
47
- * - `moveX` - the latest screen coordinates of the recently-moved touch
48
- * - `moveY` - the latest screen coordinates of the recently-moved touch
49
- * - `x0` - the screen coordinates of the responder grant
50
- * - `y0` - the screen coordinates of the responder grant
51
- * - `dx` - accumulated distance of the gesture since the touch started
52
- * - `dy` - accumulated distance of the gesture since the touch started
53
- * - `vx` - current velocity of the gesture
54
- * - `vy` - current velocity of the gesture
55
- * - `numberActiveTouches` - Number of touches currently on screen
56
- *
57
- * ### Basic Usage
58
- *
59
- * ```
60
- * componentWillMount: function() {
61
- * this._panResponder = PanResponder.create({
62
- * // Ask to be the responder:
63
- * onStartShouldSetPanResponder: (evt, gestureState) => true,
64
- * onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
65
- * onMoveShouldSetPanResponder: (evt, gestureState) => true,
66
- * onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
67
- *
68
- * onPanResponderGrant: (evt, gestureState) => {
69
- * // The guesture has started. Show visual feedback so the user knows
70
- * // what is happening!
71
- *
72
- * // gestureState.{x,y}0 will be set to zero now
73
- * },
74
- * onPanResponderMove: (evt, gestureState) => {
75
- * // The most recent move distance is gestureState.move{X,Y}
76
- *
77
- * // The accumulated gesture distance since becoming responder is
78
- * // gestureState.d{x,y}
79
- * },
80
- * onPanResponderTerminationRequest: (evt, gestureState) => true,
81
- * onPanResponderRelease: (evt, gestureState) => {
82
- * // The user has released all touches while this view is the
83
- * // responder. This typically means a gesture has succeeded
84
- * },
85
- * onPanResponderTerminate: (evt, gestureState) => {
86
- * // Another component has become the responder, so this gesture
87
- * // should be cancelled
88
- * },
89
- * onShouldBlockNativeResponder: (evt, gestureState) => {
90
- * // Returns whether this component should block native components from becoming the JS
91
- * // responder. Returns true by default. Is currently only supported on android.
92
- * return true;
93
- * },
94
- * });
95
- * },
96
- *
97
- * render: function() {
98
- * return (
99
- * <View {...this._panResponder.panHandlers} />
100
- * );
101
- * },
102
- *
103
- * ```
104
- *
105
- * ### Working Example
106
- *
107
- * To see it in action, try the
108
- * [PanResponder example in UIExplorer](https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/PanResponderExample.js)
109
- */
110
-
111
- var PanResponder = {
112
-
113
- /**
114
- *
115
- * A graphical explanation of the touch data flow:
116
- *
117
- * +----------------------------+ +--------------------------------+
118
- * | ResponderTouchHistoryStore | |TouchHistoryMath |
119
- * +----------------------------+ +----------+---------------------+
120
- * |Global store of touchHistory| |Allocation-less math util |
121
- * |including activeness, start | |on touch history (centroids |
122
- * |position, prev/cur position.| |and multitouch movement etc) |
123
- * | | | |
124
- * +----^-----------------------+ +----^---------------------------+
125
- * | |
126
- * | (records relevant history |
127
- * | of touches relevant for |
128
- * | implementing higher level |
129
- * | gestures) |
130
- * | |
131
- * +----+-----------------------+ +----|---------------------------+
132
- * | ResponderEventPlugin | | | Your App/Component |
133
- * +----------------------------+ +----|---------------------------+
134
- * |Negotiates which view gets | Low level | | High level |
135
- * |onResponderMove events. | events w/ | +-+-------+ events w/ |
136
- * |Also records history into | touchHistory| | Pan | multitouch + |
137
- * |ResponderTouchHistoryStore. +---------------->Responder+-----> accumulative|
138
- * +----------------------------+ attached to | | | distance and |
139
- * each event | +---------+ velocity. |
140
- * | |
141
- * | |
142
- * +--------------------------------+
143
- *
144
- *
145
- *
146
- * Gesture that calculates cumulative movement over time in a way that just
147
- * "does the right thing" for multiple touches. The "right thing" is very
148
- * nuanced. When moving two touches in opposite directions, the cumulative
149
- * distance is zero in each dimension. When two touches move in parallel five
150
- * pixels in the same direction, the cumulative distance is five, not ten. If
151
- * two touches start, one moves five in a direction, then stops and the other
152
- * touch moves fives in the same direction, the cumulative distance is ten.
153
- *
154
- * This logic requires a kind of processing of time "clusters" of touch events
155
- * so that two touch moves that essentially occur in parallel but move every
156
- * other frame respectively, are considered part of the same movement.
157
- *
158
- * Explanation of some of the non-obvious fields:
159
- *
160
- * - moveX/moveY: If no move event has been observed, then `(moveX, moveY)` is
161
- * invalid. If a move event has been observed, `(moveX, moveY)` is the
162
- * centroid of the most recently moved "cluster" of active touches.
163
- * (Currently all move have the same timeStamp, but later we should add some
164
- * threshold for what is considered to be "moving"). If a palm is
165
- * accidentally counted as a touch, but a finger is moving greatly, the palm
166
- * will move slightly, but we only want to count the single moving touch.
167
- * - x0/y0: Centroid location (non-cumulative) at the time of becoming
168
- * responder.
169
- * - dx/dy: Cumulative touch distance - not the same thing as sum of each touch
170
- * distance. Accounts for touch moves that are clustered together in time,
171
- * moving the same direction. Only valid when currently responder (otherwise,
172
- * it only represents the drag distance below the threshold).
173
- * - vx/vy: Velocity.
174
- */
175
-
176
- _initializeGestureState: function (gestureState) {
177
- gestureState.moveX = 0;
178
- gestureState.moveY = 0;
179
- gestureState.x0 = 0;
180
- gestureState.y0 = 0;
181
- gestureState.dx = 0;
182
- gestureState.dy = 0;
183
- gestureState.vx = 0;
184
- gestureState.vy = 0;
185
- gestureState.numberActiveTouches = 0;
186
- // All `gestureState` accounts for timeStamps up until:
187
- gestureState._accountsForMovesUpTo = 0;
188
- },
189
-
190
- /**
191
- * This is nuanced and is necessary. It is incorrect to continuously take all
192
- * active *and* recently moved touches, find the centroid, and track how that
193
- * result changes over time. Instead, we must take all recently moved
194
- * touches, and calculate how the centroid has changed just for those
195
- * recently moved touches, and append that change to an accumulator. This is
196
- * to (at least) handle the case where the user is moving three fingers, and
197
- * then one of the fingers stops but the other two continue.
198
- *
199
- * This is very different than taking all of the recently moved touches and
200
- * storing their centroid as `dx/dy`. For correctness, we must *accumulate
201
- * changes* in the centroid of recently moved touches.
202
- *
203
- * There is also some nuance with how we handle multiple moved touches in a
204
- * single event. With the way `ReactNativeEventEmitter` dispatches touches as
205
- * individual events, multiple touches generate two 'move' events, each of
206
- * them triggering `onResponderMove`. But with the way `PanResponder` works,
207
- * all of the gesture inference is performed on the first dispatch, since it
208
- * looks at all of the touches (even the ones for which there hasn't been a
209
- * native dispatch yet). Therefore, `PanResponder` does not call
210
- * `onResponderMove` passed the first dispatch. This diverges from the
211
- * typical responder callback pattern (without using `PanResponder`), but
212
- * avoids more dispatches than necessary.
213
- */
214
- _updateGestureStateOnMove: function (gestureState, touchHistory) {
215
- gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
216
- gestureState.moveX = currentCentroidXOfTouchesChangedAfter(touchHistory, gestureState._accountsForMovesUpTo);
217
- gestureState.moveY = currentCentroidYOfTouchesChangedAfter(touchHistory, gestureState._accountsForMovesUpTo);
218
- var movedAfter = gestureState._accountsForMovesUpTo;
219
- var prevX = previousCentroidXOfTouchesChangedAfter(touchHistory, movedAfter);
220
- var x = currentCentroidXOfTouchesChangedAfter(touchHistory, movedAfter);
221
- var prevY = previousCentroidYOfTouchesChangedAfter(touchHistory, movedAfter);
222
- var y = currentCentroidYOfTouchesChangedAfter(touchHistory, movedAfter);
223
- var nextDX = gestureState.dx + (x - prevX);
224
- var nextDY = gestureState.dy + (y - prevY);
225
-
226
- // TODO: This must be filtered intelligently.
227
- var dt = touchHistory.mostRecentTimeStamp - gestureState._accountsForMovesUpTo;
228
- gestureState.vx = (nextDX - gestureState.dx) / dt;
229
- gestureState.vy = (nextDY - gestureState.dy) / dt;
230
-
231
- gestureState.dx = nextDX;
232
- gestureState.dy = nextDY;
233
- gestureState._accountsForMovesUpTo = touchHistory.mostRecentTimeStamp;
234
- },
235
-
236
- /**
237
- * @param {object} config Enhanced versions of all of the responder callbacks
238
- * that provide not only the typical `ResponderSyntheticEvent`, but also the
239
- * `PanResponder` gesture state. Simply replace the word `Responder` with
240
- * `PanResponder` in each of the typical `onResponder*` callbacks. For
241
- * example, the `config` object would look like:
242
- *
243
- * - `onMoveShouldSetPanResponder: (e, gestureState) => {...}`
244
- * - `onMoveShouldSetPanResponderCapture: (e, gestureState) => {...}`
245
- * - `onStartShouldSetPanResponder: (e, gestureState) => {...}`
246
- * - `onStartShouldSetPanResponderCapture: (e, gestureState) => {...}`
247
- * - `onPanResponderReject: (e, gestureState) => {...}`
248
- * - `onPanResponderGrant: (e, gestureState) => {...}`
249
- * - `onPanResponderStart: (e, gestureState) => {...}`
250
- * - `onPanResponderEnd: (e, gestureState) => {...}`
251
- * - `onPanResponderRelease: (e, gestureState) => {...}`
252
- * - `onPanResponderMove: (e, gestureState) => {...}`
253
- * - `onPanResponderTerminate: (e, gestureState) => {...}`
254
- * - `onPanResponderTerminationRequest: (e, gestureState) => {...}`
255
- * - `onShouldBlockNativeResponder: (e, gestureState) => {...}`
256
- *
257
- * In general, for events that have capture equivalents, we update the
258
- * gestureState once in the capture phase and can use it in the bubble phase
259
- * as well.
260
- *
261
- * Be careful with onStartShould* callbacks. They only reflect updated
262
- * `gestureState` for start/end events that bubble/capture to the Node.
263
- * Once the node is the responder, you can rely on every start/end event
264
- * being processed by the gesture and `gestureState` being updated
265
- * accordingly. (numberActiveTouches) may not be totally accurate unless you
266
- * are the responder.
267
- */
268
- create: function (config) {
269
- var gestureState = {
270
- // Useful for debugging
271
- stateID: Math.random()
272
- };
273
- PanResponder._initializeGestureState(gestureState);
274
- var panHandlers = {
275
- onStartShouldSetResponder: function (e) {
276
- return config.onStartShouldSetPanResponder === undefined ? false : config.onStartShouldSetPanResponder(e, gestureState);
277
- },
278
- onMoveShouldSetResponder: function (e) {
279
- return config.onMoveShouldSetPanResponder === undefined ? false : config.onMoveShouldSetPanResponder(e, gestureState);
280
- },
281
- onStartShouldSetResponderCapture: function (e) {
282
- // TODO: Actually, we should reinitialize the state any time
283
- // touches.length increases from 0 active to > 0 active.
284
- if (e.nativeEvent.touches.length === 1) {
285
- PanResponder._initializeGestureState(gestureState);
286
- }
287
- gestureState.numberActiveTouches = e.touchHistory.numberActiveTouches;
288
- return config.onStartShouldSetPanResponderCapture !== undefined ? config.onStartShouldSetPanResponderCapture(e, gestureState) : false;
289
- },
290
-
291
- onMoveShouldSetResponderCapture: function (e) {
292
- var touchHistory = e.touchHistory;
293
- // Responder system incorrectly dispatches should* to current responder
294
- // Filter out any touch moves past the first one - we would have
295
- // already processed multi-touch geometry during the first event.
296
- if (gestureState._accountsForMovesUpTo === touchHistory.mostRecentTimeStamp) {
297
- return false;
298
- }
299
- PanResponder._updateGestureStateOnMove(gestureState, touchHistory);
300
- return config.onMoveShouldSetPanResponderCapture ? config.onMoveShouldSetPanResponderCapture(e, gestureState) : false;
301
- },
302
-
303
- onResponderGrant: function (e) {
304
- gestureState.x0 = currentCentroidX(e.touchHistory);
305
- gestureState.y0 = currentCentroidY(e.touchHistory);
306
- gestureState.dx = 0;
307
- gestureState.dy = 0;
308
- if (config.onPanResponderGrant) config.onPanResponderGrant(e, gestureState);
309
- // TODO: t7467124 investigate if this can be removed
310
- return config.onShouldBlockNativeResponder === undefined ? true : config.onShouldBlockNativeResponder();
311
- },
312
-
313
- onResponderReject: function (e) {
314
- if (config.onPanResponderReject) config.onPanResponderReject(e, gestureState);
315
- },
316
-
317
- onResponderRelease: function (e) {
318
- if (config.onPanResponderRelease) config.onPanResponderRelease(e, gestureState);
319
- PanResponder._initializeGestureState(gestureState);
320
- },
321
-
322
- onResponderStart: function (e) {
323
- var touchHistory = e.touchHistory;
324
- gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
325
- if (config.onPanResponderStart) config.onPanResponderStart(e, gestureState);
326
- },
327
-
328
- onResponderMove: function (e) {
329
- var touchHistory = e.touchHistory;
330
- // Guard against the dispatch of two touch moves when there are two
331
- // simultaneously changed touches.
332
- if (gestureState._accountsForMovesUpTo === touchHistory.mostRecentTimeStamp) {
333
- return;
334
- }
335
- // Filter out any touch moves past the first one - we would have
336
- // already processed multi-touch geometry during the first event.
337
- PanResponder._updateGestureStateOnMove(gestureState, touchHistory);
338
- if (config.onPanResponderMove) config.onPanResponderMove(e, gestureState);
339
- },
340
-
341
- onResponderEnd: function (e) {
342
- var touchHistory = e.touchHistory;
343
- gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
344
- if (config.onPanResponderEnd) config.onPanResponderEnd(e, gestureState);
345
- },
346
-
347
- onResponderTerminate: function (e) {
348
- if (config.onPanResponderTerminate) {
349
- config.onPanResponderTerminate(e, gestureState);
350
- }
351
- PanResponder._initializeGestureState(gestureState);
352
- },
353
-
354
- onResponderTerminationRequest: function (e) {
355
- return config.onPanResponderTerminationRequest === undefined ? true : config.onPanResponderTerminationRequest(e, gestureState);
356
- }
357
- };
358
- return { panHandlers: panHandlers };
359
- }
360
- };
361
-
362
- module.exports = PanResponder;
@@ -1,33 +0,0 @@
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 ReactNativeGlobalInteractionHandler
10
- *
11
- */
12
- 'use strict';
13
-
14
- var InteractionManager = require('InteractionManager');
15
-
16
- // Interaction handle is created/cleared when responder is granted or
17
- // released/terminated.
18
- var interactionHandle = null;
19
-
20
- var ReactNativeGlobalInteractionHandler = {
21
- onChange: function (numberActiveTouches) {
22
- if (numberActiveTouches === 0) {
23
- if (interactionHandle) {
24
- InteractionManager.clearInteractionHandle(interactionHandle);
25
- interactionHandle = null;
26
- }
27
- } else if (!interactionHandle) {
28
- interactionHandle = InteractionManager.createInteractionHandle();
29
- }
30
- }
31
- };
32
-
33
- module.exports = ReactNativeGlobalInteractionHandler;
@@ -1,109 +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 ReactPropTransferer
10
- */
11
-
12
- 'use strict';
13
-
14
- var _assign = require('object-assign');
15
-
16
- var emptyFunction = require('fbjs/lib/emptyFunction');
17
- var joinClasses = require('fbjs/lib/joinClasses');
18
-
19
- /**
20
- * Creates a transfer strategy that will merge prop values using the supplied
21
- * `mergeStrategy`. If a prop was previously unset, this just sets it.
22
- *
23
- * @param {function} mergeStrategy
24
- * @return {function}
25
- */
26
- function createTransferStrategy(mergeStrategy) {
27
- return function (props, key, value) {
28
- if (!props.hasOwnProperty(key)) {
29
- props[key] = value;
30
- } else {
31
- props[key] = mergeStrategy(props[key], value);
32
- }
33
- };
34
- }
35
-
36
- var transferStrategyMerge = createTransferStrategy(function (a, b) {
37
- // `merge` overrides the first object's (`props[key]` above) keys using the
38
- // second object's (`value`) keys. An object's style's existing `propA` would
39
- // get overridden. Flip the order here.
40
- return _assign({}, b, a);
41
- });
42
-
43
- /**
44
- * Transfer strategies dictate how props are transferred by `transferPropsTo`.
45
- * NOTE: if you add any more exceptions to this list you should be sure to
46
- * update `cloneWithProps()` accordingly.
47
- */
48
- var TransferStrategies = {
49
- /**
50
- * Never transfer `children`.
51
- */
52
- children: emptyFunction,
53
- /**
54
- * Transfer the `className` prop by merging them.
55
- */
56
- className: createTransferStrategy(joinClasses),
57
- /**
58
- * Transfer the `style` prop (which is an object) by merging them.
59
- */
60
- style: transferStrategyMerge
61
- };
62
-
63
- /**
64
- * Mutates the first argument by transferring the properties from the second
65
- * argument.
66
- *
67
- * @param {object} props
68
- * @param {object} newProps
69
- * @return {object}
70
- */
71
- function transferInto(props, newProps) {
72
- for (var thisKey in newProps) {
73
- if (!newProps.hasOwnProperty(thisKey)) {
74
- continue;
75
- }
76
-
77
- var transferStrategy = TransferStrategies[thisKey];
78
-
79
- if (transferStrategy && TransferStrategies.hasOwnProperty(thisKey)) {
80
- transferStrategy(props, thisKey, newProps[thisKey]);
81
- } else if (!props.hasOwnProperty(thisKey)) {
82
- props[thisKey] = newProps[thisKey];
83
- }
84
- }
85
- return props;
86
- }
87
-
88
- /**
89
- * ReactPropTransferer are capable of transferring props to another component
90
- * using a `transferPropsTo` method.
91
- *
92
- * @class ReactPropTransferer
93
- */
94
- var ReactPropTransferer = {
95
-
96
- /**
97
- * Merge two props objects using TransferStrategies.
98
- *
99
- * @param {object} oldProps original props (they take precedence)
100
- * @param {object} newProps new props to merge in
101
- * @return {object} a new object containing both sets of props merged.
102
- */
103
- mergeProps: function (oldProps, newProps) {
104
- return transferInto(_assign({}, oldProps), newProps);
105
- }
106
-
107
- };
108
-
109
- module.exports = ReactPropTransferer;