@ng-native/components 0.24.0 → 0.26.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/android/src/main/java/dev/ngnative/components/ColorSchemeModule.kt +97 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/reanimated-web.d.ts +1 -0
- package/dist/reanimated-web.js +1 -0
- package/dist/reanimated-web.js.map +1 -1
- package/dist/reanimated.d.ts +1 -0
- package/dist/reanimated.js +1 -0
- package/dist/reanimated.js.map +1 -1
- package/dist/release-on-destroy.d.ts +32 -0
- package/dist/release-on-destroy.js +45 -0
- package/dist/release-on-destroy.js.map +1 -0
- package/dist/section-list.d.ts +5 -1
- package/dist/section-list.js +11 -3
- package/dist/section-list.js.map +1 -1
- package/dist/sticky-rows.d.ts +142 -0
- package/dist/sticky-rows.js +274 -0
- package/dist/sticky-rows.js.map +1 -0
- package/dist/virtual-list-layout.d.ts +21 -0
- package/dist/virtual-list-layout.js +11 -0
- package/dist/virtual-list-layout.js.map +1 -0
- package/dist/virtual-list-num-columns.d.ts +47 -0
- package/dist/virtual-list-num-columns.js +97 -0
- package/dist/virtual-list-num-columns.js.map +1 -0
- package/dist/virtual-list.d.ts +111 -50
- package/dist/virtual-list.js +378 -197
- package/dist/virtual-list.js.map +1 -1
- package/package.json +3 -3
package/dist/virtual-list.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Component, DestroyRef, Directive, ElementRef, TemplateRef, afterEveryRender, booleanAttribute, computed, contentChild, effect, inject, input, linkedSignal, output, signal, untracked, viewChild, } from '@angular/core';
|
|
2
|
-
import { nativePlatform,
|
|
2
|
+
import { nativePlatform, } from '@ng-native/fabric';
|
|
3
3
|
import { HeightIndex } from "./height-index.js";
|
|
4
4
|
import { dismissKeyboardOnTap } from "./keyboard-taps.js";
|
|
5
5
|
import { RefreshControl } from "./refresh-control.js";
|
|
6
|
-
import {
|
|
6
|
+
import { StickyRows } from "./sticky-rows.js";
|
|
7
7
|
import { TemplateSlot } from "./template-slot.js";
|
|
8
8
|
import { ZeroSizeWarning, checksZeroSize, written } from "./zero-size-warning.js";
|
|
9
9
|
import { View } from "./view.js";
|
|
10
|
+
import { VIRTUAL_LIST_LAYOUT } from "./virtual-list-layout.js";
|
|
10
11
|
import { ScrollViewProps } from "./scroll-view-props.js";
|
|
11
12
|
import { numberOr } from "./transforms.js";
|
|
12
13
|
import * as i0 from "@angular/core";
|
|
@@ -45,6 +46,13 @@ const PARK_LIMIT = 6;
|
|
|
45
46
|
const IN_FLOW = Object.freeze({});
|
|
46
47
|
/** Points of drift below which a held position is left alone, as UIKit rounds to half-points. */
|
|
47
48
|
const HOLD_TOLERANCE = 0.5;
|
|
49
|
+
/**
|
|
50
|
+
* How long the JS thread has to be free of window changes before the window grows another
|
|
51
|
+
* viewport: FlatList's `updateCellsBatchingPeriod`.
|
|
52
|
+
*/
|
|
53
|
+
const FILL_BATCH_MS = 50;
|
|
54
|
+
/** How long without a scroll event counts as the scroll having stopped. */
|
|
55
|
+
const PAUSE_MS = 200;
|
|
48
56
|
/**
|
|
49
57
|
* Windowed list: a native scroll view whose content is sized to the full list, with only the
|
|
50
58
|
* visible slice rendered. Commits as `RCTScrollView`.
|
|
@@ -155,6 +163,22 @@ export class VirtualList extends ScrollViewProps {
|
|
|
155
163
|
...(ngDevMode ? [undefined, { debugName: "maintainVisibleContentPosition" }] : /* istanbul ignore next */ []));
|
|
156
164
|
/** Rows rendered beyond each edge of the viewport, to cover fling gaps. */
|
|
157
165
|
overscan = input(4, { ...(ngDevMode ? { debugName: "overscan" } : /* istanbul ignore next */ {}), transform: numberOr(4) });
|
|
166
|
+
/**
|
|
167
|
+
* How many viewports of rows the list fills, as FlatList's `windowSize`: the one on screen and
|
|
168
|
+
* up to `windowSize - 1` more around it. While the JS thread is
|
|
169
|
+
* idle the window grows a viewport at a time, ahead of the scroll direction first, so a fling
|
|
170
|
+
* lands on rows already drawn. About two-thirds of the extra viewports go ahead of the scroll and
|
|
171
|
+
* the rest behind. `1` fills no extra viewports, though a fast scroll still renders ahead of
|
|
172
|
+
* itself unless `velocityLead` is `0`.
|
|
173
|
+
*/
|
|
174
|
+
windowSize = input(5, { ...(ngDevMode ? { debugName: "windowSize" } : /* istanbul ignore next */ {}), transform: numberOr(5) });
|
|
175
|
+
/**
|
|
176
|
+
* How far past the viewport a scroll renders in the direction it is going, in milliseconds of
|
|
177
|
+
* its speed, up to three viewports: the rows the list will reach by the time a window change has
|
|
178
|
+
* been through JavaScript and back to native. `0` renders only the visible rows, the overscan
|
|
179
|
+
* and the fill.
|
|
180
|
+
*/
|
|
181
|
+
velocityLead = input(500, { ...(ngDevMode ? { debugName: "velocityLead" } : /* istanbul ignore next */ {}), transform: numberOr(500) });
|
|
158
182
|
/** How close to the end, in viewport heights, `(endReached)` fires. RN's default is 2. */
|
|
159
183
|
endReachedThreshold = input(2, { ...(ngDevMode ? { debugName: "endReachedThreshold" } : /* istanbul ignore next */ {}), transform: numberOr(2) });
|
|
160
184
|
/** Lay the rows out along x instead of y, and scroll that way. */
|
|
@@ -183,9 +207,6 @@ export class VirtualList extends ScrollViewProps {
|
|
|
183
207
|
viewableItemsChanged = output();
|
|
184
208
|
viewport = signal(0, /* @ts-ignore */
|
|
185
209
|
...(ngDevMode ? [{ debugName: "viewport" }] : /* istanbul ignore next */ []));
|
|
186
|
-
/** The leading edge of the viewport in content space, which sticky rows and viewability need. */
|
|
187
|
-
offset = signal(0, /* @ts-ignore */
|
|
188
|
-
...(ngDevMode ? [{ debugName: "offset" }] : /* istanbul ignore next */ []));
|
|
189
210
|
headerHeight = signal(0, /* @ts-ignore */
|
|
190
211
|
...(ngDevMode ? [{ debugName: "headerHeight" }] : /* istanbul ignore next */ []));
|
|
191
212
|
/** What native reported the content measures along the axis, once it has. */
|
|
@@ -207,23 +228,39 @@ export class VirtualList extends ScrollViewProps {
|
|
|
207
228
|
/** See ScrollView: inside Android's swipe layout the list must see a drag first. */
|
|
208
229
|
nestedScroll = computed(() => nativePlatform() === 'android' && this.refreshControl() ? true : undefined, /* @ts-ignore */
|
|
209
230
|
...(ngDevMode ? [{ debugName: "nestedScroll" }] : /* istanbul ignore next */ []));
|
|
210
|
-
/**
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
231
|
+
/** Viewports filled past the overscan, before and after the visible rows in index order. */
|
|
232
|
+
fill = signal({ before: 0, after: 0 }, /* @ts-ignore */
|
|
233
|
+
...(ngDevMode ? [{ debugName: "fill" }] : /* istanbul ignore next */ []));
|
|
234
|
+
/** The way the visible row last moved: 1 toward the end of the list, -1 toward the start. */
|
|
235
|
+
direction = signal(1, /* @ts-ignore */
|
|
236
|
+
...(ngDevMode ? [{ debugName: "direction" }] : /* istanbul ignore next */ []));
|
|
237
|
+
/** The fill, cut to what `windowSize` allows ahead of the scroll and behind it. */
|
|
238
|
+
reach = computed(() => {
|
|
239
|
+
const { before, after } = this.fill();
|
|
240
|
+
const { ahead, behind } = this.fillCaps();
|
|
241
|
+
const forward = this.direction() > 0;
|
|
242
|
+
return {
|
|
243
|
+
before: Math.min(before, forward ? behind : ahead),
|
|
244
|
+
after: Math.min(after, forward ? ahead : behind),
|
|
245
|
+
};
|
|
246
|
+
}, /* @ts-ignore */
|
|
247
|
+
...(ngDevMode ? [{ debugName: "reach" }] : /* istanbul ignore next */ []));
|
|
248
|
+
fillTimer;
|
|
223
249
|
canvasView = viewChild.required('rows', { ...(ngDevMode ? { debugName: "canvasView" } : /* istanbul ignore next */ {}), read: ElementRef });
|
|
224
|
-
/**
|
|
225
|
-
|
|
226
|
-
|
|
250
|
+
/** The sticky rows and header: see `StickyRows`. */
|
|
251
|
+
sticky = new StickyRows(this.engine, this.node, {
|
|
252
|
+
indices: this.stickyIndices,
|
|
253
|
+
header: this.stickyHeader,
|
|
254
|
+
headerHeight: this.headerHeight,
|
|
255
|
+
horizontal: () => this.horizontal(),
|
|
256
|
+
measuring: () => this.measuring(),
|
|
257
|
+
topOf: (index) => this.topOf(index),
|
|
258
|
+
heightOf: (index) => this.heightOf(index),
|
|
259
|
+
slotStyle: (index) => this.slotStyle(index),
|
|
260
|
+
flowSpacing: () => this.flowSpacing(),
|
|
261
|
+
flip: () => this.flip(),
|
|
262
|
+
flipText: () => this.flipText(),
|
|
263
|
+
});
|
|
227
264
|
/** Rows size themselves and are laid out in flow, rather than placed at a known offset. */
|
|
228
265
|
measuring = computed(() => this.itemHeight() === undefined, /* @ts-ignore */
|
|
229
266
|
...(ngDevMode ? [{ debugName: "measuring" }] : /* istanbul ignore next */ []));
|
|
@@ -246,6 +283,74 @@ export class VirtualList extends ScrollViewProps {
|
|
|
246
283
|
return this.horizontal() ? { top, bottom } : { left, right };
|
|
247
284
|
}, /* @ts-ignore */
|
|
248
285
|
...(ngDevMode ? [{ debugName: "across" }] : /* istanbul ignore next */ []));
|
|
286
|
+
/** How items are laid out across the width, when a directive on the list says: see the token. */
|
|
287
|
+
columnLayout = inject(VIRTUAL_LIST_LAYOUT, { self: true, optional: true });
|
|
288
|
+
/**
|
|
289
|
+
* Items to a line. Only for a vertical list whose rows have known heights: a line's height
|
|
290
|
+
* would otherwise wait on every item in it measuring, and FlatList's `numColumns` is vertical
|
|
291
|
+
* only too. The directive says so in development.
|
|
292
|
+
*/
|
|
293
|
+
columns = computed(() => {
|
|
294
|
+
const columns = this.columnLayout?.columns() ?? 1;
|
|
295
|
+
return this.measuring() || this.horizontal() ? 1 : columns;
|
|
296
|
+
}, /* @ts-ignore */
|
|
297
|
+
...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
298
|
+
/** Which line each item is on, when there is more than one to a line. */
|
|
299
|
+
lines = computed(() => {
|
|
300
|
+
const columns = this.columns();
|
|
301
|
+
if (columns === 1)
|
|
302
|
+
return null;
|
|
303
|
+
const count = this.items().length;
|
|
304
|
+
const sticky = this.sticky.next();
|
|
305
|
+
const of = new Int32Array(count);
|
|
306
|
+
const starts = [];
|
|
307
|
+
let column = columns;
|
|
308
|
+
for (let i = 0; i < count; i++) {
|
|
309
|
+
const alone = sticky.has(i);
|
|
310
|
+
if (alone || column === columns) {
|
|
311
|
+
starts.push(i);
|
|
312
|
+
column = 0;
|
|
313
|
+
}
|
|
314
|
+
of[i] = starts.length - 1;
|
|
315
|
+
column = alone ? columns : column + 1;
|
|
316
|
+
}
|
|
317
|
+
return { of, starts };
|
|
318
|
+
}, /* @ts-ignore */
|
|
319
|
+
...(ngDevMode ? [{ debugName: "lines" }] : /* istanbul ignore next */ []));
|
|
320
|
+
/** The props across each column, built once per change of columns, gap or padding. */
|
|
321
|
+
columnAcross = computed(() => {
|
|
322
|
+
const layout = this.columnLayout;
|
|
323
|
+
if (!layout || !this.lines())
|
|
324
|
+
return [];
|
|
325
|
+
const { left, right } = this.edges();
|
|
326
|
+
return Array.from({ length: this.columns() }, (_, column) => layout.across(column, left, right));
|
|
327
|
+
}, /* @ts-ignore */
|
|
328
|
+
...(ngDevMode ? [{ debugName: "columnAcross" }] : /* istanbul ignore next */ []));
|
|
329
|
+
/** An item's insets across the axis: its column's, or the whole width's. */
|
|
330
|
+
acrossOf(index) {
|
|
331
|
+
const lines = this.lines();
|
|
332
|
+
if (!lines || this.sticky.next().has(index))
|
|
333
|
+
return this.across();
|
|
334
|
+
return this.columnAcross()[index - lines.starts[lines.of[index]]];
|
|
335
|
+
}
|
|
336
|
+
/** The line an item is on: the item itself, when each has a line to itself. */
|
|
337
|
+
lineOf(index) {
|
|
338
|
+
const lines = this.lines();
|
|
339
|
+
// An index past the items, a sticky one given for rows not there yet, is past the last line.
|
|
340
|
+
return lines ? (lines.of[index] ?? lines.starts.length) : index;
|
|
341
|
+
}
|
|
342
|
+
/** Whether a row is on the list's last line, which no separator comes after. */
|
|
343
|
+
onLastLine(index) {
|
|
344
|
+
const lines = this.lines();
|
|
345
|
+
return lines ? lines.of[index] === lines.starts.length - 1 : index >= this.items().length - 1;
|
|
346
|
+
}
|
|
347
|
+
/** The first item on a line, or the item count for a line past the last. */
|
|
348
|
+
lineStart(line) {
|
|
349
|
+
const lines = this.lines();
|
|
350
|
+
if (!lines)
|
|
351
|
+
return Math.min(line, this.items().length);
|
|
352
|
+
return line < lines.starts.length ? lines.starts[line] : this.items().length;
|
|
353
|
+
}
|
|
249
354
|
/** Heights native has reported, by key. */
|
|
250
355
|
measured = new Map();
|
|
251
356
|
/** Bumped when a measurement changes, which is what re-sizes the list. */
|
|
@@ -268,14 +373,25 @@ export class VirtualList extends ScrollViewProps {
|
|
|
268
373
|
*/
|
|
269
374
|
table = computed(() => {
|
|
270
375
|
const height = this.itemHeight();
|
|
271
|
-
|
|
376
|
+
const lines = this.lines();
|
|
377
|
+
if (typeof height === 'number' && !lines)
|
|
272
378
|
return null;
|
|
273
379
|
// Each row's entry is its size and the gap after it, so where a row starts counts the gaps
|
|
274
380
|
// before it without a second table.
|
|
275
381
|
const gap = this.rowGap();
|
|
276
382
|
const items = this.items();
|
|
383
|
+
if (lines) {
|
|
384
|
+
// An entry a line, as tall as the tallest item on it.
|
|
385
|
+
const sizes = new Float64Array(lines.starts.length);
|
|
386
|
+
for (let i = 0; i < items.length; i++) {
|
|
387
|
+
const size = (typeof height === 'function' ? height(items[i], i) : height) + gap;
|
|
388
|
+
const line = lines.of[i];
|
|
389
|
+
sizes[line] = Math.max(sizes[line], size);
|
|
390
|
+
}
|
|
391
|
+
return new HeightIndex(sizes);
|
|
392
|
+
}
|
|
277
393
|
const sizes = new Float64Array(items.length);
|
|
278
|
-
if (height) {
|
|
394
|
+
if (typeof height === 'function') {
|
|
279
395
|
for (let i = 0; i < items.length; i++)
|
|
280
396
|
sizes[i] = height(items[i], i) + gap;
|
|
281
397
|
return new HeightIndex(sizes);
|
|
@@ -374,23 +490,26 @@ export class VirtualList extends ScrollViewProps {
|
|
|
374
490
|
return flip ? { ...spacing, transform: flip } : spacing;
|
|
375
491
|
}, /* @ts-ignore */
|
|
376
492
|
...(ngDevMode ? [{ debugName: "flowStyle" }] : /* istanbul ignore next */ []));
|
|
377
|
-
/** Top of a row: the leading padding, and every row and gap before it. */
|
|
493
|
+
/** Top of a row: the leading padding, and every row and gap before it. In columns, its line's. */
|
|
378
494
|
topOf(index) {
|
|
379
495
|
const table = this.layout();
|
|
380
|
-
return this.lead() + (table ? table.topOf(index) : index * this.stride());
|
|
496
|
+
return this.lead() + (table ? table.topOf(this.lineOf(index)) : index * this.stride());
|
|
381
497
|
}
|
|
382
|
-
/** A row's own size, without the gap after it. */
|
|
498
|
+
/** A row's own size, without the gap after it. In columns, its line's. */
|
|
383
499
|
heightOf(index) {
|
|
384
500
|
const table = this.layout();
|
|
385
|
-
|
|
501
|
+
if (!table)
|
|
502
|
+
return this.itemHeight();
|
|
503
|
+
return table.heightOf(this.lineOf(index)) - this.rowGap();
|
|
386
504
|
}
|
|
387
|
-
/** First row whose bottom, or the gap after it, is past `y`. */
|
|
505
|
+
/** First row whose bottom, or the gap after it, is past `y`. In columns, the first on its line. */
|
|
388
506
|
indexAt(y) {
|
|
389
507
|
const table = this.layout();
|
|
390
508
|
const along = y - this.lead();
|
|
391
509
|
if (!table)
|
|
392
510
|
return Math.max(0, Math.floor(along / this.stride()));
|
|
393
|
-
|
|
511
|
+
const at = table.indexAt(along);
|
|
512
|
+
return this.lines() ? this.lineStart(at) : at;
|
|
394
513
|
}
|
|
395
514
|
// --- holding position -------------------------------------------------------------------
|
|
396
515
|
/** The row the viewport's leading edge is in, taken at each scroll. */
|
|
@@ -448,13 +567,28 @@ export class VirtualList extends ScrollViewProps {
|
|
|
448
567
|
return this.showStart();
|
|
449
568
|
if (index < 0)
|
|
450
569
|
return this.atOffset();
|
|
451
|
-
|
|
570
|
+
// No further than the content lets native scroll, past the footer and the inset after it:
|
|
571
|
+
// Android stops a scroll there and iOS would show blank space past it, and the window must be
|
|
572
|
+
// built for where it is. Not cut at the start, where an inset before the rows, or a bounce,
|
|
573
|
+
// puts native above zero.
|
|
574
|
+
const header = this.headerHeight();
|
|
575
|
+
const want = this.topOf(index) + anchor.within;
|
|
576
|
+
const held = Math.min(want, this.reachable(header + want) - header);
|
|
452
577
|
if (Math.abs(held - this.lastOffset) > HOLD_TOLERANCE) {
|
|
453
578
|
this.pendingScroll = { offset: held, animated: false };
|
|
454
579
|
this.lastOffset = held;
|
|
455
580
|
}
|
|
456
|
-
|
|
457
|
-
|
|
581
|
+
// The window is built from the row the held offset lands in, which is not the anchored one
|
|
582
|
+
// when that row came out shorter than the way into it: a new column count can move an item
|
|
583
|
+
// off a line made tall by another item, onto a short one.
|
|
584
|
+
// In a single column the anchored row is kept, so a row scrolled to stays held there.
|
|
585
|
+
const top = this.lines() ? Math.max(0, Math.min(this.indexAt(held), items.length - 1)) : index;
|
|
586
|
+
if (top === index) {
|
|
587
|
+
this.anchor = { ...anchor, items, index };
|
|
588
|
+
return index;
|
|
589
|
+
}
|
|
590
|
+
this.anchorAt(top, held);
|
|
591
|
+
return top;
|
|
458
592
|
}
|
|
459
593
|
/**
|
|
460
594
|
* The row under the offset native is still at, in rows that have just replaced the old ones, as
|
|
@@ -536,23 +670,31 @@ export class VirtualList extends ScrollViewProps {
|
|
|
536
670
|
super();
|
|
537
671
|
afterEveryRender(() => {
|
|
538
672
|
this.flushScroll();
|
|
539
|
-
if (this.
|
|
673
|
+
if (this.sticky.native)
|
|
540
674
|
this.driveStickyRows();
|
|
541
675
|
this.recheckItems();
|
|
542
676
|
});
|
|
677
|
+
// Not a host `(scroll)` listener: Angular marks every view above one dirty on each event, so a
|
|
678
|
+
// fling would check the whole screen every frame. What a scroll changes is in signals, which
|
|
679
|
+
// schedule the views that read them.
|
|
680
|
+
const stopScroll = this.engine.setEventListener(this.node, 'topScroll', (event) => this.onScroll(event));
|
|
543
681
|
const stop = dismissKeyboardOnTap(this.engine, this.node, () => this.keyboardShouldPersistTaps());
|
|
544
682
|
inject(DestroyRef).onDestroy(() => {
|
|
683
|
+
stopScroll();
|
|
545
684
|
stop();
|
|
546
|
-
|
|
685
|
+
this.sticky.destroy();
|
|
686
|
+
clearTimeout(this.fillTimer);
|
|
687
|
+
clearTimeout(this.speedTimer);
|
|
547
688
|
this.zeroSize?.stop();
|
|
548
|
-
for (const held of this.drives.values())
|
|
549
|
-
held.drive.stop();
|
|
550
689
|
});
|
|
551
690
|
if (this.zeroSize)
|
|
552
691
|
this.checkZeroSize(this.zeroSize);
|
|
692
|
+
effect(() => this.scheduleFill());
|
|
553
693
|
}
|
|
554
694
|
/** The items the end and viewability were last checked against after a render. */
|
|
555
695
|
checkedItems = null;
|
|
696
|
+
/** And the table placing them, which a new column count makes again for the same items. */
|
|
697
|
+
checkedTable = null;
|
|
556
698
|
/**
|
|
557
699
|
* New items can bring the end within reach or change what is on screen with no scroll: a list
|
|
558
700
|
* shorter than its viewport, a page appended while at the end, a filter. Checked once the rows
|
|
@@ -560,9 +702,11 @@ export class VirtualList extends ScrollViewProps {
|
|
|
560
702
|
*/
|
|
561
703
|
recheckItems() {
|
|
562
704
|
const items = this.items();
|
|
563
|
-
|
|
705
|
+
const table = this.table();
|
|
706
|
+
if (items === this.checkedItems && table === this.checkedTable)
|
|
564
707
|
return;
|
|
565
708
|
this.checkedItems = items;
|
|
709
|
+
this.checkedTable = table;
|
|
566
710
|
this.checkEnd(this.headerHeight() + this.lastOffset);
|
|
567
711
|
this.announceViewable(this.lastOffset);
|
|
568
712
|
}
|
|
@@ -587,11 +731,15 @@ export class VirtualList extends ScrollViewProps {
|
|
|
587
731
|
const overscan = this.overscan();
|
|
588
732
|
if (!items.length)
|
|
589
733
|
return null;
|
|
590
|
-
|
|
591
|
-
const
|
|
734
|
+
// Counted in lines, which are rows unless items are in columns.
|
|
735
|
+
const line = this.lineOf(Math.min(this.visible(), items.length - 1));
|
|
736
|
+
const visible = this.lineStart(line);
|
|
737
|
+
// In viewports, so nothing before the first layout.
|
|
738
|
+
const fill = this.reach();
|
|
592
739
|
// Before the first layout we have no viewport, so render a screen's worth optimistically
|
|
593
740
|
// rather than nothing: an empty first frame is worse than a few extra rows.
|
|
594
|
-
const
|
|
741
|
+
const overscanned = this.lineStart(Math.max(0, line - overscan));
|
|
742
|
+
const budget = viewport > 0 ? viewport : this.heightOf(overscanned) * overscan * 2;
|
|
595
743
|
/*
|
|
596
744
|
* Measured from the top of the first *visible* row, not the first rendered one.
|
|
597
745
|
*
|
|
@@ -601,7 +749,11 @@ export class VirtualList extends ScrollViewProps {
|
|
|
601
749
|
* then the rows added below happened to be worth exactly the rows wasted above. With mixed
|
|
602
750
|
* heights they are not, and the list clips short of its own bottom.
|
|
603
751
|
*/
|
|
752
|
+
// Within three viewports of the viewport as it is now, which may have shrunk since.
|
|
753
|
+
const reach = 3 * Math.max(0, viewport);
|
|
754
|
+
const ahead = this.velocityLead() ? Math.max(-reach, Math.min(reach, this.ahead())) : 0;
|
|
604
755
|
const top = this.topOf(visible);
|
|
756
|
+
const first = Math.max(0, Math.min(overscanned, this.indexAt(top - fill.before * viewport - Math.max(0, -ahead))));
|
|
605
757
|
let last = visible;
|
|
606
758
|
while (last < items.length && this.topOf(last) < top + budget)
|
|
607
759
|
last++;
|
|
@@ -612,8 +764,13 @@ export class VirtualList extends ScrollViewProps {
|
|
|
612
764
|
* from the scroll offset instead, the window would change on every scroll event rather than
|
|
613
765
|
* when the visible row does.
|
|
614
766
|
*/
|
|
615
|
-
let end =
|
|
616
|
-
const deepest = top +
|
|
767
|
+
let end = last < items.length ? this.lineStart(this.lineOf(last) + overscan) : items.length;
|
|
768
|
+
const deepest = top +
|
|
769
|
+
this.heightOf(visible) +
|
|
770
|
+
this.rowGap() +
|
|
771
|
+
budget +
|
|
772
|
+
fill.after * viewport +
|
|
773
|
+
Math.max(0, ahead);
|
|
617
774
|
while (end < items.length && this.topOf(end) < deepest)
|
|
618
775
|
end++;
|
|
619
776
|
return { first, last: end };
|
|
@@ -643,9 +800,9 @@ export class VirtualList extends ScrollViewProps {
|
|
|
643
800
|
spacer = computed(() => {
|
|
644
801
|
const span = this.span();
|
|
645
802
|
let lead = span ? this.topOf(span.first) : 0;
|
|
646
|
-
const pinned = this.
|
|
803
|
+
const pinned = this.sticky.pinned();
|
|
647
804
|
if (span && pinned !== null && pinned < span.first) {
|
|
648
|
-
lead = this.
|
|
805
|
+
lead = this.sticky.native ? this.topOf(pinned) : lead - this.heightOf(pinned) - this.rowGap();
|
|
649
806
|
}
|
|
650
807
|
return this.horizontal() ? { width: Math.max(0, lead) } : { height: Math.max(0, lead) };
|
|
651
808
|
}, /* @ts-ignore */
|
|
@@ -653,7 +810,7 @@ export class VirtualList extends ScrollViewProps {
|
|
|
653
810
|
/** The rows from `first` up to `last`, and the pinned row above them if there is one. */
|
|
654
811
|
rowsFor(items, first, last) {
|
|
655
812
|
const rows = [];
|
|
656
|
-
const pinned = this.
|
|
813
|
+
const pinned = this.sticky.pinned();
|
|
657
814
|
const pinnedAbove = pinned !== null && pinned < first;
|
|
658
815
|
this.releaseRecycled(first, last, pinnedAbove ? pinned : null);
|
|
659
816
|
// The pinned row is on screen even when its own place in the list is not, which is the whole
|
|
@@ -665,11 +822,11 @@ export class VirtualList extends ScrollViewProps {
|
|
|
665
822
|
slot: this.recycledSlot(key, items[pinned], pinned),
|
|
666
823
|
key,
|
|
667
824
|
item: items[pinned],
|
|
668
|
-
style: this.
|
|
669
|
-
? this.
|
|
825
|
+
style: this.sticky.native
|
|
826
|
+
? this.sticky.style(pinned)
|
|
670
827
|
: this.measuring()
|
|
671
|
-
? this.
|
|
672
|
-
: this.slotStyle(pinned, this.offset()),
|
|
828
|
+
? this.sticky.flowStyle(this.topOf(first) - this.heightOf(pinned) - this.rowGap())
|
|
829
|
+
: this.slotStyle(pinned, this.sticky.offset()),
|
|
673
830
|
}));
|
|
674
831
|
}
|
|
675
832
|
for (let index = first; index < last; index++) {
|
|
@@ -682,7 +839,7 @@ export class VirtualList extends ScrollViewProps {
|
|
|
682
839
|
style: this.styleFor(index, index === pinned),
|
|
683
840
|
}));
|
|
684
841
|
}
|
|
685
|
-
if (pinnedAbove && this.
|
|
842
|
+
if (pinnedAbove && this.sticky.native && this.measuring())
|
|
686
843
|
this.leadWindow(rows, pinned, first);
|
|
687
844
|
return rows;
|
|
688
845
|
}
|
|
@@ -701,98 +858,23 @@ export class VirtualList extends ScrollViewProps {
|
|
|
701
858
|
rows[1] = this.hold({ ...lead, style: { ...lead.style, [margin]: between } });
|
|
702
859
|
}
|
|
703
860
|
styleFor(index, pinned) {
|
|
704
|
-
if (this.
|
|
705
|
-
return this.
|
|
861
|
+
if (this.sticky.native && this.sticky.next().has(index))
|
|
862
|
+
return this.sticky.style(index);
|
|
706
863
|
if (this.measuring()) {
|
|
707
|
-
return pinned ? this.
|
|
864
|
+
return pinned ? this.sticky.flowStyle(this.topOf(index)) : this.flowStyle();
|
|
708
865
|
}
|
|
709
|
-
return pinned ? this.slotStyle(index, this.offset()) : this.slotStyle(index);
|
|
710
|
-
}
|
|
711
|
-
/** A pinned row in flow, moved from where flow put it to the leading edge by a transform. */
|
|
712
|
-
pinnedFlowStyle(at) {
|
|
713
|
-
const shift = Math.max(0, this.offset() - at);
|
|
714
|
-
const move = `${this.horizontal() ? 'translateX' : 'translateY'}(${shift}px)`;
|
|
715
|
-
const flip = this.flipText();
|
|
716
|
-
return { ...this.flowSpacing(), zIndex: 1, transform: flip ? `${move} ${flip}` : move };
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* A sticky row native moves: at its own place, with the translate native had reached when
|
|
720
|
-
* scrolling paused, so the props agree with what is on screen.
|
|
721
|
-
*/
|
|
722
|
-
stickyStyle(index) {
|
|
723
|
-
const horizontal = this.horizontal();
|
|
724
|
-
const style = this.measuring()
|
|
725
|
-
? { ...this.flowSpacing() }
|
|
726
|
-
: { ...this.slotStyle(index) };
|
|
727
|
-
style['zIndex'] = 1;
|
|
728
|
-
const top = this.topOf(index);
|
|
729
|
-
const shift = Math.min(Math.max(0, this.settled() - top), this.stopOf(index) - top);
|
|
730
|
-
const move = shift > 0 ? `${horizontal ? 'translateX' : 'translateY'}(${shift}px)` : '';
|
|
731
|
-
const transform = [move, this.flipText() ?? ''].filter(Boolean).join(' ');
|
|
732
|
-
if (transform)
|
|
733
|
-
style['transform'] = transform;
|
|
734
|
-
return style;
|
|
735
|
-
}
|
|
736
|
-
/** Each sticky row, and the one after it, which pushes it off. */
|
|
737
|
-
nextSticky = computed(() => {
|
|
738
|
-
const sticky = this.stickyIndices();
|
|
739
|
-
return new Map(sticky.map((index, at) => [index, sticky[at + 1]]));
|
|
740
|
-
}, /* @ts-ignore */
|
|
741
|
-
...(ngDevMode ? [{ debugName: "nextSticky" }] : /* istanbul ignore next */ []));
|
|
742
|
-
/** Where a sticky row stops, pushed off by the next: that row's top, less this row's size. */
|
|
743
|
-
stopOf(index) {
|
|
744
|
-
const next = this.nextSticky().get(index);
|
|
745
|
-
return next === undefined ? Infinity : this.topOf(next) - this.heightOf(index);
|
|
746
|
-
}
|
|
747
|
-
/**
|
|
748
|
-
* How native moves a rendered row, or null when it does not: along the scroll view's own
|
|
749
|
-
* offset, which counts the header, from the row's top until the next sticky row pushes it off.
|
|
750
|
-
*/
|
|
751
|
-
stickyDrive(row) {
|
|
752
|
-
if (!this.nativeSticky || row.parked || !this.nextSticky().has(row.index))
|
|
753
|
-
return null;
|
|
754
|
-
const header = this.headerHeight();
|
|
755
|
-
const start = header + this.topOf(row.index);
|
|
756
|
-
return {
|
|
757
|
-
range: pinnedRange(start, header + this.stopOf(row.index)),
|
|
758
|
-
statics: this.flip() ?? [],
|
|
759
|
-
};
|
|
866
|
+
return pinned ? this.slotStyle(index, this.sticky.offset()) : this.slotStyle(index);
|
|
760
867
|
}
|
|
761
868
|
/**
|
|
762
|
-
* Hand each rendered sticky row's view to native to move
|
|
763
|
-
*
|
|
764
|
-
*
|
|
869
|
+
* Hand each rendered sticky row's view to native to move. The rows' views are the canvas's
|
|
870
|
+
* element children in window order, after the spacer, which is how `@for` over `window()`
|
|
871
|
+
* leaves them.
|
|
765
872
|
*/
|
|
766
873
|
driveStickyRows() {
|
|
767
|
-
|
|
768
|
-
return;
|
|
769
|
-
const canvas = this.canvasView().nativeElement;
|
|
770
|
-
const views = canvas.childList
|
|
874
|
+
const views = () => this.canvasView().nativeElement.childList
|
|
771
875
|
.filter((child) => child.nodeKind === 'element')
|
|
772
876
|
.slice(this.measuring() ? 1 : 0);
|
|
773
|
-
|
|
774
|
-
const live = new Set();
|
|
775
|
-
this.window().forEach((row, at) => {
|
|
776
|
-
const view = views[at];
|
|
777
|
-
const next = this.stickyDrive(row);
|
|
778
|
-
if (!view || !next)
|
|
779
|
-
return;
|
|
780
|
-
live.add(view);
|
|
781
|
-
const statics = JSON.stringify(next.statics);
|
|
782
|
-
const held = this.drives.get(view);
|
|
783
|
-
if (held?.statics === statics)
|
|
784
|
-
return held.drive.update(next.range);
|
|
785
|
-
held?.drive.stop();
|
|
786
|
-
const drive = this.engine.driveByScroll(view, this.node, axis, next.range, next.statics);
|
|
787
|
-
if (drive)
|
|
788
|
-
this.drives.set(view, { drive, statics });
|
|
789
|
-
});
|
|
790
|
-
for (const [view, held] of this.drives) {
|
|
791
|
-
if (live.has(view))
|
|
792
|
-
continue;
|
|
793
|
-
held.drive.stop();
|
|
794
|
-
this.drives.delete(view);
|
|
795
|
-
}
|
|
877
|
+
this.sticky.drive(() => this.window(), views);
|
|
796
878
|
}
|
|
797
879
|
/** Which recycling slot each rendered item holds, by key: its type, and the row it last drew. */
|
|
798
880
|
recycled = new Map();
|
|
@@ -845,10 +927,14 @@ export class VirtualList extends ScrollViewProps {
|
|
|
845
927
|
return { index: -1, slot, key, item: this.items()[0], style: PARKED };
|
|
846
928
|
}
|
|
847
929
|
recycledSlot(key, item, index) {
|
|
930
|
+
// A sticky row is a type of its own: native keeps the translate it moved one by, and a plain
|
|
931
|
+
// row taking its slot commits no transform to put it back. A row that stops or starts being
|
|
932
|
+
// sticky takes a new slot for the same reason.
|
|
933
|
+
const sticky = this.sticky.next().has(index);
|
|
848
934
|
const held = this.recycled.get(key);
|
|
849
|
-
if (held)
|
|
935
|
+
if (held && this.sticky.isType(held.type) === sticky)
|
|
850
936
|
return held.slot;
|
|
851
|
-
const type = this.itemType()?.(item, index);
|
|
937
|
+
const type = this.sticky.recyclingType(index, this.itemType()?.(item, index));
|
|
852
938
|
const slot = this.unpark(key, type) ?? this.parked.get(type)?.pop()?.slot ?? this.nextSlot++;
|
|
853
939
|
this.recycled.set(key, { slot, type, row: null });
|
|
854
940
|
return slot;
|
|
@@ -912,12 +998,13 @@ export class VirtualList extends ScrollViewProps {
|
|
|
912
998
|
const items = this.items();
|
|
913
999
|
const gaps = [];
|
|
914
1000
|
for (const row of this.window()) {
|
|
915
|
-
if (row.parked || row.index
|
|
1001
|
+
if (row.parked || this.onLastLine(row.index))
|
|
916
1002
|
continue;
|
|
917
1003
|
const style = this.measuring() ? this.measuredGapStyle(row) : this.gapStyle(row);
|
|
918
1004
|
if (!style)
|
|
919
1005
|
continue;
|
|
920
|
-
|
|
1006
|
+
// What follows it along the list: the next line's first item, not the one beside it.
|
|
1007
|
+
const trailingItem = items[this.lineStart(this.lineOf(row.index) + 1)];
|
|
921
1008
|
gaps.push({
|
|
922
1009
|
index: row.index,
|
|
923
1010
|
style,
|
|
@@ -976,23 +1063,8 @@ export class VirtualList extends ScrollViewProps {
|
|
|
976
1063
|
this.measuredGaps.clear();
|
|
977
1064
|
return style;
|
|
978
1065
|
}
|
|
979
|
-
/**
|
|
980
|
-
|
|
981
|
-
* overscroll and at the first sticky row, which pushes it off.
|
|
982
|
-
*/
|
|
983
|
-
headerStyle = computed(() => {
|
|
984
|
-
const flip = this.flipText();
|
|
985
|
-
if (!this.stickyHeader())
|
|
986
|
-
return flip ? { transform: flip } : undefined;
|
|
987
|
-
const along = this.offset() + this.headerHeight();
|
|
988
|
-
const first = this.stickyIndices()[0];
|
|
989
|
-
const limit = first === undefined ? Infinity : this.topOf(first);
|
|
990
|
-
const shift = Math.min(Math.max(0, along), limit);
|
|
991
|
-
const move = shift > 0 ? `${this.horizontal() ? 'translateX' : 'translateY'}(${shift}px)` : '';
|
|
992
|
-
const transform = [move, flip ?? ''].filter(Boolean).join(' ');
|
|
993
|
-
return transform ? { zIndex: 1, transform } : { zIndex: 1 };
|
|
994
|
-
}, /* @ts-ignore */
|
|
995
|
-
...(ngDevMode ? [{ debugName: "headerStyle" }] : /* istanbul ignore next */ []));
|
|
1066
|
+
/** The header, pinned with the rows when `stickyHeader` says so: see `StickyRows`. */
|
|
1067
|
+
headerStyle = this.sticky.headerStyle;
|
|
996
1068
|
/**
|
|
997
1069
|
* The footer, flipped back like every row when the list is inverted, as FlatList inverts its
|
|
998
1070
|
* header and footer cells too; otherwise both read upside down.
|
|
@@ -1002,25 +1074,6 @@ export class VirtualList extends ScrollViewProps {
|
|
|
1002
1074
|
return flip ? { transform: flip } : undefined;
|
|
1003
1075
|
}, /* @ts-ignore */
|
|
1004
1076
|
...(ngDevMode ? [{ debugName: "footerStyle" }] : /* istanbul ignore next */ []));
|
|
1005
|
-
/**
|
|
1006
|
-
* The sticky row currently holding the leading edge: the last one at or before the offset.
|
|
1007
|
-
* Null when the list has scrolled back above the first of them.
|
|
1008
|
-
*/
|
|
1009
|
-
pinnedIndex = computed(() => {
|
|
1010
|
-
const sticky = this.stickyIndices();
|
|
1011
|
-
if (sticky.length === 0)
|
|
1012
|
-
return null;
|
|
1013
|
-
const offset = this.offset();
|
|
1014
|
-
let pinned = null;
|
|
1015
|
-
for (const index of sticky) {
|
|
1016
|
-
if (this.topOf(index) <= offset)
|
|
1017
|
-
pinned = index;
|
|
1018
|
-
else
|
|
1019
|
-
break;
|
|
1020
|
-
}
|
|
1021
|
-
return pinned;
|
|
1022
|
-
}, /* @ts-ignore */
|
|
1023
|
-
...(ngDevMode ? [{ debugName: "pinnedIndex" }] : /* istanbul ignore next */ []));
|
|
1024
1077
|
/** Which rows are on screen far enough to count, by the caller's threshold. */
|
|
1025
1078
|
viewableAt(offset) {
|
|
1026
1079
|
const viewport = this.viewport();
|
|
@@ -1090,16 +1143,22 @@ export class VirtualList extends ScrollViewProps {
|
|
|
1090
1143
|
const offset = this.topOf(index) + within;
|
|
1091
1144
|
this.lastOffset = offset;
|
|
1092
1145
|
this.anchor = { key: this.keyAt(index), within, items, index };
|
|
1093
|
-
this.
|
|
1146
|
+
this.jumpTo(index);
|
|
1147
|
+
// The start of its line, which is what a scroll event there gives, so the fill keeps its way.
|
|
1148
|
+
this.moveTo(this.lineStart(this.lineOf(index)));
|
|
1094
1149
|
this.scrollToOffset({ offset: this.headerHeight() + offset, animated: options.animated });
|
|
1095
1150
|
}
|
|
1096
1151
|
/** Scroll to an offset along the list's own axis: x when it is horizontal, y otherwise. */
|
|
1097
1152
|
scrollToOffset(options) {
|
|
1098
1153
|
const { offset, animated = true } = options;
|
|
1154
|
+
this.jumpTo(this.indexAt(offset - this.headerHeight()));
|
|
1099
1155
|
const [x, y] = this.horizontal() ? [offset, 0] : [0, offset];
|
|
1156
|
+
this.sticky.jumping(this.reachable(offset), animated);
|
|
1100
1157
|
this.engine.dispatchCommand(this.node, 'scrollTo', [x, y, animated]);
|
|
1101
1158
|
}
|
|
1102
1159
|
scrollToEnd(options = {}) {
|
|
1160
|
+
this.sticky.jumping(this.reachable(Infinity), options.animated ?? true);
|
|
1161
|
+
this.jumpTo(this.items().length - 1);
|
|
1103
1162
|
this.engine.dispatchCommand(this.node, 'scrollToEnd', [options.animated ?? true]);
|
|
1104
1163
|
}
|
|
1105
1164
|
slotStyle(index, pinnedAt) {
|
|
@@ -1109,7 +1168,7 @@ export class VirtualList extends ScrollViewProps {
|
|
|
1109
1168
|
const key = horizontal ? 'left' : 'top';
|
|
1110
1169
|
const extent = horizontal ? 'width' : 'height';
|
|
1111
1170
|
const flip = this.flipText();
|
|
1112
|
-
const across = this.
|
|
1171
|
+
const across = this.acrossOf(index);
|
|
1113
1172
|
let style = this.slots.get(index);
|
|
1114
1173
|
// The flip is part of the comparison because turning the list over changes every row, and a
|
|
1115
1174
|
// cached slot would otherwise keep the orientation it was built with.
|
|
@@ -1138,25 +1197,123 @@ export class VirtualList extends ScrollViewProps {
|
|
|
1138
1197
|
// window is built, so that both edges can be measured from the same place.
|
|
1139
1198
|
// Not clamped to the items: an input set in the same task as this event has not reached the
|
|
1140
1199
|
// list yet, and the window clamps when it renders.
|
|
1200
|
+
this.trackSpeed(content, event.nativeEvent?.timestamp);
|
|
1141
1201
|
const visible = this.indexAt(content);
|
|
1142
1202
|
if (visible !== this.visible())
|
|
1143
|
-
this.
|
|
1203
|
+
this.moveTo(visible);
|
|
1144
1204
|
this.lastOffset = content;
|
|
1145
1205
|
this.anchorAt(visible, content);
|
|
1146
|
-
|
|
1147
|
-
// signal - and only then. Without them this stays a field, and a fling that moves no row in
|
|
1148
|
-
// or out of the window costs no change detection at all.
|
|
1149
|
-
if (this.pinning())
|
|
1150
|
-
this.offset.set(content);
|
|
1151
|
-
if (this.nativeSticky && this.pinning())
|
|
1152
|
-
this.settleAfterPause(content);
|
|
1206
|
+
this.sticky.scrolled(content, along);
|
|
1153
1207
|
this.checkEnd(along);
|
|
1154
1208
|
this.announceViewable(content);
|
|
1155
1209
|
}
|
|
1156
|
-
/**
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1210
|
+
/**
|
|
1211
|
+
* Points the window reaches past the viewport for the scroll's speed, positive toward the end,
|
|
1212
|
+
* in steps of a quarter viewport: written only when it moves a step, so a fling costs a pass
|
|
1213
|
+
* for it every few frames rather than on every scroll event.
|
|
1214
|
+
*/
|
|
1215
|
+
ahead = signal(0, /* @ts-ignore */
|
|
1216
|
+
...(ngDevMode ? [{ debugName: "ahead" }] : /* istanbul ignore next */ []));
|
|
1217
|
+
/** The speed's lead before rounding to a step, eased from one event to the next. */
|
|
1218
|
+
eased = 0;
|
|
1219
|
+
/** The offset of the last scroll event, and when it arrived. */
|
|
1220
|
+
lastScroll = { offset: 0, at: -Infinity };
|
|
1221
|
+
/** Lets go of the reach once scroll events stop, which is all a scroll that stops sends. */
|
|
1222
|
+
speedTimer;
|
|
1223
|
+
/**
|
|
1224
|
+
* Follow the scroll's speed, from each scroll event's offset and the time native sent it, in
|
|
1225
|
+
* milliseconds, which iOS and Android both give. Not the time it reached JavaScript: a thread
|
|
1226
|
+
* that fell behind gets a fling's events in a burst, which would read as no time at all between
|
|
1227
|
+
* them. Where native gives no time, as on the web, the time it arrived.
|
|
1228
|
+
*/
|
|
1229
|
+
trackSpeed(offset, sent) {
|
|
1230
|
+
const ms = this.velocityLead();
|
|
1231
|
+
const now = typeof sent === 'number' && Number.isFinite(sent) ? sent : performance.now();
|
|
1232
|
+
const elapsed = now - this.lastScroll.at;
|
|
1233
|
+
const moved = offset - this.lastScroll.offset;
|
|
1234
|
+
this.lastScroll = { offset, at: now };
|
|
1235
|
+
const viewport = this.viewport();
|
|
1236
|
+
// A pause, or the first event of a scroll, starts the speed over.
|
|
1237
|
+
if (!ms || !viewport || elapsed <= 0 || elapsed > PAUSE_MS) {
|
|
1238
|
+
this.eased = 0;
|
|
1239
|
+
}
|
|
1240
|
+
else {
|
|
1241
|
+
const reach = 3 * viewport;
|
|
1242
|
+
const clamp = (value) => Math.max(-reach, Math.min(reach, value));
|
|
1243
|
+
// Halfway to the new speed, so one late event does not throw the window around.
|
|
1244
|
+
this.eased = clamp((this.eased + clamp((moved / elapsed) * ms)) / 2);
|
|
1245
|
+
}
|
|
1246
|
+
const step = viewport / 4;
|
|
1247
|
+
const ahead = step ? Math.round(this.eased / step) * step : 0;
|
|
1248
|
+
this.ahead.set(ahead);
|
|
1249
|
+
clearTimeout(this.speedTimer);
|
|
1250
|
+
if (ahead)
|
|
1251
|
+
this.speedTimer = setTimeout(() => this.stopSpeed(), PAUSE_MS);
|
|
1252
|
+
}
|
|
1253
|
+
/** Start the speed over: a pause, or a jump, which is no fling. */
|
|
1254
|
+
stopSpeed() {
|
|
1255
|
+
clearTimeout(this.speedTimer);
|
|
1256
|
+
this.lastScroll = { offset: 0, at: -Infinity };
|
|
1257
|
+
this.eased = 0;
|
|
1258
|
+
this.ahead.set(0);
|
|
1259
|
+
}
|
|
1260
|
+
/** The most viewports rendered ahead of the scroll direction and behind it. */
|
|
1261
|
+
fillCaps() {
|
|
1262
|
+
const extra = Math.max(0, Math.floor(this.windowSize()) - 1);
|
|
1263
|
+
const behind = Math.floor(extra / 3);
|
|
1264
|
+
return { ahead: extra - behind, behind };
|
|
1265
|
+
}
|
|
1266
|
+
/** Move the window to a new visible row. */
|
|
1267
|
+
moveTo(visible) {
|
|
1268
|
+
this.turn(Math.sign(visible - this.visible()));
|
|
1269
|
+
this.visible.set(visible);
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* Start the fill over before a scroll the list is told to make lands past the rendered rows, so
|
|
1273
|
+
* it renders one viewport there, not the whole filled window, in a single pass. A scroll the
|
|
1274
|
+
* user makes keeps it: one past the rendered rows is a fling outrunning them, which is what the
|
|
1275
|
+
* fill is for.
|
|
1276
|
+
*/
|
|
1277
|
+
jumpTo(index) {
|
|
1278
|
+
const span = this.span();
|
|
1279
|
+
if (span && (index < span.first || index >= span.last))
|
|
1280
|
+
this.fill.set({ before: 0, after: 0 });
|
|
1281
|
+
// Nor is the scroll that reports it a fling: its speed starts over from where it lands.
|
|
1282
|
+
this.stopSpeed();
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Follow a change of scroll direction: the rows filled behind are now ahead, and those ahead are
|
|
1286
|
+
* kept only up to what is kept behind.
|
|
1287
|
+
*/
|
|
1288
|
+
turn(direction) {
|
|
1289
|
+
if (!direction || direction === this.direction())
|
|
1290
|
+
return;
|
|
1291
|
+
this.direction.set(direction);
|
|
1292
|
+
this.fill.set(this.reach());
|
|
1293
|
+
}
|
|
1294
|
+
/** The side the window grows on next, ahead of the scroll first, or null once both are full. */
|
|
1295
|
+
nextFill(reach) {
|
|
1296
|
+
const { ahead, behind } = this.fillCaps();
|
|
1297
|
+
const [front, back] = this.direction() > 0 ? ['after', 'before'] : ['before', 'after'];
|
|
1298
|
+
return reach[front] < ahead ? front : reach[back] < behind ? back : null;
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Grow the window by a viewport once the JS thread has been free for a batch period, ahead of
|
|
1302
|
+
* the scroll first. Every window change restarts the wait, so a fling is never slowed by it.
|
|
1303
|
+
*/
|
|
1304
|
+
scheduleFill() {
|
|
1305
|
+
clearTimeout(this.fillTimer);
|
|
1306
|
+
const reach = this.reach();
|
|
1307
|
+
// Keep a cut made by a lower windowSize, so raising it again fills a batch at a time.
|
|
1308
|
+
const fill = untracked(this.fill);
|
|
1309
|
+
if (fill.before !== reach.before || fill.after !== reach.after)
|
|
1310
|
+
this.fill.set(reach);
|
|
1311
|
+
if (!this.span() || this.viewport() <= 0)
|
|
1312
|
+
return;
|
|
1313
|
+
const side = this.nextFill(reach);
|
|
1314
|
+
if (!side)
|
|
1315
|
+
return;
|
|
1316
|
+
this.fillTimer = setTimeout(() => this.fill.set({ ...reach, [side]: reach[side] + 1 }), FILL_BATCH_MS);
|
|
1160
1317
|
}
|
|
1161
1318
|
onLayout(event) {
|
|
1162
1319
|
const layout = event.nativeEvent?.layout;
|
|
@@ -1191,19 +1348,42 @@ export class VirtualList extends ScrollViewProps {
|
|
|
1191
1348
|
onContentSize(event) {
|
|
1192
1349
|
const size = event.nativeEvent;
|
|
1193
1350
|
this.contentSize = (this.horizontal() ? size?.width : size?.height) ?? 0;
|
|
1194
|
-
this.contentSizeFor = this.extent();
|
|
1351
|
+
this.contentSizeFor = this.headerHeight() + this.extent();
|
|
1195
1352
|
this.checkEnd(this.headerHeight() + this.lastOffset);
|
|
1196
1353
|
}
|
|
1354
|
+
/** The scroll view's content along the axis, header and all. */
|
|
1355
|
+
contentExtent() {
|
|
1356
|
+
// Native's size is for the rows it last laid out; until it reports for these, their own extent.
|
|
1357
|
+
const own = this.headerHeight() + this.extent();
|
|
1358
|
+
return this.contentSizeFor === own ? this.contentSize : own;
|
|
1359
|
+
}
|
|
1360
|
+
/** The user took the scroll over: native's own events move the rows from here. */
|
|
1361
|
+
onDragBegin() {
|
|
1362
|
+
this.sticky.dragged();
|
|
1363
|
+
}
|
|
1364
|
+
/** A scroll came to rest: see `StickyRows.rested`. */
|
|
1365
|
+
onScrollEnd() {
|
|
1366
|
+
this.sticky.rested();
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* How far toward `offset` the content lets native scroll. Android stops a scroll at its end and
|
|
1370
|
+
* says nothing of it; iOS goes past, and its scroll end event says where it came to rest.
|
|
1371
|
+
*/
|
|
1372
|
+
reachable(offset) {
|
|
1373
|
+
const viewport = this.viewport();
|
|
1374
|
+
const total = this.contentExtent();
|
|
1375
|
+
// Past the content by the inset after it, where the scroll view lets it go.
|
|
1376
|
+
const inset = this.contentInset();
|
|
1377
|
+
const after = (this.horizontal() ? inset?.right : inset?.bottom) ?? 0;
|
|
1378
|
+
const end = viewport > 0 ? Math.max(0, total - viewport + after) : total;
|
|
1379
|
+
return Math.min(Math.max(0, offset), end);
|
|
1380
|
+
}
|
|
1197
1381
|
checkEnd(y) {
|
|
1198
1382
|
const count = this.items().length;
|
|
1199
1383
|
const viewport = this.viewport();
|
|
1200
1384
|
if (!count || !viewport)
|
|
1201
1385
|
return;
|
|
1202
|
-
|
|
1203
|
-
const extent = this.extent();
|
|
1204
|
-
const reported = this.contentSizeFor === extent ? this.contentSize : 0;
|
|
1205
|
-
const total = reported || this.headerHeight() + extent;
|
|
1206
|
-
const distanceFromEnd = total - (y + viewport);
|
|
1386
|
+
const distanceFromEnd = this.contentExtent() - (y + viewport);
|
|
1207
1387
|
// Away from the end again re-arms it, as React Native does, so a load that failed is retried
|
|
1208
1388
|
// the next time the user comes back down.
|
|
1209
1389
|
if (distanceFromEnd > this.endReachedThreshold() * viewport) {
|
|
@@ -1216,7 +1396,7 @@ export class VirtualList extends ScrollViewProps {
|
|
|
1216
1396
|
this.endReached.emit({ distanceFromEnd });
|
|
1217
1397
|
}
|
|
1218
1398
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: VirtualList, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1219
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: VirtualList, isStandalone: true, selector: "virtual-list", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: true, transformFunction: null }, itemHeight: { classPropertyName: "itemHeight", publicName: "itemHeight", isSignal: true, isRequired: false, transformFunction: null }, estimatedItemHeight: { classPropertyName: "estimatedItemHeight", publicName: "estimatedItemHeight", isSignal: true, isRequired: false, transformFunction: null }, contentPadding: { classPropertyName: "contentPadding", publicName: "contentPadding", isSignal: true, isRequired: false, transformFunction: null }, rowGap: { classPropertyName: "rowGap", publicName: "rowGap", isSignal: true, isRequired: false, transformFunction: null }, keyExtractor: { classPropertyName: "keyExtractor", publicName: "keyExtractor", isSignal: true, isRequired: false, transformFunction: null }, itemType: { classPropertyName: "itemType", publicName: "itemType", isSignal: true, isRequired: false, transformFunction: null }, maintainVisibleContentPosition: { classPropertyName: "maintainVisibleContentPosition", publicName: "maintainVisibleContentPosition", isSignal: true, isRequired: false, transformFunction: null }, overscan: { classPropertyName: "overscan", publicName: "overscan", isSignal: true, isRequired: false, transformFunction: null }, endReachedThreshold: { classPropertyName: "endReachedThreshold", publicName: "endReachedThreshold", isSignal: true, isRequired: false, transformFunction: null }, horizontal: { classPropertyName: "horizontal", publicName: "horizontal", isSignal: true, isRequired: false, transformFunction: null }, inverted: { classPropertyName: "inverted", publicName: "inverted", isSignal: true, isRequired: false, transformFunction: null }, stickyIndices: { classPropertyName: "stickyIndices", publicName: "stickyIndices", isSignal: true, isRequired: false, transformFunction: null }, stickyHeader: { classPropertyName: "stickyHeader", publicName: "stickyHeader", isSignal: true, isRequired: false, transformFunction: null }, keyboardShouldPersistTaps: { classPropertyName: "keyboardShouldPersistTaps", publicName: "keyboardShouldPersistTaps", isSignal: true, isRequired: false, transformFunction: null }, itemVisiblePercentThreshold: { classPropertyName: "itemVisiblePercentThreshold", publicName: "itemVisiblePercentThreshold", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { endReached: "endReached", viewableItemsChanged: "viewableItemsChanged" }, host: { listeners: { "
|
|
1399
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: VirtualList, isStandalone: true, selector: "virtual-list", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: true, transformFunction: null }, itemHeight: { classPropertyName: "itemHeight", publicName: "itemHeight", isSignal: true, isRequired: false, transformFunction: null }, estimatedItemHeight: { classPropertyName: "estimatedItemHeight", publicName: "estimatedItemHeight", isSignal: true, isRequired: false, transformFunction: null }, contentPadding: { classPropertyName: "contentPadding", publicName: "contentPadding", isSignal: true, isRequired: false, transformFunction: null }, rowGap: { classPropertyName: "rowGap", publicName: "rowGap", isSignal: true, isRequired: false, transformFunction: null }, keyExtractor: { classPropertyName: "keyExtractor", publicName: "keyExtractor", isSignal: true, isRequired: false, transformFunction: null }, itemType: { classPropertyName: "itemType", publicName: "itemType", isSignal: true, isRequired: false, transformFunction: null }, maintainVisibleContentPosition: { classPropertyName: "maintainVisibleContentPosition", publicName: "maintainVisibleContentPosition", isSignal: true, isRequired: false, transformFunction: null }, overscan: { classPropertyName: "overscan", publicName: "overscan", isSignal: true, isRequired: false, transformFunction: null }, windowSize: { classPropertyName: "windowSize", publicName: "windowSize", isSignal: true, isRequired: false, transformFunction: null }, velocityLead: { classPropertyName: "velocityLead", publicName: "velocityLead", isSignal: true, isRequired: false, transformFunction: null }, endReachedThreshold: { classPropertyName: "endReachedThreshold", publicName: "endReachedThreshold", isSignal: true, isRequired: false, transformFunction: null }, horizontal: { classPropertyName: "horizontal", publicName: "horizontal", isSignal: true, isRequired: false, transformFunction: null }, inverted: { classPropertyName: "inverted", publicName: "inverted", isSignal: true, isRequired: false, transformFunction: null }, stickyIndices: { classPropertyName: "stickyIndices", publicName: "stickyIndices", isSignal: true, isRequired: false, transformFunction: null }, stickyHeader: { classPropertyName: "stickyHeader", publicName: "stickyHeader", isSignal: true, isRequired: false, transformFunction: null }, keyboardShouldPersistTaps: { classPropertyName: "keyboardShouldPersistTaps", publicName: "keyboardShouldPersistTaps", isSignal: true, isRequired: false, transformFunction: null }, itemVisiblePercentThreshold: { classPropertyName: "itemVisiblePercentThreshold", publicName: "itemVisiblePercentThreshold", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { endReached: "endReached", viewableItemsChanged: "viewableItemsChanged" }, host: { listeners: { "scrollBeginDrag": "onDragBegin()", "momentumScrollEnd": "onScrollEnd()", "layout": "onLayout($event)", "contentSizeChange": "onContentSize($event)" }, properties: { "flexDirection": "horizontal() ? 'row' : 'column'", "horizontal": "horizontal()", "nestedScrollEnabled": "nestedScroll()", "transform": "flip()", "scrollEventThrottle": "scrollEventThrottle()" } }, queries: [{ propertyName: "separator", first: true, predicate: VirtualListSeparator, descendants: true, isSignal: true }, { propertyName: "refreshControl", first: true, predicate: RefreshControl, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "canvasView", first: true, predicate: ["rows"], descendants: true, read: ElementRef, isSignal: true }], exportAs: ["virtualList"], usesInheritance: true, ngImport: i0, template: `
|
|
1220
1400
|
<ng-content select="refresh-control" />
|
|
1221
1401
|
<view [style]="content()" collapsable="false">
|
|
1222
1402
|
<view [style]="headerStyle()" (layout)="onHeaderLayout($event)"
|
|
@@ -1290,12 +1470,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
1290
1470
|
// where it would have ended up.
|
|
1291
1471
|
'[transform]': 'flip()',
|
|
1292
1472
|
'[scrollEventThrottle]': 'scrollEventThrottle()',
|
|
1293
|
-
'(
|
|
1473
|
+
'(scrollBeginDrag)': 'onDragBegin()',
|
|
1474
|
+
'(momentumScrollEnd)': 'onScrollEnd()',
|
|
1294
1475
|
'(layout)': 'onLayout($event)',
|
|
1295
1476
|
'(contentSizeChange)': 'onContentSize($event)',
|
|
1296
1477
|
},
|
|
1297
1478
|
}]
|
|
1298
|
-
}], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: true }] }], itemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeight", required: false }] }], estimatedItemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "estimatedItemHeight", required: false }] }], contentPadding: [{ type: i0.Input, args: [{ isSignal: true, alias: "contentPadding", required: false }] }], rowGap: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowGap", required: false }] }], keyExtractor: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyExtractor", required: false }] }], itemType: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemType", required: false }] }], maintainVisibleContentPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "maintainVisibleContentPosition", required: false }] }], overscan: [{ type: i0.Input, args: [{ isSignal: true, alias: "overscan", required: false }] }], endReachedThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "endReachedThreshold", required: false }] }], horizontal: [{ type: i0.Input, args: [{ isSignal: true, alias: "horizontal", required: false }] }], inverted: [{ type: i0.Input, args: [{ isSignal: true, alias: "inverted", required: false }] }], stickyIndices: [{ type: i0.Input, args: [{ isSignal: true, alias: "stickyIndices", required: false }] }], stickyHeader: [{ type: i0.Input, args: [{ isSignal: true, alias: "stickyHeader", required: false }] }], keyboardShouldPersistTaps: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyboardShouldPersistTaps", required: false }] }], itemVisiblePercentThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemVisiblePercentThreshold", required: false }] }], endReached: [{ type: i0.Output, args: ["endReached"] }], viewableItemsChanged: [{ type: i0.Output, args: ["viewableItemsChanged"] }], separator: [{ type: i0.ContentChild, args: [i0.forwardRef(() => VirtualListSeparator), { isSignal: true }] }], refreshControl: [{ type: i0.ContentChild, args: [i0.forwardRef(() => RefreshControl), { isSignal: true }] }], canvasView: [{ type: i0.ViewChild, args: ['rows', { ...{ read: ElementRef }, isSignal: true }] }] } });
|
|
1479
|
+
}], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: true }] }], itemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeight", required: false }] }], estimatedItemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "estimatedItemHeight", required: false }] }], contentPadding: [{ type: i0.Input, args: [{ isSignal: true, alias: "contentPadding", required: false }] }], rowGap: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowGap", required: false }] }], keyExtractor: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyExtractor", required: false }] }], itemType: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemType", required: false }] }], maintainVisibleContentPosition: [{ type: i0.Input, args: [{ isSignal: true, alias: "maintainVisibleContentPosition", required: false }] }], overscan: [{ type: i0.Input, args: [{ isSignal: true, alias: "overscan", required: false }] }], windowSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "windowSize", required: false }] }], velocityLead: [{ type: i0.Input, args: [{ isSignal: true, alias: "velocityLead", required: false }] }], endReachedThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "endReachedThreshold", required: false }] }], horizontal: [{ type: i0.Input, args: [{ isSignal: true, alias: "horizontal", required: false }] }], inverted: [{ type: i0.Input, args: [{ isSignal: true, alias: "inverted", required: false }] }], stickyIndices: [{ type: i0.Input, args: [{ isSignal: true, alias: "stickyIndices", required: false }] }], stickyHeader: [{ type: i0.Input, args: [{ isSignal: true, alias: "stickyHeader", required: false }] }], keyboardShouldPersistTaps: [{ type: i0.Input, args: [{ isSignal: true, alias: "keyboardShouldPersistTaps", required: false }] }], itemVisiblePercentThreshold: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemVisiblePercentThreshold", required: false }] }], endReached: [{ type: i0.Output, args: ["endReached"] }], viewableItemsChanged: [{ type: i0.Output, args: ["viewableItemsChanged"] }], separator: [{ type: i0.ContentChild, args: [i0.forwardRef(() => VirtualListSeparator), { isSignal: true }] }], refreshControl: [{ type: i0.ContentChild, args: [i0.forwardRef(() => RefreshControl), { isSignal: true }] }], canvasView: [{ type: i0.ViewChild, args: ['rows', { ...{ read: ElementRef }, isSignal: true }] }] } });
|
|
1299
1480
|
/** Whether a cached slot style already has every one of these props. */
|
|
1300
1481
|
function holds(style, props) {
|
|
1301
1482
|
return Object.entries(props).every(([prop, value]) => style[prop] === value);
|