Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Jul 24, 2023
1 parent db9b7c1 commit a9405a0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const calculateJumps = (cache: Cache, items: ItemResize[]): ItemJump[] => {
});
};

// Scroll offset and sizes can have sub-pixel value if window.devicePixelRatio has decimal value
const SUBPIXEL_THRESHOLD = 1.5; // 0.5 * 3

export const SCROLL_IDLE = 0;
Expand Down Expand Up @@ -218,9 +219,10 @@ export const createVirtualStore = (

if (scrollOffset === 0) {
// Do nothing to stick to the start
}
// Check including subpixels because window.devicePixelRatio can have decimal value
else if (scrollOffset > getScrollOffsetMax() - SUBPIXEL_THRESHOLD) {
} else if (
scrollOffset >
getScrollOffsetMax() - SUBPIXEL_THRESHOLD
) {
// Keep end to stick to the end
diff = sumJumps(allJumps);
} else {
Expand Down Expand Up @@ -262,9 +264,9 @@ export const createVirtualStore = (
}
case ACTION_WINDOW_RESIZE: {
if (viewportSize !== payload) {
viewportSize = payload;
mutated = UPDATE_SIZE;
}
viewportSize = payload;
break;
}
case ACTION_SCROLL:
Expand Down

0 comments on commit a9405a0

Please sign in to comment.