From ed8d5c82bb7153ec60612d79dd8f6c1d03763700 Mon Sep 17 00:00:00 2001 From: Anthony Guimard Date: Tue, 5 Mar 2024 17:12:34 +0100 Subject: [PATCH] fix(firefox): fix missing TouchEvent on firefox and use early returns --- app/hooks/useCanvasDrawing.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/hooks/useCanvasDrawing.tsx b/app/hooks/useCanvasDrawing.tsx index fa1b6b2..7afffe9 100644 --- a/app/hooks/useCanvasDrawing.tsx +++ b/app/hooks/useCanvasDrawing.tsx @@ -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 }; } }