Skip to content

Commit

Permalink
fix: mobile context menu won't show on long press (excalidraw#4741)
Browse files Browse the repository at this point in the history
* scribble fix only if not Android

* Update src/components/App.tsx

Co-authored-by: David Luzar <[email protected]>
  • Loading branch information
zsviczian and dwelle authored Feb 7, 2022
1 parent 66c92fc commit d450c36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ import {
shouldRotateWithDiscreteAngle,
isArrowKey,
KEYS,
isAndroid,
} from "../keys";
import { distance2d, getGridPoint, isPathALoop } from "../math";
import { renderScene } from "../renderer";
Expand Down Expand Up @@ -1274,7 +1275,10 @@ class App extends React.Component<AppProps, AppState> {

private onTapStart = (event: TouchEvent) => {
// fix for Apple Pencil Scribble
event.preventDefault();
// On Android, preventing the event would disable contextMenu on tap-hold
if (!isAndroid) {
event.preventDefault();
}

if (!didTapTwice) {
didTapTwice = true;
Expand All @@ -1297,6 +1301,9 @@ class App extends React.Component<AppProps, AppState> {
didTapTwice = false;
clearTimeout(tappedTwiceTimer);
}
if (isAndroid) {
event.preventDefault();
}

if (event.touches.length === 2) {
this.setState({
Expand Down
1 change: 1 addition & 0 deletions src/keys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const isDarwin = /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
export const isWindows = /^Win/.test(window.navigator.platform);
export const isAndroid = /\b(android)\b/i.test(navigator.userAgent);

export const CODES = {
EQUAL: "Equal",
Expand Down

0 comments on commit d450c36

Please sign in to comment.