@react-stately/virtualizer 3.1.6 → 3.1.7-alpha.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/dist/main.js +1077 -1844
- package/dist/main.js.map +1 -1
- package/dist/module.js +1055 -1815
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/module.js
CHANGED
|
@@ -1,2008 +1,1248 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useLayoutEffect
|
|
3
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
1
|
+
import {useState as $he21n$useState, useMemo as $he21n$useMemo, useEffect as $he21n$useEffect, useCallback as $he21n$useCallback} from "react";
|
|
2
|
+
import {useLayoutEffect as $he21n$useLayoutEffect} from "@react-aria/utils";
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
-
* governing permissions and limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
// import {Point} from './Point';
|
|
17
|
-
// import { DragTarget, DropTarget } from '@react-types/shared';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* [CollectionView]{@link CollectionView} supports arbitrary layout objects, which compute what views are visible, and how
|
|
21
|
-
* to position and style them. However, layouts do not create the views themselves directly. Instead,
|
|
22
|
-
* layouts produce lightweight {@link LayoutInfo} objects which describe various properties of a view,
|
|
23
|
-
* such as its position and size. The {@link CollectionView} is then responsible for creating the actual
|
|
24
|
-
* views as needed, based on this layout information.
|
|
25
|
-
*
|
|
26
|
-
* Every layout extends from the {@link Layout} abstract base class. Layouts must implement a minimum of the
|
|
27
|
-
* two methods listed below. All other methods can be optionally overridden to implement custom behavior.
|
|
28
|
-
*
|
|
29
|
-
* @see {@link getVisibleLayoutInfos}
|
|
30
|
-
* @see {@link getLayoutInfo}
|
|
31
|
-
*/
|
|
32
|
-
export class Layout {
|
|
33
|
-
constructor() {
|
|
34
|
-
this.virtualizer = void 0;
|
|
35
|
-
}
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
var $e2db9807015c93cd$exports = {};
|
|
36
8
|
|
|
37
|
-
|
|
9
|
+
$parcel$export($e2db9807015c93cd$exports, "Layout", () => $e2db9807015c93cd$export$c84671f46d6a1ca);
|
|
10
|
+
class $e2db9807015c93cd$export$c84671f46d6a1ca {
|
|
11
|
+
/**
|
|
38
12
|
* Returns whether the layout should invalidate in response to
|
|
39
13
|
* visible rectangle changes. By default, it only invalidates
|
|
40
14
|
* when the collection view's size changes. Return true always
|
|
41
15
|
* to make the layout invalidate while scrolling (e.g. sticky headers).
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/**
|
|
16
|
+
*/ shouldInvalidate(newRect, oldRect) {
|
|
17
|
+
// By default, invalidate when the size changes
|
|
18
|
+
return newRect.width !== oldRect.width || newRect.height !== oldRect.height;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
48
21
|
* This method allows the layout to perform any pre-computation
|
|
49
22
|
* it needs to in order to prepare {@link LayoutInfo}s for retrieval.
|
|
50
23
|
* Called by the collection view before {@link getVisibleLayoutInfos}
|
|
51
24
|
* or {@link getLayoutInfo} are called.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
validate(invalidationContext) {} // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns an array of {@link LayoutInfo} objects which are inside the given rectangle.
|
|
59
|
-
* Should be implemented by subclasses.
|
|
60
|
-
* @param rect The rectangle that should contain the returned LayoutInfo objects.
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/**
|
|
25
|
+
*/ validate(invalidationContext) {
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
65
28
|
* Returns a {@link DragTarget} describing a view at the given point to be dragged.
|
|
66
29
|
* Return `null` to cancel the drag. The default implementation returns the view at the given point.
|
|
67
30
|
* @param point The point at which the drag occurred.
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
/**
|
|
31
|
+
*/ // getDragTarget(point: Point): DragTarget | null {
|
|
32
|
+
// let target = this.virtualizer.keyAtPoint(point);
|
|
33
|
+
// if (!target) {
|
|
34
|
+
// return null;
|
|
35
|
+
// }
|
|
36
|
+
// return {
|
|
37
|
+
// type: 'item',
|
|
38
|
+
// key: target
|
|
39
|
+
// };
|
|
40
|
+
// }
|
|
41
|
+
/**
|
|
81
42
|
* Returns a {@link DragTarget} object describing where a drop should occur. Return `null`
|
|
82
43
|
* to reject the drop. The dropped items will be inserted before the resulting target.
|
|
83
44
|
* @param point The point at which the drop occurred.
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/**
|
|
45
|
+
*/ // getDropTarget(point: Point): DropTarget | null {
|
|
46
|
+
// return null;
|
|
47
|
+
// }
|
|
48
|
+
/**
|
|
90
49
|
* Returns the starting attributes for an animated insertion.
|
|
91
50
|
* The view is animated from this {@link LayoutInfo} to the one returned by {@link getLayoutInfo}.
|
|
92
51
|
* The default implementation just returns its input.
|
|
93
52
|
*
|
|
94
53
|
* @param layoutInfo The proposed LayoutInfo for this view.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/**
|
|
54
|
+
*/ getInitialLayoutInfo(layoutInfo) {
|
|
55
|
+
return layoutInfo;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
100
58
|
* Returns the ending attributes for an animated removal.
|
|
101
59
|
* The view is animated from the {@link LayoutInfo} returned by {@link getLayoutInfo}
|
|
102
60
|
* to the one returned by this method. The default implementation returns its input.
|
|
103
61
|
*
|
|
104
62
|
* @param layoutInfo The original LayoutInfo for this view.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
getFinalLayoutInfo(layoutInfo) {
|
|
109
|
-
return layoutInfo;
|
|
110
|
-
}
|
|
111
|
-
|
|
63
|
+
*/ getFinalLayoutInfo(layoutInfo) {
|
|
64
|
+
return layoutInfo;
|
|
65
|
+
}
|
|
112
66
|
}
|
|
113
67
|
|
|
114
|
-
/**
|
|
115
|
-
* Instances of this lightweight class are created by {@link Layout} subclasses
|
|
116
|
-
* to represent each view in the {@link CollectionView}. LayoutInfo objects describe
|
|
117
|
-
* various properties of a view, such as its position and size, and style information.
|
|
118
|
-
* The collection view uses this information when creating actual views to display.
|
|
119
|
-
*/
|
|
120
|
-
export class LayoutInfo {
|
|
121
|
-
/**
|
|
122
|
-
* A string representing the view type. Should be `'item'` for item views.
|
|
123
|
-
* Other types are used by supplementary views.
|
|
124
|
-
*/
|
|
125
68
|
|
|
126
|
-
|
|
127
|
-
* A unique key for this view. For item views, it should match the content key.
|
|
128
|
-
*/
|
|
69
|
+
var $84802bfc2c93a467$exports = {};
|
|
129
70
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* The rectangle describing the size and position of this view.
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Whether the size is estimated. `false` by default.
|
|
140
|
-
*/
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Whether the layout info sticks to the viewport when scrolling.
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* The view's opacity. 1 by default.
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* A CSS transform string to apply to the view. `null` by default.
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* The z-index of the view. 0 by default.
|
|
156
|
-
*/
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Whether the layout info allows its contents to overflow its container.
|
|
160
|
-
* @default false
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
/**
|
|
71
|
+
$parcel$export($84802bfc2c93a467$exports, "LayoutInfo", () => $84802bfc2c93a467$export$7e0eeb9da702a085);
|
|
72
|
+
class $84802bfc2c93a467$export$7e0eeb9da702a085 {
|
|
73
|
+
/**
|
|
164
74
|
* @param type A string representing the view type. Should be `'item'` for item views.
|
|
165
75
|
Other types are used by supplementary views.
|
|
166
76
|
* @param key The unique key for this view.
|
|
167
77
|
* @param rect The rectangle describing the size and position of this view.
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
this.key = key;
|
|
182
|
-
this.parentKey = null;
|
|
183
|
-
this.rect = rect;
|
|
184
|
-
this.estimatedSize = false;
|
|
185
|
-
this.isSticky = false;
|
|
186
|
-
this.opacity = 1;
|
|
187
|
-
this.transform = null;
|
|
188
|
-
this.zIndex = 0;
|
|
189
|
-
this.allowOverflow = false;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
78
|
+
*/ constructor(type, key, rect){
|
|
79
|
+
this.type = type;
|
|
80
|
+
this.key = key;
|
|
81
|
+
this.parentKey = null;
|
|
82
|
+
this.rect = rect;
|
|
83
|
+
this.estimatedSize = false;
|
|
84
|
+
this.isSticky = false;
|
|
85
|
+
this.opacity = 1;
|
|
86
|
+
this.transform = null;
|
|
87
|
+
this.zIndex = 0;
|
|
88
|
+
this.allowOverflow = false;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
192
91
|
* Returns a copy of the LayoutInfo.
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
res.allowOverflow = this.allowOverflow;
|
|
205
|
-
return res;
|
|
206
|
-
}
|
|
207
|
-
|
|
92
|
+
*/ copy() {
|
|
93
|
+
let res = new $84802bfc2c93a467$export$7e0eeb9da702a085(this.type, this.key, this.rect.copy());
|
|
94
|
+
res.estimatedSize = this.estimatedSize;
|
|
95
|
+
res.opacity = this.opacity;
|
|
96
|
+
res.transform = this.transform;
|
|
97
|
+
res.parentKey = this.parentKey;
|
|
98
|
+
res.isSticky = this.isSticky;
|
|
99
|
+
res.zIndex = this.zIndex;
|
|
100
|
+
res.allowOverflow = this.allowOverflow;
|
|
101
|
+
return res;
|
|
102
|
+
}
|
|
208
103
|
}
|
|
209
|
-
export class Point {
|
|
210
|
-
/** The x-coordinate of the point. */
|
|
211
104
|
|
|
212
|
-
/** The y-coordinate of the point. */
|
|
213
|
-
constructor(x, y) {
|
|
214
|
-
if (x === void 0) {
|
|
215
|
-
x = 0;
|
|
216
|
-
}
|
|
217
105
|
|
|
218
|
-
|
|
219
|
-
y = 0;
|
|
220
|
-
}
|
|
106
|
+
var $412cc72545c8d16d$exports = {};
|
|
221
107
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
108
|
+
$parcel$export($412cc72545c8d16d$exports, "Point", () => $412cc72545c8d16d$export$baf26146a414f24a);
|
|
109
|
+
class $412cc72545c8d16d$export$baf26146a414f24a {
|
|
110
|
+
constructor(x = 0, y = 0){
|
|
111
|
+
this.x = x;
|
|
112
|
+
this.y = y;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
228
115
|
* Returns a copy of this point.
|
|
229
|
-
*/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return new Point(this.x, this.y);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
116
|
+
*/ copy() {
|
|
117
|
+
return new $412cc72545c8d16d$export$baf26146a414f24a(this.x, this.y);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
236
120
|
* Checks if two points are equal.
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return this.x === point.x && this.y === point.y;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
121
|
+
*/ equals(point) {
|
|
122
|
+
return this.x === point.x && this.y === point.y;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
244
125
|
* Returns true if this point is the origin.
|
|
245
|
-
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
isOrigin() {
|
|
249
|
-
return this.x === 0 && this.y === 0;
|
|
250
|
-
}
|
|
251
|
-
|
|
126
|
+
*/ isOrigin() {
|
|
127
|
+
return this.x === 0 && this.y === 0;
|
|
128
|
+
}
|
|
252
129
|
}
|
|
253
130
|
|
|
254
|
-
/**
|
|
255
|
-
* Represents a rectangle.
|
|
256
|
-
*/
|
|
257
|
-
export class Rect {
|
|
258
|
-
/** The x-coordinate of the rectangle. */
|
|
259
|
-
|
|
260
|
-
/** The y-coordinate of the rectangle. */
|
|
261
|
-
|
|
262
|
-
/** The width of the rectangle. */
|
|
263
131
|
|
|
264
|
-
|
|
265
|
-
constructor(x, y, width, height) {
|
|
266
|
-
if (x === void 0) {
|
|
267
|
-
x = 0;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (y === void 0) {
|
|
271
|
-
y = 0;
|
|
272
|
-
}
|
|
132
|
+
var $159dcb078ef84557$exports = {};
|
|
273
133
|
|
|
274
|
-
|
|
275
|
-
width = 0;
|
|
276
|
-
}
|
|
134
|
+
$parcel$export($159dcb078ef84557$exports, "Rect", () => $159dcb078ef84557$export$c79fc6492f3af13d);
|
|
277
135
|
|
|
278
|
-
|
|
279
|
-
|
|
136
|
+
class $159dcb078ef84557$export$c79fc6492f3af13d {
|
|
137
|
+
constructor(x = 0, y = 0, width = 0, height = 0){
|
|
138
|
+
this.x = x;
|
|
139
|
+
this.y = y;
|
|
140
|
+
this.width = width;
|
|
141
|
+
this.height = height;
|
|
280
142
|
}
|
|
281
|
-
|
|
282
|
-
this.x = void 0;
|
|
283
|
-
this.y = void 0;
|
|
284
|
-
this.width = void 0;
|
|
285
|
-
this.height = void 0;
|
|
286
|
-
this.x = x;
|
|
287
|
-
this.y = y;
|
|
288
|
-
this.width = width;
|
|
289
|
-
this.height = height;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
143
|
+
/**
|
|
292
144
|
* The maximum x-coordinate in the rectangle.
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return this.x + this.width;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
145
|
+
*/ get maxX() {
|
|
146
|
+
return this.x + this.width;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
300
149
|
* The maximum y-coordinate in the rectangle.
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
return this.y + this.height;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
150
|
+
*/ get maxY() {
|
|
151
|
+
return this.y + this.height;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
308
154
|
* The area of the rectangle.
|
|
309
|
-
*/
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return this.width * this.height;
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
155
|
+
*/ get area() {
|
|
156
|
+
return this.width * this.height;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
316
159
|
* The top left corner of the rectangle.
|
|
317
|
-
*/
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
return new Point(this.x, this.y);
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
160
|
+
*/ get topLeft() {
|
|
161
|
+
return new $412cc72545c8d16d$export$baf26146a414f24a(this.x, this.y);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
324
164
|
* The top right corner of the rectangle.
|
|
325
|
-
*/
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return new Point(this.maxX, this.y);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
165
|
+
*/ get topRight() {
|
|
166
|
+
return new $412cc72545c8d16d$export$baf26146a414f24a(this.maxX, this.y);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
332
169
|
* The bottom left corner of the rectangle.
|
|
333
|
-
*/
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return new Point(this.x, this.maxY);
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
170
|
+
*/ get bottomLeft() {
|
|
171
|
+
return new $412cc72545c8d16d$export$baf26146a414f24a(this.x, this.maxY);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
340
174
|
* The bottom right corner of the rectangle.
|
|
341
|
-
*/
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return new Point(this.maxX, this.maxY);
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
175
|
+
*/ get bottomRight() {
|
|
176
|
+
return new $412cc72545c8d16d$export$baf26146a414f24a(this.maxX, this.maxY);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
348
179
|
* Returns whether this rectangle intersects another rectangle.
|
|
349
180
|
* @param rect - The rectangle to check.
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
return this.x <= rect.x + rect.width && rect.x <= this.x + this.width && this.y <= rect.y + rect.height && rect.y <= this.y + this.height;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
181
|
+
*/ intersects(rect) {
|
|
182
|
+
return this.x <= rect.x + rect.width && rect.x <= this.x + this.width && this.y <= rect.y + rect.height && rect.y <= this.y + this.height;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
357
185
|
* Returns whether this rectangle fully contains another rectangle.
|
|
358
186
|
* @param rect - The rectangle to check.
|
|
359
|
-
*/
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return this.x <= rect.x && this.y <= rect.y && this.maxX >= rect.maxX && this.maxY >= rect.maxY;
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
187
|
+
*/ containsRect(rect) {
|
|
188
|
+
return this.x <= rect.x && this.y <= rect.y && this.maxX >= rect.maxX && this.maxY >= rect.maxY;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
366
191
|
* Returns whether the rectangle contains the given point.
|
|
367
192
|
* @param point - The point to check.
|
|
368
|
-
*/
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return this.x <= point.x && this.y <= point.y && this.maxX >= point.x && this.maxY >= point.y;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
193
|
+
*/ containsPoint(point) {
|
|
194
|
+
return this.x <= point.x && this.y <= point.y && this.maxX >= point.x && this.maxY >= point.y;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
375
197
|
* Returns the first corner of this rectangle (from top to bottom, left to right)
|
|
376
198
|
* that is contained in the given rectangle, or null of the rectangles do not intersect.
|
|
377
199
|
* @param rect - The rectangle to check.
|
|
378
|
-
*/
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
200
|
+
*/ getCornerInRect(rect) {
|
|
201
|
+
for (let key of [
|
|
202
|
+
'topLeft',
|
|
203
|
+
'topRight',
|
|
204
|
+
'bottomLeft',
|
|
205
|
+
'bottomRight'
|
|
206
|
+
]){
|
|
207
|
+
if (rect.containsPoint(this[key])) return key;
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
386
210
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
sizeEquals(size) {
|
|
400
|
-
return this.width === size.width && this.height === size.height;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
211
|
+
equals(rect) {
|
|
212
|
+
return rect.x === this.x && rect.y === this.y && rect.width === this.width && rect.height === this.height;
|
|
213
|
+
}
|
|
214
|
+
pointEquals(point) {
|
|
215
|
+
return this.x === point.x && this.y === point.y;
|
|
216
|
+
}
|
|
217
|
+
sizeEquals(size) {
|
|
218
|
+
return this.width === size.width && this.height === size.height;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
403
221
|
* Returns a copy of this rectangle.
|
|
404
|
-
*/
|
|
405
|
-
|
|
222
|
+
*/ copy() {
|
|
223
|
+
return new $159dcb078ef84557$export$c79fc6492f3af13d(this.x, this.y, this.width, this.height);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
406
226
|
|
|
407
|
-
copy() {
|
|
408
|
-
return new Rect(this.x, this.y, this.width, this.height);
|
|
409
|
-
}
|
|
410
227
|
|
|
411
|
-
}
|
|
412
|
-
export class Size {
|
|
413
|
-
constructor(width, height) {
|
|
414
|
-
if (width === void 0) {
|
|
415
|
-
width = 0;
|
|
416
|
-
}
|
|
228
|
+
var $22e89a13b0a391cf$exports = {};
|
|
417
229
|
|
|
418
|
-
|
|
419
|
-
|
|
230
|
+
$parcel$export($22e89a13b0a391cf$exports, "Size", () => $22e89a13b0a391cf$export$cb6da89c6af1a8ec);
|
|
231
|
+
class $22e89a13b0a391cf$export$cb6da89c6af1a8ec {
|
|
232
|
+
constructor(width = 0, height = 0){
|
|
233
|
+
this.width = width;
|
|
234
|
+
this.height = height;
|
|
420
235
|
}
|
|
421
|
-
|
|
422
|
-
this.width = void 0;
|
|
423
|
-
this.height = void 0;
|
|
424
|
-
this.width = width;
|
|
425
|
-
this.height = height;
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
236
|
+
/**
|
|
428
237
|
* Returns a copy of this size.
|
|
429
|
-
*/
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
return new Size(this.width, this.height);
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
238
|
+
*/ copy() {
|
|
239
|
+
return new $22e89a13b0a391cf$export$cb6da89c6af1a8ec(this.width, this.height);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
436
242
|
* Returns whether this size is equal to another one.
|
|
437
|
-
*/
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
equals(other) {
|
|
441
|
-
return this.width === other.width && this.height === other.height;
|
|
442
|
-
}
|
|
443
|
-
|
|
243
|
+
*/ equals(other) {
|
|
244
|
+
return this.width === other.width && this.height === other.height;
|
|
245
|
+
}
|
|
444
246
|
}
|
|
445
|
-
let $db50d694530b1570aea7db33f212f7$var$KEY = 0;
|
|
446
|
-
/**
|
|
447
|
-
* [CollectionView]{@link CollectionView} creates instances of the [ReusableView]{@link ReusableView} class to
|
|
448
|
-
* represent views currently being displayed. ReusableViews manage a DOM node, handle
|
|
449
|
-
* applying {@link LayoutInfo} objects to the view, and render content
|
|
450
|
-
* as needed. Subclasses must implement the {@link render} method at a
|
|
451
|
-
* minimum. Other methods can be overridden to customize behavior.
|
|
452
|
-
*/
|
|
453
247
|
|
|
454
|
-
export class ReusableView {
|
|
455
|
-
/** The CollectionVirtualizer this view is a part of. */
|
|
456
248
|
|
|
457
|
-
|
|
249
|
+
var $4287aeba6cd94157$exports = {};
|
|
458
250
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
this.virtualizer = virtualizer;
|
|
468
|
-
this.key = ++$db50d694530b1570aea7db33f212f7$var$KEY;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
251
|
+
$parcel$export($4287aeba6cd94157$exports, "ReusableView", () => $4287aeba6cd94157$export$1a5223887c560441);
|
|
252
|
+
let $4287aeba6cd94157$var$KEY = 0;
|
|
253
|
+
class $4287aeba6cd94157$export$1a5223887c560441 {
|
|
254
|
+
constructor(virtualizer){
|
|
255
|
+
this.virtualizer = virtualizer;
|
|
256
|
+
this.key = ++$4287aeba6cd94157$var$KEY;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
471
259
|
* Prepares the view for reuse. Called just before the view is removed from the DOM.
|
|
472
|
-
*/
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
this.rendered = null;
|
|
478
|
-
this.layoutInfo = null;
|
|
479
|
-
}
|
|
480
|
-
|
|
260
|
+
*/ prepareForReuse() {
|
|
261
|
+
this.content = null;
|
|
262
|
+
this.rendered = null;
|
|
263
|
+
this.layoutInfo = null;
|
|
264
|
+
}
|
|
481
265
|
}
|
|
482
|
-
// use high res timer if available
|
|
483
|
-
let $ea7b4dd250709a616043c0e9cf5f62a$var$perf = typeof window !== 'undefined' ? window.performance : null; // @ts-ignore
|
|
484
266
|
|
|
485
|
-
let $ea7b4dd250709a616043c0e9cf5f62a$var$perfNow = $ea7b4dd250709a616043c0e9cf5f62a$var$perf && ($ea7b4dd250709a616043c0e9cf5f62a$var$perf.now || $ea7b4dd250709a616043c0e9cf5f62a$var$perf.webkitNow || $ea7b4dd250709a616043c0e9cf5f62a$var$perf.msNow || $ea7b4dd250709a616043c0e9cf5f62a$var$perf.mozNow);
|
|
486
|
-
let $ea7b4dd250709a616043c0e9cf5f62a$var$getTime = $ea7b4dd250709a616043c0e9cf5f62a$var$perfNow ? $ea7b4dd250709a616043c0e9cf5f62a$var$perfNow.bind($ea7b4dd250709a616043c0e9cf5f62a$var$perf) : function () {
|
|
487
|
-
return Date.now ? Date.now() : new Date().getTime();
|
|
488
|
-
};
|
|
489
|
-
let $ea7b4dd250709a616043c0e9cf5f62a$var$fixTs;
|
|
490
267
|
|
|
491
|
-
|
|
492
|
-
let canceled = false;
|
|
493
|
-
let raf_id;
|
|
494
|
-
let promise = new Promise(resolve => {
|
|
495
|
-
let start = $ea7b4dd250709a616043c0e9cf5f62a$var$getTime();
|
|
496
|
-
let diffX = end.x - begin.x;
|
|
497
|
-
let diffY = end.y - begin.y;
|
|
498
|
-
raf_id = requestAnimationFrame(function run(t) {
|
|
499
|
-
// if we're using a high res timer, make sure timestamp is not the old epoch-based value.
|
|
500
|
-
// http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
|
|
501
|
-
if ($ea7b4dd250709a616043c0e9cf5f62a$var$fixTs == null) {
|
|
502
|
-
$ea7b4dd250709a616043c0e9cf5f62a$var$fixTs = t > 1e12 !== $ea7b4dd250709a616043c0e9cf5f62a$var$getTime() > 1e12;
|
|
503
|
-
}
|
|
268
|
+
var $768d3e68d680b21c$exports = {};
|
|
504
269
|
|
|
505
|
-
|
|
506
|
-
t = $ea7b4dd250709a616043c0e9cf5f62a$var$getTime();
|
|
507
|
-
} // check if we're done
|
|
270
|
+
$parcel$export($768d3e68d680b21c$exports, "useVirtualizerState", () => $768d3e68d680b21c$export$1505db82fe357e65);
|
|
508
271
|
|
|
509
272
|
|
|
510
|
-
let delta = t - start;
|
|
511
273
|
|
|
512
|
-
if (delta > duration) {
|
|
513
|
-
fn(end);
|
|
514
|
-
resolve();
|
|
515
|
-
} else {
|
|
516
|
-
// call frame callback after computing eased time and get the next frame
|
|
517
|
-
let proceed = fn(new Point(begin.x + diffX * ease(delta / duration), begin.y + diffY * ease(delta / duration)));
|
|
518
274
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
275
|
+
// use high res timer if available
|
|
276
|
+
let $6a9b8d711ba49ea7$var$perf = typeof window !== 'undefined' ? window.performance : null;
|
|
277
|
+
// @ts-ignore
|
|
278
|
+
let $6a9b8d711ba49ea7$var$perfNow = $6a9b8d711ba49ea7$var$perf && ($6a9b8d711ba49ea7$var$perf.now || $6a9b8d711ba49ea7$var$perf.webkitNow || $6a9b8d711ba49ea7$var$perf.msNow || $6a9b8d711ba49ea7$var$perf.mozNow);
|
|
279
|
+
let $6a9b8d711ba49ea7$var$getTime = $6a9b8d711ba49ea7$var$perfNow ? $6a9b8d711ba49ea7$var$perfNow.bind($6a9b8d711ba49ea7$var$perf) : function() {
|
|
280
|
+
return Date.now ? Date.now() : new Date().getTime();
|
|
281
|
+
};
|
|
282
|
+
let $6a9b8d711ba49ea7$var$fixTs;
|
|
283
|
+
function $6a9b8d711ba49ea7$export$dc0b63720788090c(begin, end, duration, ease, fn) {
|
|
284
|
+
let canceled = false;
|
|
285
|
+
let raf_id;
|
|
286
|
+
let promise = new Promise((resolve)=>{
|
|
287
|
+
let start = $6a9b8d711ba49ea7$var$getTime();
|
|
288
|
+
let diffX = end.x - begin.x;
|
|
289
|
+
let diffY = end.y - begin.y;
|
|
290
|
+
raf_id = requestAnimationFrame(function run(t) {
|
|
291
|
+
// if we're using a high res timer, make sure timestamp is not the old epoch-based value.
|
|
292
|
+
// http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision
|
|
293
|
+
if ($6a9b8d711ba49ea7$var$fixTs == null) $6a9b8d711ba49ea7$var$fixTs = t > 1000000000000 !== $6a9b8d711ba49ea7$var$getTime() > 1000000000000;
|
|
294
|
+
if ($6a9b8d711ba49ea7$var$fixTs) t = $6a9b8d711ba49ea7$var$getTime();
|
|
295
|
+
// check if we're done
|
|
296
|
+
let delta = t - start;
|
|
297
|
+
if (delta > duration) {
|
|
298
|
+
fn(end);
|
|
299
|
+
resolve();
|
|
300
|
+
} else {
|
|
301
|
+
// call frame callback after computing eased time and get the next frame
|
|
302
|
+
let proceed = fn(new $412cc72545c8d16d$export$baf26146a414f24a(begin.x + diffX * ease(delta / duration), begin.y + diffY * ease(delta / duration)));
|
|
303
|
+
if (proceed !== false && !canceled) raf_id = requestAnimationFrame(run);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
523
306
|
});
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
return promise;
|
|
532
|
-
} // easing functions
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
function $ea7b4dd250709a616043c0e9cf5f62a$export$easeOut(t) {
|
|
536
|
-
return Math.sin(t * Math.PI / 2);
|
|
307
|
+
promise.cancel = function() {
|
|
308
|
+
canceled = true;
|
|
309
|
+
cancelAnimationFrame(raf_id);
|
|
310
|
+
};
|
|
311
|
+
return promise;
|
|
537
312
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
let res = new Set();
|
|
541
|
-
|
|
542
|
-
for (let key of a.keys()) {
|
|
543
|
-
if (!b.has(key)) {
|
|
544
|
-
res.add(key);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
return res;
|
|
313
|
+
function $6a9b8d711ba49ea7$export$77860c106b4a6a2e(t) {
|
|
314
|
+
return t;
|
|
549
315
|
}
|
|
550
|
-
|
|
551
|
-
*
|
|
552
|
-
* keys to add to and remove from a to make it equal to b.
|
|
553
|
-
* @private
|
|
554
|
-
*/
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
function $e73002b1b269f5d359247972bfd09$export$difference(a, b) {
|
|
558
|
-
let toRemove = $e73002b1b269f5d359247972bfd09$export$keyDiff(a, b);
|
|
559
|
-
let toAdd = $e73002b1b269f5d359247972bfd09$export$keyDiff(b, a);
|
|
560
|
-
let toUpdate = new Set();
|
|
561
|
-
|
|
562
|
-
for (let key of a.keys()) {
|
|
563
|
-
if (b.has(key)) {
|
|
564
|
-
toUpdate.add(key);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return {
|
|
569
|
-
toRemove,
|
|
570
|
-
toAdd,
|
|
571
|
-
toUpdate
|
|
572
|
-
};
|
|
316
|
+
function $6a9b8d711ba49ea7$export$57636bb43b1ccbb0(t) {
|
|
317
|
+
return Math.sin(t * Math.PI / 2);
|
|
573
318
|
}
|
|
574
|
-
/**
|
|
575
|
-
* Returns an iterator that yields the items in all of the given iterators.
|
|
576
|
-
* @private
|
|
577
|
-
*/
|
|
578
319
|
|
|
579
320
|
|
|
580
|
-
function
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
for (let iterator of iterators) {
|
|
586
|
-
yield* iterator;
|
|
587
|
-
}
|
|
321
|
+
function $c984faf4f5b24890$export$37a26b283fd7740e(a, b) {
|
|
322
|
+
let res = new Set();
|
|
323
|
+
for (let key of a.keys())if (!b.has(key)) res.add(key);
|
|
324
|
+
return res;
|
|
588
325
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
326
|
+
function $c984faf4f5b24890$export$acaf96a27438246b(a, b) {
|
|
327
|
+
let toRemove = $c984faf4f5b24890$export$37a26b283fd7740e(a, b);
|
|
328
|
+
let toAdd = $c984faf4f5b24890$export$37a26b283fd7740e(b, a);
|
|
329
|
+
let toUpdate = new Set;
|
|
330
|
+
for (let key of a.keys())if (b.has(key)) toUpdate.add(key);
|
|
331
|
+
return {
|
|
332
|
+
toRemove: toRemove,
|
|
333
|
+
toAdd: toAdd,
|
|
334
|
+
toUpdate: toUpdate
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function* $c984faf4f5b24890$export$cfc14088dfefce5f(...iterators) {
|
|
338
|
+
for (let iterator of iterators)yield* iterator;
|
|
339
|
+
}
|
|
340
|
+
function $c984faf4f5b24890$export$6897c284b6f9f4dc(object) {
|
|
341
|
+
let res = {
|
|
342
|
+
};
|
|
343
|
+
for(let key in object)res[object[key]] = key;
|
|
344
|
+
return res;
|
|
606
345
|
}
|
|
607
346
|
|
|
608
|
-
class $e15f96b53dee9114a5d189b4490e08b$export$OverscanManager {
|
|
609
|
-
constructor() {
|
|
610
|
-
this.startTime = 0;
|
|
611
|
-
this.averagePerf = new $e15f96b53dee9114a5d189b4490e08b$var$RollingAverage();
|
|
612
|
-
this.averageTime = new $e15f96b53dee9114a5d189b4490e08b$var$RollingAverage();
|
|
613
|
-
this.velocity = new Point(5, 5);
|
|
614
|
-
this.overscanX = new $e15f96b53dee9114a5d189b4490e08b$var$RollingAverage();
|
|
615
|
-
this.overscanY = new $e15f96b53dee9114a5d189b4490e08b$var$RollingAverage();
|
|
616
|
-
this.visibleRect = new Rect();
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
setVisibleRect(rect) {
|
|
620
|
-
let time = performance.now() - this.startTime;
|
|
621
|
-
|
|
622
|
-
if (time < 500) {
|
|
623
|
-
this.averageTime.addSample(time);
|
|
624
|
-
|
|
625
|
-
if (rect.x !== this.visibleRect.x && time > 0) {
|
|
626
|
-
this.velocity.x = (rect.x - this.visibleRect.x) / time;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
if (rect.y !== this.visibleRect.y && time > 0) {
|
|
630
|
-
this.velocity.y = (rect.y - this.visibleRect.y) / time;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
347
|
|
|
634
|
-
this.startTime = performance.now();
|
|
635
|
-
this.visibleRect = rect;
|
|
636
|
-
}
|
|
637
348
|
|
|
638
|
-
collectMetrics() {
|
|
639
|
-
let time = performance.now() - this.startTime;
|
|
640
349
|
|
|
641
|
-
|
|
642
|
-
|
|
350
|
+
class $ffa819e9899a870b$var$RollingAverage {
|
|
351
|
+
addSample(sample) {
|
|
352
|
+
this.count++;
|
|
353
|
+
this.value += (sample - this.value) / this.count;
|
|
643
354
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
this.overscanY.addSample(o);
|
|
355
|
+
constructor(){
|
|
356
|
+
this.count = 0;
|
|
357
|
+
this.value = 0;
|
|
648
358
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
359
|
+
}
|
|
360
|
+
class $ffa819e9899a870b$export$4455ee6afb38dcbb {
|
|
361
|
+
setVisibleRect(rect) {
|
|
362
|
+
let time = performance.now() - this.startTime;
|
|
363
|
+
if (time < 500) {
|
|
364
|
+
this.averageTime.addSample(time);
|
|
365
|
+
if (rect.x !== this.visibleRect.x && time > 0) this.velocity.x = (rect.x - this.visibleRect.x) / time;
|
|
366
|
+
if (rect.y !== this.visibleRect.y && time > 0) this.velocity.y = (rect.y - this.visibleRect.y) / time;
|
|
367
|
+
}
|
|
368
|
+
this.startTime = performance.now();
|
|
369
|
+
this.visibleRect = rect;
|
|
370
|
+
}
|
|
371
|
+
collectMetrics() {
|
|
372
|
+
let time = performance.now() - this.startTime;
|
|
373
|
+
if (time < 500) this.averagePerf.addSample(time);
|
|
374
|
+
if (this.visibleRect.height > 0) {
|
|
375
|
+
let o = Math.abs(this.velocity.y * (this.averageTime.value + this.averagePerf.value));
|
|
376
|
+
this.overscanY.addSample(o);
|
|
377
|
+
}
|
|
378
|
+
if (this.visibleRect.width > 0) {
|
|
379
|
+
let o = Math.abs(this.velocity.x * (this.averageTime.value + this.averagePerf.value));
|
|
380
|
+
this.overscanX.addSample(o);
|
|
381
|
+
}
|
|
653
382
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
383
|
+
getOverscannedRect() {
|
|
384
|
+
let overscanned = this.visibleRect.copy();
|
|
385
|
+
let overscanY = Math.round(Math.min(this.visibleRect.height * 2, this.overscanY.value) / 100) * 100;
|
|
386
|
+
if (this.velocity.y > 0) {
|
|
387
|
+
overscanned.y -= overscanY * 0.2;
|
|
388
|
+
overscanned.height += overscanY + overscanY * 0.2;
|
|
389
|
+
} else {
|
|
390
|
+
overscanned.y -= overscanY;
|
|
391
|
+
overscanned.height += overscanY + overscanY * 0.2;
|
|
392
|
+
}
|
|
393
|
+
let overscanX = Math.round(Math.min(this.visibleRect.width * 2, this.overscanX.value) / 100) * 100;
|
|
394
|
+
if (this.velocity.x > 0) {
|
|
395
|
+
overscanned.x -= overscanX * 0.2;
|
|
396
|
+
overscanned.width += overscanX + overscanX * 0.2;
|
|
397
|
+
} else {
|
|
398
|
+
overscanned.x -= overscanX;
|
|
399
|
+
overscanned.width += overscanX + overscanX * 0.2;
|
|
400
|
+
}
|
|
401
|
+
return overscanned;
|
|
666
402
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
overscanned.width += overscanX + overscanX * 0.2;
|
|
403
|
+
constructor(){
|
|
404
|
+
this.startTime = 0;
|
|
405
|
+
this.averagePerf = new $ffa819e9899a870b$var$RollingAverage();
|
|
406
|
+
this.averageTime = new $ffa819e9899a870b$var$RollingAverage();
|
|
407
|
+
this.velocity = new $412cc72545c8d16d$export$baf26146a414f24a(5, 5);
|
|
408
|
+
this.overscanX = new $ffa819e9899a870b$var$RollingAverage();
|
|
409
|
+
this.overscanY = new $ffa819e9899a870b$var$RollingAverage();
|
|
410
|
+
this.visibleRect = new $159dcb078ef84557$export$c79fc6492f3af13d();
|
|
676
411
|
}
|
|
677
|
-
|
|
678
|
-
return overscanned;
|
|
679
|
-
}
|
|
680
|
-
|
|
681
412
|
}
|
|
682
413
|
|
|
683
|
-
class $ab2c59ad03985fabe3061564f2$export$Transaction {
|
|
684
|
-
constructor() {
|
|
685
|
-
this.level = 0;
|
|
686
|
-
this.actions = [];
|
|
687
|
-
this.animated = true;
|
|
688
|
-
this.initialMap = new Map();
|
|
689
|
-
this.finalMap = new Map();
|
|
690
|
-
this.initialLayoutInfo = new Map();
|
|
691
|
-
this.finalLayoutInfo = new Map();
|
|
692
|
-
this.removed = new Map();
|
|
693
|
-
this.toRemove = new Map();
|
|
694
|
-
}
|
|
695
414
|
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
/**
|
|
699
|
-
* The CollectionView class renders a scrollable collection of data using customizable layouts,
|
|
700
|
-
* and manages animated updates to the data over time. It supports very large collections by
|
|
701
|
-
* only rendering visible views to the DOM, reusing them as you scroll. Collection views can
|
|
702
|
-
* present any type of view, including non-item views such as section headers and footers.
|
|
703
|
-
* Optionally, the {@link EditableCollectionView} subclass can be used to enable user interaction
|
|
704
|
-
* with the collection, including drag and drop, multiple selection, and keyboard interacton.
|
|
705
|
-
*
|
|
706
|
-
* Collection views get their data from a {@link DataSource} object that you provide. Items are
|
|
707
|
-
* grouped into sections by the data source, and the collection view calls its methods to retrieve
|
|
708
|
-
* the data. When data changes, the data source emits change events, and the collection view
|
|
709
|
-
* updates as appropriate, optionally with an animated transition. There is one built-in data source
|
|
710
|
-
* implementation, {@link ArrayDataSource}, which renders content from a 2d array.
|
|
711
|
-
*
|
|
712
|
-
* Collection views use {@link Layout} objects to compute what views should be visible, and how
|
|
713
|
-
* to position and style them. This means that collection views can have their items arranged in
|
|
714
|
-
* a stack, a grid, a circle, or any other layout you can think of. The layout can be changed
|
|
715
|
-
* dynamically at runtime as well, optionally with an animated transition between the layouts.
|
|
716
|
-
*
|
|
717
|
-
* Layouts produce information on what views should appear in the collection view, but do not create
|
|
718
|
-
* the views themselves directly. It is the responsibility of the {@link CollectionViewDelegate} object
|
|
719
|
-
* to create instances of {@link ReusableView} subclasses which render the items into DOM nodes.
|
|
720
|
-
* The delegate determines what type of view to display for each item, and creates instances of
|
|
721
|
-
* views as needed by the collection view. Those views are then reused by the collection view as
|
|
722
|
-
* the user scrolls through the content.
|
|
723
|
-
*/
|
|
724
|
-
class $d389afd47bc06952d9e630a237a8$export$Virtualizer {
|
|
725
|
-
/**
|
|
726
|
-
* The collection view delegate. The delegate is used by the collection view
|
|
727
|
-
* to create and configure views.
|
|
728
|
-
*/
|
|
729
|
-
|
|
730
|
-
/** The duration of animated layout changes, in milliseconds. Default is 500ms. */
|
|
731
|
-
|
|
732
|
-
/**
|
|
733
|
-
* Whether to enable scroll anchoring. This will attempt to restore the scroll position
|
|
734
|
-
* after layout changes outside the viewport. Default is off.
|
|
735
|
-
*/
|
|
736
415
|
|
|
737
|
-
/** Whether to anchor the scroll position when at the top of the content. Default is off. */
|
|
738
416
|
|
|
739
|
-
/**
|
|
740
|
-
* Whether to overscan the visible area to pre-render items slightly outside and
|
|
741
|
-
* improve performance. Default is on.
|
|
742
|
-
*/
|
|
743
|
-
constructor(options) {
|
|
744
|
-
var _options$transitionDu;
|
|
745
417
|
|
|
746
|
-
if (options === void 0) {
|
|
747
|
-
options = {};
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
this.delegate = void 0;
|
|
751
|
-
this.transitionDuration = void 0;
|
|
752
|
-
this.anchorScrollPosition = void 0;
|
|
753
|
-
this.anchorScrollPositionAtTop = void 0;
|
|
754
|
-
this.shouldOverscan = void 0;
|
|
755
|
-
this._collection = void 0;
|
|
756
|
-
this._layout = void 0;
|
|
757
|
-
this._contentSize = void 0;
|
|
758
|
-
this._visibleRect = void 0;
|
|
759
|
-
this._visibleLayoutInfos = void 0;
|
|
760
|
-
this._reusableViews = void 0;
|
|
761
|
-
this._visibleViews = void 0;
|
|
762
|
-
this._renderedContent = void 0;
|
|
763
|
-
this._children = void 0;
|
|
764
|
-
this._invalidationContext = void 0;
|
|
765
|
-
this._overscanManager = void 0;
|
|
766
|
-
this._relayoutRaf = void 0;
|
|
767
|
-
this._scrollAnimation = void 0;
|
|
768
|
-
this._isScrolling = void 0;
|
|
769
|
-
this._sizeUpdateQueue = void 0;
|
|
770
|
-
this._animatedContentOffset = void 0;
|
|
771
|
-
this._transaction = void 0;
|
|
772
|
-
this._nextTransaction = void 0;
|
|
773
|
-
this._transactionQueue = void 0;
|
|
774
|
-
this._contentSize = new Size();
|
|
775
|
-
this._visibleRect = new Rect();
|
|
776
|
-
this._reusableViews = {};
|
|
777
|
-
this._visibleLayoutInfos = new Map();
|
|
778
|
-
this._visibleViews = new Map();
|
|
779
|
-
this._renderedContent = new WeakMap();
|
|
780
|
-
this._children = new Set();
|
|
781
|
-
this._invalidationContext = null;
|
|
782
|
-
this._overscanManager = new $e15f96b53dee9114a5d189b4490e08b$export$OverscanManager();
|
|
783
|
-
this._scrollAnimation = null;
|
|
784
|
-
this._isScrolling = false;
|
|
785
|
-
this._sizeUpdateQueue = new Map();
|
|
786
|
-
this._animatedContentOffset = new Point(0, 0);
|
|
787
|
-
this._transaction = null;
|
|
788
|
-
this._nextTransaction = null;
|
|
789
|
-
this._transactionQueue = []; // Set options from passed object if given
|
|
790
418
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
this
|
|
799
|
-
|
|
419
|
+
class $6b14b0a55eb74a2c$export$febc5573c75cefb0 {
|
|
420
|
+
constructor(){
|
|
421
|
+
this.level = 0;
|
|
422
|
+
this.actions = [];
|
|
423
|
+
this.animated = true;
|
|
424
|
+
this.initialMap = new Map();
|
|
425
|
+
this.finalMap = new Map();
|
|
426
|
+
this.initialLayoutInfo = new Map();
|
|
427
|
+
this.finalLayoutInfo = new Map();
|
|
428
|
+
this.removed = new Map();
|
|
429
|
+
this.toRemove = new Map();
|
|
800
430
|
}
|
|
801
|
-
|
|
431
|
+
}
|
|
802
432
|
|
|
803
|
-
_setContentSize(size) {
|
|
804
|
-
this._contentSize = size;
|
|
805
|
-
this.delegate.setContentSize(size);
|
|
806
|
-
}
|
|
807
433
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
434
|
+
class $db9fd92d994d4bf6$export$89be5a243e59c4b2 {
|
|
435
|
+
constructor(options = {
|
|
436
|
+
}){
|
|
437
|
+
this._contentSize = new $22e89a13b0a391cf$export$cb6da89c6af1a8ec;
|
|
438
|
+
this._visibleRect = new $159dcb078ef84557$export$c79fc6492f3af13d;
|
|
439
|
+
this._reusableViews = {
|
|
440
|
+
};
|
|
441
|
+
this._visibleLayoutInfos = new Map();
|
|
442
|
+
this._visibleViews = new Map();
|
|
443
|
+
this._renderedContent = new WeakMap();
|
|
444
|
+
this._children = new Set();
|
|
445
|
+
this._invalidationContext = null;
|
|
446
|
+
this._overscanManager = new $ffa819e9899a870b$export$4455ee6afb38dcbb();
|
|
447
|
+
this._scrollAnimation = null;
|
|
448
|
+
this._isScrolling = false;
|
|
449
|
+
this._sizeUpdateQueue = new Map();
|
|
450
|
+
this._animatedContentOffset = new $412cc72545c8d16d$export$baf26146a414f24a(0, 0);
|
|
451
|
+
this._transaction = null;
|
|
452
|
+
this._nextTransaction = null;
|
|
453
|
+
this._transactionQueue = [];
|
|
454
|
+
// Set options from passed object if given
|
|
455
|
+
this.transitionDuration = options.transitionDuration ?? 500;
|
|
456
|
+
this.anchorScrollPosition = options.anchorScrollPosition || false;
|
|
457
|
+
this.anchorScrollPositionAtTop = options.anchorScrollPositionAtTop || false;
|
|
458
|
+
this.shouldOverscan = options.shouldOverscan !== false;
|
|
459
|
+
for (let key of [
|
|
460
|
+
'delegate',
|
|
461
|
+
'size',
|
|
462
|
+
'layout',
|
|
463
|
+
'collection'
|
|
464
|
+
])if (options[key]) this[key] = options[key];
|
|
465
|
+
}
|
|
466
|
+
_setContentSize(size) {
|
|
467
|
+
this._contentSize = size;
|
|
468
|
+
this.delegate.setContentSize(size);
|
|
469
|
+
}
|
|
470
|
+
_setContentOffset(offset) {
|
|
471
|
+
let rect = new $159dcb078ef84557$export$c79fc6492f3af13d(offset.x, offset.y, this._visibleRect.width, this._visibleRect.height);
|
|
472
|
+
this.delegate.setVisibleRect(rect);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
813
475
|
* Get the size of the scrollable content.
|
|
814
|
-
*/
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
get contentSize() {
|
|
818
|
-
return this._contentSize;
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Get the collection view's currently visible rectangle.
|
|
822
|
-
*/
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
get visibleRect() {
|
|
826
|
-
return this._visibleRect;
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* Set the collection view's currently visible rectangle.
|
|
830
|
-
*/
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
set visibleRect(rect) {
|
|
834
|
-
this._setVisibleRect(rect);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
_setVisibleRect(rect, forceUpdate) {
|
|
838
|
-
if (forceUpdate === void 0) {
|
|
839
|
-
forceUpdate = false;
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
let current = this._visibleRect; // Ignore if the rects are equal
|
|
843
|
-
|
|
844
|
-
if (rect.equals(current)) {
|
|
845
|
-
return;
|
|
476
|
+
*/ get contentSize() {
|
|
477
|
+
return this._contentSize;
|
|
846
478
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
479
|
+
/**
|
|
480
|
+
* Get the collection view's currently visible rectangle.
|
|
481
|
+
*/ get visibleRect() {
|
|
482
|
+
return this._visibleRect;
|
|
850
483
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
484
|
+
/**
|
|
485
|
+
* Set the collection view's currently visible rectangle.
|
|
486
|
+
*/ set visibleRect(rect) {
|
|
487
|
+
this._setVisibleRect(rect);
|
|
488
|
+
}
|
|
489
|
+
_setVisibleRect(rect, forceUpdate = false) {
|
|
490
|
+
let current = this._visibleRect;
|
|
491
|
+
// Ignore if the rects are equal
|
|
492
|
+
if (rect.equals(current)) return;
|
|
493
|
+
if (this.shouldOverscan) this._overscanManager.setVisibleRect(rect);
|
|
494
|
+
let shouldInvalidate = this.layout && this.layout.shouldInvalidate(rect, this._visibleRect);
|
|
495
|
+
this._resetAnimatedContentOffset();
|
|
496
|
+
this._visibleRect = rect;
|
|
497
|
+
if (shouldInvalidate) this.relayout({
|
|
498
|
+
offsetChanged: !rect.pointEquals(current),
|
|
499
|
+
sizeChanged: !rect.sizeEquals(current)
|
|
500
|
+
});
|
|
501
|
+
else this.updateSubviews(forceUpdate);
|
|
502
|
+
}
|
|
503
|
+
get collection() {
|
|
504
|
+
return this._collection;
|
|
505
|
+
}
|
|
506
|
+
set collection(data) {
|
|
507
|
+
this._setData(data);
|
|
508
|
+
}
|
|
509
|
+
_setData(data) {
|
|
510
|
+
if (data === this._collection) return;
|
|
511
|
+
if (this._collection) this._runTransaction(()=>{
|
|
512
|
+
this._collection = data;
|
|
513
|
+
}, this.transitionDuration > 0);
|
|
514
|
+
else {
|
|
515
|
+
this._collection = data;
|
|
516
|
+
this.reloadData();
|
|
517
|
+
}
|
|
879
518
|
}
|
|
880
|
-
|
|
881
|
-
if (this._collection) {
|
|
882
|
-
this._runTransaction(() => {
|
|
883
|
-
this._collection = data;
|
|
884
|
-
}, this.transitionDuration > 0);
|
|
885
|
-
} else {
|
|
886
|
-
this._collection = data;
|
|
887
|
-
this.reloadData();
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
/**
|
|
519
|
+
/**
|
|
891
520
|
* Reloads the data from the data source and relayouts the collection view.
|
|
892
521
|
* Does not animate any changes. Equivalent to re-assigning the same data source
|
|
893
522
|
* to the collection view.
|
|
894
|
-
*/
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
/**
|
|
523
|
+
*/ reloadData() {
|
|
524
|
+
this.relayout({
|
|
525
|
+
contentChanged: true
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
903
529
|
* Returns the item with the given key.
|
|
904
|
-
*/
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
return this._collection ? this._collection.getItem(key) : null;
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
530
|
+
*/ getItem(key) {
|
|
531
|
+
return this._collection ? this._collection.getItem(key) : null;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
911
534
|
* Get the collection view's layout.
|
|
912
|
-
*/
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
return this._layout;
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
535
|
+
*/ get layout() {
|
|
536
|
+
return this._layout;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
919
539
|
* Set the collection view's layout.
|
|
920
|
-
*/
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
this.setLayout(layout);
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
540
|
+
*/ set layout(layout) {
|
|
541
|
+
this.setLayout(layout);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
927
544
|
* Sets the collection view's layout, optionally with an animated transition
|
|
928
545
|
* from the current layout to the new layout.
|
|
929
546
|
* @param layout The layout to switch to.
|
|
930
547
|
* @param animated Whether to animate the layout change.
|
|
931
|
-
*/
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
layout.virtualizer = this;
|
|
950
|
-
this._layout = layout;
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
if (animated) {
|
|
954
|
-
// Animated layout transitions are really simple, thanks to our transaction support.
|
|
955
|
-
// We just set the layout inside a transaction action, which runs after the initial
|
|
956
|
-
// layout infos for the animation are retrieved from the previous layout. Then, the
|
|
957
|
-
// final layout infos are retrieved from the new layout, and animations occur.
|
|
958
|
-
this._runTransaction(applyLayout);
|
|
959
|
-
} else {
|
|
960
|
-
applyLayout();
|
|
961
|
-
this.relayout();
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
_getReuseType(layoutInfo, content) {
|
|
966
|
-
if (layoutInfo.type === 'item' && content) {
|
|
967
|
-
let type = this.delegate.getType ? this.delegate.getType(content) : 'item';
|
|
968
|
-
let reuseType = type === 'item' ? 'item' : layoutInfo.type + '_' + type;
|
|
969
|
-
return {
|
|
970
|
-
type,
|
|
971
|
-
reuseType
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
return {
|
|
976
|
-
type: layoutInfo.type,
|
|
977
|
-
reuseType: layoutInfo.type
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
getReusableView(layoutInfo) {
|
|
982
|
-
let content = this.getItem(layoutInfo.key);
|
|
983
|
-
|
|
984
|
-
let {
|
|
985
|
-
reuseType
|
|
986
|
-
} = this._getReuseType(layoutInfo, content);
|
|
987
|
-
|
|
988
|
-
if (!this._reusableViews[reuseType]) {
|
|
989
|
-
this._reusableViews[reuseType] = [];
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
let reusable = this._reusableViews[reuseType];
|
|
993
|
-
let view = reusable.length > 0 ? reusable.pop() : new ReusableView(this);
|
|
994
|
-
view.viewType = reuseType;
|
|
995
|
-
|
|
996
|
-
if (!this._animatedContentOffset.isOrigin()) {
|
|
997
|
-
layoutInfo = layoutInfo.copy();
|
|
998
|
-
layoutInfo.rect.x += this._animatedContentOffset.x;
|
|
999
|
-
layoutInfo.rect.y += this._animatedContentOffset.y;
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
view.layoutInfo = layoutInfo;
|
|
1003
|
-
|
|
1004
|
-
this._renderView(view);
|
|
1005
|
-
|
|
1006
|
-
return view;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
_renderView(reusableView) {
|
|
1010
|
-
let {
|
|
1011
|
-
type,
|
|
1012
|
-
key
|
|
1013
|
-
} = reusableView.layoutInfo;
|
|
1014
|
-
reusableView.content = this.getItem(key);
|
|
1015
|
-
reusableView.rendered = this._renderContent(type, reusableView.content);
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
_renderContent(type, content) {
|
|
1019
|
-
let cached = this._renderedContent.get(content);
|
|
1020
|
-
|
|
1021
|
-
if (cached != null) {
|
|
1022
|
-
return cached;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
let rendered = this.delegate.renderView(type, content);
|
|
1026
|
-
|
|
1027
|
-
if (content) {
|
|
1028
|
-
this._renderedContent.set(content, rendered);
|
|
548
|
+
*/ setLayout(layout, animated = false) {
|
|
549
|
+
if (layout === this._layout) return;
|
|
550
|
+
let applyLayout = ()=>{
|
|
551
|
+
if (this._layout) // @ts-ignore
|
|
552
|
+
this._layout.virtualizer = null;
|
|
553
|
+
layout.virtualizer = this;
|
|
554
|
+
this._layout = layout;
|
|
555
|
+
};
|
|
556
|
+
if (animated) // Animated layout transitions are really simple, thanks to our transaction support.
|
|
557
|
+
// We just set the layout inside a transaction action, which runs after the initial
|
|
558
|
+
// layout infos for the animation are retrieved from the previous layout. Then, the
|
|
559
|
+
// final layout infos are retrieved from the new layout, and animations occur.
|
|
560
|
+
this._runTransaction(applyLayout);
|
|
561
|
+
else {
|
|
562
|
+
applyLayout();
|
|
563
|
+
this.relayout();
|
|
564
|
+
}
|
|
1029
565
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
566
|
+
_getReuseType(layoutInfo, content) {
|
|
567
|
+
if (layoutInfo.type === 'item' && content) {
|
|
568
|
+
let type = this.delegate.getType ? this.delegate.getType(content) : 'item';
|
|
569
|
+
let reuseType = type === 'item' ? 'item' : layoutInfo.type + '_' + type;
|
|
570
|
+
return {
|
|
571
|
+
type: type,
|
|
572
|
+
reuseType: reuseType
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
type: layoutInfo.type,
|
|
577
|
+
reuseType: layoutInfo.type
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
getReusableView(layoutInfo) {
|
|
581
|
+
let content = this.getItem(layoutInfo.key);
|
|
582
|
+
let { reuseType: reuseType } = this._getReuseType(layoutInfo, content);
|
|
583
|
+
if (!this._reusableViews[reuseType]) this._reusableViews[reuseType] = [];
|
|
584
|
+
let reusable = this._reusableViews[reuseType];
|
|
585
|
+
let view = reusable.length > 0 ? reusable.pop() : new $4287aeba6cd94157$export$1a5223887c560441(this);
|
|
586
|
+
view.viewType = reuseType;
|
|
587
|
+
if (!this._animatedContentOffset.isOrigin()) {
|
|
588
|
+
layoutInfo = layoutInfo.copy();
|
|
589
|
+
layoutInfo.rect.x += this._animatedContentOffset.x;
|
|
590
|
+
layoutInfo.rect.y += this._animatedContentOffset.y;
|
|
591
|
+
}
|
|
592
|
+
view.layoutInfo = layoutInfo;
|
|
593
|
+
this._renderView(view);
|
|
594
|
+
return view;
|
|
595
|
+
}
|
|
596
|
+
_renderView(reusableView) {
|
|
597
|
+
let { type: type , key: key } = reusableView.layoutInfo;
|
|
598
|
+
reusableView.content = this.getItem(key);
|
|
599
|
+
reusableView.rendered = this._renderContent(type, reusableView.content);
|
|
600
|
+
}
|
|
601
|
+
_renderContent(type, content) {
|
|
602
|
+
let cached = this._renderedContent.get(content);
|
|
603
|
+
if (cached != null) return cached;
|
|
604
|
+
let rendered = this.delegate.renderView(type, content);
|
|
605
|
+
if (content) this._renderedContent.set(content, rendered);
|
|
606
|
+
return rendered;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
1034
609
|
* Returns an array of all currently visible views, including both
|
|
1035
610
|
* item views and supplementary views.
|
|
1036
|
-
*/
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
return Array.from(this._visibleViews.values());
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
611
|
+
*/ get visibleViews() {
|
|
612
|
+
return Array.from(this._visibleViews.values());
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
1043
615
|
* Gets the visible view for the given type and key. Returns null if
|
|
1044
616
|
* the view is not currently visible.
|
|
1045
617
|
*
|
|
1046
618
|
* @param key The key of the view to retrieve.
|
|
1047
|
-
*/
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
return this._visibleViews.get(key) || null;
|
|
1052
|
-
}
|
|
1053
|
-
/**
|
|
619
|
+
*/ getView(key) {
|
|
620
|
+
return this._visibleViews.get(key) || null;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
1054
623
|
* Returns an array of visible views matching the given type.
|
|
1055
624
|
* @param type The view type to find.
|
|
1056
|
-
*/
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
625
|
+
*/ getViewsOfType(type) {
|
|
626
|
+
return this.visibleViews.filter((v)=>v.layoutInfo && v.layoutInfo.type === type
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
1063
630
|
* Returns the key for the given view. Returns null
|
|
1064
631
|
* if the view is not currently visible.
|
|
1065
|
-
*/
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
keyForView(view) {
|
|
1069
|
-
if (view && view.layoutInfo) {
|
|
1070
|
-
return view.layoutInfo.key;
|
|
632
|
+
*/ keyForView(view) {
|
|
633
|
+
if (view && view.layoutInfo) return view.layoutInfo.key;
|
|
634
|
+
return null;
|
|
1071
635
|
}
|
|
1072
|
-
|
|
1073
|
-
return null;
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
636
|
+
/**
|
|
1076
637
|
* Returns the key for the item view currently at the given point.
|
|
1077
|
-
*/
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
if (!layoutInfo) {
|
|
1086
|
-
return null;
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
return layoutInfo.key;
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
638
|
+
*/ keyAtPoint(point) {
|
|
639
|
+
let rect = new $159dcb078ef84557$export$c79fc6492f3af13d(point.x, point.y, 1, 1);
|
|
640
|
+
let layoutInfos = this.layout.getVisibleLayoutInfos(rect);
|
|
641
|
+
let layoutInfo = layoutInfos[0];
|
|
642
|
+
if (!layoutInfo) return null;
|
|
643
|
+
return layoutInfo.key;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
1092
646
|
* Cleanup for when the Virtualizer will be unmounted.
|
|
1093
|
-
*/
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
willUnmount() {
|
|
1097
|
-
cancelAnimationFrame(this._relayoutRaf);
|
|
1098
|
-
}
|
|
1099
|
-
/**
|
|
1100
|
-
* Triggers a layout invalidation, and updates the visible subviews.
|
|
1101
|
-
*/
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
relayout(context) {
|
|
1105
|
-
if (context === void 0) {
|
|
1106
|
-
context = {};
|
|
647
|
+
*/ willUnmount() {
|
|
648
|
+
cancelAnimationFrame(this._relayoutRaf);
|
|
1107
649
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
650
|
+
/**
|
|
651
|
+
* Triggers a layout invalidation, and updates the visible subviews.
|
|
652
|
+
*/ relayout(context = {
|
|
653
|
+
}) {
|
|
654
|
+
// Ignore relayouts while animating the scroll position
|
|
655
|
+
if (this._scrollAnimation || typeof requestAnimationFrame === 'undefined') return;
|
|
656
|
+
// If we already scheduled a relayout, extend the invalidation
|
|
657
|
+
// context so we coalesce multiple relayouts in the same frame.
|
|
658
|
+
if (this._invalidationContext) {
|
|
659
|
+
Object.assign(this._invalidationContext, context);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
this._invalidationContext = context;
|
|
663
|
+
this._relayoutRaf = requestAnimationFrame(()=>{
|
|
664
|
+
this._relayoutRaf = null;
|
|
665
|
+
this.relayoutNow();
|
|
666
|
+
});
|
|
1119
667
|
}
|
|
1120
|
-
|
|
1121
|
-
this._invalidationContext = context;
|
|
1122
|
-
this._relayoutRaf = requestAnimationFrame(() => {
|
|
1123
|
-
this._relayoutRaf = null;
|
|
1124
|
-
this.relayoutNow();
|
|
1125
|
-
});
|
|
1126
|
-
}
|
|
1127
|
-
/**
|
|
668
|
+
/**
|
|
1128
669
|
* Performs a relayout immediately. Prefer {@link relayout} over this method
|
|
1129
670
|
* where possible, since it coalesces multiple layout passes in the same tick.
|
|
1130
|
-
*/
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
// a scheduled relayoutNow call that has this._invalidationContext set as its default context arg (relayoutNow() in relayout)
|
|
1143
|
-
|
|
1144
|
-
context = _babelRuntimeHelpersEsmExtends({}, this._invalidationContext, context);
|
|
1145
|
-
} // Reset the invalidation context
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
this._invalidationContext = null; // Do nothing if we don't have a layout or content, or we are
|
|
1149
|
-
// in the middle of an animated scroll transition.
|
|
1150
|
-
|
|
1151
|
-
if (!this.layout || !this._collection || this._scrollAnimation) {
|
|
1152
|
-
return;
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
let scrollAnchor = this._getScrollAnchor(); // Trigger the beforeLayout hook, if provided
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
if (typeof context.beforeLayout === 'function') {
|
|
1159
|
-
context.beforeLayout();
|
|
1160
|
-
} // Validate the layout
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
this.layout.validate(context);
|
|
1164
|
-
|
|
1165
|
-
this._setContentSize(this.layout.getContentSize()); // Trigger the afterLayout hook, if provided
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
if (typeof context.afterLayout === 'function') {
|
|
1169
|
-
context.afterLayout();
|
|
1170
|
-
} // Adjust scroll position based on scroll anchor, and constrain.
|
|
1171
|
-
// If the content changed, scroll to the top.
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
let visibleRect = this.getVisibleRect();
|
|
1175
|
-
|
|
1176
|
-
let restoredScrollAnchor = this._restoreScrollAnchor(scrollAnchor, context);
|
|
1177
|
-
|
|
1178
|
-
let contentOffsetX = context.contentChanged ? 0 : restoredScrollAnchor.x;
|
|
1179
|
-
let contentOffsetY = context.contentChanged ? 0 : restoredScrollAnchor.y;
|
|
1180
|
-
contentOffsetX = Math.max(0, Math.min(this.contentSize.width - visibleRect.width, contentOffsetX));
|
|
1181
|
-
contentOffsetY = Math.max(0, Math.min(this.contentSize.height - visibleRect.height, contentOffsetY));
|
|
1182
|
-
let hasLayoutUpdates = false;
|
|
1183
|
-
|
|
1184
|
-
if (contentOffsetX !== visibleRect.x || contentOffsetY !== visibleRect.y) {
|
|
1185
|
-
// If this is an animated relayout, we do not immediately scroll because it would be jittery.
|
|
1186
|
-
// Save the difference between the current and new content offsets, and apply it to the
|
|
1187
|
-
// individual content items instead. At the end of the animation, we'll reset and set the
|
|
1188
|
-
// scroll offset for real. This ensures jitter-free animation since we don't need to sync
|
|
1189
|
-
// the scroll animation and the content animation.
|
|
1190
|
-
if (context.animated || !this._animatedContentOffset.isOrigin()) {
|
|
1191
|
-
this._animatedContentOffset.x += visibleRect.x - contentOffsetX;
|
|
1192
|
-
this._animatedContentOffset.y += visibleRect.y - contentOffsetY;
|
|
1193
|
-
hasLayoutUpdates = this.updateSubviews(context.contentChanged);
|
|
1194
|
-
} else {
|
|
1195
|
-
this._setContentOffset(new Point(contentOffsetX, contentOffsetY));
|
|
1196
|
-
}
|
|
1197
|
-
} else {
|
|
1198
|
-
hasLayoutUpdates = this.updateSubviews(context.contentChanged);
|
|
1199
|
-
} // Apply layout infos, unless this is coming from an animated transaction
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
if (!(context.transaction && context.animated)) {
|
|
1203
|
-
this._applyLayoutInfos();
|
|
1204
|
-
} // Wait for animations, and apply the afterAnimation hook, if provided
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
if (context.animated && hasLayoutUpdates) {
|
|
1208
|
-
this._enableTransitions();
|
|
1209
|
-
|
|
1210
|
-
let done = () => {
|
|
1211
|
-
this._disableTransitions(); // Reset scroll position after animations (see above comment).
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
if (!this._animatedContentOffset.isOrigin()) {
|
|
1215
|
-
// Get the content offset to scroll to, taking _animatedContentOffset into account.
|
|
1216
|
-
let {
|
|
1217
|
-
x,
|
|
1218
|
-
y
|
|
1219
|
-
} = this.getVisibleRect();
|
|
1220
|
-
|
|
1221
|
-
this._resetAnimatedContentOffset();
|
|
1222
|
-
|
|
1223
|
-
this._setContentOffset(new Point(x, y));
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
if (typeof context.afterAnimation === 'function') {
|
|
1227
|
-
context.afterAnimation();
|
|
671
|
+
*/ relayoutNow(context = this._invalidationContext || {
|
|
672
|
+
}) {
|
|
673
|
+
// Cancel the scheduled relayout, since we're doing it now.
|
|
674
|
+
if (this._relayoutRaf) {
|
|
675
|
+
cancelAnimationFrame(this._relayoutRaf);
|
|
676
|
+
this._relayoutRaf = null;
|
|
677
|
+
// Update the provided context with the current invalidationContext since we are cancelling
|
|
678
|
+
// a scheduled relayoutNow call that has this._invalidationContext set as its default context arg (relayoutNow() in relayout)
|
|
679
|
+
context = {
|
|
680
|
+
...this._invalidationContext,
|
|
681
|
+
...context
|
|
682
|
+
};
|
|
1228
683
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
684
|
+
// Reset the invalidation context
|
|
685
|
+
this._invalidationContext = null;
|
|
686
|
+
// Do nothing if we don't have a layout or content, or we are
|
|
687
|
+
// in the middle of an animated scroll transition.
|
|
688
|
+
if (!this.layout || !this._collection || this._scrollAnimation) return;
|
|
689
|
+
let scrollAnchor = this._getScrollAnchor();
|
|
690
|
+
// Trigger the beforeLayout hook, if provided
|
|
691
|
+
if (typeof context.beforeLayout === 'function') context.beforeLayout();
|
|
692
|
+
// Validate the layout
|
|
693
|
+
this.layout.validate(context);
|
|
694
|
+
this._setContentSize(this.layout.getContentSize());
|
|
695
|
+
// Trigger the afterLayout hook, if provided
|
|
696
|
+
if (typeof context.afterLayout === 'function') context.afterLayout();
|
|
697
|
+
// Adjust scroll position based on scroll anchor, and constrain.
|
|
698
|
+
// If the content changed, scroll to the top.
|
|
699
|
+
let visibleRect = this.getVisibleRect();
|
|
700
|
+
let restoredScrollAnchor = this._restoreScrollAnchor(scrollAnchor, context);
|
|
701
|
+
let contentOffsetX = context.contentChanged ? 0 : restoredScrollAnchor.x;
|
|
702
|
+
let contentOffsetY = context.contentChanged ? 0 : restoredScrollAnchor.y;
|
|
703
|
+
contentOffsetX = Math.max(0, Math.min(this.contentSize.width - visibleRect.width, contentOffsetX));
|
|
704
|
+
contentOffsetY = Math.max(0, Math.min(this.contentSize.height - visibleRect.height, contentOffsetY));
|
|
705
|
+
let hasLayoutUpdates = false;
|
|
706
|
+
if (contentOffsetX !== visibleRect.x || contentOffsetY !== visibleRect.y) {
|
|
707
|
+
// If this is an animated relayout, we do not immediately scroll because it would be jittery.
|
|
708
|
+
// Save the difference between the current and new content offsets, and apply it to the
|
|
709
|
+
// individual content items instead. At the end of the animation, we'll reset and set the
|
|
710
|
+
// scroll offset for real. This ensures jitter-free animation since we don't need to sync
|
|
711
|
+
// the scroll animation and the content animation.
|
|
712
|
+
if (context.animated || !this._animatedContentOffset.isOrigin()) {
|
|
713
|
+
this._animatedContentOffset.x += visibleRect.x - contentOffsetX;
|
|
714
|
+
this._animatedContentOffset.y += visibleRect.y - contentOffsetY;
|
|
715
|
+
hasLayoutUpdates = this.updateSubviews(context.contentChanged);
|
|
716
|
+
} else this._setContentOffset(new $412cc72545c8d16d$export$baf26146a414f24a(contentOffsetX, contentOffsetY));
|
|
717
|
+
} else hasLayoutUpdates = this.updateSubviews(context.contentChanged);
|
|
718
|
+
// Apply layout infos, unless this is coming from an animated transaction
|
|
719
|
+
if (!(context.transaction && context.animated)) this._applyLayoutInfos();
|
|
720
|
+
// Wait for animations, and apply the afterAnimation hook, if provided
|
|
721
|
+
if (context.animated && hasLayoutUpdates) {
|
|
722
|
+
this._enableTransitions();
|
|
723
|
+
let done = ()=>{
|
|
724
|
+
this._disableTransitions();
|
|
725
|
+
// Reset scroll position after animations (see above comment).
|
|
726
|
+
if (!this._animatedContentOffset.isOrigin()) {
|
|
727
|
+
// Get the content offset to scroll to, taking _animatedContentOffset into account.
|
|
728
|
+
let { x: x , y: y } = this.getVisibleRect();
|
|
729
|
+
this._resetAnimatedContentOffset();
|
|
730
|
+
this._setContentOffset(new $412cc72545c8d16d$export$baf26146a414f24a(x, y));
|
|
731
|
+
}
|
|
732
|
+
if (typeof context.afterAnimation === 'function') context.afterAnimation();
|
|
733
|
+
};
|
|
734
|
+
// Sometimes the animation takes slightly longer than expected.
|
|
735
|
+
setTimeout(done, this.transitionDuration + 100);
|
|
736
|
+
return;
|
|
737
|
+
} else if (typeof context.afterAnimation === 'function') context.afterAnimation();
|
|
1236
738
|
}
|
|
1237
|
-
|
|
1238
|
-
/**
|
|
739
|
+
/**
|
|
1239
740
|
* Corrects DOM order of visible views to match item order of collection.
|
|
1240
|
-
*/
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
for (let key of this._visibleLayoutInfos.keys()) {
|
|
1250
|
-
let view = this._visibleViews.get(key);
|
|
1251
|
-
|
|
1252
|
-
this._children.delete(view);
|
|
1253
|
-
|
|
1254
|
-
this._children.add(view);
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
_enableTransitions() {
|
|
1259
|
-
this.delegate.beginAnimations();
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
_disableTransitions() {
|
|
1263
|
-
this.delegate.endAnimations();
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
_getScrollAnchor() {
|
|
1267
|
-
if (!this.anchorScrollPosition) {
|
|
1268
|
-
return null;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
let visibleRect = this.getVisibleRect(); // Ask the delegate to provide a scroll anchor, if possible
|
|
1272
|
-
|
|
1273
|
-
if (this.delegate.getScrollAnchor) {
|
|
1274
|
-
let key = this.delegate.getScrollAnchor(visibleRect);
|
|
1275
|
-
|
|
1276
|
-
if (key) {
|
|
1277
|
-
let layoutInfo = this.layout.getLayoutInfo(key);
|
|
1278
|
-
let corner = layoutInfo.rect.getCornerInRect(visibleRect);
|
|
1279
|
-
|
|
1280
|
-
if (corner) {
|
|
1281
|
-
let key = layoutInfo.key;
|
|
1282
|
-
let offset = layoutInfo.rect[corner].y - visibleRect.y;
|
|
1283
|
-
return {
|
|
1284
|
-
key,
|
|
1285
|
-
layoutInfo,
|
|
1286
|
-
corner,
|
|
1287
|
-
offset
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
} // No need to anchor the scroll position if it is at the top
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
if (visibleRect.y === 0 && !this.anchorScrollPositionAtTop) {
|
|
1295
|
-
return null;
|
|
1296
|
-
} // Find a view with a visible corner that has the smallest distance to the top of the collection view
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
let cornerAnchor = null;
|
|
1300
|
-
|
|
1301
|
-
for (let [key, view] of this._visibleViews) {
|
|
1302
|
-
let layoutInfo = view.layoutInfo;
|
|
1303
|
-
|
|
1304
|
-
if (layoutInfo && layoutInfo.rect.area > 0) {
|
|
1305
|
-
let corner = layoutInfo.rect.getCornerInRect(visibleRect);
|
|
1306
|
-
|
|
1307
|
-
if (corner) {
|
|
1308
|
-
let offset = layoutInfo.rect[corner].y - visibleRect.y;
|
|
1309
|
-
|
|
1310
|
-
if (!cornerAnchor || offset < cornerAnchor.offset) {
|
|
1311
|
-
cornerAnchor = {
|
|
1312
|
-
key,
|
|
1313
|
-
layoutInfo,
|
|
1314
|
-
corner,
|
|
1315
|
-
offset
|
|
1316
|
-
};
|
|
1317
|
-
}
|
|
741
|
+
*/ _correctItemOrder() {
|
|
742
|
+
// Defer until after scrolling and animated transactions are complete
|
|
743
|
+
if (this._isScrolling || this._transaction) return;
|
|
744
|
+
for (let key of this._visibleLayoutInfos.keys()){
|
|
745
|
+
let view = this._visibleViews.get(key);
|
|
746
|
+
this._children.delete(view);
|
|
747
|
+
this._children.add(view);
|
|
1318
748
|
}
|
|
1319
|
-
}
|
|
1320
749
|
}
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
getVisibleLayoutInfos() {
|
|
1350
|
-
let rect = this.shouldOverscan ? this._overscanManager.getOverscannedRect() : this.getVisibleRect();
|
|
1351
|
-
this._visibleLayoutInfos = this._getLayoutInfoMap(rect);
|
|
1352
|
-
return this._visibleLayoutInfos;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
_getLayoutInfoMap(rect, copy) {
|
|
1356
|
-
if (copy === void 0) {
|
|
1357
|
-
copy = false;
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
let layoutInfos = this.layout.getVisibleLayoutInfos(rect);
|
|
1361
|
-
let map = new Map();
|
|
1362
|
-
|
|
1363
|
-
for (let layoutInfo of layoutInfos) {
|
|
1364
|
-
if (copy) {
|
|
1365
|
-
layoutInfo = layoutInfo.copy();
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
map.set(layoutInfo.key, layoutInfo);
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
return map;
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
updateSubviews(forceUpdate) {
|
|
1375
|
-
if (forceUpdate === void 0) {
|
|
1376
|
-
forceUpdate = false;
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
if (!this._collection) {
|
|
1380
|
-
return;
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
let visibleLayoutInfos = this.getVisibleLayoutInfos();
|
|
1384
|
-
let currentlyVisible = this._visibleViews;
|
|
1385
|
-
let toAdd, toRemove, toUpdate; // If this is a force update, remove and re-add all views.
|
|
1386
|
-
// Otherwise, find and update the diff.
|
|
1387
|
-
|
|
1388
|
-
if (forceUpdate) {
|
|
1389
|
-
toAdd = visibleLayoutInfos;
|
|
1390
|
-
toRemove = currentlyVisible;
|
|
1391
|
-
toUpdate = new Set();
|
|
1392
|
-
} else {
|
|
1393
|
-
({
|
|
1394
|
-
toAdd,
|
|
1395
|
-
toRemove,
|
|
1396
|
-
toUpdate
|
|
1397
|
-
} = $e73002b1b269f5d359247972bfd09$export$difference(currentlyVisible, visibleLayoutInfos));
|
|
1398
|
-
|
|
1399
|
-
for (let key of toUpdate) {
|
|
1400
|
-
let view = currentlyVisible.get(key);
|
|
1401
|
-
|
|
1402
|
-
if (!view || !view.layoutInfo) {
|
|
1403
|
-
continue;
|
|
750
|
+
_enableTransitions() {
|
|
751
|
+
this.delegate.beginAnimations();
|
|
752
|
+
}
|
|
753
|
+
_disableTransitions() {
|
|
754
|
+
this.delegate.endAnimations();
|
|
755
|
+
}
|
|
756
|
+
_getScrollAnchor() {
|
|
757
|
+
if (!this.anchorScrollPosition) return null;
|
|
758
|
+
let visibleRect = this.getVisibleRect();
|
|
759
|
+
// Ask the delegate to provide a scroll anchor, if possible
|
|
760
|
+
if (this.delegate.getScrollAnchor) {
|
|
761
|
+
let key = this.delegate.getScrollAnchor(visibleRect);
|
|
762
|
+
if (key) {
|
|
763
|
+
let layoutInfo = this.layout.getLayoutInfo(key);
|
|
764
|
+
let corner = layoutInfo.rect.getCornerInRect(visibleRect);
|
|
765
|
+
if (corner) {
|
|
766
|
+
let key = layoutInfo.key;
|
|
767
|
+
let offset = layoutInfo.rect[corner].y - visibleRect.y;
|
|
768
|
+
return {
|
|
769
|
+
key: key,
|
|
770
|
+
layoutInfo: layoutInfo,
|
|
771
|
+
corner: corner,
|
|
772
|
+
offset: offset
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
}
|
|
1404
776
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
777
|
+
// No need to anchor the scroll position if it is at the top
|
|
778
|
+
if (visibleRect.y === 0 && !this.anchorScrollPositionAtTop) return null;
|
|
779
|
+
// Find a view with a visible corner that has the smallest distance to the top of the collection view
|
|
780
|
+
let cornerAnchor = null;
|
|
781
|
+
for (let [key, view] of this._visibleViews){
|
|
782
|
+
let layoutInfo = view.layoutInfo;
|
|
783
|
+
if (layoutInfo && layoutInfo.rect.area > 0) {
|
|
784
|
+
let corner = layoutInfo.rect.getCornerInRect(visibleRect);
|
|
785
|
+
if (corner) {
|
|
786
|
+
let offset = layoutInfo.rect[corner].y - visibleRect.y;
|
|
787
|
+
if (!cornerAnchor || offset < cornerAnchor.offset) cornerAnchor = {
|
|
788
|
+
key: key,
|
|
789
|
+
layoutInfo: layoutInfo,
|
|
790
|
+
corner: corner,
|
|
791
|
+
offset: offset
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
}
|
|
1421
795
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
if (
|
|
1427
|
-
|
|
796
|
+
return cornerAnchor;
|
|
797
|
+
}
|
|
798
|
+
_restoreScrollAnchor(scrollAnchor, context) {
|
|
799
|
+
let contentOffset = this.getVisibleRect();
|
|
800
|
+
if (scrollAnchor) {
|
|
801
|
+
let finalAnchor = context.transaction?.animated ? context.transaction.finalMap.get(scrollAnchor.key) : this.layout.getLayoutInfo(scrollAnchor.layoutInfo.key);
|
|
802
|
+
if (finalAnchor) {
|
|
803
|
+
let adjustment = finalAnchor.rect[scrollAnchor.corner].y - contentOffset.y - scrollAnchor.offset;
|
|
804
|
+
contentOffset.y += adjustment;
|
|
805
|
+
}
|
|
1428
806
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
807
|
+
return contentOffset;
|
|
808
|
+
}
|
|
809
|
+
getVisibleRect() {
|
|
810
|
+
let v = this.visibleRect;
|
|
811
|
+
let x = v.x - this._animatedContentOffset.x;
|
|
812
|
+
let y = v.y - this._animatedContentOffset.y;
|
|
813
|
+
return new $159dcb078ef84557$export$c79fc6492f3af13d(x, y, v.width, v.height);
|
|
814
|
+
}
|
|
815
|
+
getVisibleLayoutInfos() {
|
|
816
|
+
let rect = this.shouldOverscan ? this._overscanManager.getOverscannedRect() : this.getVisibleRect();
|
|
817
|
+
this._visibleLayoutInfos = this._getLayoutInfoMap(rect);
|
|
818
|
+
return this._visibleLayoutInfos;
|
|
819
|
+
}
|
|
820
|
+
_getLayoutInfoMap(rect, copy = false) {
|
|
821
|
+
let layoutInfos = this.layout.getVisibleLayoutInfos(rect);
|
|
822
|
+
let map = new Map;
|
|
823
|
+
for (let layoutInfo of layoutInfos){
|
|
824
|
+
if (copy) layoutInfo = layoutInfo.copy();
|
|
825
|
+
map.set(layoutInfo.key, layoutInfo);
|
|
826
|
+
}
|
|
827
|
+
return map;
|
|
828
|
+
}
|
|
829
|
+
updateSubviews(forceUpdate = false) {
|
|
830
|
+
if (!this._collection) return;
|
|
831
|
+
let visibleLayoutInfos = this.getVisibleLayoutInfos();
|
|
832
|
+
let currentlyVisible = this._visibleViews;
|
|
833
|
+
let toAdd, toRemove, toUpdate;
|
|
834
|
+
// If this is a force update, remove and re-add all views.
|
|
835
|
+
// Otherwise, find and update the diff.
|
|
836
|
+
if (forceUpdate) {
|
|
837
|
+
toAdd = visibleLayoutInfos;
|
|
838
|
+
toRemove = currentlyVisible;
|
|
839
|
+
toUpdate = new Set();
|
|
1452
840
|
} else {
|
|
1453
|
-
|
|
841
|
+
({ toAdd: toAdd , toRemove: toRemove , toUpdate: toUpdate } = $c984faf4f5b24890$export$acaf96a27438246b(currentlyVisible, visibleLayoutInfos));
|
|
842
|
+
for (let key of toUpdate){
|
|
843
|
+
let view = currentlyVisible.get(key);
|
|
844
|
+
if (!view || !view.layoutInfo) continue;
|
|
845
|
+
let item = this.getItem(visibleLayoutInfos.get(key).key);
|
|
846
|
+
if (view.content === item) toUpdate.delete(key);
|
|
847
|
+
else {
|
|
848
|
+
// If the view type changes, delete and recreate the view instead of updating
|
|
849
|
+
let { reuseType: reuseType } = this._getReuseType(view.layoutInfo, item);
|
|
850
|
+
if (view.viewType !== reuseType) {
|
|
851
|
+
toUpdate.delete(key);
|
|
852
|
+
toAdd.add(key);
|
|
853
|
+
toRemove.add(key);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
// We are done if the sets are equal
|
|
858
|
+
if (toAdd.size === 0 && toRemove.size === 0 && toUpdate.size === 0) {
|
|
859
|
+
if (this._transaction) this._applyLayoutInfos();
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
1454
862
|
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
863
|
+
// Track views that should be removed. They are not removed from
|
|
864
|
+
// the DOM immediately, since we may reuse and need to re-insert
|
|
865
|
+
// them back into the DOM anyway.
|
|
866
|
+
let removed = new Set();
|
|
867
|
+
for (let key of toRemove.keys()){
|
|
868
|
+
let view = this._visibleViews.get(key);
|
|
869
|
+
if (view) {
|
|
870
|
+
removed.add(view);
|
|
871
|
+
this._visibleViews.delete(key);
|
|
872
|
+
// If we are in the middle of a transaction, wait until the end
|
|
873
|
+
// of the animations to remove the views from the DOM. Also means
|
|
874
|
+
// we can't reuse those views immediately.
|
|
875
|
+
if (this._transaction) this._transaction.toRemove.set(key, view);
|
|
876
|
+
else this.reuseView(view);
|
|
877
|
+
}
|
|
1469
878
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
879
|
+
for (let key1 of toAdd.keys()){
|
|
880
|
+
let layoutInfo = visibleLayoutInfos.get(key1);
|
|
881
|
+
let view;
|
|
882
|
+
// If we're in a transaction, and a layout change happens
|
|
883
|
+
// during the animations such that a view that was going
|
|
884
|
+
// to be removed is now not, we don't create a new view
|
|
885
|
+
// since the old one is still in the DOM, marked as toRemove.
|
|
886
|
+
if (this._transaction) {
|
|
887
|
+
// if transaction, get initial layout attributes for the animation
|
|
888
|
+
if (this._transaction.initialLayoutInfo.has(key1)) layoutInfo = this._transaction.initialLayoutInfo.get(key1);
|
|
889
|
+
view = this._transaction.toRemove.get(key1);
|
|
890
|
+
if (view) {
|
|
891
|
+
this._transaction.toRemove.delete(key1);
|
|
892
|
+
this._applyLayoutInfo(view, layoutInfo);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
if (!view) {
|
|
896
|
+
// Create or reuse a view for this row
|
|
897
|
+
view = this.getReusableView(layoutInfo);
|
|
898
|
+
// Add the view to the DOM if needed
|
|
899
|
+
if (!removed.has(view)) this._children.add(view);
|
|
900
|
+
}
|
|
901
|
+
this._visibleViews.set(key1, view);
|
|
902
|
+
removed.delete(view);
|
|
1477
903
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
view = this.getReusableView(layoutInfo); // Add the view to the DOM if needed
|
|
1483
|
-
|
|
1484
|
-
if (!removed.has(view)) {
|
|
1485
|
-
this._children.add(view);
|
|
904
|
+
for (let key2 of toUpdate){
|
|
905
|
+
let view = currentlyVisible.get(key2);
|
|
906
|
+
this._renderedContent.delete(key2);
|
|
907
|
+
this._renderView(view);
|
|
1486
908
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
requestAnimationFrame(() => this._applyLayoutInfos());
|
|
909
|
+
// Remove the remaining rows to delete from the DOM
|
|
910
|
+
if (!this._transaction) this.removeViews(removed);
|
|
911
|
+
this._correctItemOrder();
|
|
912
|
+
this._flushVisibleViews();
|
|
913
|
+
let hasLayoutUpdates = this._transaction && (toAdd.size > 0 || toRemove.size > 0 || this._hasLayoutUpdates());
|
|
914
|
+
if (hasLayoutUpdates) requestAnimationFrame(()=>{
|
|
915
|
+
// If we're in a transaction, apply animations to visible views
|
|
916
|
+
// and "to be removed" views, which animate off screen.
|
|
917
|
+
if (this._transaction) requestAnimationFrame(()=>this._applyLayoutInfos()
|
|
918
|
+
);
|
|
919
|
+
});
|
|
920
|
+
return hasLayoutUpdates;
|
|
921
|
+
}
|
|
922
|
+
afterRender() {
|
|
923
|
+
if (this.shouldOverscan) this._overscanManager.collectMetrics();
|
|
924
|
+
}
|
|
925
|
+
_flushVisibleViews() {
|
|
926
|
+
// CollectionVirtualizer deals with a flattened set of LayoutInfos, but they can represent heirarchy
|
|
927
|
+
// by referencing a parentKey. Just before rendering the visible views, we rebuild this heirarchy
|
|
928
|
+
// by creating a mapping of views by parent key and recursively calling the delegate's renderWrapper
|
|
929
|
+
// method to build the final tree.
|
|
930
|
+
let viewsByParentKey = new Map([
|
|
931
|
+
[
|
|
932
|
+
null,
|
|
933
|
+
[]
|
|
934
|
+
]
|
|
935
|
+
]);
|
|
936
|
+
for (let view1 of this._children){
|
|
937
|
+
if (!viewsByParentKey.has(view1.layoutInfo.parentKey)) viewsByParentKey.set(view1.layoutInfo.parentKey, []);
|
|
938
|
+
viewsByParentKey.get(view1.layoutInfo.parentKey).push(view1);
|
|
939
|
+
if (!viewsByParentKey.has(view1.layoutInfo.key)) viewsByParentKey.set(view1.layoutInfo.key, []);
|
|
1519
940
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
// CollectionVirtualizer deals with a flattened set of LayoutInfos, but they can represent heirarchy
|
|
1534
|
-
// by referencing a parentKey. Just before rendering the visible views, we rebuild this heirarchy
|
|
1535
|
-
// by creating a mapping of views by parent key and recursively calling the delegate's renderWrapper
|
|
1536
|
-
// method to build the final tree.
|
|
1537
|
-
let viewsByParentKey = new Map([[null, []]]);
|
|
1538
|
-
|
|
1539
|
-
for (let view of this._children) {
|
|
1540
|
-
if (!viewsByParentKey.has(view.layoutInfo.parentKey)) {
|
|
1541
|
-
viewsByParentKey.set(view.layoutInfo.parentKey, []);
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
viewsByParentKey.get(view.layoutInfo.parentKey).push(view);
|
|
1545
|
-
|
|
1546
|
-
if (!viewsByParentKey.has(view.layoutInfo.key)) {
|
|
1547
|
-
viewsByParentKey.set(view.layoutInfo.key, []);
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
let buildTree = (parent, views) => views.map(view => {
|
|
1552
|
-
let children = viewsByParentKey.get(view.layoutInfo.key);
|
|
1553
|
-
return this.delegate.renderWrapper(parent, view, children, childViews => buildTree(view, childViews));
|
|
1554
|
-
});
|
|
1555
|
-
|
|
1556
|
-
let children = buildTree(null, viewsByParentKey.get(null));
|
|
1557
|
-
this.delegate.setVisibleViews(children);
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
_applyLayoutInfo(view, layoutInfo) {
|
|
1561
|
-
if (view.layoutInfo === layoutInfo) {
|
|
1562
|
-
return false;
|
|
941
|
+
let buildTree = (parent, views)=>views.map((view)=>{
|
|
942
|
+
let children = viewsByParentKey.get(view.layoutInfo.key);
|
|
943
|
+
return this.delegate.renderWrapper(parent, view, children, (childViews)=>buildTree(view, childViews)
|
|
944
|
+
);
|
|
945
|
+
})
|
|
946
|
+
;
|
|
947
|
+
let children1 = buildTree(null, viewsByParentKey.get(null));
|
|
948
|
+
this.delegate.setVisibleViews(children1);
|
|
949
|
+
}
|
|
950
|
+
_applyLayoutInfo(view, layoutInfo) {
|
|
951
|
+
if (view.layoutInfo === layoutInfo) return false;
|
|
952
|
+
view.layoutInfo = layoutInfo;
|
|
953
|
+
return true;
|
|
1563
954
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
let cur = view.layoutInfo;
|
|
1574
|
-
|
|
1575
|
-
if (cur) {
|
|
1576
|
-
let layoutInfo = this.layout.getLayoutInfo(cur.key);
|
|
1577
|
-
|
|
1578
|
-
if (this._applyLayoutInfo(view, layoutInfo)) {
|
|
1579
|
-
updated = true;
|
|
955
|
+
_applyLayoutInfos() {
|
|
956
|
+
let updated = false;
|
|
957
|
+
// Apply layout infos to visible views
|
|
958
|
+
for (let view of this._visibleViews.values()){
|
|
959
|
+
let cur = view.layoutInfo;
|
|
960
|
+
if (cur) {
|
|
961
|
+
let layoutInfo = this.layout.getLayoutInfo(cur.key);
|
|
962
|
+
if (this._applyLayoutInfo(view, layoutInfo)) updated = true;
|
|
963
|
+
}
|
|
1580
964
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
965
|
+
// Apply final layout infos for views that will be removed
|
|
966
|
+
if (this._transaction) {
|
|
967
|
+
for (let view of this._transaction.toRemove.values()){
|
|
968
|
+
let cur = view.layoutInfo;
|
|
969
|
+
let layoutInfo = this.layout.getLayoutInfo(cur.key);
|
|
970
|
+
if (this._applyLayoutInfo(view, layoutInfo)) updated = true;
|
|
971
|
+
}
|
|
972
|
+
for (let view2 of this._transaction.removed.values()){
|
|
973
|
+
let cur = view2.layoutInfo;
|
|
974
|
+
let layoutInfo = this._transaction.finalLayoutInfo.get(cur.key) || cur;
|
|
975
|
+
layoutInfo = this.layout.getFinalLayoutInfo(layoutInfo.copy());
|
|
976
|
+
if (this._applyLayoutInfo(view2, layoutInfo)) updated = true;
|
|
977
|
+
}
|
|
1592
978
|
}
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
let
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
979
|
+
if (updated) this._flushVisibleViews();
|
|
980
|
+
}
|
|
981
|
+
_hasLayoutUpdates() {
|
|
982
|
+
if (!this._transaction) return false;
|
|
983
|
+
for (let view of this._visibleViews.values()){
|
|
984
|
+
let cur = view.layoutInfo;
|
|
985
|
+
if (!cur) return true;
|
|
986
|
+
let layoutInfo = this.layout.getLayoutInfo(cur.key);
|
|
987
|
+
if (// Uses equals rather than pointEquals so that width/height changes are taken into account
|
|
988
|
+
!cur.rect.equals(layoutInfo.rect) || cur.opacity !== layoutInfo.opacity || cur.transform !== layoutInfo.transform) return true;
|
|
1602
989
|
}
|
|
1603
|
-
|
|
990
|
+
return false;
|
|
1604
991
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
992
|
+
reuseView(view) {
|
|
993
|
+
view.prepareForReuse();
|
|
994
|
+
this._reusableViews[view.viewType].push(view);
|
|
1608
995
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
_hasLayoutUpdates() {
|
|
1612
|
-
if (!this._transaction) {
|
|
1613
|
-
return false;
|
|
996
|
+
removeViews(toRemove) {
|
|
997
|
+
for (let view of toRemove)this._children.delete(view);
|
|
1614
998
|
}
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
}
|
|
999
|
+
updateItemSize(key, size) {
|
|
1000
|
+
// TODO: we should be able to invalidate a single index path
|
|
1001
|
+
// @ts-ignore
|
|
1002
|
+
if (!this.layout.updateItemSize) return;
|
|
1003
|
+
// If the scroll position is currently animating, add the update
|
|
1004
|
+
// to a queue to be processed after the animation is complete.
|
|
1005
|
+
if (this._scrollAnimation) {
|
|
1006
|
+
this._sizeUpdateQueue.set(key, size);
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
// @ts-ignore
|
|
1010
|
+
let changed = this.layout.updateItemSize(key, size);
|
|
1011
|
+
if (changed) this.relayout();
|
|
1629
1012
|
}
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
reuseView(view) {
|
|
1635
|
-
view.prepareForReuse();
|
|
1636
|
-
|
|
1637
|
-
this._reusableViews[view.viewType].push(view);
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
removeViews(toRemove) {
|
|
1641
|
-
for (let view of toRemove) {
|
|
1642
|
-
this._children.delete(view);
|
|
1013
|
+
startScrolling() {
|
|
1014
|
+
this._isScrolling = true;
|
|
1643
1015
|
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
// @ts-ignore
|
|
1649
|
-
if (!this.layout.updateItemSize) {
|
|
1650
|
-
return;
|
|
1651
|
-
} // If the scroll position is currently animating, add the update
|
|
1652
|
-
// to a queue to be processed after the animation is complete.
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
if (this._scrollAnimation) {
|
|
1656
|
-
this._sizeUpdateQueue.set(key, size);
|
|
1657
|
-
|
|
1658
|
-
return;
|
|
1659
|
-
} // @ts-ignore
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
let changed = this.layout.updateItemSize(key, size);
|
|
1663
|
-
|
|
1664
|
-
if (changed) {
|
|
1665
|
-
this.relayout();
|
|
1016
|
+
endScrolling() {
|
|
1017
|
+
this._isScrolling = false;
|
|
1018
|
+
this._correctItemOrder();
|
|
1019
|
+
this._flushVisibleViews();
|
|
1666
1020
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
endScrolling() {
|
|
1674
|
-
this._isScrolling = false;
|
|
1675
|
-
|
|
1676
|
-
this._correctItemOrder();
|
|
1677
|
-
|
|
1678
|
-
this._flushVisibleViews();
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
_resetAnimatedContentOffset() {
|
|
1682
|
-
// Reset the animated content offset of subviews. See comment in relayoutNow for details.
|
|
1683
|
-
if (!this._animatedContentOffset.isOrigin()) {
|
|
1684
|
-
this._animatedContentOffset = new Point(0, 0);
|
|
1685
|
-
|
|
1686
|
-
this._applyLayoutInfos();
|
|
1021
|
+
_resetAnimatedContentOffset() {
|
|
1022
|
+
// Reset the animated content offset of subviews. See comment in relayoutNow for details.
|
|
1023
|
+
if (!this._animatedContentOffset.isOrigin()) {
|
|
1024
|
+
this._animatedContentOffset = new $412cc72545c8d16d$export$baf26146a414f24a(0, 0);
|
|
1025
|
+
this._applyLayoutInfos();
|
|
1026
|
+
}
|
|
1687
1027
|
}
|
|
1688
|
-
|
|
1689
|
-
/**
|
|
1028
|
+
/**
|
|
1690
1029
|
* Scrolls the item with the given key into view, optionally with an animation.
|
|
1691
1030
|
* @param key The key of the item to scroll into view.
|
|
1692
1031
|
* @param duration The duration of the scroll animation.
|
|
1693
|
-
*/
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
} = options;
|
|
1715
|
-
let x = this.visibleRect.x;
|
|
1716
|
-
let y = this.visibleRect.y;
|
|
1717
|
-
let minX = layoutInfo.rect.x - offsetX;
|
|
1718
|
-
let minY = layoutInfo.rect.y - offsetY;
|
|
1719
|
-
let maxX = x + this.visibleRect.width;
|
|
1720
|
-
let maxY = y + this.visibleRect.height;
|
|
1721
|
-
|
|
1722
|
-
if (shouldScrollX) {
|
|
1723
|
-
if (minX <= x || maxX === 0) {
|
|
1724
|
-
x = minX;
|
|
1725
|
-
} else if (layoutInfo.rect.maxX > maxX) {
|
|
1726
|
-
x += layoutInfo.rect.maxX - maxX;
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
if (shouldScrollY) {
|
|
1731
|
-
if (minY <= y || maxY === 0) {
|
|
1732
|
-
y = minY;
|
|
1733
|
-
} else if (layoutInfo.rect.maxY > maxY) {
|
|
1734
|
-
y += layoutInfo.rect.maxY - maxY;
|
|
1735
|
-
}
|
|
1032
|
+
*/ scrollToItem(key, options) {
|
|
1033
|
+
// key can be 0, so check if null or undefined
|
|
1034
|
+
if (key == null) return;
|
|
1035
|
+
let layoutInfo = this.layout.getLayoutInfo(key);
|
|
1036
|
+
if (!layoutInfo) return;
|
|
1037
|
+
let { duration: duration = 300 , shouldScrollX: shouldScrollX = true , shouldScrollY: shouldScrollY = true , offsetX: offsetX = 0 , offsetY: offsetY = 0 } = options;
|
|
1038
|
+
let x = this.visibleRect.x;
|
|
1039
|
+
let y = this.visibleRect.y;
|
|
1040
|
+
let minX = layoutInfo.rect.x - offsetX;
|
|
1041
|
+
let minY = layoutInfo.rect.y - offsetY;
|
|
1042
|
+
let maxX = x + this.visibleRect.width;
|
|
1043
|
+
let maxY = y + this.visibleRect.height;
|
|
1044
|
+
if (shouldScrollX) {
|
|
1045
|
+
if (minX <= x || maxX === 0) x = minX;
|
|
1046
|
+
else if (layoutInfo.rect.maxX > maxX) x += layoutInfo.rect.maxX - maxX;
|
|
1047
|
+
}
|
|
1048
|
+
if (shouldScrollY) {
|
|
1049
|
+
if (minY <= y || maxY === 0) y = minY;
|
|
1050
|
+
else if (layoutInfo.rect.maxY > maxY) y += layoutInfo.rect.maxY - maxY;
|
|
1051
|
+
}
|
|
1052
|
+
return this.scrollTo(new $412cc72545c8d16d$export$baf26146a414f24a(x, y), duration);
|
|
1736
1053
|
}
|
|
1737
|
-
|
|
1738
|
-
return this.scrollTo(new Point(x, y), duration);
|
|
1739
|
-
}
|
|
1740
|
-
/**
|
|
1054
|
+
/**
|
|
1741
1055
|
* Performs an animated scroll to the given offset.
|
|
1742
1056
|
* @param offset - The offset to scroll to.
|
|
1743
1057
|
* @param duration The duration of the animation.
|
|
1744
1058
|
* @returns A promise that resolves when the animation is complete.
|
|
1745
|
-
*/
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
duration = 300;
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
// Cancel the current scroll animation
|
|
1754
|
-
if (this._scrollAnimation) {
|
|
1755
|
-
this._scrollAnimation.cancel();
|
|
1756
|
-
|
|
1757
|
-
this._scrollAnimation = null;
|
|
1758
|
-
} // Set the content offset synchronously if the duration is zero
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
if (duration <= 0 || this.visibleRect.pointEquals(offset)) {
|
|
1762
|
-
this._setContentOffset(offset);
|
|
1763
|
-
|
|
1764
|
-
return Promise.resolve();
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
this.startScrolling();
|
|
1768
|
-
this._scrollAnimation = $ea7b4dd250709a616043c0e9cf5f62a$export$tween(this.visibleRect, offset, duration, $ea7b4dd250709a616043c0e9cf5f62a$export$easeOut, offset => {
|
|
1769
|
-
this._setContentOffset(offset);
|
|
1770
|
-
});
|
|
1771
|
-
|
|
1772
|
-
this._scrollAnimation.then(() => {
|
|
1773
|
-
this._scrollAnimation = null; // Process view size updates that occurred during the animation.
|
|
1774
|
-
// Only views that are still visible will be actually updated.
|
|
1775
|
-
|
|
1776
|
-
for (let [key, size] of this._sizeUpdateQueue) {
|
|
1777
|
-
this.updateItemSize(key, size);
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
this._sizeUpdateQueue.clear();
|
|
1781
|
-
|
|
1782
|
-
this.relayout();
|
|
1783
|
-
|
|
1784
|
-
this._processTransactionQueue();
|
|
1785
|
-
|
|
1786
|
-
this.endScrolling();
|
|
1787
|
-
});
|
|
1788
|
-
|
|
1789
|
-
return this._scrollAnimation;
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
_runTransaction(action, animated) {
|
|
1793
|
-
this._startTransaction();
|
|
1794
|
-
|
|
1795
|
-
if (this._nextTransaction) {
|
|
1796
|
-
this._nextTransaction.actions.push(action);
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1799
|
-
this._endTransaction(animated);
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
|
-
_startTransaction() {
|
|
1803
|
-
if (!this._nextTransaction) {
|
|
1804
|
-
this._nextTransaction = new $ab2c59ad03985fabe3061564f2$export$Transaction();
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
this._nextTransaction.level++;
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
_endTransaction(animated) {
|
|
1811
|
-
if (!this._nextTransaction) {
|
|
1812
|
-
return false;
|
|
1813
|
-
} // Save whether the transaction should be animated.
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
if (animated != null) {
|
|
1817
|
-
this._nextTransaction.animated = animated;
|
|
1818
|
-
} // If we haven't reached level 0, we are still in a
|
|
1819
|
-
// nested transaction. Wait for the parent to end.
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
if (--this._nextTransaction.level > 0) {
|
|
1823
|
-
return false;
|
|
1824
|
-
} // Do nothing for empty transactions
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
if (this._nextTransaction.actions.length === 0) {
|
|
1828
|
-
this._nextTransaction = null;
|
|
1829
|
-
return false;
|
|
1830
|
-
} // Default animations to true
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
if (this._nextTransaction.animated == null) {
|
|
1834
|
-
this._nextTransaction.animated = true;
|
|
1835
|
-
} // Enqueue the transaction
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
this._transactionQueue.push(this._nextTransaction);
|
|
1839
|
-
|
|
1840
|
-
this._nextTransaction = null;
|
|
1841
|
-
|
|
1842
|
-
this._processTransactionQueue();
|
|
1843
|
-
|
|
1844
|
-
return true;
|
|
1845
|
-
}
|
|
1846
|
-
|
|
1847
|
-
_processTransactionQueue() {
|
|
1848
|
-
// If the current transaction is animating, wait until the end
|
|
1849
|
-
// to process the next transaction.
|
|
1850
|
-
if (this._transaction || this._scrollAnimation) {
|
|
1851
|
-
return;
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
let next = this._transactionQueue.shift();
|
|
1855
|
-
|
|
1856
|
-
if (next) {
|
|
1857
|
-
this._performTransaction(next);
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
_getContentRect() {
|
|
1862
|
-
return new Rect(0, 0, this.contentSize.width, this.contentSize.height);
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1865
|
-
_performTransaction(transaction) {
|
|
1866
|
-
this._transaction = transaction;
|
|
1867
|
-
this.relayoutNow({
|
|
1868
|
-
transaction: transaction,
|
|
1869
|
-
animated: transaction.animated,
|
|
1870
|
-
beforeLayout: () => {
|
|
1871
|
-
// Get the initial layout infos for all views before the updates
|
|
1872
|
-
// so we can figure out which views to add and remove.
|
|
1873
|
-
if (transaction.animated) {
|
|
1874
|
-
transaction.initialMap = this._getLayoutInfoMap(this._getContentRect(), true);
|
|
1875
|
-
} // Apply the actions that occurred during this transaction
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
for (let action of transaction.actions) {
|
|
1879
|
-
action();
|
|
1059
|
+
*/ scrollTo(offset1, duration = 300) {
|
|
1060
|
+
// Cancel the current scroll animation
|
|
1061
|
+
if (this._scrollAnimation) {
|
|
1062
|
+
this._scrollAnimation.cancel();
|
|
1063
|
+
this._scrollAnimation = null;
|
|
1880
1064
|
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
transaction.finalMap = this._getLayoutInfoMap(this._getContentRect());
|
|
1886
|
-
|
|
1887
|
-
this._setupTransactionAnimations(transaction);
|
|
1888
|
-
} else {
|
|
1889
|
-
this._transaction = null;
|
|
1065
|
+
// Set the content offset synchronously if the duration is zero
|
|
1066
|
+
if (duration <= 0 || this.visibleRect.pointEquals(offset1)) {
|
|
1067
|
+
this._setContentOffset(offset1);
|
|
1068
|
+
return Promise.resolve();
|
|
1890
1069
|
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
this.
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1070
|
+
this.startScrolling();
|
|
1071
|
+
this._scrollAnimation = $6a9b8d711ba49ea7$export$dc0b63720788090c(this.visibleRect, offset1, duration, $6a9b8d711ba49ea7$export$57636bb43b1ccbb0, (offset)=>{
|
|
1072
|
+
this._setContentOffset(offset);
|
|
1073
|
+
});
|
|
1074
|
+
this._scrollAnimation.then(()=>{
|
|
1075
|
+
this._scrollAnimation = null;
|
|
1076
|
+
// Process view size updates that occurred during the animation.
|
|
1077
|
+
// Only views that are still visible will be actually updated.
|
|
1078
|
+
for (let [key, size] of this._sizeUpdateQueue)this.updateItemSize(key, size);
|
|
1079
|
+
this._sizeUpdateQueue.clear();
|
|
1080
|
+
this.relayout();
|
|
1081
|
+
this._processTransactionQueue();
|
|
1082
|
+
this.endScrolling();
|
|
1083
|
+
});
|
|
1084
|
+
return this._scrollAnimation;
|
|
1085
|
+
}
|
|
1086
|
+
_runTransaction(action, animated) {
|
|
1087
|
+
this._startTransaction();
|
|
1088
|
+
if (this._nextTransaction) this._nextTransaction.actions.push(action);
|
|
1089
|
+
this._endTransaction(animated);
|
|
1090
|
+
}
|
|
1091
|
+
_startTransaction() {
|
|
1092
|
+
if (!this._nextTransaction) this._nextTransaction = new $6b14b0a55eb74a2c$export$febc5573c75cefb0;
|
|
1093
|
+
this._nextTransaction.level++;
|
|
1094
|
+
}
|
|
1095
|
+
_endTransaction(animated) {
|
|
1096
|
+
if (!this._nextTransaction) return false;
|
|
1097
|
+
// Save whether the transaction should be animated.
|
|
1098
|
+
if (animated != null) this._nextTransaction.animated = animated;
|
|
1099
|
+
// If we haven't reached level 0, we are still in a
|
|
1100
|
+
// nested transaction. Wait for the parent to end.
|
|
1101
|
+
if (--this._nextTransaction.level > 0) return false;
|
|
1102
|
+
// Do nothing for empty transactions
|
|
1103
|
+
if (this._nextTransaction.actions.length === 0) {
|
|
1104
|
+
this._nextTransaction = null;
|
|
1105
|
+
return false;
|
|
1900
1106
|
}
|
|
1901
|
-
|
|
1902
|
-
this.
|
|
1903
|
-
|
|
1904
|
-
this.
|
|
1905
|
-
|
|
1906
|
-
this._flushVisibleViews();
|
|
1907
|
-
|
|
1107
|
+
// Default animations to true
|
|
1108
|
+
if (this._nextTransaction.animated == null) this._nextTransaction.animated = true;
|
|
1109
|
+
// Enqueue the transaction
|
|
1110
|
+
this._transactionQueue.push(this._nextTransaction);
|
|
1111
|
+
this._nextTransaction = null;
|
|
1908
1112
|
this._processTransactionQueue();
|
|
1909
|
-
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
}
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1113
|
+
return true;
|
|
1114
|
+
}
|
|
1115
|
+
_processTransactionQueue() {
|
|
1116
|
+
// If the current transaction is animating, wait until the end
|
|
1117
|
+
// to process the next transaction.
|
|
1118
|
+
if (this._transaction || this._scrollAnimation) return;
|
|
1119
|
+
let next = this._transactionQueue.shift();
|
|
1120
|
+
if (next) this._performTransaction(next);
|
|
1121
|
+
}
|
|
1122
|
+
_getContentRect() {
|
|
1123
|
+
return new $159dcb078ef84557$export$c79fc6492f3af13d(0, 0, this.contentSize.width, this.contentSize.height);
|
|
1124
|
+
}
|
|
1125
|
+
_performTransaction(transaction) {
|
|
1126
|
+
this._transaction = transaction;
|
|
1127
|
+
this.relayoutNow({
|
|
1128
|
+
transaction: transaction,
|
|
1129
|
+
animated: transaction.animated,
|
|
1130
|
+
beforeLayout: ()=>{
|
|
1131
|
+
// Get the initial layout infos for all views before the updates
|
|
1132
|
+
// so we can figure out which views to add and remove.
|
|
1133
|
+
if (transaction.animated) transaction.initialMap = this._getLayoutInfoMap(this._getContentRect(), true);
|
|
1134
|
+
// Apply the actions that occurred during this transaction
|
|
1135
|
+
for (let action of transaction.actions)action();
|
|
1136
|
+
},
|
|
1137
|
+
afterLayout: ()=>{
|
|
1138
|
+
// Get the final layout infos after the updates
|
|
1139
|
+
if (transaction.animated) {
|
|
1140
|
+
transaction.finalMap = this._getLayoutInfoMap(this._getContentRect());
|
|
1141
|
+
this._setupTransactionAnimations(transaction);
|
|
1142
|
+
} else this._transaction = null;
|
|
1143
|
+
},
|
|
1144
|
+
afterAnimation: ()=>{
|
|
1145
|
+
// Remove and reuse views when animations are done
|
|
1146
|
+
if (transaction.toRemove.size > 0 || transaction.removed.size > 0) for (let view of $c984faf4f5b24890$export$cfc14088dfefce5f(transaction.toRemove.values(), transaction.removed.values())){
|
|
1147
|
+
this._children.delete(view);
|
|
1148
|
+
this.reuseView(view);
|
|
1149
|
+
}
|
|
1150
|
+
this._transaction = null;
|
|
1151
|
+
// Ensure DOM order is correct for accessibility after animations are complete
|
|
1152
|
+
this._correctItemOrder();
|
|
1153
|
+
this._flushVisibleViews();
|
|
1154
|
+
this._processTransactionQueue();
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
_setupTransactionAnimations(transaction) {
|
|
1159
|
+
let { initialMap: initialMap , finalMap: finalMap } = transaction;
|
|
1160
|
+
// Store initial and final layout infos for animations
|
|
1161
|
+
for (let [key, layoutInfo] of initialMap)if (finalMap.has(key)) // Store the initial layout info for use during animations.
|
|
1922
1162
|
transaction.initialLayoutInfo.set(key, layoutInfo);
|
|
1923
|
-
|
|
1924
|
-
// This view was removed. Store the layout info for use
|
|
1163
|
+
else // This view was removed. Store the layout info for use
|
|
1925
1164
|
// in Layout#getFinalLayoutInfo during animations.
|
|
1926
1165
|
transaction.finalLayoutInfo.set(layoutInfo.key, layoutInfo);
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
let
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
transaction.removed.set(key, view);
|
|
1942
|
-
|
|
1943
|
-
this._visibleViews.delete(key); // In case something weird happened, where we have a view but no
|
|
1944
|
-
// initial layout info, use the one attached to the view.
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
if (view.layoutInfo) {
|
|
1948
|
-
if (!transaction.finalLayoutInfo.has(view.layoutInfo.key)) {
|
|
1949
|
-
transaction.finalLayoutInfo.set(view.layoutInfo.key, view.layoutInfo);
|
|
1950
|
-
}
|
|
1166
|
+
// Get initial layout infos for views that were added
|
|
1167
|
+
for (let [key3, layoutInfo1] of finalMap)if (!initialMap.has(key3)) {
|
|
1168
|
+
let initialLayoutInfo = this.layout.getInitialLayoutInfo(layoutInfo1.copy());
|
|
1169
|
+
transaction.initialLayoutInfo.set(key3, initialLayoutInfo);
|
|
1170
|
+
}
|
|
1171
|
+
// Figure out which views were removed.
|
|
1172
|
+
for (let [key4, view] of this._visibleViews)if (!finalMap.has(key4)) {
|
|
1173
|
+
transaction.removed.set(key4, view);
|
|
1174
|
+
this._visibleViews.delete(key4);
|
|
1175
|
+
// In case something weird happened, where we have a view but no
|
|
1176
|
+
// initial layout info, use the one attached to the view.
|
|
1177
|
+
if (view.layoutInfo) {
|
|
1178
|
+
if (!transaction.finalLayoutInfo.has(view.layoutInfo.key)) transaction.finalLayoutInfo.set(view.layoutInfo.key, view.layoutInfo);
|
|
1179
|
+
}
|
|
1951
1180
|
}
|
|
1952
|
-
}
|
|
1953
1181
|
}
|
|
1954
|
-
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1955
1184
|
|
|
1185
|
+
function $768d3e68d680b21c$export$1505db82fe357e65(opts) {
|
|
1186
|
+
let [visibleViews, setVisibleViews] = $he21n$useState([]);
|
|
1187
|
+
let [contentSize, setContentSize] = $he21n$useState(new $22e89a13b0a391cf$export$cb6da89c6af1a8ec());
|
|
1188
|
+
let [isAnimating, setAnimating] = $he21n$useState(false);
|
|
1189
|
+
let [isScrolling, setScrolling] = $he21n$useState(false);
|
|
1190
|
+
let virtualizer = $he21n$useMemo(()=>new $db9fd92d994d4bf6$export$89be5a243e59c4b2()
|
|
1191
|
+
, []);
|
|
1192
|
+
virtualizer.delegate = {
|
|
1193
|
+
setVisibleViews: setVisibleViews,
|
|
1194
|
+
setVisibleRect (rect) {
|
|
1195
|
+
virtualizer.visibleRect = rect;
|
|
1196
|
+
opts.onVisibleRectChange(rect);
|
|
1197
|
+
},
|
|
1198
|
+
setContentSize: setContentSize,
|
|
1199
|
+
renderView: opts.renderView,
|
|
1200
|
+
renderWrapper: opts.renderWrapper,
|
|
1201
|
+
beginAnimations: ()=>setAnimating(true)
|
|
1202
|
+
,
|
|
1203
|
+
endAnimations: ()=>setAnimating(false)
|
|
1204
|
+
,
|
|
1205
|
+
getScrollAnchor: opts.getScrollAnchor
|
|
1206
|
+
};
|
|
1207
|
+
virtualizer.layout = opts.layout;
|
|
1208
|
+
virtualizer.collection = opts.collection;
|
|
1209
|
+
virtualizer.transitionDuration = opts.transitionDuration;
|
|
1210
|
+
$he21n$useLayoutEffect(()=>{
|
|
1211
|
+
virtualizer.afterRender();
|
|
1212
|
+
});
|
|
1213
|
+
// eslint-disable-next-line arrow-body-style
|
|
1214
|
+
$he21n$useEffect(()=>{
|
|
1215
|
+
return ()=>virtualizer.willUnmount()
|
|
1216
|
+
;
|
|
1217
|
+
}, []);
|
|
1218
|
+
return {
|
|
1219
|
+
virtualizer: virtualizer,
|
|
1220
|
+
visibleViews: visibleViews,
|
|
1221
|
+
setVisibleRect: $he21n$useCallback((rect)=>{
|
|
1222
|
+
virtualizer.visibleRect = rect;
|
|
1223
|
+
}, [
|
|
1224
|
+
virtualizer
|
|
1225
|
+
]),
|
|
1226
|
+
contentSize: contentSize,
|
|
1227
|
+
isAnimating: isAnimating,
|
|
1228
|
+
isScrolling: isScrolling,
|
|
1229
|
+
startScrolling: $he21n$useCallback(()=>{
|
|
1230
|
+
virtualizer.startScrolling();
|
|
1231
|
+
setScrolling(true);
|
|
1232
|
+
}, [
|
|
1233
|
+
virtualizer
|
|
1234
|
+
]),
|
|
1235
|
+
endScrolling: $he21n$useCallback(()=>{
|
|
1236
|
+
virtualizer.endScrolling();
|
|
1237
|
+
setScrolling(false);
|
|
1238
|
+
}, [
|
|
1239
|
+
virtualizer
|
|
1240
|
+
])
|
|
1241
|
+
};
|
|
1956
1242
|
}
|
|
1957
1243
|
|
|
1958
|
-
export function useVirtualizerState(opts) {
|
|
1959
|
-
let [visibleViews, setVisibleViews] = useState([]);
|
|
1960
|
-
let [contentSize, setContentSize] = useState(new Size());
|
|
1961
|
-
let [isAnimating, setAnimating] = useState(false);
|
|
1962
|
-
let [isScrolling, setScrolling] = useState(false);
|
|
1963
|
-
let virtualizer = useMemo(() => new $d389afd47bc06952d9e630a237a8$export$Virtualizer(), []);
|
|
1964
|
-
virtualizer.delegate = {
|
|
1965
|
-
setVisibleViews,
|
|
1966
1244
|
|
|
1967
|
-
setVisibleRect(rect) {
|
|
1968
|
-
virtualizer.visibleRect = rect;
|
|
1969
|
-
opts.onVisibleRectChange(rect);
|
|
1970
|
-
},
|
|
1971
1245
|
|
|
1972
|
-
setContentSize,
|
|
1973
|
-
renderView: opts.renderView,
|
|
1974
|
-
renderWrapper: opts.renderWrapper,
|
|
1975
|
-
beginAnimations: () => setAnimating(true),
|
|
1976
|
-
endAnimations: () => setAnimating(false),
|
|
1977
|
-
getScrollAnchor: opts.getScrollAnchor
|
|
1978
|
-
};
|
|
1979
|
-
virtualizer.layout = opts.layout;
|
|
1980
|
-
virtualizer.collection = opts.collection;
|
|
1981
|
-
virtualizer.transitionDuration = opts.transitionDuration;
|
|
1982
|
-
useLayoutEffect(() => {
|
|
1983
|
-
virtualizer.afterRender();
|
|
1984
|
-
}); // eslint-disable-next-line arrow-body-style
|
|
1985
1246
|
|
|
1986
|
-
|
|
1987
|
-
return () => virtualizer.willUnmount();
|
|
1988
|
-
}, []);
|
|
1989
|
-
return {
|
|
1990
|
-
virtualizer,
|
|
1991
|
-
visibleViews,
|
|
1992
|
-
setVisibleRect: useCallback(rect => {
|
|
1993
|
-
virtualizer.visibleRect = rect;
|
|
1994
|
-
}, [virtualizer]),
|
|
1995
|
-
contentSize,
|
|
1996
|
-
isAnimating,
|
|
1997
|
-
isScrolling,
|
|
1998
|
-
startScrolling: useCallback(() => {
|
|
1999
|
-
virtualizer.startScrolling();
|
|
2000
|
-
setScrolling(true);
|
|
2001
|
-
}, [virtualizer]),
|
|
2002
|
-
endScrolling: useCallback(() => {
|
|
2003
|
-
virtualizer.endScrolling();
|
|
2004
|
-
setScrolling(false);
|
|
2005
|
-
}, [virtualizer])
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
1247
|
+
export {$e2db9807015c93cd$export$c84671f46d6a1ca as Layout, $84802bfc2c93a467$export$7e0eeb9da702a085 as LayoutInfo, $412cc72545c8d16d$export$baf26146a414f24a as Point, $159dcb078ef84557$export$c79fc6492f3af13d as Rect, $22e89a13b0a391cf$export$cb6da89c6af1a8ec as Size, $4287aeba6cd94157$export$1a5223887c560441 as ReusableView, $768d3e68d680b21c$export$1505db82fe357e65 as useVirtualizerState};
|
|
2008
1248
|
//# sourceMappingURL=module.js.map
|