2016-04-26 03:37:16 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-04-26 03:37:16 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2016-04-26 03:37:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const InteractionManager = require('./InteractionManager');
|
2018-04-08 04:02:43 +00:00
|
|
|
const TouchHistoryMath = require('./TouchHistoryMath');
|
2016-04-26 03:37:16 +00:00
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
const currentCentroidXOfTouchesChangedAfter =
|
|
|
|
TouchHistoryMath.currentCentroidXOfTouchesChangedAfter;
|
|
|
|
const currentCentroidYOfTouchesChangedAfter =
|
|
|
|
TouchHistoryMath.currentCentroidYOfTouchesChangedAfter;
|
|
|
|
const previousCentroidXOfTouchesChangedAfter =
|
|
|
|
TouchHistoryMath.previousCentroidXOfTouchesChangedAfter;
|
|
|
|
const previousCentroidYOfTouchesChangedAfter =
|
|
|
|
TouchHistoryMath.previousCentroidYOfTouchesChangedAfter;
|
2016-04-26 20:18:13 +00:00
|
|
|
const currentCentroidX = TouchHistoryMath.currentCentroidX;
|
|
|
|
const currentCentroidY = TouchHistoryMath.currentCentroidY;
|
2016-04-26 03:37:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* `PanResponder` reconciles several touches into a single gesture. It makes
|
|
|
|
* single-touch gestures resilient to extra touches, and can be used to
|
|
|
|
* recognize simple multi-touch gestures.
|
|
|
|
*
|
2016-12-02 23:11:50 +00:00
|
|
|
* By default, `PanResponder` holds an `InteractionManager` handle to block
|
2016-04-26 07:22:28 +00:00
|
|
|
* long-running JS events from interrupting active gestures.
|
|
|
|
*
|
2016-04-26 03:37:16 +00:00
|
|
|
* It provides a predictable wrapper of the responder handlers provided by the
|
|
|
|
* [gesture responder system](docs/gesture-responder-system.html).
|
|
|
|
* For each handler, it provides a new `gestureState` object alongside the
|
|
|
|
* native event object:
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* onPanResponderMove: (event, gestureState) => {}
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* A native event is a synthetic touch event with the following form:
|
|
|
|
*
|
|
|
|
* - `nativeEvent`
|
|
|
|
* + `changedTouches` - Array of all touch events that have changed since the last event
|
|
|
|
* + `identifier` - The ID of the touch
|
|
|
|
* + `locationX` - The X position of the touch, relative to the element
|
|
|
|
* + `locationY` - The Y position of the touch, relative to the element
|
|
|
|
* + `pageX` - The X position of the touch, relative to the root element
|
|
|
|
* + `pageY` - The Y position of the touch, relative to the root element
|
|
|
|
* + `target` - The node id of the element receiving the touch event
|
|
|
|
* + `timestamp` - A time identifier for the touch, useful for velocity calculation
|
|
|
|
* + `touches` - Array of all current touches on the screen
|
|
|
|
*
|
|
|
|
* A `gestureState` object has the following:
|
|
|
|
*
|
|
|
|
* - `stateID` - ID of the gestureState- persisted as long as there at least
|
|
|
|
* one touch on screen
|
|
|
|
* - `moveX` - the latest screen coordinates of the recently-moved touch
|
|
|
|
* - `moveY` - the latest screen coordinates of the recently-moved touch
|
|
|
|
* - `x0` - the screen coordinates of the responder grant
|
|
|
|
* - `y0` - the screen coordinates of the responder grant
|
|
|
|
* - `dx` - accumulated distance of the gesture since the touch started
|
|
|
|
* - `dy` - accumulated distance of the gesture since the touch started
|
|
|
|
* - `vx` - current velocity of the gesture
|
|
|
|
* - `vy` - current velocity of the gesture
|
|
|
|
* - `numberActiveTouches` - Number of touches currently on screen
|
|
|
|
*
|
|
|
|
* ### Basic Usage
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* componentWillMount: function() {
|
|
|
|
* this._panResponder = PanResponder.create({
|
|
|
|
* // Ask to be the responder:
|
|
|
|
* onStartShouldSetPanResponder: (evt, gestureState) => true,
|
|
|
|
* onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
|
|
|
|
* onMoveShouldSetPanResponder: (evt, gestureState) => true,
|
|
|
|
* onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
|
|
|
|
*
|
|
|
|
* onPanResponderGrant: (evt, gestureState) => {
|
2017-04-03 16:11:43 +00:00
|
|
|
* // The gesture has started. Show visual feedback so the user knows
|
2016-04-26 03:37:16 +00:00
|
|
|
* // what is happening!
|
|
|
|
*
|
2016-10-11 15:07:19 +00:00
|
|
|
* // gestureState.d{x,y} will be set to zero now
|
2016-04-26 03:37:16 +00:00
|
|
|
* },
|
|
|
|
* onPanResponderMove: (evt, gestureState) => {
|
|
|
|
* // The most recent move distance is gestureState.move{X,Y}
|
|
|
|
*
|
|
|
|
* // The accumulated gesture distance since becoming responder is
|
|
|
|
* // gestureState.d{x,y}
|
|
|
|
* },
|
|
|
|
* onPanResponderTerminationRequest: (evt, gestureState) => true,
|
|
|
|
* onPanResponderRelease: (evt, gestureState) => {
|
|
|
|
* // The user has released all touches while this view is the
|
|
|
|
* // responder. This typically means a gesture has succeeded
|
|
|
|
* },
|
|
|
|
* onPanResponderTerminate: (evt, gestureState) => {
|
|
|
|
* // Another component has become the responder, so this gesture
|
|
|
|
* // should be cancelled
|
|
|
|
* },
|
|
|
|
* onShouldBlockNativeResponder: (evt, gestureState) => {
|
|
|
|
* // Returns whether this component should block native components from becoming the JS
|
|
|
|
* // responder. Returns true by default. Is currently only supported on android.
|
|
|
|
* return true;
|
|
|
|
* },
|
|
|
|
* });
|
|
|
|
* },
|
|
|
|
*
|
|
|
|
* render: function() {
|
|
|
|
* return (
|
|
|
|
* <View {...this._panResponder.panHandlers} />
|
|
|
|
* );
|
|
|
|
* },
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* ### Working Example
|
|
|
|
*
|
|
|
|
* To see it in action, try the
|
2017-05-06 03:50:47 +00:00
|
|
|
* [PanResponder example in RNTester](https://github.com/facebook/react-native/blob/master/RNTester/js/PanResponderExample.js)
|
2016-04-26 03:37:16 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
const PanResponder = {
|
2016-04-26 03:37:16 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* A graphical explanation of the touch data flow:
|
|
|
|
*
|
|
|
|
* +----------------------------+ +--------------------------------+
|
|
|
|
* | ResponderTouchHistoryStore | |TouchHistoryMath |
|
|
|
|
* +----------------------------+ +----------+---------------------+
|
|
|
|
* |Global store of touchHistory| |Allocation-less math util |
|
|
|
|
* |including activeness, start | |on touch history (centroids |
|
|
|
|
* |position, prev/cur position.| |and multitouch movement etc) |
|
|
|
|
* | | | |
|
|
|
|
* +----^-----------------------+ +----^---------------------------+
|
|
|
|
* | |
|
|
|
|
* | (records relevant history |
|
|
|
|
* | of touches relevant for |
|
|
|
|
* | implementing higher level |
|
|
|
|
* | gestures) |
|
|
|
|
* | |
|
|
|
|
* +----+-----------------------+ +----|---------------------------+
|
|
|
|
* | ResponderEventPlugin | | | Your App/Component |
|
|
|
|
* +----------------------------+ +----|---------------------------+
|
|
|
|
* |Negotiates which view gets | Low level | | High level |
|
|
|
|
* |onResponderMove events. | events w/ | +-+-------+ events w/ |
|
|
|
|
* |Also records history into | touchHistory| | Pan | multitouch + |
|
|
|
|
* |ResponderTouchHistoryStore. +---------------->Responder+-----> accumulative|
|
|
|
|
* +----------------------------+ attached to | | | distance and |
|
|
|
|
* each event | +---------+ velocity. |
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* +--------------------------------+
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Gesture that calculates cumulative movement over time in a way that just
|
|
|
|
* "does the right thing" for multiple touches. The "right thing" is very
|
|
|
|
* nuanced. When moving two touches in opposite directions, the cumulative
|
|
|
|
* distance is zero in each dimension. When two touches move in parallel five
|
|
|
|
* pixels in the same direction, the cumulative distance is five, not ten. If
|
|
|
|
* two touches start, one moves five in a direction, then stops and the other
|
|
|
|
* touch moves fives in the same direction, the cumulative distance is ten.
|
|
|
|
*
|
|
|
|
* This logic requires a kind of processing of time "clusters" of touch events
|
|
|
|
* so that two touch moves that essentially occur in parallel but move every
|
|
|
|
* other frame respectively, are considered part of the same movement.
|
|
|
|
*
|
|
|
|
* Explanation of some of the non-obvious fields:
|
|
|
|
*
|
|
|
|
* - moveX/moveY: If no move event has been observed, then `(moveX, moveY)` is
|
|
|
|
* invalid. If a move event has been observed, `(moveX, moveY)` is the
|
|
|
|
* centroid of the most recently moved "cluster" of active touches.
|
|
|
|
* (Currently all move have the same timeStamp, but later we should add some
|
|
|
|
* threshold for what is considered to be "moving"). If a palm is
|
|
|
|
* accidentally counted as a touch, but a finger is moving greatly, the palm
|
|
|
|
* will move slightly, but we only want to count the single moving touch.
|
|
|
|
* - x0/y0: Centroid location (non-cumulative) at the time of becoming
|
|
|
|
* responder.
|
|
|
|
* - dx/dy: Cumulative touch distance - not the same thing as sum of each touch
|
|
|
|
* distance. Accounts for touch moves that are clustered together in time,
|
|
|
|
* moving the same direction. Only valid when currently responder (otherwise,
|
|
|
|
* it only represents the drag distance below the threshold).
|
|
|
|
* - vx/vy: Velocity.
|
|
|
|
*/
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
_initializeGestureState: function(gestureState) {
|
2016-04-26 03:37:16 +00:00
|
|
|
gestureState.moveX = 0;
|
|
|
|
gestureState.moveY = 0;
|
|
|
|
gestureState.x0 = 0;
|
|
|
|
gestureState.y0 = 0;
|
|
|
|
gestureState.dx = 0;
|
|
|
|
gestureState.dy = 0;
|
|
|
|
gestureState.vx = 0;
|
|
|
|
gestureState.vy = 0;
|
|
|
|
gestureState.numberActiveTouches = 0;
|
|
|
|
// All `gestureState` accounts for timeStamps up until:
|
|
|
|
gestureState._accountsForMovesUpTo = 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is nuanced and is necessary. It is incorrect to continuously take all
|
|
|
|
* active *and* recently moved touches, find the centroid, and track how that
|
|
|
|
* result changes over time. Instead, we must take all recently moved
|
|
|
|
* touches, and calculate how the centroid has changed just for those
|
|
|
|
* recently moved touches, and append that change to an accumulator. This is
|
|
|
|
* to (at least) handle the case where the user is moving three fingers, and
|
|
|
|
* then one of the fingers stops but the other two continue.
|
|
|
|
*
|
|
|
|
* This is very different than taking all of the recently moved touches and
|
|
|
|
* storing their centroid as `dx/dy`. For correctness, we must *accumulate
|
|
|
|
* changes* in the centroid of recently moved touches.
|
|
|
|
*
|
|
|
|
* There is also some nuance with how we handle multiple moved touches in a
|
|
|
|
* single event. With the way `ReactNativeEventEmitter` dispatches touches as
|
|
|
|
* individual events, multiple touches generate two 'move' events, each of
|
|
|
|
* them triggering `onResponderMove`. But with the way `PanResponder` works,
|
|
|
|
* all of the gesture inference is performed on the first dispatch, since it
|
|
|
|
* looks at all of the touches (even the ones for which there hasn't been a
|
|
|
|
* native dispatch yet). Therefore, `PanResponder` does not call
|
|
|
|
* `onResponderMove` passed the first dispatch. This diverges from the
|
|
|
|
* typical responder callback pattern (without using `PanResponder`), but
|
|
|
|
* avoids more dispatches than necessary.
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
_updateGestureStateOnMove: function(gestureState, touchHistory) {
|
2016-04-26 03:37:16 +00:00
|
|
|
gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
|
2018-05-11 02:06:46 +00:00
|
|
|
gestureState.moveX = currentCentroidXOfTouchesChangedAfter(
|
|
|
|
touchHistory,
|
|
|
|
gestureState._accountsForMovesUpTo,
|
|
|
|
);
|
|
|
|
gestureState.moveY = currentCentroidYOfTouchesChangedAfter(
|
|
|
|
touchHistory,
|
|
|
|
gestureState._accountsForMovesUpTo,
|
|
|
|
);
|
2016-04-26 20:18:13 +00:00
|
|
|
const movedAfter = gestureState._accountsForMovesUpTo;
|
2018-05-11 02:06:46 +00:00
|
|
|
const prevX = previousCentroidXOfTouchesChangedAfter(
|
|
|
|
touchHistory,
|
|
|
|
movedAfter,
|
|
|
|
);
|
2016-04-26 20:18:13 +00:00
|
|
|
const x = currentCentroidXOfTouchesChangedAfter(touchHistory, movedAfter);
|
2018-05-11 02:06:46 +00:00
|
|
|
const prevY = previousCentroidYOfTouchesChangedAfter(
|
|
|
|
touchHistory,
|
|
|
|
movedAfter,
|
|
|
|
);
|
2016-04-26 20:18:13 +00:00
|
|
|
const y = currentCentroidYOfTouchesChangedAfter(touchHistory, movedAfter);
|
|
|
|
const nextDX = gestureState.dx + (x - prevX);
|
|
|
|
const nextDY = gestureState.dy + (y - prevY);
|
2016-04-26 03:37:16 +00:00
|
|
|
|
|
|
|
// TODO: This must be filtered intelligently.
|
2018-05-11 02:06:46 +00:00
|
|
|
const dt =
|
|
|
|
touchHistory.mostRecentTimeStamp - gestureState._accountsForMovesUpTo;
|
2016-04-26 03:37:16 +00:00
|
|
|
gestureState.vx = (nextDX - gestureState.dx) / dt;
|
|
|
|
gestureState.vy = (nextDY - gestureState.dy) / dt;
|
|
|
|
|
|
|
|
gestureState.dx = nextDX;
|
|
|
|
gestureState.dy = nextDY;
|
|
|
|
gestureState._accountsForMovesUpTo = touchHistory.mostRecentTimeStamp;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {object} config Enhanced versions of all of the responder callbacks
|
|
|
|
* that provide not only the typical `ResponderSyntheticEvent`, but also the
|
|
|
|
* `PanResponder` gesture state. Simply replace the word `Responder` with
|
|
|
|
* `PanResponder` in each of the typical `onResponder*` callbacks. For
|
|
|
|
* example, the `config` object would look like:
|
|
|
|
*
|
|
|
|
* - `onMoveShouldSetPanResponder: (e, gestureState) => {...}`
|
|
|
|
* - `onMoveShouldSetPanResponderCapture: (e, gestureState) => {...}`
|
|
|
|
* - `onStartShouldSetPanResponder: (e, gestureState) => {...}`
|
|
|
|
* - `onStartShouldSetPanResponderCapture: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderReject: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderGrant: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderStart: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderEnd: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderRelease: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderMove: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderTerminate: (e, gestureState) => {...}`
|
|
|
|
* - `onPanResponderTerminationRequest: (e, gestureState) => {...}`
|
|
|
|
* - `onShouldBlockNativeResponder: (e, gestureState) => {...}`
|
|
|
|
*
|
|
|
|
* In general, for events that have capture equivalents, we update the
|
|
|
|
* gestureState once in the capture phase and can use it in the bubble phase
|
|
|
|
* as well.
|
|
|
|
*
|
|
|
|
* Be careful with onStartShould* callbacks. They only reflect updated
|
|
|
|
* `gestureState` for start/end events that bubble/capture to the Node.
|
|
|
|
* Once the node is the responder, you can rely on every start/end event
|
|
|
|
* being processed by the gesture and `gestureState` being updated
|
|
|
|
* accordingly. (numberActiveTouches) may not be totally accurate unless you
|
|
|
|
* are the responder.
|
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
create: function(config) {
|
2016-04-26 20:18:13 +00:00
|
|
|
const interactionState = {
|
|
|
|
handle: (null: ?number),
|
|
|
|
};
|
|
|
|
const gestureState = {
|
2016-04-26 03:37:16 +00:00
|
|
|
// Useful for debugging
|
2016-04-26 07:22:28 +00:00
|
|
|
stateID: Math.random(),
|
2016-04-26 03:37:16 +00:00
|
|
|
};
|
|
|
|
PanResponder._initializeGestureState(gestureState);
|
2016-04-26 20:18:13 +00:00
|
|
|
const panHandlers = {
|
2018-05-11 02:06:46 +00:00
|
|
|
onStartShouldSetResponder: function(e) {
|
|
|
|
return config.onStartShouldSetPanResponder === undefined
|
|
|
|
? false
|
|
|
|
: config.onStartShouldSetPanResponder(e, gestureState);
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
2018-05-11 02:06:46 +00:00
|
|
|
onMoveShouldSetResponder: function(e) {
|
|
|
|
return config.onMoveShouldSetPanResponder === undefined
|
|
|
|
? false
|
|
|
|
: config.onMoveShouldSetPanResponder(e, gestureState);
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
2018-05-11 02:06:46 +00:00
|
|
|
onStartShouldSetResponderCapture: function(e) {
|
2016-04-26 03:37:16 +00:00
|
|
|
// TODO: Actually, we should reinitialize the state any time
|
|
|
|
// touches.length increases from 0 active to > 0 active.
|
|
|
|
if (e.nativeEvent.touches.length === 1) {
|
|
|
|
PanResponder._initializeGestureState(gestureState);
|
|
|
|
}
|
|
|
|
gestureState.numberActiveTouches = e.touchHistory.numberActiveTouches;
|
2018-05-11 02:06:46 +00:00
|
|
|
return config.onStartShouldSetPanResponderCapture !== undefined
|
|
|
|
? config.onStartShouldSetPanResponderCapture(e, gestureState)
|
|
|
|
: false;
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onMoveShouldSetResponderCapture: function(e) {
|
2016-04-26 20:18:13 +00:00
|
|
|
const touchHistory = e.touchHistory;
|
2016-04-26 03:37:16 +00:00
|
|
|
// Responder system incorrectly dispatches should* to current responder
|
|
|
|
// Filter out any touch moves past the first one - we would have
|
|
|
|
// already processed multi-touch geometry during the first event.
|
2018-05-11 02:06:46 +00:00
|
|
|
if (
|
|
|
|
gestureState._accountsForMovesUpTo ===
|
|
|
|
touchHistory.mostRecentTimeStamp
|
|
|
|
) {
|
2016-04-26 03:37:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PanResponder._updateGestureStateOnMove(gestureState, touchHistory);
|
2018-05-11 02:06:46 +00:00
|
|
|
return config.onMoveShouldSetPanResponderCapture
|
|
|
|
? config.onMoveShouldSetPanResponderCapture(e, gestureState)
|
|
|
|
: false;
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderGrant: function(e) {
|
2016-04-26 20:18:13 +00:00
|
|
|
if (!interactionState.handle) {
|
|
|
|
interactionState.handle = InteractionManager.createInteractionHandle();
|
|
|
|
}
|
2016-04-26 03:37:16 +00:00
|
|
|
gestureState.x0 = currentCentroidX(e.touchHistory);
|
|
|
|
gestureState.y0 = currentCentroidY(e.touchHistory);
|
|
|
|
gestureState.dx = 0;
|
|
|
|
gestureState.dy = 0;
|
2016-04-26 07:22:28 +00:00
|
|
|
if (config.onPanResponderGrant) {
|
|
|
|
config.onPanResponderGrant(e, gestureState);
|
|
|
|
}
|
2016-04-26 03:37:16 +00:00
|
|
|
// TODO: t7467124 investigate if this can be removed
|
2018-05-11 02:06:46 +00:00
|
|
|
return config.onShouldBlockNativeResponder === undefined
|
|
|
|
? true
|
|
|
|
: config.onShouldBlockNativeResponder();
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderReject: function(e) {
|
|
|
|
clearInteractionHandle(
|
|
|
|
interactionState,
|
|
|
|
config.onPanResponderReject,
|
|
|
|
e,
|
|
|
|
gestureState,
|
|
|
|
);
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderRelease: function(e) {
|
|
|
|
clearInteractionHandle(
|
|
|
|
interactionState,
|
|
|
|
config.onPanResponderRelease,
|
|
|
|
e,
|
|
|
|
gestureState,
|
|
|
|
);
|
2016-04-26 03:37:16 +00:00
|
|
|
PanResponder._initializeGestureState(gestureState);
|
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderStart: function(e) {
|
2016-04-26 20:18:13 +00:00
|
|
|
const touchHistory = e.touchHistory;
|
2016-04-26 03:37:16 +00:00
|
|
|
gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
|
2016-04-26 07:22:28 +00:00
|
|
|
if (config.onPanResponderStart) {
|
|
|
|
config.onPanResponderStart(e, gestureState);
|
|
|
|
}
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderMove: function(e) {
|
2016-04-26 20:18:13 +00:00
|
|
|
const touchHistory = e.touchHistory;
|
2016-04-26 03:37:16 +00:00
|
|
|
// Guard against the dispatch of two touch moves when there are two
|
|
|
|
// simultaneously changed touches.
|
2018-05-11 02:06:46 +00:00
|
|
|
if (
|
|
|
|
gestureState._accountsForMovesUpTo ===
|
|
|
|
touchHistory.mostRecentTimeStamp
|
|
|
|
) {
|
2016-04-26 03:37:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Filter out any touch moves past the first one - we would have
|
|
|
|
// already processed multi-touch geometry during the first event.
|
|
|
|
PanResponder._updateGestureStateOnMove(gestureState, touchHistory);
|
2016-04-26 07:22:28 +00:00
|
|
|
if (config.onPanResponderMove) {
|
|
|
|
config.onPanResponderMove(e, gestureState);
|
|
|
|
}
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderEnd: function(e) {
|
2016-04-26 20:18:13 +00:00
|
|
|
const touchHistory = e.touchHistory;
|
2016-04-26 03:37:16 +00:00
|
|
|
gestureState.numberActiveTouches = touchHistory.numberActiveTouches;
|
2018-05-11 02:06:46 +00:00
|
|
|
clearInteractionHandle(
|
|
|
|
interactionState,
|
|
|
|
config.onPanResponderEnd,
|
|
|
|
e,
|
|
|
|
gestureState,
|
|
|
|
);
|
2016-04-26 03:37:16 +00:00
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderTerminate: function(e) {
|
|
|
|
clearInteractionHandle(
|
|
|
|
interactionState,
|
|
|
|
config.onPanResponderTerminate,
|
|
|
|
e,
|
|
|
|
gestureState,
|
|
|
|
);
|
2016-04-26 03:37:16 +00:00
|
|
|
PanResponder._initializeGestureState(gestureState);
|
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
onResponderTerminationRequest: function(e) {
|
|
|
|
return config.onPanResponderTerminationRequest === undefined
|
|
|
|
? true
|
|
|
|
: config.onPanResponderTerminationRequest(e, gestureState);
|
|
|
|
},
|
2016-04-26 03:37:16 +00:00
|
|
|
};
|
2016-07-15 18:45:34 +00:00
|
|
|
return {
|
|
|
|
panHandlers,
|
|
|
|
getInteractionHandle(): ?number {
|
|
|
|
return interactionState.handle;
|
|
|
|
},
|
|
|
|
};
|
2018-05-11 02:06:46 +00:00
|
|
|
},
|
2016-04-26 03:37:16 +00:00
|
|
|
};
|
|
|
|
|
2016-04-26 20:18:13 +00:00
|
|
|
function clearInteractionHandle(
|
|
|
|
interactionState: {handle: ?number},
|
|
|
|
callback: Function,
|
|
|
|
event: Object,
|
2018-05-11 02:06:46 +00:00
|
|
|
gestureState: Object,
|
2016-04-26 20:18:13 +00:00
|
|
|
) {
|
|
|
|
if (interactionState.handle) {
|
|
|
|
InteractionManager.clearInteractionHandle(interactionState.handle);
|
|
|
|
interactionState.handle = null;
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback(event, gestureState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PanResponder;
|