From 5e680255e2412a5a8523b1a2c757518aeb225435 Mon Sep 17 00:00:00 2001 From: xiefenga <1294699027@qq.com> Date: Fri, 10 Mar 2023 20:56:19 +0800 Subject: [PATCH] fix: fix tabs scroll slowly in some version --- src/hooks/useTouchMove.ts | 3 ++- src/util.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/hooks/useTouchMove.ts b/src/hooks/useTouchMove.ts index dcb126a2..64a29612 100644 --- a/src/hooks/useTouchMove.ts +++ b/src/hooks/useTouchMove.ts @@ -1,5 +1,6 @@ import * as React from 'react'; import { useState, useRef } from 'react'; +import { getWheelDeltaOfPx } from '../util'; type TouchEventHandler = (e: TouchEvent) => void; type WheelEventHandler = (e: WheelEvent) => void; @@ -79,7 +80,7 @@ export default function useTouchMove( const lastWheelDirectionRef = useRef<'x' | 'y'>(); function onWheel(e: WheelEvent) { - const { deltaX, deltaY } = e; + const [deltaX, deltaY] = getWheelDeltaOfPx(e); // Convert both to x & y since wheel only happened on PC let mixed: number = 0; diff --git a/src/util.ts b/src/util.ts index 5084d5fc..31bd9548 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,4 @@ -import React from 'react'; +import type React from 'react'; /** * We trade Map as deps which may change with same value but different ref object. @@ -23,3 +23,18 @@ const RC_TABS_DOUBLE_QUOTE = 'TABS_DQ'; export function genDataNodeKey(key: React.Key): string { return String(key).replace(/"/g, RC_TABS_DOUBLE_QUOTE); } + +export function isLineMode(event: WheelEvent) { + return event.deltaMode === WheelEvent.DOM_DELTA_LINE +} + +export function getWheelDeltaOfPx(event: WheelEvent) { + const { deltaX, deltaY } = event + const deltaXOfPx = isLineMode(event) + ? deltaX * 100 / 3 + : deltaX; + const deltaYOfPx = isLineMode(event) + ? deltaY * 100 / 3 + : deltaY; + return [deltaXOfPx, deltaYOfPx] +} \ No newline at end of file