react-virtualized
Version:
React components for efficiently rendering large, scrollable lists and tabular data
36 lines (34 loc) • 1.99 kB
JavaScript
/**
* Helper method that determines when to recalculate row or column metadata.
*
* @param cellCount Number of rows or columns in the current axis
* @param cellsSize Width or height of cells for the current axis
* @param computeMetadataCallback Method to invoke if cell metadata should be recalculated
* @param computeMetadataCallbackProps Parameters to pass to :computeMetadataCallback
* @param nextCellsCount Newly updated number of rows or columns in the current axis
* @param nextCellsSize Newly updated width or height of cells for the current axis
* @param nextScrollToIndex Newly updated scroll-to-index
* @param scrollToIndex Scroll-to-index
* @param updateScrollOffsetForScrollToIndex Callback to invoke if the scroll position should be recalculated
*/
export default function calculateSizeAndPositionDataAndUpdateScrollOffset(_ref) {
var cellCount = _ref.cellCount;
var cellSize = _ref.cellSize;
var computeMetadataCallback = _ref.computeMetadataCallback;
var computeMetadataCallbackProps = _ref.computeMetadataCallbackProps;
var nextCellsCount = _ref.nextCellsCount;
var nextCellSize = _ref.nextCellSize;
var nextScrollToIndex = _ref.nextScrollToIndex;
var scrollToIndex = _ref.scrollToIndex;
var updateScrollOffsetForScrollToIndex = _ref.updateScrollOffsetForScrollToIndex;
// Don't compare cell sizes if they are functions because inline functions would cause infinite loops.
// In that event users should use the manual recompute methods to inform of changes.
if (cellCount !== nextCellsCount || (typeof cellSize === 'number' || typeof nextCellSize === 'number') && cellSize !== nextCellSize) {
computeMetadataCallback(computeMetadataCallbackProps);
// Updated cell metadata may have hidden the previous scrolled-to item.
// In this case we should also update the scrollTop to ensure it stays visible.
if (scrollToIndex >= 0 && scrollToIndex === nextScrollToIndex) {
updateScrollOffsetForScrollToIndex();
}
}
}