Skip to content

Commit

Permalink
Merge pull request #198 from inokawa/overscan-zero
Browse files Browse the repository at this point in the history
Improve jump compensation and change minimum overscan to 0
  • Loading branch information
inokawa authored Feb 12, 2024
2 parents 44f5f1b + dcf54a4 commit 21d0e8e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const overscanStartIndex = (
scrollDirection: ScrollDirection
): number => {
return max(
startIndex - (scrollDirection === SCROLL_DOWN ? 1 : max(1, overscan)),
startIndex - (scrollDirection === SCROLL_DOWN ? 1 : max(0, overscan)),
0
);
};
Expand All @@ -104,7 +104,7 @@ export const overscanEndIndex = (
count: number
): number => {
return min(
endIndex + (scrollDirection === SCROLL_UP ? 1 : max(1, overscan)),
endIndex + (scrollDirection === SCROLL_UP ? 1 : max(0, overscan)),
count - 1
);
};
Expand Down Expand Up @@ -189,6 +189,9 @@ export const createVirtualStore = (
const getMaxScrollOffset = (): number =>
// total size can become smaller than viewport size
max(0, getScrollableSize() - viewportSize);
const getItemOffset = (index: number): number => {
return computeStartOffset(cache, index) - pendingJump;
};

const applyJump = (j: number) => {
if (j) {
Expand Down Expand Up @@ -239,9 +242,7 @@ export const createVirtualStore = (
)
.includes(UNCACHED);
},
_getItemOffset(index) {
return computeStartOffset(cache, index) - pendingJump;
},
_getItemOffset: getItemOffset,
_getItemSize(index) {
return getItemSize(cache, index);
},
Expand Down Expand Up @@ -314,10 +315,9 @@ export const createVirtualStore = (
}
} else {
// Keep start at mid
const [startIndex] = _prevRange;
diff = calculateJump(
cache,
updated.filter(([index]) => index < startIndex)
updated.filter(([index]) => getItemOffset(index) < scrollOffset)
);
}
applyJump(diff);
Expand Down

0 comments on commit 21d0e8e

Please sign in to comment.