@depup/react-virtualized 9.22.6-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +34 -0
- package/changes.json +22 -0
- package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.example.js +184 -0
- package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.jest.js +338 -0
- package/dist/commonjs/ArrowKeyStepper/ArrowKeyStepper.js +204 -0
- package/dist/commonjs/ArrowKeyStepper/index.js +19 -0
- package/dist/commonjs/ArrowKeyStepper/types.js +5 -0
- package/dist/commonjs/AutoSizer/AutoSizer.example.js +104 -0
- package/dist/commonjs/AutoSizer/AutoSizer.jest.js +341 -0
- package/dist/commonjs/AutoSizer/AutoSizer.js +199 -0
- package/dist/commonjs/AutoSizer/AutoSizer.ssr.js +25 -0
- package/dist/commonjs/AutoSizer/index.js +19 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +100 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +99 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +107 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +102 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +107 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.example.js +129 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.jest.js +345 -0
- package/dist/commonjs/CellMeasurer/CellMeasurer.js +195 -0
- package/dist/commonjs/CellMeasurer/CellMeasurerCache.jest.js +298 -0
- package/dist/commonjs/CellMeasurer/CellMeasurerCache.js +202 -0
- package/dist/commonjs/CellMeasurer/index.js +22 -0
- package/dist/commonjs/CellMeasurer/types.js +14 -0
- package/dist/commonjs/Collection/Collection.example.js +231 -0
- package/dist/commonjs/Collection/Collection.jest.js +829 -0
- package/dist/commonjs/Collection/Collection.js +266 -0
- package/dist/commonjs/Collection/CollectionView.js +553 -0
- package/dist/commonjs/Collection/Section.jest.js +63 -0
- package/dist/commonjs/Collection/Section.js +57 -0
- package/dist/commonjs/Collection/SectionManager.jest.js +121 -0
- package/dist/commonjs/Collection/SectionManager.js +134 -0
- package/dist/commonjs/Collection/TestData.js +77 -0
- package/dist/commonjs/Collection/index.js +15 -0
- package/dist/commonjs/Collection/types.js +22 -0
- package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.jest.js +34 -0
- package/dist/commonjs/Collection/utils/calculateSizeAndPositionData.js +38 -0
- package/dist/commonjs/ColumnSizer/ColumnSizer.example.js +159 -0
- package/dist/commonjs/ColumnSizer/ColumnSizer.jest.js +129 -0
- package/dist/commonjs/ColumnSizer/ColumnSizer.js +103 -0
- package/dist/commonjs/ColumnSizer/index.js +15 -0
- package/dist/commonjs/Grid/Grid.example.js +330 -0
- package/dist/commonjs/Grid/Grid.jest.js +2561 -0
- package/dist/commonjs/Grid/Grid.js +1432 -0
- package/dist/commonjs/Grid/Grid.ssr.js +62 -0
- package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.jest.js +92 -0
- package/dist/commonjs/Grid/accessibilityOverscanIndicesGetter.js +40 -0
- package/dist/commonjs/Grid/defaultCellRangeRenderer.js +139 -0
- package/dist/commonjs/Grid/defaultOverscanIndicesGetter.jest.js +92 -0
- package/dist/commonjs/Grid/defaultOverscanIndicesGetter.js +36 -0
- package/dist/commonjs/Grid/index.js +40 -0
- package/dist/commonjs/Grid/types.js +8 -0
- package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.jest.js +375 -0
- package/dist/commonjs/Grid/utils/CellSizeAndPositionManager.js +296 -0
- package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +201 -0
- package/dist/commonjs/Grid/utils/ScalingCellSizeAndPositionManager.js +204 -0
- package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +84 -0
- package/dist/commonjs/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +59 -0
- package/dist/commonjs/Grid/utils/maxElementSize.js +22 -0
- package/dist/commonjs/Grid/utils/updateScrollIndexHelper.jest.js +180 -0
- package/dist/commonjs/Grid/utils/updateScrollIndexHelper.js +85 -0
- package/dist/commonjs/InfiniteLoader/InfiniteLoader.example.js +179 -0
- package/dist/commonjs/InfiniteLoader/InfiniteLoader.jest.js +571 -0
- package/dist/commonjs/InfiniteLoader/InfiniteLoader.js +274 -0
- package/dist/commonjs/InfiniteLoader/index.js +15 -0
- package/dist/commonjs/List/List.example.js +236 -0
- package/dist/commonjs/List/List.jest.js +517 -0
- package/dist/commonjs/List/List.js +318 -0
- package/dist/commonjs/List/index.js +19 -0
- package/dist/commonjs/List/types.js +6 -0
- package/dist/commonjs/Masonry/Masonry.example.js +287 -0
- package/dist/commonjs/Masonry/Masonry.jest.js +450 -0
- package/dist/commonjs/Masonry/Masonry.js +431 -0
- package/dist/commonjs/Masonry/PositionCache.js +88 -0
- package/dist/commonjs/Masonry/createCellPositioner.js +59 -0
- package/dist/commonjs/Masonry/index.js +22 -0
- package/dist/commonjs/MultiGrid/CellMeasurerCacheDecorator.js +106 -0
- package/dist/commonjs/MultiGrid/MultiGrid.example.js +131 -0
- package/dist/commonjs/MultiGrid/MultiGrid.jest.js +584 -0
- package/dist/commonjs/MultiGrid/MultiGrid.js +743 -0
- package/dist/commonjs/MultiGrid/index.js +15 -0
- package/dist/commonjs/ScrollSync/ScrollSync.example.js +257 -0
- package/dist/commonjs/ScrollSync/ScrollSync.jest.js +66 -0
- package/dist/commonjs/ScrollSync/ScrollSync.js +88 -0
- package/dist/commonjs/ScrollSync/index.js +15 -0
- package/dist/commonjs/Table/Column.jest.js +90 -0
- package/dist/commonjs/Table/Column.js +93 -0
- package/dist/commonjs/Table/SortDirection.js +19 -0
- package/dist/commonjs/Table/SortIndicator.js +40 -0
- package/dist/commonjs/Table/Table.example.js +325 -0
- package/dist/commonjs/Table/Table.jest.js +1257 -0
- package/dist/commonjs/Table/Table.js +742 -0
- package/dist/commonjs/Table/createMultiSort.jest.js +165 -0
- package/dist/commonjs/Table/createMultiSort.js +99 -0
- package/dist/commonjs/Table/defaultCellDataGetter.js +21 -0
- package/dist/commonjs/Table/defaultCellRenderer.js +19 -0
- package/dist/commonjs/Table/defaultHeaderRenderer.js +35 -0
- package/dist/commonjs/Table/defaultHeaderRowRenderer.js +21 -0
- package/dist/commonjs/Table/defaultRowRenderer.js +87 -0
- package/dist/commonjs/Table/index.js +78 -0
- package/dist/commonjs/Table/types.js +39 -0
- package/dist/commonjs/WindowScroller/WindowScroller.e2e.js +298 -0
- package/dist/commonjs/WindowScroller/WindowScroller.example.js +167 -0
- package/dist/commonjs/WindowScroller/WindowScroller.header-resize.e2e.js +359 -0
- package/dist/commonjs/WindowScroller/WindowScroller.jest.js +536 -0
- package/dist/commonjs/WindowScroller/WindowScroller.js +268 -0
- package/dist/commonjs/WindowScroller/WindowScroller.ssr.js +25 -0
- package/dist/commonjs/WindowScroller/index.js +23 -0
- package/dist/commonjs/WindowScroller/utils/dimensions.js +89 -0
- package/dist/commonjs/WindowScroller/utils/onScroll.js +70 -0
- package/dist/commonjs/index.js +180 -0
- package/dist/commonjs/jest-setup.js +7 -0
- package/dist/commonjs/utils/TestHelper.js +36 -0
- package/dist/commonjs/utils/animationFrame.js +29 -0
- package/dist/commonjs/utils/createCallbackMemoizer.jest.js +219 -0
- package/dist/commonjs/utils/createCallbackMemoizer.js +31 -0
- package/dist/commonjs/utils/getUpdatedOffsetForIndex.jest.js +68 -0
- package/dist/commonjs/utils/getUpdatedOffsetForIndex.js +38 -0
- package/dist/commonjs/utils/initCellMetadata.js +37 -0
- package/dist/commonjs/utils/requestAnimationTimeout.js +38 -0
- package/dist/commonjs/vendor/binarySearchBounds.js +200 -0
- package/dist/commonjs/vendor/detectElementResize.js +192 -0
- package/dist/commonjs/vendor/intervalTree.js +361 -0
- package/dist/es/ArrowKeyStepper/ArrowKeyStepper.example.js +176 -0
- package/dist/es/ArrowKeyStepper/ArrowKeyStepper.jest.js +332 -0
- package/dist/es/ArrowKeyStepper/ArrowKeyStepper.js +197 -0
- package/dist/es/ArrowKeyStepper/index.js +3 -0
- package/dist/es/ArrowKeyStepper/types.js +4 -0
- package/dist/es/AutoSizer/AutoSizer.example.js +96 -0
- package/dist/es/AutoSizer/AutoSizer.jest.js +335 -0
- package/dist/es/AutoSizer/AutoSizer.js +190 -0
- package/dist/es/AutoSizer/AutoSizer.js.flow +200 -0
- package/dist/es/AutoSizer/AutoSizer.ssr.js +19 -0
- package/dist/es/AutoSizer/index.js +2 -0
- package/dist/es/AutoSizer/index.js.flow +4 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightGrid.example.js +91 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightList.example.js +90 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicHeightTableColumn.example.js +98 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthGrid.example.js +93 -0
- package/dist/es/CellMeasurer/CellMeasurer.DynamicWidthMultiGrid.example.js +98 -0
- package/dist/es/CellMeasurer/CellMeasurer.example.js +120 -0
- package/dist/es/CellMeasurer/CellMeasurer.jest.js +340 -0
- package/dist/es/CellMeasurer/CellMeasurer.js +187 -0
- package/dist/es/CellMeasurer/CellMeasurerCache.jest.js +293 -0
- package/dist/es/CellMeasurer/CellMeasurerCache.js +196 -0
- package/dist/es/CellMeasurer/index.js +4 -0
- package/dist/es/CellMeasurer/types.js +13 -0
- package/dist/es/Collection/Collection.example.js +223 -0
- package/dist/es/Collection/Collection.jest.js +824 -0
- package/dist/es/Collection/Collection.js +257 -0
- package/dist/es/Collection/CollectionView.js +544 -0
- package/dist/es/Collection/Section.jest.js +60 -0
- package/dist/es/Collection/Section.js +51 -0
- package/dist/es/Collection/SectionManager.jest.js +118 -0
- package/dist/es/Collection/SectionManager.js +128 -0
- package/dist/es/Collection/TestData.js +71 -0
- package/dist/es/Collection/index.js +3 -0
- package/dist/es/Collection/types.js +21 -0
- package/dist/es/Collection/utils/calculateSizeAndPositionData.jest.js +31 -0
- package/dist/es/Collection/utils/calculateSizeAndPositionData.js +31 -0
- package/dist/es/ColumnSizer/ColumnSizer.example.js +150 -0
- package/dist/es/ColumnSizer/ColumnSizer.jest.js +123 -0
- package/dist/es/ColumnSizer/ColumnSizer.js +95 -0
- package/dist/es/ColumnSizer/index.js +3 -0
- package/dist/es/Grid/Grid.example.js +321 -0
- package/dist/es/Grid/Grid.jest.js +2555 -0
- package/dist/es/Grid/Grid.js +1425 -0
- package/dist/es/Grid/Grid.ssr.js +57 -0
- package/dist/es/Grid/accessibilityOverscanIndicesGetter.jest.js +87 -0
- package/dist/es/Grid/accessibilityOverscanIndicesGetter.js +33 -0
- package/dist/es/Grid/defaultCellRangeRenderer.js +134 -0
- package/dist/es/Grid/defaultOverscanIndicesGetter.jest.js +87 -0
- package/dist/es/Grid/defaultOverscanIndicesGetter.js +29 -0
- package/dist/es/Grid/index.js +15 -0
- package/dist/es/Grid/types.js +96 -0
- package/dist/es/Grid/utils/CellSizeAndPositionManager.jest.js +372 -0
- package/dist/es/Grid/utils/CellSizeAndPositionManager.js +290 -0
- package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.jest.js +198 -0
- package/dist/es/Grid/utils/ScalingCellSizeAndPositionManager.js +198 -0
- package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.jest.js +81 -0
- package/dist/es/Grid/utils/calculateSizeAndPositionDataAndUpdateScrollOffset.js +53 -0
- package/dist/es/Grid/utils/maxElementSize.js +16 -0
- package/dist/es/Grid/utils/updateScrollIndexHelper.jest.js +174 -0
- package/dist/es/Grid/utils/updateScrollIndexHelper.js +79 -0
- package/dist/es/InfiniteLoader/InfiniteLoader.example.js +170 -0
- package/dist/es/InfiniteLoader/InfiniteLoader.jest.js +565 -0
- package/dist/es/InfiniteLoader/InfiniteLoader.js +263 -0
- package/dist/es/InfiniteLoader/index.js +3 -0
- package/dist/es/List/List.example.js +227 -0
- package/dist/es/List/List.jest.js +511 -0
- package/dist/es/List/List.js +312 -0
- package/dist/es/List/index.js +3 -0
- package/dist/es/List/types.js +21 -0
- package/dist/es/Masonry/Masonry.example.js +278 -0
- package/dist/es/Masonry/Masonry.jest.js +444 -0
- package/dist/es/Masonry/Masonry.js +421 -0
- package/dist/es/Masonry/PositionCache.js +82 -0
- package/dist/es/Masonry/createCellPositioner.js +53 -0
- package/dist/es/Masonry/index.js +4 -0
- package/dist/es/MultiGrid/CellMeasurerCacheDecorator.js +100 -0
- package/dist/es/MultiGrid/MultiGrid.example.js +122 -0
- package/dist/es/MultiGrid/MultiGrid.jest.js +579 -0
- package/dist/es/MultiGrid/MultiGrid.js +733 -0
- package/dist/es/MultiGrid/index.js +3 -0
- package/dist/es/ScrollSync/ScrollSync.example.js +248 -0
- package/dist/es/ScrollSync/ScrollSync.jest.js +60 -0
- package/dist/es/ScrollSync/ScrollSync.js +80 -0
- package/dist/es/ScrollSync/index.js +3 -0
- package/dist/es/Table/Column.jest.js +84 -0
- package/dist/es/Table/Column.js +85 -0
- package/dist/es/Table/SortDirection.js +13 -0
- package/dist/es/Table/SortIndicator.js +31 -0
- package/dist/es/Table/Table.example.js +316 -0
- package/dist/es/Table/Table.jest.js +1251 -0
- package/dist/es/Table/Table.js +735 -0
- package/dist/es/Table/createMultiSort.jest.js +162 -0
- package/dist/es/Table/createMultiSort.js +93 -0
- package/dist/es/Table/defaultCellDataGetter.js +15 -0
- package/dist/es/Table/defaultCellRenderer.js +13 -0
- package/dist/es/Table/defaultHeaderRenderer.js +25 -0
- package/dist/es/Table/defaultHeaderRowRenderer.js +12 -0
- package/dist/es/Table/defaultRowRenderer.js +77 -0
- package/dist/es/Table/index.js +12 -0
- package/dist/es/Table/types.js +38 -0
- package/dist/es/WindowScroller/WindowScroller.e2e.js +295 -0
- package/dist/es/WindowScroller/WindowScroller.example.js +158 -0
- package/dist/es/WindowScroller/WindowScroller.header-resize.e2e.js +356 -0
- package/dist/es/WindowScroller/WindowScroller.jest.js +530 -0
- package/dist/es/WindowScroller/WindowScroller.js +259 -0
- package/dist/es/WindowScroller/WindowScroller.js.flow +277 -0
- package/dist/es/WindowScroller/WindowScroller.ssr.js +19 -0
- package/dist/es/WindowScroller/index.js +3 -0
- package/dist/es/WindowScroller/index.js.flow +6 -0
- package/dist/es/WindowScroller/utils/dimensions.js +81 -0
- package/dist/es/WindowScroller/utils/dimensions.js.flow +91 -0
- package/dist/es/WindowScroller/utils/onScroll.js +64 -0
- package/dist/es/WindowScroller/utils/onScroll.js.flow +94 -0
- package/dist/es/index.js +13 -0
- package/dist/es/jest-setup.js +5 -0
- package/dist/es/utils/TestHelper.js +30 -0
- package/dist/es/utils/animationFrame.js +23 -0
- package/dist/es/utils/createCallbackMemoizer.jest.js +216 -0
- package/dist/es/utils/createCallbackMemoizer.js +25 -0
- package/dist/es/utils/getUpdatedOffsetForIndex.jest.js +65 -0
- package/dist/es/utils/getUpdatedOffsetForIndex.js +32 -0
- package/dist/es/utils/initCellMetadata.js +31 -0
- package/dist/es/utils/requestAnimationTimeout.js +32 -0
- package/dist/es/vendor/binarySearchBounds.js +194 -0
- package/dist/es/vendor/detectElementResize.js +186 -0
- package/dist/es/vendor/intervalTree.js +354 -0
- package/dist/umd/react-virtualized.js +4638 -0
- package/package.json +188 -0
- package/styles.css +80 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import CellSizeAndPositionManager from './CellSizeAndPositionManager';
|
|
2
|
+
describe('CellSizeAndPositionManager', function () {
|
|
3
|
+
function getCellSizeAndPositionManager() {
|
|
4
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
5
|
+
_ref$cellCount = _ref.cellCount,
|
|
6
|
+
cellCount = _ref$cellCount === void 0 ? 100 : _ref$cellCount,
|
|
7
|
+
_ref$estimatedCellSiz = _ref.estimatedCellSize,
|
|
8
|
+
estimatedCellSize = _ref$estimatedCellSiz === void 0 ? 15 : _ref$estimatedCellSiz;
|
|
9
|
+
var cellSizeGetterCalls = [];
|
|
10
|
+
var cellSizeAndPositionManager = new CellSizeAndPositionManager({
|
|
11
|
+
cellCount: cellCount,
|
|
12
|
+
cellSizeGetter: function cellSizeGetter(_ref2) {
|
|
13
|
+
var index = _ref2.index;
|
|
14
|
+
cellSizeGetterCalls.push(index);
|
|
15
|
+
return 10;
|
|
16
|
+
},
|
|
17
|
+
estimatedCellSize: estimatedCellSize
|
|
18
|
+
});
|
|
19
|
+
return {
|
|
20
|
+
cellSizeAndPositionManager: cellSizeAndPositionManager,
|
|
21
|
+
cellSizeGetterCalls: cellSizeGetterCalls
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
describe('configure', function () {
|
|
25
|
+
it('should update inner :cellCount and :estimatedCellSize', function () {
|
|
26
|
+
var _getCellSizeAndPositi = getCellSizeAndPositionManager(),
|
|
27
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi.cellSizeAndPositionManager;
|
|
28
|
+
expect(cellSizeAndPositionManager.getCellCount()).toEqual(100);
|
|
29
|
+
expect(cellSizeAndPositionManager.getEstimatedCellSize()).toEqual(15);
|
|
30
|
+
cellSizeAndPositionManager.configure({
|
|
31
|
+
cellCount: 20,
|
|
32
|
+
estimatedCellSize: 30
|
|
33
|
+
});
|
|
34
|
+
expect(cellSizeAndPositionManager.getCellCount()).toEqual(20);
|
|
35
|
+
expect(cellSizeAndPositionManager.getEstimatedCellSize()).toEqual(30);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('findNearestCell', function () {
|
|
39
|
+
it('should error if given NaN', function () {
|
|
40
|
+
var _getCellSizeAndPositi2 = getCellSizeAndPositionManager(),
|
|
41
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi2.cellSizeAndPositionManager;
|
|
42
|
+
expect(function () {
|
|
43
|
+
return cellSizeAndPositionManager._findNearestCell(NaN);
|
|
44
|
+
}).toThrow();
|
|
45
|
+
});
|
|
46
|
+
it('should gracefully handle offets outisde of bounds (to account for elastic scrolling)', function () {
|
|
47
|
+
var _getCellSizeAndPositi3 = getCellSizeAndPositionManager(),
|
|
48
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi3.cellSizeAndPositionManager;
|
|
49
|
+
expect(cellSizeAndPositionManager._findNearestCell(-100)).toEqual(0);
|
|
50
|
+
expect(cellSizeAndPositionManager._findNearestCell(1234567890)).toEqual(99);
|
|
51
|
+
});
|
|
52
|
+
it('should find the first cell', function () {
|
|
53
|
+
var _getCellSizeAndPositi4 = getCellSizeAndPositionManager(),
|
|
54
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi4.cellSizeAndPositionManager;
|
|
55
|
+
expect(cellSizeAndPositionManager._findNearestCell(0)).toEqual(0);
|
|
56
|
+
expect(cellSizeAndPositionManager._findNearestCell(9)).toEqual(0);
|
|
57
|
+
});
|
|
58
|
+
it('should find the last cell', function () {
|
|
59
|
+
var _getCellSizeAndPositi5 = getCellSizeAndPositionManager(),
|
|
60
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi5.cellSizeAndPositionManager;
|
|
61
|
+
expect(cellSizeAndPositionManager._findNearestCell(990)).toEqual(99);
|
|
62
|
+
expect(cellSizeAndPositionManager._findNearestCell(991)).toEqual(99);
|
|
63
|
+
});
|
|
64
|
+
it('should find the a cell that exactly matches a specified offset in the middle', function () {
|
|
65
|
+
var _getCellSizeAndPositi6 = getCellSizeAndPositionManager(),
|
|
66
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi6.cellSizeAndPositionManager;
|
|
67
|
+
expect(cellSizeAndPositionManager._findNearestCell(100)).toEqual(10);
|
|
68
|
+
});
|
|
69
|
+
it('should find the cell closest to (but before) the specified offset in the middle', function () {
|
|
70
|
+
var _getCellSizeAndPositi7 = getCellSizeAndPositionManager(),
|
|
71
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi7.cellSizeAndPositionManager;
|
|
72
|
+
expect(cellSizeAndPositionManager._findNearestCell(101)).toEqual(10);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('getSizeAndPositionOfCell', function () {
|
|
76
|
+
it('should error if an invalid index is specified', function () {
|
|
77
|
+
var _getCellSizeAndPositi8 = getCellSizeAndPositionManager(),
|
|
78
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi8.cellSizeAndPositionManager;
|
|
79
|
+
expect(function () {
|
|
80
|
+
return cellSizeAndPositionManager.getSizeAndPositionOfCell(-1);
|
|
81
|
+
}).toThrow();
|
|
82
|
+
expect(function () {
|
|
83
|
+
return cellSizeAndPositionManager.getSizeAndPositionOfCell(100);
|
|
84
|
+
}).toThrow();
|
|
85
|
+
});
|
|
86
|
+
it('should return the correct size and position information for the requested cell', function () {
|
|
87
|
+
var _getCellSizeAndPositi9 = getCellSizeAndPositionManager(),
|
|
88
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi9.cellSizeAndPositionManager;
|
|
89
|
+
expect(cellSizeAndPositionManager.getSizeAndPositionOfCell(0).offset).toEqual(0);
|
|
90
|
+
expect(cellSizeAndPositionManager.getSizeAndPositionOfCell(0).size).toEqual(10);
|
|
91
|
+
expect(cellSizeAndPositionManager.getSizeAndPositionOfCell(1).offset).toEqual(10);
|
|
92
|
+
expect(cellSizeAndPositionManager.getSizeAndPositionOfCell(2).offset).toEqual(20);
|
|
93
|
+
});
|
|
94
|
+
it('should only measure the necessary cells to return the information requested', function () {
|
|
95
|
+
var _getCellSizeAndPositi10 = getCellSizeAndPositionManager(),
|
|
96
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi10.cellSizeAndPositionManager,
|
|
97
|
+
cellSizeGetterCalls = _getCellSizeAndPositi10.cellSizeGetterCalls;
|
|
98
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(0);
|
|
99
|
+
expect(cellSizeGetterCalls).toEqual([0]);
|
|
100
|
+
});
|
|
101
|
+
it('should just-in-time measure all cells up to the requested cell if no cells have yet been measured', function () {
|
|
102
|
+
var _getCellSizeAndPositi11 = getCellSizeAndPositionManager(),
|
|
103
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi11.cellSizeAndPositionManager,
|
|
104
|
+
cellSizeGetterCalls = _getCellSizeAndPositi11.cellSizeGetterCalls;
|
|
105
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
106
|
+
expect(cellSizeGetterCalls).toEqual([0, 1, 2, 3, 4, 5]);
|
|
107
|
+
});
|
|
108
|
+
it('should just-in-time measure cells up to the requested cell if some but not all cells have been measured', function () {
|
|
109
|
+
var _getCellSizeAndPositi12 = getCellSizeAndPositionManager(),
|
|
110
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi12.cellSizeAndPositionManager,
|
|
111
|
+
cellSizeGetterCalls = _getCellSizeAndPositi12.cellSizeGetterCalls;
|
|
112
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
113
|
+
cellSizeGetterCalls.splice(0);
|
|
114
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(10);
|
|
115
|
+
expect(cellSizeGetterCalls).toEqual([6, 7, 8, 9, 10]);
|
|
116
|
+
});
|
|
117
|
+
it('should return cached size and position data if cell has already been measured', function () {
|
|
118
|
+
var _getCellSizeAndPositi13 = getCellSizeAndPositionManager(),
|
|
119
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi13.cellSizeAndPositionManager,
|
|
120
|
+
cellSizeGetterCalls = _getCellSizeAndPositi13.cellSizeGetterCalls;
|
|
121
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
122
|
+
cellSizeGetterCalls.splice(0);
|
|
123
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
124
|
+
expect(cellSizeGetterCalls).toEqual([]);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe('getSizeAndPositionOfLastMeasuredCell', function () {
|
|
128
|
+
it('should return an empty object if no cached cells are present', function () {
|
|
129
|
+
var _getCellSizeAndPositi14 = getCellSizeAndPositionManager(),
|
|
130
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi14.cellSizeAndPositionManager;
|
|
131
|
+
expect(cellSizeAndPositionManager.getSizeAndPositionOfLastMeasuredCell()).toEqual({
|
|
132
|
+
offset: 0,
|
|
133
|
+
size: 0
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
it('should return size and position data for the highest/last measured cell', function () {
|
|
137
|
+
var _getCellSizeAndPositi15 = getCellSizeAndPositionManager(),
|
|
138
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi15.cellSizeAndPositionManager;
|
|
139
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
140
|
+
expect(cellSizeAndPositionManager.getSizeAndPositionOfLastMeasuredCell()).toEqual({
|
|
141
|
+
offset: 50,
|
|
142
|
+
size: 10
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe('getTotalSize', function () {
|
|
147
|
+
it('should calculate total size based purely on :estimatedCellSize if no measurements have been done', function () {
|
|
148
|
+
var _getCellSizeAndPositi16 = getCellSizeAndPositionManager(),
|
|
149
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi16.cellSizeAndPositionManager;
|
|
150
|
+
expect(cellSizeAndPositionManager.getTotalSize()).toEqual(1500);
|
|
151
|
+
});
|
|
152
|
+
it('should calculate total size based on a mixture of actual cell sizes and :estimatedCellSize if some cells have been measured', function () {
|
|
153
|
+
var _getCellSizeAndPositi17 = getCellSizeAndPositionManager(),
|
|
154
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi17.cellSizeAndPositionManager;
|
|
155
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(49);
|
|
156
|
+
expect(cellSizeAndPositionManager.getTotalSize()).toEqual(1250);
|
|
157
|
+
});
|
|
158
|
+
it('should calculate total size based on the actual measured sizes if all cells have been measured', function () {
|
|
159
|
+
var _getCellSizeAndPositi18 = getCellSizeAndPositionManager(),
|
|
160
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi18.cellSizeAndPositionManager;
|
|
161
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(99);
|
|
162
|
+
expect(cellSizeAndPositionManager.getTotalSize()).toEqual(1000);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe('getUpdatedOffsetForIndex', function () {
|
|
166
|
+
function getUpdatedOffsetForIndexHelper(_ref3) {
|
|
167
|
+
var _ref3$align = _ref3.align,
|
|
168
|
+
align = _ref3$align === void 0 ? 'auto' : _ref3$align,
|
|
169
|
+
_ref3$cellCount = _ref3.cellCount,
|
|
170
|
+
cellCount = _ref3$cellCount === void 0 ? 10 : _ref3$cellCount,
|
|
171
|
+
_ref3$cellSize = _ref3.cellSize,
|
|
172
|
+
cellSize = _ref3$cellSize === void 0 ? 10 : _ref3$cellSize,
|
|
173
|
+
_ref3$containerSize = _ref3.containerSize,
|
|
174
|
+
containerSize = _ref3$containerSize === void 0 ? 50 : _ref3$containerSize,
|
|
175
|
+
_ref3$currentOffset = _ref3.currentOffset,
|
|
176
|
+
currentOffset = _ref3$currentOffset === void 0 ? 0 : _ref3$currentOffset,
|
|
177
|
+
_ref3$estimatedCellSi = _ref3.estimatedCellSize,
|
|
178
|
+
estimatedCellSize = _ref3$estimatedCellSi === void 0 ? 15 : _ref3$estimatedCellSi,
|
|
179
|
+
_ref3$targetIndex = _ref3.targetIndex,
|
|
180
|
+
targetIndex = _ref3$targetIndex === void 0 ? 0 : _ref3$targetIndex;
|
|
181
|
+
var cellSizeAndPositionManager = new CellSizeAndPositionManager({
|
|
182
|
+
cellCount: cellCount,
|
|
183
|
+
cellSizeGetter: function cellSizeGetter() {
|
|
184
|
+
return cellSize;
|
|
185
|
+
},
|
|
186
|
+
estimatedCellSize: estimatedCellSize
|
|
187
|
+
});
|
|
188
|
+
return cellSizeAndPositionManager.getUpdatedOffsetForIndex({
|
|
189
|
+
align: align,
|
|
190
|
+
containerSize: containerSize,
|
|
191
|
+
currentOffset: currentOffset,
|
|
192
|
+
targetIndex: targetIndex
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
it('should scroll to the beginning', function () {
|
|
196
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
197
|
+
currentOffset: 100,
|
|
198
|
+
targetIndex: 0
|
|
199
|
+
})).toEqual(0);
|
|
200
|
+
});
|
|
201
|
+
it('should scroll to the end', function () {
|
|
202
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
203
|
+
currentOffset: 0,
|
|
204
|
+
targetIndex: 9
|
|
205
|
+
})).toEqual(50);
|
|
206
|
+
});
|
|
207
|
+
it('should scroll forward to the middle', function () {
|
|
208
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
209
|
+
currentOffset: 0,
|
|
210
|
+
targetIndex: 6
|
|
211
|
+
})).toEqual(20);
|
|
212
|
+
});
|
|
213
|
+
it('should scroll backward to the middle', function () {
|
|
214
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
215
|
+
currentOffset: 50,
|
|
216
|
+
targetIndex: 2
|
|
217
|
+
})).toEqual(20);
|
|
218
|
+
});
|
|
219
|
+
it('should not scroll if an item is already visible', function () {
|
|
220
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
221
|
+
currentOffset: 20,
|
|
222
|
+
targetIndex: 3
|
|
223
|
+
})).toEqual(20);
|
|
224
|
+
});
|
|
225
|
+
it('should honor specified :align values', function () {
|
|
226
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
227
|
+
align: 'auto',
|
|
228
|
+
currentOffset: 0,
|
|
229
|
+
targetIndex: 5
|
|
230
|
+
})).toEqual(10);
|
|
231
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
232
|
+
align: 'start',
|
|
233
|
+
currentOffset: 0,
|
|
234
|
+
targetIndex: 5
|
|
235
|
+
})).toEqual(50);
|
|
236
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
237
|
+
align: 'auto',
|
|
238
|
+
currentOffset: 50,
|
|
239
|
+
targetIndex: 4
|
|
240
|
+
})).toEqual(40);
|
|
241
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
242
|
+
align: 'end',
|
|
243
|
+
currentOffset: 50,
|
|
244
|
+
targetIndex: 5
|
|
245
|
+
})).toEqual(10);
|
|
246
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
247
|
+
align: 'center',
|
|
248
|
+
currentOffset: 50,
|
|
249
|
+
targetIndex: 5
|
|
250
|
+
})).toEqual(30);
|
|
251
|
+
});
|
|
252
|
+
it('should not scroll past the safe bounds even if the specified :align requests it', function () {
|
|
253
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
254
|
+
align: 'end',
|
|
255
|
+
currentOffset: 50,
|
|
256
|
+
targetIndex: 0
|
|
257
|
+
})).toEqual(0);
|
|
258
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
259
|
+
align: 'center',
|
|
260
|
+
currentOffset: 50,
|
|
261
|
+
targetIndex: 1
|
|
262
|
+
})).toEqual(0);
|
|
263
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
264
|
+
align: 'start',
|
|
265
|
+
currentOffset: 0,
|
|
266
|
+
targetIndex: 9
|
|
267
|
+
})).toEqual(50);
|
|
268
|
+
|
|
269
|
+
// TRICKY: We would expect this to be positioned at 50.
|
|
270
|
+
// But since the :estimatedCellSize is 15 and we only measure up to the 8th item,
|
|
271
|
+
// The helper assumes it can scroll farther than it actually can.
|
|
272
|
+
// Not sure if this edge case is worth "fixing" or just acknowledging...
|
|
273
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
274
|
+
align: 'center',
|
|
275
|
+
currentOffset: 0,
|
|
276
|
+
targetIndex: 8
|
|
277
|
+
})).toEqual(55);
|
|
278
|
+
});
|
|
279
|
+
it('should always return an offset of 0 when :containerSize is 0', function () {
|
|
280
|
+
expect(getUpdatedOffsetForIndexHelper({
|
|
281
|
+
containerSize: 0,
|
|
282
|
+
currentOffset: 50,
|
|
283
|
+
targetIndex: 2
|
|
284
|
+
})).toEqual(0);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
describe('getVisibleCellRange', function () {
|
|
288
|
+
it('should not return any indices if :cellCount is 0', function () {
|
|
289
|
+
var _getCellSizeAndPositi19 = getCellSizeAndPositionManager({
|
|
290
|
+
cellCount: 0
|
|
291
|
+
}),
|
|
292
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi19.cellSizeAndPositionManager;
|
|
293
|
+
var _cellSizeAndPositionM = cellSizeAndPositionManager.getVisibleCellRange({
|
|
294
|
+
containerSize: 50,
|
|
295
|
+
offset: 0
|
|
296
|
+
}),
|
|
297
|
+
start = _cellSizeAndPositionM.start,
|
|
298
|
+
stop = _cellSizeAndPositionM.stop;
|
|
299
|
+
expect(start).toEqual(undefined);
|
|
300
|
+
expect(stop).toEqual(undefined);
|
|
301
|
+
});
|
|
302
|
+
it('should return a visible range of cells for the beginning of the list', function () {
|
|
303
|
+
var _getCellSizeAndPositi20 = getCellSizeAndPositionManager(),
|
|
304
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi20.cellSizeAndPositionManager;
|
|
305
|
+
var _cellSizeAndPositionM2 = cellSizeAndPositionManager.getVisibleCellRange({
|
|
306
|
+
containerSize: 50,
|
|
307
|
+
offset: 0
|
|
308
|
+
}),
|
|
309
|
+
start = _cellSizeAndPositionM2.start,
|
|
310
|
+
stop = _cellSizeAndPositionM2.stop;
|
|
311
|
+
expect(start).toEqual(0);
|
|
312
|
+
expect(stop).toEqual(4);
|
|
313
|
+
});
|
|
314
|
+
it('should return a visible range of cells for the middle of the list where some are partially visible', function () {
|
|
315
|
+
var _getCellSizeAndPositi21 = getCellSizeAndPositionManager(),
|
|
316
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi21.cellSizeAndPositionManager;
|
|
317
|
+
var _cellSizeAndPositionM3 = cellSizeAndPositionManager.getVisibleCellRange({
|
|
318
|
+
containerSize: 50,
|
|
319
|
+
offset: 425
|
|
320
|
+
}),
|
|
321
|
+
start = _cellSizeAndPositionM3.start,
|
|
322
|
+
stop = _cellSizeAndPositionM3.stop;
|
|
323
|
+
// 42 and 47 are partially visible
|
|
324
|
+
expect(start).toEqual(42);
|
|
325
|
+
expect(stop).toEqual(47);
|
|
326
|
+
});
|
|
327
|
+
it('should return a visible range of cells for the end of the list', function () {
|
|
328
|
+
var _getCellSizeAndPositi22 = getCellSizeAndPositionManager(),
|
|
329
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi22.cellSizeAndPositionManager;
|
|
330
|
+
var _cellSizeAndPositionM4 = cellSizeAndPositionManager.getVisibleCellRange({
|
|
331
|
+
containerSize: 50,
|
|
332
|
+
offset: 950
|
|
333
|
+
}),
|
|
334
|
+
start = _cellSizeAndPositionM4.start,
|
|
335
|
+
stop = _cellSizeAndPositionM4.stop;
|
|
336
|
+
expect(start).toEqual(95);
|
|
337
|
+
expect(stop).toEqual(99);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
describe('resetCell', function () {
|
|
341
|
+
it('should clear size and position metadata for the specified index and all cells after it', function () {
|
|
342
|
+
var _getCellSizeAndPositi23 = getCellSizeAndPositionManager(),
|
|
343
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi23.cellSizeAndPositionManager;
|
|
344
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
345
|
+
cellSizeAndPositionManager.resetCell(3);
|
|
346
|
+
expect(cellSizeAndPositionManager.getLastMeasuredIndex()).toEqual(2);
|
|
347
|
+
cellSizeAndPositionManager.resetCell(0);
|
|
348
|
+
expect(cellSizeAndPositionManager.getLastMeasuredIndex()).toEqual(-1);
|
|
349
|
+
});
|
|
350
|
+
it('should not clear size and position metadata for cells before the specified index', function () {
|
|
351
|
+
var _getCellSizeAndPositi24 = getCellSizeAndPositionManager(),
|
|
352
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi24.cellSizeAndPositionManager,
|
|
353
|
+
cellSizeGetterCalls = _getCellSizeAndPositi24.cellSizeGetterCalls;
|
|
354
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
355
|
+
cellSizeGetterCalls.splice(0);
|
|
356
|
+
cellSizeAndPositionManager.resetCell(3);
|
|
357
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(4);
|
|
358
|
+
expect(cellSizeGetterCalls).toEqual([3, 4]);
|
|
359
|
+
});
|
|
360
|
+
it('should not skip over any unmeasured or previously-cleared cells', function () {
|
|
361
|
+
var _getCellSizeAndPositi25 = getCellSizeAndPositionManager(),
|
|
362
|
+
cellSizeAndPositionManager = _getCellSizeAndPositi25.cellSizeAndPositionManager;
|
|
363
|
+
cellSizeAndPositionManager.getSizeAndPositionOfCell(5);
|
|
364
|
+
cellSizeAndPositionManager.resetCell(2);
|
|
365
|
+
expect(cellSizeAndPositionManager.getLastMeasuredIndex()).toEqual(1);
|
|
366
|
+
cellSizeAndPositionManager.resetCell(4);
|
|
367
|
+
expect(cellSizeAndPositionManager.getLastMeasuredIndex()).toEqual(1);
|
|
368
|
+
cellSizeAndPositionManager.resetCell(0);
|
|
369
|
+
expect(cellSizeAndPositionManager.getLastMeasuredIndex()).toEqual(-1);
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
});
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
/*:: import type {Alignment, CellSizeGetter, VisibleCellRange} from '../types';*/
|
|
5
|
+
/*:: type CellSizeAndPositionManagerParams = {
|
|
6
|
+
cellCount: number,
|
|
7
|
+
cellSizeGetter: CellSizeGetter,
|
|
8
|
+
estimatedCellSize: number,
|
|
9
|
+
};*/
|
|
10
|
+
/*:: type ConfigureParams = {
|
|
11
|
+
cellCount: number,
|
|
12
|
+
estimatedCellSize: number,
|
|
13
|
+
cellSizeGetter: CellSizeGetter,
|
|
14
|
+
};*/
|
|
15
|
+
/*:: type GetUpdatedOffsetForIndex = {
|
|
16
|
+
align: Alignment,
|
|
17
|
+
containerSize: number,
|
|
18
|
+
currentOffset: number,
|
|
19
|
+
targetIndex: number,
|
|
20
|
+
};*/
|
|
21
|
+
/*:: type GetVisibleCellRangeParams = {
|
|
22
|
+
containerSize: number,
|
|
23
|
+
offset: number,
|
|
24
|
+
};*/
|
|
25
|
+
/*:: type SizeAndPositionData = {
|
|
26
|
+
offset: number,
|
|
27
|
+
size: number,
|
|
28
|
+
};*/
|
|
29
|
+
/**
|
|
30
|
+
* Just-in-time calculates and caches size and position information for a collection of cells.
|
|
31
|
+
*/
|
|
32
|
+
var CellSizeAndPositionManager = /*#__PURE__*/function () {
|
|
33
|
+
function CellSizeAndPositionManager(_ref /*:: */) {
|
|
34
|
+
var cellCount = _ref /*:: */.cellCount,
|
|
35
|
+
cellSizeGetter = _ref /*:: */.cellSizeGetter,
|
|
36
|
+
estimatedCellSize = _ref /*:: */.estimatedCellSize;
|
|
37
|
+
_classCallCheck(this, CellSizeAndPositionManager);
|
|
38
|
+
// Cache of size and position data for cells, mapped by cell index.
|
|
39
|
+
// Note that invalid values may exist in this map so only rely on cells up to this._lastMeasuredIndex
|
|
40
|
+
_defineProperty(this, "_cellSizeAndPositionData", {});
|
|
41
|
+
// Measurements for cells up to this index can be trusted; cells afterward should be estimated.
|
|
42
|
+
_defineProperty(this, "_lastMeasuredIndex", -1);
|
|
43
|
+
// Used in deferred mode to track which cells have been queued for measurement.
|
|
44
|
+
_defineProperty(this, "_lastBatchedIndex", -1);
|
|
45
|
+
_defineProperty(this, "_cellCount", void 0);
|
|
46
|
+
_defineProperty(this, "_cellSizeGetter", void 0);
|
|
47
|
+
_defineProperty(this, "_estimatedCellSize", void 0);
|
|
48
|
+
this._cellSizeGetter = cellSizeGetter;
|
|
49
|
+
this._cellCount = cellCount;
|
|
50
|
+
this._estimatedCellSize = estimatedCellSize;
|
|
51
|
+
}
|
|
52
|
+
return _createClass(CellSizeAndPositionManager, [{
|
|
53
|
+
key: "areOffsetsAdjusted",
|
|
54
|
+
value: function areOffsetsAdjusted() {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "configure",
|
|
59
|
+
value: function configure(_ref2 /*:: */) {
|
|
60
|
+
var cellCount = _ref2 /*:: */.cellCount,
|
|
61
|
+
estimatedCellSize = _ref2 /*:: */.estimatedCellSize,
|
|
62
|
+
cellSizeGetter = _ref2 /*:: */.cellSizeGetter;
|
|
63
|
+
this._cellCount = cellCount;
|
|
64
|
+
this._estimatedCellSize = estimatedCellSize;
|
|
65
|
+
this._cellSizeGetter = cellSizeGetter;
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "getCellCount",
|
|
69
|
+
value: function getCellCount() /*: number*/{
|
|
70
|
+
return this._cellCount;
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "getEstimatedCellSize",
|
|
74
|
+
value: function getEstimatedCellSize() /*: number*/{
|
|
75
|
+
return this._estimatedCellSize;
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "getLastMeasuredIndex",
|
|
79
|
+
value: function getLastMeasuredIndex() /*: number*/{
|
|
80
|
+
return this._lastMeasuredIndex;
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "getOffsetAdjustment",
|
|
84
|
+
value: function getOffsetAdjustment() {
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* This method returns the size and position for the cell at the specified index.
|
|
90
|
+
* It just-in-time calculates (or used cached values) for cells leading up to the index.
|
|
91
|
+
*/
|
|
92
|
+
}, {
|
|
93
|
+
key: "getSizeAndPositionOfCell",
|
|
94
|
+
value: function getSizeAndPositionOfCell(index /*: number*/) /*: SizeAndPositionData*/{
|
|
95
|
+
if (index < 0 || index >= this._cellCount) {
|
|
96
|
+
throw Error("Requested index ".concat(index, " is outside of range 0..").concat(this._cellCount));
|
|
97
|
+
}
|
|
98
|
+
if (index > this._lastMeasuredIndex) {
|
|
99
|
+
var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
|
|
100
|
+
var offset = lastMeasuredCellSizeAndPosition.offset + lastMeasuredCellSizeAndPosition.size;
|
|
101
|
+
for (var i = this._lastMeasuredIndex + 1; i <= index; i++) {
|
|
102
|
+
var size = this._cellSizeGetter({
|
|
103
|
+
index: i
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// undefined or NaN probably means a logic error in the size getter.
|
|
107
|
+
// null means we're using CellMeasurer and haven't yet measured a given index.
|
|
108
|
+
if (size === undefined || isNaN(size)) {
|
|
109
|
+
throw Error("Invalid size returned for cell ".concat(i, " of value ").concat(size));
|
|
110
|
+
} else if (size === null) {
|
|
111
|
+
this._cellSizeAndPositionData[i] = {
|
|
112
|
+
offset: offset,
|
|
113
|
+
size: 0
|
|
114
|
+
};
|
|
115
|
+
this._lastBatchedIndex = index;
|
|
116
|
+
} else {
|
|
117
|
+
this._cellSizeAndPositionData[i] = {
|
|
118
|
+
offset: offset,
|
|
119
|
+
size: size
|
|
120
|
+
};
|
|
121
|
+
offset += size;
|
|
122
|
+
this._lastMeasuredIndex = index;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return this._cellSizeAndPositionData[index];
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
key: "getSizeAndPositionOfLastMeasuredCell",
|
|
130
|
+
value: function getSizeAndPositionOfLastMeasuredCell() /*: SizeAndPositionData*/{
|
|
131
|
+
return this._lastMeasuredIndex >= 0 ? this._cellSizeAndPositionData[this._lastMeasuredIndex] : {
|
|
132
|
+
offset: 0,
|
|
133
|
+
size: 0
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Total size of all cells being measured.
|
|
139
|
+
* This value will be completely estimated initially.
|
|
140
|
+
* As cells are measured, the estimate will be updated.
|
|
141
|
+
*/
|
|
142
|
+
}, {
|
|
143
|
+
key: "getTotalSize",
|
|
144
|
+
value: function getTotalSize() /*: number*/{
|
|
145
|
+
var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
|
|
146
|
+
var totalSizeOfMeasuredCells = lastMeasuredCellSizeAndPosition.offset + lastMeasuredCellSizeAndPosition.size;
|
|
147
|
+
var numUnmeasuredCells = this._cellCount - this._lastMeasuredIndex - 1;
|
|
148
|
+
var totalSizeOfUnmeasuredCells = numUnmeasuredCells * this._estimatedCellSize;
|
|
149
|
+
return totalSizeOfMeasuredCells + totalSizeOfUnmeasuredCells;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Determines a new offset that ensures a certain cell is visible, given the current offset.
|
|
154
|
+
* If the cell is already visible then the current offset will be returned.
|
|
155
|
+
* If the current offset is too great or small, it will be adjusted just enough to ensure the specified index is visible.
|
|
156
|
+
*
|
|
157
|
+
* @param align Desired alignment within container; one of "auto" (default), "start", or "end"
|
|
158
|
+
* @param containerSize Size (width or height) of the container viewport
|
|
159
|
+
* @param currentOffset Container's current (x or y) offset
|
|
160
|
+
* @param totalSize Total size (width or height) of all cells
|
|
161
|
+
* @return Offset to use to ensure the specified cell is visible
|
|
162
|
+
*/
|
|
163
|
+
}, {
|
|
164
|
+
key: "getUpdatedOffsetForIndex",
|
|
165
|
+
value: function getUpdatedOffsetForIndex(_ref3 /*:: */) /*: number*/{
|
|
166
|
+
var _ref3$align = _ref3 /*:: */.align,
|
|
167
|
+
align = _ref3$align === void 0 ? 'auto' : _ref3$align,
|
|
168
|
+
containerSize = _ref3 /*:: */.containerSize,
|
|
169
|
+
currentOffset = _ref3 /*:: */.currentOffset,
|
|
170
|
+
targetIndex = _ref3 /*:: */.targetIndex;
|
|
171
|
+
if (containerSize <= 0) {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
var datum = this.getSizeAndPositionOfCell(targetIndex);
|
|
175
|
+
var maxOffset = datum.offset;
|
|
176
|
+
var minOffset = maxOffset - containerSize + datum.size;
|
|
177
|
+
var idealOffset;
|
|
178
|
+
switch (align) {
|
|
179
|
+
case 'start':
|
|
180
|
+
idealOffset = maxOffset;
|
|
181
|
+
break;
|
|
182
|
+
case 'end':
|
|
183
|
+
idealOffset = minOffset;
|
|
184
|
+
break;
|
|
185
|
+
case 'center':
|
|
186
|
+
idealOffset = maxOffset - (containerSize - datum.size) / 2;
|
|
187
|
+
break;
|
|
188
|
+
default:
|
|
189
|
+
idealOffset = Math.max(minOffset, Math.min(maxOffset, currentOffset));
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
var totalSize = this.getTotalSize();
|
|
193
|
+
return Math.max(0, Math.min(totalSize - containerSize, idealOffset));
|
|
194
|
+
}
|
|
195
|
+
}, {
|
|
196
|
+
key: "getVisibleCellRange",
|
|
197
|
+
value: function getVisibleCellRange(params /*: GetVisibleCellRangeParams*/) /*: VisibleCellRange*/{
|
|
198
|
+
var containerSize = params.containerSize,
|
|
199
|
+
offset = params.offset;
|
|
200
|
+
var totalSize = this.getTotalSize();
|
|
201
|
+
if (totalSize === 0) {
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
var maxOffset = offset + containerSize;
|
|
205
|
+
var start = this._findNearestCell(offset);
|
|
206
|
+
var datum = this.getSizeAndPositionOfCell(start);
|
|
207
|
+
offset = datum.offset + datum.size;
|
|
208
|
+
var stop = start;
|
|
209
|
+
while (offset < maxOffset && stop < this._cellCount - 1) {
|
|
210
|
+
stop++;
|
|
211
|
+
offset += this.getSizeAndPositionOfCell(stop).size;
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
start: start,
|
|
215
|
+
stop: stop
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Clear all cached values for cells after the specified index.
|
|
221
|
+
* This method should be called for any cell that has changed its size.
|
|
222
|
+
* It will not immediately perform any calculations; they'll be performed the next time getSizeAndPositionOfCell() is called.
|
|
223
|
+
*/
|
|
224
|
+
}, {
|
|
225
|
+
key: "resetCell",
|
|
226
|
+
value: function resetCell(index /*: number*/) /*: void*/{
|
|
227
|
+
this._lastMeasuredIndex = Math.min(this._lastMeasuredIndex, index - 1);
|
|
228
|
+
}
|
|
229
|
+
}, {
|
|
230
|
+
key: "_binarySearch",
|
|
231
|
+
value: function _binarySearch(high /*: number*/, low /*: number*/, offset /*: number*/) /*: number*/{
|
|
232
|
+
while (low <= high) {
|
|
233
|
+
var middle = low + Math.floor((high - low) / 2);
|
|
234
|
+
var currentOffset = this.getSizeAndPositionOfCell(middle).offset;
|
|
235
|
+
if (currentOffset === offset) {
|
|
236
|
+
return middle;
|
|
237
|
+
} else if (currentOffset < offset) {
|
|
238
|
+
low = middle + 1;
|
|
239
|
+
} else if (currentOffset > offset) {
|
|
240
|
+
high = middle - 1;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (low > 0) {
|
|
244
|
+
return low - 1;
|
|
245
|
+
} else {
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}, {
|
|
250
|
+
key: "_exponentialSearch",
|
|
251
|
+
value: function _exponentialSearch(index /*: number*/, offset /*: number*/) /*: number*/{
|
|
252
|
+
var interval = 1;
|
|
253
|
+
while (index < this._cellCount && this.getSizeAndPositionOfCell(index).offset < offset) {
|
|
254
|
+
index += interval;
|
|
255
|
+
interval *= 2;
|
|
256
|
+
}
|
|
257
|
+
return this._binarySearch(Math.min(index, this._cellCount - 1), Math.floor(index / 2), offset);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Searches for the cell (index) nearest the specified offset.
|
|
262
|
+
*
|
|
263
|
+
* If no exact match is found the next lowest cell index will be returned.
|
|
264
|
+
* This allows partially visible cells (with offsets just before/above the fold) to be visible.
|
|
265
|
+
*/
|
|
266
|
+
}, {
|
|
267
|
+
key: "_findNearestCell",
|
|
268
|
+
value: function _findNearestCell(offset /*: number*/) /*: number*/{
|
|
269
|
+
if (isNaN(offset)) {
|
|
270
|
+
throw Error("Invalid offset ".concat(offset, " specified"));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Our search algorithms find the nearest match at or below the specified offset.
|
|
274
|
+
// So make sure the offset is at least 0 or no match will be found.
|
|
275
|
+
offset = Math.max(0, offset);
|
|
276
|
+
var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
|
|
277
|
+
var lastMeasuredIndex = Math.max(0, this._lastMeasuredIndex);
|
|
278
|
+
if (lastMeasuredCellSizeAndPosition.offset >= offset) {
|
|
279
|
+
// If we've already measured cells within this range just use a binary search as it's faster.
|
|
280
|
+
return this._binarySearch(lastMeasuredIndex, 0, offset);
|
|
281
|
+
} else {
|
|
282
|
+
// If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
|
|
283
|
+
// The exponential search avoids pre-computing sizes for the full set of cells as a binary search would.
|
|
284
|
+
// The overall complexity for this approach is O(log n).
|
|
285
|
+
return this._exponentialSearch(lastMeasuredIndex, offset);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}]);
|
|
289
|
+
}();
|
|
290
|
+
export { CellSizeAndPositionManager as default };
|