1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _calculateAverageHeight = require('./calculate-average-height');
|
8 |
|
9 | var _calculateAverageHeight2 = _interopRequireDefault(_calculateAverageHeight);
|
10 |
|
11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12 |
|
13 | var calculateRows = function calculateRows(_ref) {
|
14 | var measuredRows = _ref.measuredRows,
|
15 | height = _ref.height,
|
16 | rowKey = _ref.rowKey,
|
17 | rows = _ref.rows,
|
18 | _ref$scrollTop = _ref.scrollTop,
|
19 | scrollTop = _ref$scrollTop === undefined ? 0 : _ref$scrollTop;
|
20 |
|
21 |
|
22 |
|
23 | var averageHeight = (0, _calculateAverageHeight2.default)({ measuredRows: measuredRows, rows: rows, rowKey: rowKey });
|
24 | var amountOfRowsToRender = Math.ceil(height / averageHeight) + 2;
|
25 |
|
26 | var startIndex = Math.floor(scrollTop / averageHeight);
|
27 | var rowsToRender = rows.slice(startIndex, startIndex + amountOfRowsToRender);
|
28 |
|
29 | if (process.env.NODE_ENV !== 'production' && window.LOG_VIRTUALIZED) {
|
30 | console.log(
|
31 | 'update rows to render', 'scroll top', scrollTop, 'measured rows', measuredRows, 'amount of rows to render', amountOfRowsToRender, 'rows to render', rowsToRender, 'start index', startIndex);
|
32 | }
|
33 |
|
34 |
|
35 | if (!rowsToRender.length) {
|
36 | return null;
|
37 | }
|
38 |
|
39 | var startHeight = startIndex * averageHeight;
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | var endHeight = Math.max((rows.length - amountOfRowsToRender) * averageHeight - startHeight, 0);
|
45 |
|
46 | if (process.env.NODE_ENV !== 'production' && window.LOG_VIRTUALIZED) {
|
47 | console.log(
|
48 | 'average height', averageHeight, 'body height', height, 'scroll top', scrollTop, 'start height', startHeight, 'end height', endHeight);
|
49 | }
|
50 |
|
51 | return {
|
52 | amountOfRowsToRender: amountOfRowsToRender,
|
53 | startIndex: startIndex,
|
54 | showExtraRow: !(startIndex % 2),
|
55 | startHeight: startHeight,
|
56 | endHeight: endHeight
|
57 | };
|
58 | };
|
59 |
|
60 | exports.default = calculateRows; |
\ | No newline at end of file |