Permalink
Browse files

Swipe: recognizer using overall gesture direction and velocity

swipe should detect the overall swipe direction, not the last interval
one

more importantly, it should use the overall velocity, so that if you’ve
swiped but slowed the motion down before touchend, swipe is still
detected.

need to capture overallVelocity for these tests, which we didn’t have
  • Loading branch information...
annam authored and arschmitz committed Sep 17, 2014
1 parent e40dcde commit 963fe697515273fee508414bc29e2656465cea55
Showing with 12 additions and 6 deletions.
  1. +6 −1 src/input.js
  2. +6 −5 src/recognizers/swipe.js
View
@@ -173,7 +173,12 @@ function computeInputData(manager, input) {
computeDeltaXY(session, input);
input.offsetDirection = getDirection(input.deltaX, input.deltaY);
-
+
+ var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
+ input.overallVelocityX = overallVelocity.x;
+ input.overallVelocityY = overallVelocity.y;
+ input.overallVelocity = (abs(overallVelocity.x) > abs(overallVelocity.y)) ? overallVelocity.x : overallVelocity.y;
+
input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
View
@@ -30,21 +30,22 @@ inherit(SwipeRecognizer, AttrRecognizer, {
var velocity;
if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
- velocity = input.velocity;
+ velocity = input.overallVelocity;
} else if (direction & DIRECTION_HORIZONTAL) {
- velocity = input.velocityX;
+ velocity = input.overallVelocityX;
} else if (direction & DIRECTION_VERTICAL) {
- velocity = input.velocityY;
+ velocity = input.overallVelocityY;
}
return this._super.attrTest.call(this, input) &&
- direction & input.direction &&
+ direction & input.offsetDirection &&
input.distance > this.options.threshold &&
+ input.maxPointers == this.options.pointers &&
abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
},
emit: function(input) {
- var direction = directionStr(input.direction);
+ var direction = directionStr(input.offsetDirection);
if (direction) {
this.manager.emit(this.options.event + direction, input);
}

0 comments on commit 963fe69

Please sign in to comment.