Skip to content

Commit

Permalink
Swipe: recognizer using overall gesture direction and velocity
Browse files Browse the repository at this point in the history
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 Aug 8, 2015
1 parent e40dcde commit 963fe69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 6 additions & 5 deletions src/recognizers/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 963fe69

Please sign in to comment.