From 8551fcded3e5e8d47d9fd0485d1a4b22e3e2339d Mon Sep 17 00:00:00 2001 From: Kilian Cirera Sant Date: Wed, 25 Jan 2023 11:22:37 -0800 Subject: [PATCH 1/2] fix(zoom): prevent wheel interfering with pinch Using a macbook, a touchpad pinch gesture will trigger `useGesture`'s pinch event, as desired, but it will also trigger the wheel event. Except in Safari. With this change, the wheel event handler bails if a pinch gesture is ongoing. Fixes: #1638 --- packages/visx-zoom/src/Zoom.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/visx-zoom/src/Zoom.tsx b/packages/visx-zoom/src/Zoom.tsx index 36b973ae9..9dc65d65b 100644 --- a/packages/visx-zoom/src/Zoom.tsx +++ b/packages/visx-zoom/src/Zoom.tsx @@ -327,10 +327,16 @@ function Zoom({ }, onDragEnd: dragEnd, onPinch: handlePinch, - onWheel: ({ event, active }) => { - // currently onWheelEnd emits one final wheel event which causes 2x scale - // updates for the last tick. ensuring that the gesture is active avoids this - if (!active) return; + onWheel: ({ event, active, pinching }) => { + if ( + // Outside of Safari, the wheel event is fired together with the pinch event. + pinching || + // currently onWheelEnd emits one final wheel event which causes 2x scale + // updates for the last tick. ensuring that the gesture is active avoids this + !active + ) { + return; + } handleWheel(event); }, }, From 9007a27a4c146bf85f1e115687a54cf0c63e32b5 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Tue, 21 Mar 2023 18:12:14 -0700 Subject: [PATCH 2/2] Update packages/visx-zoom/src/Zoom.tsx --- packages/visx-zoom/src/Zoom.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/visx-zoom/src/Zoom.tsx b/packages/visx-zoom/src/Zoom.tsx index 9dc65d65b..cd7c51070 100644 --- a/packages/visx-zoom/src/Zoom.tsx +++ b/packages/visx-zoom/src/Zoom.tsx @@ -329,7 +329,7 @@ function Zoom({ onPinch: handlePinch, onWheel: ({ event, active, pinching }) => { if ( - // Outside of Safari, the wheel event is fired together with the pinch event. + // Outside of Safari, the wheel event is fired together with the pinch event pinching || // currently onWheelEnd emits one final wheel event which causes 2x scale // updates for the last tick. ensuring that the gesture is active avoids this