forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaultOverscanIndicesGetter.js
More file actions
36 lines (33 loc) · 1.41 KB
/
defaultOverscanIndicesGetter.js
File metadata and controls
36 lines (33 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
export const SCROLL_DIRECTION_BACKWARD = -1
export const SCROLL_DIRECTION_FORWARD = 1
export const SCROLL_DIRECTION_HORIZONTAL = 'horizontal'
export const SCROLL_DIRECTION_VERTICAL = 'vertical'
/**
* Calculates the number of cells to overscan before and after a specified range.
* This function ensures that overscanning doesn't exceed the available cells.
*
* @param direction One of SCROLL_DIRECTION_HORIZONTAL or SCROLL_DIRECTION_VERTICAL
* @param cellCount Number of rows or columns in the current axis
* @param scrollDirection One of SCROLL_DIRECTION_BACKWARD or SCROLL_DIRECTION_FORWARD
* @param overscanCellsCount Maximum number of cells to over-render in either direction
* @param startIndex Begin of range of visible cells
* @param stopIndex End of range of visible cells
*/
export default function defaultOverscanIndicesGetter ({ direction, cellCount, overscanCellsCount, scrollDirection, startIndex, stopIndex }) {
let overscanStartIndex
let overscanStopIndex
switch (scrollDirection) {
case SCROLL_DIRECTION_FORWARD:
overscanStartIndex = startIndex
overscanStopIndex = stopIndex + overscanCellsCount
break
case SCROLL_DIRECTION_BACKWARD:
overscanStartIndex = startIndex - overscanCellsCount
overscanStopIndex = stopIndex
break
}
return {
overscanStartIndex: Math.max(0, overscanStartIndex),
overscanStopIndex: Math.min(cellCount - 1, overscanStopIndex)
}
}