Skip to content

Commit

Permalink
Remove unnecessary scroll offset check when scrolling stops
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Oct 26, 2023
1 parent de8a1d8 commit e79a459
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ export const createScroller = (
let touching = false;
let justTouchEnded = false;

const syncViewportToScrollPosition = () => {
store._update(ACTION_SCROLL, normalizeOffset(root[scrollToKey]));
};

const onScrollStopped = debounce(() => {
if (touching) {
// Wait while touching
Expand All @@ -175,8 +171,6 @@ export const createScroller = (

justTouchEnded = false;

// Check scroll position once just after scrolling stopped
syncViewportToScrollPosition();
store._update(ACTION_SCROLL_END);
}, 150);

Expand All @@ -185,7 +179,7 @@ export const createScroller = (
stillMomentumScrolling = true;
}

syncViewportToScrollPosition();
store._update(ACTION_SCROLL, normalizeOffset(root[scrollToKey]));
onScrollStopped();
};

Expand Down Expand Up @@ -304,22 +298,17 @@ export const createWindowScroller = (
return getOffsetToWindow(parent as HTMLElement, nodeOffset);
};

const syncViewportToScrollPosition = () => {
if (!visible) return;
store._update(
ACTION_SCROLL,
normalizeOffset(window[scrollToKey]) - getOffsetToWindow(root, 0)
);
};

const onScrollStopped = debounce(() => {
// Check scroll position once just after scrolling stopped
syncViewportToScrollPosition();
store._update(ACTION_SCROLL_END);
}, 150);

const onScroll = () => {
syncViewportToScrollPosition();
if (!visible) return;

store._update(
ACTION_SCROLL,
normalizeOffset(window[scrollToKey]) - getOffsetToWindow(root, 0)
);
onScrollStopped();
};

Expand Down

0 comments on commit e79a459

Please sign in to comment.