Skip to content

Commit

Permalink
fix name input on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
qchateau committed Sep 17, 2020
1 parent f5c188a commit 86ef870
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Input {
this.mouseDown = false;
this.onInput = onInput;
this.maxDragLength = maxDragLength;
this.preventDefaultTouchStart = false;

element.addEventListener("touchstart", this.onTouchStart.bind(this), {
passive: false,
Expand All @@ -48,7 +49,13 @@ class Input {
}

onTouchStart(e) {
e.preventDefault(); // very important, otherwise chrome throttles inputs
if (this.preventDefaultTouchStart) {
// preventing the touchstart will prevent
// chrome from throttling touchmove on mobile
// but will also prevent the "input" field
// from working
e.preventDefault();
}
this.touchStartX = e.changedTouches[0].clientX;
this.touchStartY = e.changedTouches[0].clientY;
this.onInput({
Expand Down
1 change: 1 addition & 0 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ class GameManager {
}

newGame() {
this.input.preventDefaultTouchStart = true;
const playerName = this.getPlayerName();
this.currentGame = new GameEngine(
this.getWsHref(),
Expand Down

0 comments on commit 86ef870

Please sign in to comment.