Skip to content

Commit

Permalink
fix(firefox): fix missing TouchEvent on firefox and use early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonours committed Mar 5, 2024
1 parent cc1d584 commit ed8d5c8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/hooks/useCanvasDrawing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ export const useCanvasDrawing = (
let y = 0;
const rect = canvasRef.current?.getBoundingClientRect();
if (rect) {
if (e instanceof TouchEvent) {
if (window.TouchEvent && e instanceof TouchEvent) {
e.preventDefault();
x = e.touches[0].clientX - rect.left;
y = e.touches[0].clientY - rect.top;
} else {

return { x, y };
}

if (e instanceof MouseEvent) {
x = e.clientX - rect.left;
y = e.clientY - rect.top;

return { x, y };
}
}

Expand Down

0 comments on commit ed8d5c8

Please sign in to comment.