react-measured-grid

react-measured-grid API MeasuredGrid ScrollPosition PositionTracker demos repo

ScrollPosition API

The ScrollPosition class is used to describe a scrolling position in terms of:

Instances of the class are used with MeasuredGrid for horizontal scrolling or vertical scrolling. For horizontal scrolling, the index is a column index. For vertical scrolling, the index is a row index.

The alignment describes how the row or column are aligned with the view window. Possible values are:

The additional offset is a number of pixels of additional scrolling. Positive values position the grid in the view window away from the grid’s start and closer to its end. Negative values position the grid in the view window closer to the grid’s start and away from its end.

Conversions

Conversion between a total scroll offset in pixels and a ScrollPosition is mediated in part by a PositionTracker and its estimates. Notably there is not a 1-to-1 correspondence between the two ways of representing a scrolling position.

Conversions generally favor in-range positions and ScrollPosition’s with an in-item offset.

An in-range position is one that specifies a position that is within the range of the size of the grid. An in-range scrollPosition also uses an in-range index, an index that is between 0 and one less than the number of items. As a special case, when there are zero items, a 0 index is still considered as being in-range.

An in-item additional offset is one that allows the indexed item to contain the view window’s point of alignment. When a position is at the border point between two items, which of the two indexes to use for an in-item offset depends on the alignment: the prior index if the alignment is ‘end’, the latter index if the alignment is ‘start’.

Methods

The following are methods that are available for use:

ScrollPosition(index, alignment, offset)

The rest of the methods are instance methods.

copy()

changeAlignment(alignment, positionTracker, viewSize)

getAlignment()

getAlignedOffset()

getIndex()

getTotalOffset(positionTracker, viewSize)

getViewStartOffset(positionTracker, viewSize)

incrementOffset(offsetDelta)

update(index, alignment, offset)

updateFrom(scrollPosition)

withContainingIndex(positionTracker, viewSize)