Skip to content

Commit

Permalink
fix autoHideSuspend bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KingSora committed Aug 26, 2023
1 parent 596a9d8 commit 5c6af50
Showing 1 changed file with 30 additions and 15 deletions.
@@ -1,4 +1,4 @@
import { on, runEachAndClear, selfClearTimeout } from '~/support';
import { noop, on, runEachAndClear, selfClearTimeout } from '~/support';
import { getEnvironment } from '~/environment';
import { createState, createOptionCheck } from '~/setups/setups';
import { createScrollbarsSetupEvents } from '~/setups/scrollbarsSetup/scrollbarsSetup.events';
Expand Down Expand Up @@ -48,6 +48,7 @@ export const createScrollbarsSetup = (
let autoHideNotNever: boolean | undefined;
let mouseInHost: boolean | undefined;
let prevTheme: string | null | undefined;
let instanceAutoHideSuspendScrollDestroyFn = noop;
let instanceAutoHideDelay = 0;

const state = createState({});
Expand Down Expand Up @@ -167,6 +168,7 @@ export const createScrollbarsSetup = (
const [clickScroll, clickScrollChanged] = checkOption<boolean>('scrollbars.clickScroll');

const trulyAppeared = _appear && !force;
const hasOverflow = _hasOverflow.x || _hasOverflow.y;
const updateScrollbars = _overflowEdgeChanged || _overflowAmountChanged || _directionChanged;
const updateVisibility = _overflowStyleChanged || visibilityChanged;
const showNativeOverlaidScrollbars =
Expand All @@ -183,6 +185,25 @@ export const createScrollbarsSetup = (

instanceAutoHideDelay = autoHideDelay;

if (trulyAppeared) {
if (autoHideSuspend && hasOverflow) {
manageAutoHideSuspension(false);
instanceAutoHideSuspendScrollDestroyFn();
autoHideSuspendTimeout(() => {
instanceAutoHideSuspendScrollDestroyFn = on(
_scrollEventElement,
'scroll',
manageAutoHideSuspension.bind(0, true),
{
_once: true,
}
);
});
} else {
manageAutoHideSuspension(true);
}
}

if (showNativeOverlaidScrollbarsChanged) {
_scrollbarsAddRemoveClass(classNameScrollbarThemeNone, showNativeOverlaidScrollbars);
}
Expand All @@ -192,20 +213,11 @@ export const createScrollbarsSetup = (

prevTheme = theme;
}
if (autoHideSuspendChanged || trulyAppeared) {
if (autoHideSuspend && trulyAppeared && (_hasOverflow.x || _hasOverflow.y)) {
manageAutoHideSuspension(false);
autoHideSuspendTimeout(() =>
destroyFns.push(
on(_scrollEventElement, 'scroll', manageAutoHideSuspension.bind(0, true), {
_once: true,
})
)
);
} else {
manageAutoHideSuspension(true);
}

if (autoHideSuspendChanged && !autoHideSuspend) {
manageAutoHideSuspension(true);
}

if (autoHideChanged) {
autoHideIsMove = autoHide === 'move';
autoHideIsLeave = autoHide === 'leave';
Expand Down Expand Up @@ -237,6 +249,9 @@ export const createScrollbarsSetup = (
}
},
scrollbarsSetupState,
runEachAndClear.bind(0, destroyFns),
() => {
runEachAndClear(destroyFns);
instanceAutoHideSuspendScrollDestroyFn();
},
];
};

0 comments on commit 5c6af50

Please sign in to comment.