Skip to content

Commit

Permalink
feat: increaseViewportBy for VirtuosoGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
petyosi committed Oct 14, 2024
1 parent 62d577d commit 67bc341
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/VirtuosoGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ const {
logLevel: 'logLevel',
restoreStateFrom: 'restoreStateFrom',
initialTopMostItemIndex: 'initialTopMostItemIndex',
increaseViewportBy: 'increaseViewportBy',
},
methods: {
scrollTo: 'scrollTo',
Expand Down
14 changes: 13 additions & 1 deletion src/component-interfaces/VirtuosoGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,22 @@ export interface VirtuosoGridProps<D, C = unknown> extends GridRootProps {
/**
* Set the overscan property to make the component "chunk" the rendering of new items on scroll.
* The property causes the component to render more items than the necessary, but reduces the re-renders on scroll.
* Setting `{ main: number, reverse: number }` lets you extend the list in both the main and the reverse scrollable directions.
* Setting `{ main: number, reverse: number }` lets you extend the grid in both the main and the reverse scrollable directions.
* See the `increaseViewportBy` property for a similar behavior (equivalent to the `overscan` in react-window).
*/
overscan?: number | { main: number; reverse: number }

/**
*
* *The property accepts pixel values.*
*
* Set the increaseViewportBy property to artificially increase the viewport size, causing items to be rendered before outside of the viewport.
* The property causes the component to render more items than the necessary, but can help with slow loading content.
* Using `{ top?: number, bottom?: number }` lets you set the increase for each end separately.
*
*/
increaseViewportBy?: number | { top: number; bottom: number }

/**
* If specified, the component will use the function to generate the `key` property for each list item.
*/
Expand Down
3 changes: 2 additions & 1 deletion src/gridSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function dimensionComparator(prev: ElementDimensions, next: ElementDimensions) {

export const gridSystem = /*#__PURE__*/ u.system(
([
{ overscan, visibleRange, listBoundary },
{ overscan, visibleRange, listBoundary, increaseViewportBy },
{ scrollTop, viewportHeight, scrollBy, scrollTo, smoothScrollTargetReached, scrollContainerState, footerHeight, headerHeight },
stateFlags,
scrollSeek,
Expand Down Expand Up @@ -408,6 +408,7 @@ export const gridSystem = /*#__PURE__*/ u.system(
scrollTop,
scrollHeight,
overscan,
increaseViewportBy,
scrollBy,
scrollTo,
scrollToIndex,
Expand Down

0 comments on commit 67bc341

Please sign in to comment.