fix: wheel event handled twice issue (#1050)

This commit is contained in:
Peng Xiao 2022-12-03 21:10:19 +08:00 committed by GitHub
parent d155ac5968
commit 8404528aa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ export function useZoomEvents<T extends HTMLElement>(
const rOriginPoint = React.useRef<number[] | undefined>(undefined)
const rPinchPoint = React.useRef<number[] | undefined>(undefined)
const rDelta = React.useRef<number[]>([0, 0])
const rWheelLastTimeStamp = React.useRef<number>(0)
const { inputs, bounds, callbacks } = useTLContext()
@ -32,7 +33,9 @@ export function useZoomEvents<T extends HTMLElement>(
const handleWheel = React.useCallback<Handler<'wheel', WheelEvent>>(
({ event: e }) => {
e.preventDefault()
if (inputs.isPinching) return
if (inputs.isPinching || e.timeStamp <= rWheelLastTimeStamp.current) return
rWheelLastTimeStamp.current = e.timeStamp
const [x, y, z] = normalizeWheel(e)