forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCellMeasurerCacheDecorator.js
107 lines (90 loc) · 2.48 KB
/
CellMeasurerCacheDecorator.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/** @flow */
import {CellMeasurerCache} from '../CellMeasurer';
type CellMeasurerCacheDecoratorParams = {
cellMeasurerCache: CellMeasurerCache,
columnIndexOffset: number,
rowIndexOffset: number,
};
type IndexParam = {
index: number,
};
/**
* Caches measurements for a given cell.
*/
export default class CellMeasurerCacheDecorator {
_cellMeasurerCache: CellMeasurerCache;
_columnIndexOffset: number;
_rowIndexOffset: number;
constructor(params: CellMeasurerCacheDecoratorParams = {}) {
const {
cellMeasurerCache,
columnIndexOffset = 0,
rowIndexOffset = 0,
} = params;
this._cellMeasurerCache = cellMeasurerCache;
this._columnIndexOffset = columnIndexOffset;
this._rowIndexOffset = rowIndexOffset;
}
clear(rowIndex: number, columnIndex: number): void {
this._cellMeasurerCache.clear(
rowIndex + this._rowIndexOffset,
columnIndex + this._columnIndexOffset,
);
}
clearAll(): void {
this._cellMeasurerCache.clearAll();
}
columnWidth = ({index}: IndexParam) => {
this._cellMeasurerCache.columnWidth({
index: index + this._columnIndexOffset,
});
};
get defaultHeight(): number {
return this._cellMeasurerCache.defaultHeight;
}
get defaultWidth(): number {
return this._cellMeasurerCache.defaultWidth;
}
hasFixedHeight(): boolean {
return this._cellMeasurerCache.hasFixedHeight();
}
hasFixedWidth(): boolean {
return this._cellMeasurerCache.hasFixedWidth();
}
getHeight(rowIndex: number, columnIndex: ?number = 0): ?number {
return this._cellMeasurerCache.getHeight(
rowIndex + this._rowIndexOffset,
columnIndex + this._columnIndexOffset,
);
}
getWidth(rowIndex: number, columnIndex: ?number = 0): ?number {
return this._cellMeasurerCache.getWidth(
rowIndex + this._rowIndexOffset,
columnIndex + this._columnIndexOffset,
);
}
has(rowIndex: number, columnIndex: ?number = 0): boolean {
return this._cellMeasurerCache.has(
rowIndex + this._rowIndexOffset,
columnIndex + this._columnIndexOffset,
);
}
rowHeight = ({index}: IndexParam) => {
this._cellMeasurerCache.rowHeight({
index: index + this._rowIndexOffset,
});
};
set(
rowIndex: number,
columnIndex: number,
width: number,
height: number,
): void {
this._cellMeasurerCache.set(
rowIndex + this._rowIndexOffset,
columnIndex + this._columnIndexOffset,
(width: number),
(height: number),
);
}
}