Skip to content

Commit

Permalink
Remove SCROLL_MANUAL from ScrollDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Jul 27, 2023
1 parent a368d28 commit a982149
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/core/scroller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { hasNegativeOffsetInRtl } from "./dom";
import {
ACTION_SCROLL,
ACTION_MANUAL_SCROLL,
ACTION_BEFORE_MANUAL_SCROLL,
ScrollJump,
VirtualStore,
SCROLL_IDLE,
ACTION_SCROLL_END,
UPDATE_SIZE,
ACTION_MANUAL_SCROLL_END,
ACTION_MANUAL_SCROLL,
} from "./store";
import { debounce, throttle, max, min, timeout } from "./utils";

Expand Down Expand Up @@ -90,7 +90,7 @@ export const createScroller = (
while (true) {
// Sync viewport to scroll destination
// In order to scroll to the correct position, mount the items and measure their sizes before scrolling.
store._update(ACTION_MANUAL_SCROLL, getOffset());
store._update(ACTION_BEFORE_MANUAL_SCROLL, getOffset());

if (!store._hasUnmeasuredItemsInRange(index)) {
break;
Expand Down Expand Up @@ -132,7 +132,7 @@ export const createScroller = (

// Scroll with the updated value
rootElement[scrollToKey] = normalizeOffset(getOffset());
store._update(ACTION_MANUAL_SCROLL_END);
store._update(ACTION_MANUAL_SCROLL);
};

return {
Expand Down
24 changes: 12 additions & 12 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,25 @@ const SUBPIXEL_THRESHOLD = 1.5; // 0.5 * 3
export const SCROLL_IDLE = 0;
export const SCROLL_DOWN = 1;
export const SCROLL_UP = 2;
export const SCROLL_MANUAL = 3;
type ScrollDirection =
| typeof SCROLL_IDLE
| typeof SCROLL_DOWN
| typeof SCROLL_UP
| typeof SCROLL_MANUAL;
| typeof SCROLL_UP;

export const ACTION_ITEM_RESIZE = 1;
export const ACTION_WINDOW_RESIZE = 2;
export const ACTION_SCROLL = 3;
export const ACTION_MANUAL_SCROLL = 4;
export const ACTION_BEFORE_MANUAL_SCROLL = 4;
export const ACTION_SCROLL_END = 5;
export const ACTION_MANUAL_SCROLL_END = 6;
export const ACTION_MANUAL_SCROLL = 6;

type Actions =
| [type: typeof ACTION_ITEM_RESIZE, entries: ItemResize[]]
| [type: typeof ACTION_WINDOW_RESIZE, size: number]
| [type: typeof ACTION_SCROLL, offset: number]
| [type: typeof ACTION_MANUAL_SCROLL, offset: number]
| [type: typeof ACTION_BEFORE_MANUAL_SCROLL, offset: number]
| [type: typeof ACTION_SCROLL_END, dummy?: void]
| [type: typeof ACTION_MANUAL_SCROLL_END, dummy?: void];
| [type: typeof ACTION_MANUAL_SCROLL, dummy?: void];

type Subscriber = (sync?: boolean) => void;

Expand Down Expand Up @@ -102,6 +100,7 @@ export const createVirtualStore = (
(cacheSnapshot as unknown as Cache | undefined) ??
resetCache(elementsCount, initialItemSize);
let _scrollDirection: ScrollDirection = SCROLL_IDLE;
let _isManualScrolling = false;
let _resized = false;
let _prevRange: ItemsRange = [0, initialItemCount];

Expand Down Expand Up @@ -222,7 +221,7 @@ export const createVirtualStore = (
// Calculate jump
if (_scrollDirection === SCROLL_UP) {
diff = sumJumps(calculateJumps(cache, updated));
} else if (_scrollDirection === SCROLL_MANUAL) {
} else if (_isManualScrolling) {
const allJumps = calculateJumps(cache, updated);
const [startIndex] = _prevRange;

Expand Down Expand Up @@ -279,7 +278,7 @@ export const createVirtualStore = (
break;
}
case ACTION_SCROLL:
case ACTION_MANUAL_SCROLL: {
case ACTION_BEFORE_MANUAL_SCROLL: {
// Skip if offset is not changed
if (scrollOffset === payload) {
break;
Expand All @@ -292,7 +291,7 @@ export const createVirtualStore = (
if (
(_scrollDirection === SCROLL_IDLE || !isJustResized) &&
// Ignore until manual scrolling
_scrollDirection !== SCROLL_MANUAL
!_isManualScrolling
) {
updatedScrollState = updateScrollDirection(
scrollOffset > payload ? SCROLL_UP : SCROLL_DOWN
Expand All @@ -313,10 +312,11 @@ export const createVirtualStore = (
}
case ACTION_SCROLL_END: {
updatedScrollState = updateScrollDirection(SCROLL_IDLE);
_isManualScrolling = false;
break;
}
case ACTION_MANUAL_SCROLL_END: {
updatedScrollState = updateScrollDirection(SCROLL_MANUAL);
case ACTION_MANUAL_SCROLL: {
_isManualScrolling = true;
break;
}
}
Expand Down

0 comments on commit a982149

Please sign in to comment.