Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower tap movement and time thresholds #1830

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,14 +1031,18 @@ vjs.Component.prototype.onResize;
*/
vjs.Component.prototype.emitTapEvents = function(){
var touchStart, firstTouch, touchTime, couldBeTap, noTap,
xdiff, ydiff, touchDistance, tapMovementThreshold;
xdiff, ydiff, touchDistance, tapMovementThreshold, touchTimeThreshold;

// Track the start time so we can determine how long the touch lasted
touchStart = 0;
firstTouch = null;

// Maximum movement allowed during a touch event to still be considered a tap
tapMovementThreshold = 22;
// Other popular libs use anywhere from 2 (hammer.js) to 15, so 10 seems like a nice, round number.
tapMovementThreshold = 10;

// The maximum length a touch can be while still being considered a tap
touchTimeThreshold = 200;

this.on('touchstart', function(event) {
// If more than one finger, don't consider treating this as a click
Expand Down Expand Up @@ -1082,8 +1086,8 @@ vjs.Component.prototype.emitTapEvents = function(){
if (couldBeTap === true) {
// Measure how long the touch lasted
touchTime = new Date().getTime() - touchStart;
// The touch needs to be quick in order to consider it a tap
if (touchTime < 250) {
// Make sure the touch was less than the threshold to be considered a tap
if (touchTime < touchTimeThreshold) {
event.preventDefault(); // Don't let browser turn this into a click
this.trigger('tap');
// It may be good to copy the touchend event object and change the
Expand Down
2 changes: 1 addition & 1 deletion test/unit/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ test('should emit a tap event', function(){
{ pageX: 0, pageY: 0 }
]});
vjs.trigger(comp.el(), {type: 'touchmove', touches: [
{ pageX: 10, pageY: 10 }
{ pageX: 7, pageY: 7 }
]});
comp.trigger('touchend');

Expand Down