From be4e127f6cca425fdc40ca9d95261add2ad03c92 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Sun, 19 May 2024 14:23:43 +0200 Subject: [PATCH] fix: Two finger panning is slow (#7849) Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com> --- packages/excalidraw/components/App.tsx | 7 +++++-- .../tests/__snapshots__/regressionTests.test.tsx.snap | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index deb33c568..d991814d4 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -5097,8 +5097,11 @@ class App extends React.Component { this.translateCanvas({ zoom: zoomState.zoom, - scrollX: zoomState.scrollX + deltaX / nextZoom, - scrollY: zoomState.scrollY + deltaY / nextZoom, + // 2x multiplier is just a magic number that makes this work correctly + // on touchscreen devices (note: if we get report that panning is slower/faster + // than actual movement, consider swapping with devicePixelRatio) + scrollX: zoomState.scrollX + 2 * (deltaX / nextZoom), + scrollY: zoomState.scrollY + 2 * (deltaY / nextZoom), shouldCacheIgnoreZoom: true, }); }); diff --git a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap index 8d5642f85..0855a70d8 100644 --- a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap +++ b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap @@ -10752,7 +10752,7 @@ exports[`regression tests > pinch-to-zoom works > [end of test] appState 1`] = ` "pendingImageElementId": null, "previousSelectedElementIds": {}, "resizingElement": null, - "scrollX": -2.916666666666668, + "scrollX": -6.2500000000000036, "scrollY": 0, "scrolledOutside": false, "selectedElementIds": {}, @@ -13688,8 +13688,8 @@ exports[`regression tests > two-finger scroll works > [end of test] appState 1`] "pendingImageElementId": null, "previousSelectedElementIds": {}, "resizingElement": null, - "scrollX": 10, - "scrollY": -10, + "scrollX": 20, + "scrollY": -18.535533905932738, "scrolledOutside": false, "selectedElementIds": {}, "selectedElementsAreBeingDragged": false,