Skip to content

Commit 963fe69

Browse files
annamarschmitz
authored andcommitted
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
1 parent e40dcde commit 963fe69

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/input.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ function computeInputData(manager, input) {
173173

174174
computeDeltaXY(session, input);
175175
input.offsetDirection = getDirection(input.deltaX, input.deltaY);
176-
176+
177+
var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
178+
input.overallVelocityX = overallVelocity.x;
179+
input.overallVelocityY = overallVelocity.y;
180+
input.overallVelocity = (abs(overallVelocity.x) > abs(overallVelocity.y)) ? overallVelocity.x : overallVelocity.y;
181+
177182
input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
178183
input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
179184

src/recognizers/swipe.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,22 @@ inherit(SwipeRecognizer, AttrRecognizer, {
3030
var velocity;
3131

3232
if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
33-
velocity = input.velocity;
33+
velocity = input.overallVelocity;
3434
} else if (direction & DIRECTION_HORIZONTAL) {
35-
velocity = input.velocityX;
35+
velocity = input.overallVelocityX;
3636
} else if (direction & DIRECTION_VERTICAL) {
37-
velocity = input.velocityY;
37+
velocity = input.overallVelocityY;
3838
}
3939

4040
return this._super.attrTest.call(this, input) &&
41-
direction & input.direction &&
41+
direction & input.offsetDirection &&
4242
input.distance > this.options.threshold &&
43+
input.maxPointers == this.options.pointers &&
4344
abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
4445
},
4546

4647
emit: function(input) {
47-
var direction = directionStr(input.direction);
48+
var direction = directionStr(input.offsetDirection);
4849
if (direction) {
4950
this.manager.emit(this.options.event + direction, input);
5051
}

0 commit comments

Comments
 (0)