8000 fix(gesture): don't trigger swipe if not the main direction · code-tree/material@acdeb82 · GitHub
[go: up one dir, main page]

Skip to content

Commit acdeb82

Browse files
committed
fix(gesture): don't trigger swipe if not the main direction
A horizontal swipe action should not be triggered if the main direction of the swipe was actually vertical (and vice versa).
1 parent bbaa5b8 commit acdeb82

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/core/services/gesture/gesture.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
169169
* Register handlers. These listen to touch/start/move events, interpret them,
170170
* and dispatch gesture events depending on options & conditions. These are all
171171
* instances of GestureHandler.
172-
* @see GestureHandler
172+
* @see GestureHandler
173173
*/
174174
return self
175175
/*
@@ -305,15 +305,18 @@ function MdGesture($$MdGestureHandler, $$rAF, $timeout) {
305305
onEnd: function (ev, pointer) {
306306
var eventType;
307307

308-
if (Math.abs(pointer.velocityX) > this.state.options.minVelocity &&
309-
Math.abs(pointer.distanceX) > this.state.options.minDistance) {
310-
eventType = pointer.directionX == 'left' ? '$md.swipeleft' : '$md.swiperight';
311-
this.dispatchEvent(ev, eventType);
312-
}
313-
else if (Math.abs(pointer.velocityY) > this.state.options.minVelocity &&
314-
Math.abs(pointer.distanceY) > this.state.options.minDistance) {
315-
eventType = pointer.directionY == 'up' ? '$md.swipeup' : '$md.swipedown';
316-
this.dispatchEvent(ev, eventType);
308+
if (Math.abs(pointer.distanceX) > Math.abs(pointer.distanceY)) {
309+
if (Math.abs(pointer.velocityX) > this.state.options.minVelocity &&
310+
Math.abs(pointer.distanceX) > this.state.options.minDistance) {
311+
eventType = pointer.directionX == 'left' ? '$md.swipeleft' : '$md.swiperight';
312+
this.dispatchEvent(ev, eventType);
313+
}
314+
} else {
315+
if (Math.abs(pointer.velocityY) > this.state.options.minVelocity &&
316+
Math.abs(pointer.distanceY) > this.state.options.minDistance) {
317+
eventType = pointer.directionY == 'up' ? '$md.swipeup' : '$md.swipedown';
318+
this.dispatchEvent(ev, eventType);
319+
}
317320
}
318321
}
319322
});
@@ -496,7 +499,7 @@ function attachToDocument( $mdGesture, $$MdGestureHandler ) {
496499
* click event will be sent ~400ms after a touchend event happens.
497500
* The only way to know if this click is real is to prevent any normal
498501
* click events, and add a flag to events sent by material so we know not to prevent those.
499-
*
502+
*
500503
* Two exceptions to click events that should be prevented are:
501504
* - click events sent by the keyboard (eg form submit)
502505
* - events that originate from an Ionic app

0 commit comments

Comments
 (0)
0