Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix tabs scroll slowly in some version #658

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/hooks/useTouchMove.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from 'react';
import { useRef, useState } from 'react';
import { useState, useRef } from 'react';
import { getWheelDeltaOfPx } from '../util';


type TouchEventHandler = (e: TouchEvent) => void;
type WheelEventHandler = (e: WheelEvent) => void;
Expand Down Expand Up @@ -79,7 +81,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;
Expand Down
18 changes: 16 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type React from 'react';
import type { ReactNode } from 'react';
import type { ReactNode, default as React } from 'react';
import type { EditableConfig } from './interface';

/**
Expand Down Expand Up @@ -27,6 +26,21 @@
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

Check warning on line 36 in src/util.ts

View check run for this annotation

Codecov / codecov/patch

src/util.ts#L36

Added line #L36 was not covered by tests
: deltaX;
const deltaYOfPx = isLineMode(event)
? deltaY * 100 / 3

Check warning on line 39 in src/util.ts

View check run for this annotation

Codecov / codecov/patch

src/util.ts#L39

Added line #L39 was not covered by tests
: deltaY;
return [deltaXOfPx, deltaYOfPx]
}

export function getRemovable(
closable?: boolean,
closeIcon?: ReactNode,
Expand Down