Skip to content

Commit

Permalink
Always call preventDefault on canvas touch events to fix alt double t…
Browse files Browse the repository at this point in the history
…aps on iOS 13.4.
  • Loading branch information
DirtyHairy committed Apr 5, 2020
1 parent 6228eff commit 697fcc8
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions src/web/stella/driver/TouchIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ class TouchIO {
this._canvas.removeEventListener('touchmove', this._onTouchMove);
}

private _cancelEvent(touch: NormalizedTouch): boolean {
return touch.type !== TouchType.alt;
}

private _onTouchStart = (e: TouchEvent): void => {
let cancel = false;

for (let i = 0; i < e.changedTouches.length; i++) {
const normalizedTouch = new NormalizedTouch(e.changedTouches.item(i), this._canvas),
id = normalizedTouch.touch.identifier;
Expand Down Expand Up @@ -152,31 +146,19 @@ class TouchIO {
default:
throw new Error('invalid touch type');
}

if (this._cancelEvent(normalizedTouch) || this._fullscreenDoubleTapDetector.isDispatching()) {
cancel = true;
}
}

if (cancel) {
e.preventDefault();
}
e.preventDefault();
};

private _onTouchEnd = (e: TouchEvent): void => {
let cancel = false;

for (let i = 0; i < e.changedTouches.length; i++) {
const normalizedTouch = this._pendingTouches.get(e.changedTouches.item(i).identifier);

if (!normalizedTouch) {
continue;
}

if (this._cancelEvent(normalizedTouch) || this._fullscreenDoubleTapDetector.isDispatching()) {
cancel = true;
}

switch (normalizedTouch.type) {
case TouchType.alt:
this._isAlt = false;
Expand Down Expand Up @@ -213,14 +195,10 @@ class TouchIO {
this._pendingTouches.delete(normalizedTouch.touch.identifier);
}

if (cancel) {
e.preventDefault();
}
e.preventDefault();
};

private _onTouchMove = (e: TouchEvent): void => {
let cancel = false;

for (let i = 0; i < e.changedTouches.length; i++) {
const touch = e.changedTouches.item(i),
normalizedTouch = this._pendingTouches.get(touch.identifier);
Expand All @@ -229,10 +207,6 @@ class TouchIO {
continue;
}

if (this._cancelEvent(normalizedTouch)) {
cancel = true;
}

if (normalizedTouch.type !== TouchType.joystick) {
continue;
}
Expand All @@ -255,9 +229,7 @@ class TouchIO {
}
}

if (cancel) {
e.preventDefault();
}
e.preventDefault();
};

toggleFullscreen: Event<void>;
Expand Down

0 comments on commit 697fcc8

Please sign in to comment.