Skip to content

Commit

Permalink
fix(tap): cancel simulated click w/ hold events
Browse files Browse the repository at this point in the history
Gesture hold event and ionic’s tap will both fire since the tap has no
strict duration between its start and end (a click will always fire no
matter how long the press is held). If a hold event fires from
ionic.Gesture, then the simulated click which would fire on
touchend/mouseup should be canceled.
  • Loading branch information
Adam Bradley committed Jun 10, 2014
1 parent a8af748 commit f5bb023
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/utils/gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@
// we trigger the hold event
this.timer = setTimeout(function() {
if(ionic.Gestures.detection.current.name == 'hold') {
ionic.tap.cancelClick();
inst.trigger('hold', ev);
}
}, inst.options.hold_timeout);
Expand Down Expand Up @@ -1088,8 +1089,9 @@

// do a single tap
if(!did_doubletap || inst.options.tap_always) {
ionic.tap.cancelClick();
ionic.Gestures.detection.current.name = 'tap';
inst.trigger(ionic.Gestures.detection.current.name, ev);
inst.trigger('tap', ev);
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions js/utils/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ ionic.tap = {
setTolerance: function(releaseTolerance, releaseButtonTolerance) {
TAP_RELEASE_TOLERANCE = releaseTolerance;
TAP_RELEASE_BUTTON_TOLERANCE = releaseButtonTolerance;
},

cancelClick: function() {
// used to cancel any simulated clicks which may happen on a touchend/mouseup
// gestures uses this method within its tap and hold events
tapPointerMoved = true;
}

};
Expand Down

0 comments on commit f5bb023

Please sign in to comment.