Skip to content

Commit

Permalink
fix: increase touchmove threshold for "taps" on mobile (#190)
Browse files Browse the repository at this point in the history
This fixes an issue which on mobile devices, particularly Chrome, means that you cannot tap to toggle the control bar.
  • Loading branch information
marcodeltorob authored and gkatsev committed Nov 15, 2019
1 parent c2a275e commit 4e92c33
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/canvas-player-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,41 @@ class CanvasPlayerControls extends videojs.EventTarget {
}

onMoveEnd(e) {

// We want to have the same behavior in VR360 Player and standar player.
// in touchend we want to know if was a touch click, for a click we show the bar,
// otherwise continue with the mouse logic.
//
// Maximum movement allowed during a touch event to still be considered a tap
// Other popular libs use anywhere from 2 (hammer.js) to 15,
// so 10 seems like a nice, round number.
if (e.type === 'touchend' && this.touchMoveCount_ < 10) {

if (this.player.userActive() === false) {
this.player.userActive(true);
return;
}

this.player.userActive(false);
return;
}

if (!this.shouldTogglePlay) {
return;
}
this.togglePlay();

// We want the same behavior in Desktop for VR360 and standar player
if(e.type == 'mouseup') {
this.togglePlay();
}

}

onMove(e) {
// its hard to tap without a touchmove, if there have been less
// than one, we should still toggle play
if (e.type === 'touchmove' && this.touchMoveCount_ < 1) {
this.touchMoveCount_++;
return;
}

// Increase touchMoveCount_ since Android detects 1 - 6 touches when user click normaly
this.touchMoveCount_++;

this.shouldTogglePlay = false;
}

Expand Down

0 comments on commit 4e92c33

Please sign in to comment.