@solidtv/solid 1.6.5 → 1.7.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/src/core/dom-renderer/domRenderer.d.ts +7 -7
- package/dist/src/core/dom-renderer/domRenderer.js +1 -9
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +4 -4
- package/dist/src/core/elementNode.d.ts +23 -5
- package/dist/src/core/elementNode.js +194 -45
- package/dist/src/core/elementNode.js.map +1 -1
- package/dist/src/core/flex.js +2 -1
- package/dist/src/core/flex.js.map +1 -1
- package/dist/src/core/focusManager.js +144 -99
- package/dist/src/core/focusManager.js.map +1 -1
- package/dist/src/core/index.d.ts +3 -0
- package/dist/src/core/index.js +2 -0
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/intrinsicTypes.d.ts +5 -2
- package/dist/src/core/lightningInit.d.ts +2 -2
- package/dist/src/core/lightningInit.js +71 -32
- package/dist/src/core/lightningInit.js.map +1 -1
- package/dist/src/core/nodeTypes.d.ts +1 -1
- package/dist/src/core/nodeTypes.js +2 -3
- package/dist/src/core/nodeTypes.js.map +1 -1
- package/dist/src/core/shaders.d.ts +1 -1
- package/dist/src/core/states.js +20 -4
- package/dist/src/core/states.js.map +1 -1
- package/dist/src/primitives/FPSCounter.jsx +3 -3
- package/dist/src/primitives/FPSCounter.jsx.map +1 -1
- package/dist/src/primitives/Image.jsx +2 -10
- package/dist/src/primitives/Image.jsx.map +1 -1
- package/dist/src/primitives/Lazy.jsx +7 -1
- package/dist/src/primitives/Lazy.jsx.map +1 -1
- package/dist/src/primitives/Virtual.d.ts +4 -0
- package/dist/src/primitives/Virtual.jsx +192 -106
- package/dist/src/primitives/Virtual.jsx.map +1 -1
- package/dist/src/primitives/VirtualGrid.jsx +87 -18
- package/dist/src/primitives/VirtualGrid.jsx.map +1 -1
- package/dist/src/primitives/utils/handleNavigation.js +12 -5
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
- package/dist/src/primitives/utils/withScrolling.js +63 -57
- package/dist/src/primitives/utils/withScrolling.js.map +1 -1
- package/dist/src/render.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -5
- package/src/core/dom-renderer/domRenderer.ts +4 -12
- package/src/core/dom-renderer/domRendererTypes.ts +4 -4
- package/src/core/elementNode.ts +219 -50
- package/src/core/flex.ts +2 -1
- package/src/core/focusManager.ts +173 -135
- package/src/core/index.ts +4 -0
- package/src/core/intrinsicTypes.ts +10 -2
- package/src/core/lightningInit.ts +85 -35
- package/src/core/nodeTypes.ts +6 -3
- package/src/core/shaders.ts +1 -1
- package/src/core/states.ts +19 -4
- package/src/primitives/FPSCounter.tsx +4 -4
- package/src/primitives/Image.tsx +2 -9
- package/src/primitives/Lazy.tsx +8 -1
- package/src/primitives/Virtual.tsx +211 -117
- package/src/primitives/VirtualGrid.tsx +98 -21
- package/src/primitives/utils/handleNavigation.ts +12 -5
- package/src/primitives/utils/withScrolling.ts +63 -62
package/src/core/states.ts
CHANGED
|
@@ -10,7 +10,13 @@ export default class States extends Array<DollarString> {
|
|
|
10
10
|
|
|
11
11
|
constructor(callback: () => void, initialState: NodeStates = {}) {
|
|
12
12
|
if (isArray(initialState)) {
|
|
13
|
-
|
|
13
|
+
// By index: a spread runs the iterator protocol (an iterator and an
|
|
14
|
+
// argument list per call).
|
|
15
|
+
super();
|
|
16
|
+
const n = initialState.length;
|
|
17
|
+
for (let i = 0; i < n; i++) {
|
|
18
|
+
this[i] = initialState[i]!;
|
|
19
|
+
}
|
|
14
20
|
} else if (isString(initialState)) {
|
|
15
21
|
super(initialState); // Assert as DollarString
|
|
16
22
|
} else {
|
|
@@ -66,9 +72,18 @@ export default class States extends Array<DollarString> {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
merge(newStates: NodeStates) {
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
if (newStates === this) {
|
|
76
|
+
// A self-merge clears the list, as it did when merge emptied the list
|
|
77
|
+
// and then pushed a spread of it.
|
|
78
|
+
this.length = 0;
|
|
79
|
+
} else if (isArray(newStates)) {
|
|
80
|
+
// Copied by index, then cut to length: a spread ran the iterator
|
|
81
|
+
// protocol over the list (with forwardStates, the parent's States).
|
|
82
|
+
const n = newStates.length;
|
|
83
|
+
for (let i = 0; i < n; i++) {
|
|
84
|
+
this[i] = newStates[i]!;
|
|
85
|
+
}
|
|
86
|
+
this.length = n;
|
|
72
87
|
} else if (isString(newStates)) {
|
|
73
88
|
this.length = 0; // Clear the current states
|
|
74
89
|
this.push(newStates); // Assert as DollarString
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type NodeProps, RendererMain } from '@solidtv/solid';
|
|
2
2
|
import { createSignal } from 'solid-js';
|
|
3
3
|
|
|
4
4
|
const fpsStyle = {
|
|
@@ -70,8 +70,8 @@ const calcFps = (fps: number) => {
|
|
|
70
70
|
setAvgFps(Math.round(totalFps / count));
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
function updateMemoryInfo(
|
|
74
|
-
const memInfo =
|
|
73
|
+
function updateMemoryInfo(renderer: RendererMain) {
|
|
74
|
+
const memInfo = renderer.memoryInfo();
|
|
75
75
|
setCriticalThresholdSignal(bytesToMb(memInfo.criticalThreshold));
|
|
76
76
|
setTargetThresholdSignal(bytesToMb(memInfo.targetThreshold));
|
|
77
77
|
setRenderableMemUsedSignal(bytesToMb(memInfo.renderableMemUsed));
|
|
@@ -88,7 +88,7 @@ export function setupFPS(root: any) {
|
|
|
88
88
|
if (fps > 5) {
|
|
89
89
|
calcFps(fps);
|
|
90
90
|
if (frameCount % 10 === 0) {
|
|
91
|
-
updateMemoryInfo(target
|
|
91
|
+
updateMemoryInfo(target);
|
|
92
92
|
frameCount = 0;
|
|
93
93
|
}
|
|
94
94
|
frameCount++;
|
package/src/primitives/Image.tsx
CHANGED
|
@@ -43,15 +43,8 @@ export const Image: Component<ImageProps> = (props) => {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.then((resp) => {
|
|
49
|
-
// if texture fails to load, this is still called after the failed handler
|
|
50
|
-
if (resp.data) setTexture(srcTexture);
|
|
51
|
-
})
|
|
52
|
-
.catch(() => {
|
|
53
|
-
// handle potential errors from getTextureData
|
|
54
|
-
});
|
|
46
|
+
// Renderer 2.x loads a texture only once a node shows it
|
|
47
|
+
setTexture(srcTexture);
|
|
55
48
|
});
|
|
56
49
|
|
|
57
50
|
return (
|
package/src/primitives/Lazy.tsx
CHANGED
|
@@ -150,11 +150,18 @@ function createLazy<T>(
|
|
|
150
150
|
// proximity check must use child units.
|
|
151
151
|
const rendered = container.children.length;
|
|
152
152
|
|
|
153
|
+
// B16: the mount lands only after this press (the key handler's writes
|
|
154
|
+
// are batched), so it has to start while this press's move still has a
|
|
155
|
+
// child to land on: a buffer below 2 acts as 2. With buffer 1 the press
|
|
156
|
+
// that reached the rendered edge found no child and bubbled, so every
|
|
157
|
+
// other press was lost.
|
|
158
|
+
const edge = Math.max(buffer(), 2);
|
|
159
|
+
|
|
153
160
|
// Already mounted everything (offset is in data units — a diverged child
|
|
154
161
|
// count must neither stop mounting early nor keep it running forever),
|
|
155
162
|
// or still far enough from the rendered edge that the buffer covers the
|
|
156
163
|
// next selection — no work to do.
|
|
157
|
-
if (offset() >= maxOffset || selected < rendered -
|
|
164
|
+
if (offset() >= maxOffset || selected < rendered - edge) return;
|
|
158
165
|
|
|
159
166
|
const bump = () => setOffset((prev) => Math.min(prev + 1, maxOffset));
|
|
160
167
|
|
|
@@ -21,6 +21,10 @@ export type VirtualProps<T> = lng.NewOmit<lngp.RowProps, 'children'> & {
|
|
|
21
21
|
onEndReached?: () => void;
|
|
22
22
|
onEndReachedThreshold?: number;
|
|
23
23
|
debugInfo?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated No effect since 1.7: a window shift always moves the row by
|
|
26
|
+
* one unscaled slot (item size + gap), the distance flex moves the items.
|
|
27
|
+
*/
|
|
24
28
|
factorScale?: boolean;
|
|
25
29
|
uniformSize?: boolean;
|
|
26
30
|
children: (item: s.Accessor<T>, index: s.Accessor<number>) => s.JSX.Element;
|
|
@@ -73,23 +77,23 @@ function createVirtual<T>(
|
|
|
73
77
|
atStart: boolean;
|
|
74
78
|
cursor: number;
|
|
75
79
|
};
|
|
76
|
-
const [
|
|
80
|
+
const noItems: T[] = [];
|
|
81
|
+
// One state object, updated in place by computeSlice, so a press allocates
|
|
82
|
+
// no state. The mounted items have a signal of their own: <List> re-runs
|
|
83
|
+
// only when the window's items change, not on every press.
|
|
84
|
+
const slice: SliceState = {
|
|
77
85
|
start: 0,
|
|
78
|
-
slice:
|
|
86
|
+
slice: noItems,
|
|
79
87
|
selected: 0,
|
|
80
88
|
delta: 0,
|
|
81
89
|
shiftBy: 0,
|
|
82
90
|
atStart: true,
|
|
83
91
|
cursor: 0,
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (delta > half) return delta - windowLen;
|
|
90
|
-
if (delta < -half) return delta + windowLen;
|
|
91
|
-
return delta;
|
|
92
|
-
}
|
|
92
|
+
};
|
|
93
|
+
const [sliceItems, setSliceItems] = s.createSignal<T[]>(noItems);
|
|
94
|
+
// Set when the window's items change, cleared by the row's next flex pass
|
|
95
|
+
// (onLayout): the window shift lays the row out only if nothing else has.
|
|
96
|
+
let layoutPending = false;
|
|
93
97
|
|
|
94
98
|
function computeSize(selected: number = 0) {
|
|
95
99
|
if (uniformSize() && cachedScaledSize) {
|
|
@@ -100,47 +104,65 @@ function createVirtual<T>(
|
|
|
100
104
|
const prevSelectedChild = viewRef.children[selected];
|
|
101
105
|
|
|
102
106
|
if (prevSelectedChild instanceof lng.ElementNode) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
// B14: a shift moves the row by one slot, the item's unscaled size
|
|
108
|
+
// plus the gap: the distance flex moves the items when the window
|
|
109
|
+
// shifts (flex has no scale term). Shifting by a scaled size
|
|
110
|
+
// (`factorScale`, which read the scale from `style.focus` or the
|
|
111
|
+
// child's current `scale`) moved the focused item (scale - 1) * size
|
|
112
|
+
// further on every shift. `factorScale` no longer has an effect.
|
|
113
|
+
const slotSize = (prevSelectedChild[dimension] || 0) + gap;
|
|
114
|
+
cachedScaledSize = slotSize;
|
|
115
|
+
return slotSize;
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
118
|
return 0;
|
|
112
119
|
}
|
|
113
120
|
|
|
114
|
-
function
|
|
115
|
-
|
|
121
|
+
function applySlice(
|
|
122
|
+
start: number,
|
|
123
|
+
windowItems: T[],
|
|
124
|
+
selected: number,
|
|
116
125
|
delta: number,
|
|
117
|
-
|
|
126
|
+
shiftBy: number,
|
|
127
|
+
atStart: boolean,
|
|
128
|
+
c: number,
|
|
118
129
|
): SliceState {
|
|
130
|
+
const prevItems = slice.slice;
|
|
131
|
+
slice.start = start;
|
|
132
|
+
slice.slice = windowItems;
|
|
133
|
+
slice.selected = selected;
|
|
134
|
+
slice.delta = delta;
|
|
135
|
+
slice.shiftBy = shiftBy;
|
|
136
|
+
slice.atStart = atStart;
|
|
137
|
+
slice.cursor = c;
|
|
138
|
+
if (windowItems !== prevItems) {
|
|
139
|
+
layoutPending = true;
|
|
140
|
+
setSliceItems(windowItems);
|
|
141
|
+
}
|
|
142
|
+
return slice;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function computeSlice(c: number, delta: number): SliceState {
|
|
146
|
+
const prev = slice;
|
|
119
147
|
const total = itemCount();
|
|
120
|
-
if (total === 0)
|
|
121
|
-
return {
|
|
122
|
-
start: 0,
|
|
123
|
-
slice: [],
|
|
124
|
-
selected: 0,
|
|
125
|
-
delta,
|
|
126
|
-
shiftBy: 0,
|
|
127
|
-
atStart: true,
|
|
128
|
-
cursor: 0,
|
|
129
|
-
};
|
|
148
|
+
if (total === 0) return applySlice(0, noItems, 0, delta, 0, true, 0);
|
|
130
149
|
|
|
131
150
|
if (total <= props.displaySize) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
151
|
+
const clamped = utils.clamp(c, 0, total - 1);
|
|
152
|
+
return applySlice(
|
|
153
|
+
0,
|
|
154
|
+
items() as T[],
|
|
155
|
+
clamped,
|
|
136
156
|
delta,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
157
|
+
0,
|
|
158
|
+
c <= 0,
|
|
159
|
+
clamped,
|
|
160
|
+
);
|
|
141
161
|
}
|
|
142
162
|
|
|
143
163
|
const length = props.displaySize + bufferSize();
|
|
164
|
+
// Items mounted: `length`, or fewer for none/center with wrap (below).
|
|
165
|
+
let windowLength = length;
|
|
144
166
|
let start = prev.start;
|
|
145
167
|
let selected = prev.selected;
|
|
146
168
|
let atStart = prev.atStart;
|
|
@@ -328,32 +350,52 @@ function createVirtual<T>(
|
|
|
328
350
|
}
|
|
329
351
|
case 'none':
|
|
330
352
|
default:
|
|
331
|
-
|
|
332
|
-
|
|
353
|
+
// B13: the window follows the cursor, keeping an item mounted on
|
|
354
|
+
// each side of it so the next press finds a child. The row itself
|
|
355
|
+
// does not scroll. VirtualRow does not implement "center": it
|
|
356
|
+
// behaves as "none".
|
|
357
|
+
start = prev.start;
|
|
358
|
+
if (effectiveWrap()) {
|
|
359
|
+
// A modular window, as in the other wrap modes: keep the cursor in
|
|
360
|
+
// slots 1 .. windowLength - 2, so an item is mounted on each side
|
|
361
|
+
// of it across the end of the data. Outside the window (a jump),
|
|
362
|
+
// the cursor goes to slot 1. With fewer items than `length` the
|
|
363
|
+
// window holds each item once (a longer one would mount an item
|
|
364
|
+
// twice).
|
|
365
|
+
windowLength = total < length ? total : length;
|
|
366
|
+
const slot = utils.mod(c - start, total);
|
|
367
|
+
if (slot < 1 || slot >= windowLength) {
|
|
368
|
+
start = utils.mod(c - 1, total);
|
|
369
|
+
} else if (slot > windowLength - 2) {
|
|
370
|
+
start = utils.mod(c + 2 - windowLength, total);
|
|
371
|
+
}
|
|
372
|
+
selected = utils.mod(c - start, total);
|
|
373
|
+
} else {
|
|
374
|
+
if (c + 1 >= start + length) {
|
|
375
|
+
start = c + 2 - length;
|
|
376
|
+
} else if (c - 1 < start) {
|
|
377
|
+
start = c - 1;
|
|
378
|
+
}
|
|
379
|
+
start = utils.clamp(start, 0, Math.max(0, total - length));
|
|
380
|
+
selected = c - start;
|
|
381
|
+
}
|
|
333
382
|
shiftBy = 0;
|
|
334
383
|
break;
|
|
335
384
|
}
|
|
336
385
|
|
|
337
386
|
let newSlice = prev.slice;
|
|
338
387
|
if (start !== prev.start || newSlice.length === 0) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
388
|
+
const all = items();
|
|
389
|
+
if (effectiveWrap()) {
|
|
390
|
+
newSlice = new Array<T>(windowLength);
|
|
391
|
+
for (let i = 0; i < windowLength; i++) {
|
|
392
|
+
newSlice[i] = all[utils.mod(start + i, total)] as T;
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
newSlice = all.slice(start, start + windowLength) as T[];
|
|
396
|
+
}
|
|
345
397
|
}
|
|
346
398
|
|
|
347
|
-
const state: SliceState = {
|
|
348
|
-
start,
|
|
349
|
-
slice: newSlice,
|
|
350
|
-
selected,
|
|
351
|
-
delta,
|
|
352
|
-
shiftBy,
|
|
353
|
-
atStart,
|
|
354
|
-
cursor: c,
|
|
355
|
-
};
|
|
356
|
-
|
|
357
399
|
if (props.debugInfo) {
|
|
358
400
|
console.log(`[Virtual]`, {
|
|
359
401
|
cursor: c,
|
|
@@ -361,11 +403,11 @@ function createVirtual<T>(
|
|
|
361
403
|
start,
|
|
362
404
|
selected,
|
|
363
405
|
shiftBy,
|
|
364
|
-
slice:
|
|
406
|
+
slice: newSlice,
|
|
365
407
|
});
|
|
366
408
|
}
|
|
367
409
|
|
|
368
|
-
return
|
|
410
|
+
return applySlice(start, newSlice, selected, delta, shiftBy, atStart, c);
|
|
369
411
|
}
|
|
370
412
|
|
|
371
413
|
let viewRef!: lngp.NavigableElement;
|
|
@@ -390,15 +432,69 @@ function createVirtual<T>(
|
|
|
390
432
|
}
|
|
391
433
|
|
|
392
434
|
let lastNavTime = 0;
|
|
393
|
-
function getAdaptiveDuration(duration: number = 250) {
|
|
394
|
-
const now = performance.now();
|
|
395
|
-
const delta = now - lastNavTime;
|
|
396
|
-
lastNavTime = now;
|
|
397
|
-
if (delta < duration) return delta;
|
|
398
|
-
return duration;
|
|
399
|
-
}
|
|
400
435
|
|
|
401
436
|
let originalPosition: number | undefined;
|
|
437
|
+
|
|
438
|
+
// The window shift after a press, run in a microtask once the new window
|
|
439
|
+
// is mounted. One function for every press (no closure per press): the
|
|
440
|
+
// press stores what it needs here.
|
|
441
|
+
let shiftView!: lng.ElementNode;
|
|
442
|
+
let shiftActive!: lng.ElementNode;
|
|
443
|
+
let shiftPrevChildPos = 0;
|
|
444
|
+
// The shift animation's props and settings, reused: renderer v2 and the
|
|
445
|
+
// DOM renderer copy both when they create the animation. The settings are
|
|
446
|
+
// copied again from the row's animationSettings on every shift, into a
|
|
447
|
+
// new object only when the row's settings object changes.
|
|
448
|
+
const shiftProps: Partial<lng.AnimateProps> = isRow ? { x: 0 } : { y: 0 };
|
|
449
|
+
let shiftSettings: lng.AnimationSettings = {};
|
|
450
|
+
let shiftSettingsFrom: lng.AnimationSettings | undefined;
|
|
451
|
+
function applyShift() {
|
|
452
|
+
const view = shiftView;
|
|
453
|
+
const active = shiftActive;
|
|
454
|
+
// One flex pass per window shift: lay out here only if the post-mutation
|
|
455
|
+
// layout has not already run since the window changed.
|
|
456
|
+
if (layoutPending) view.updateLayout();
|
|
457
|
+
const childSize = computeSize(slice.selected);
|
|
458
|
+
|
|
459
|
+
if (
|
|
460
|
+
cachedAnimationController &&
|
|
461
|
+
cachedAnimationController.state === 'running'
|
|
462
|
+
) {
|
|
463
|
+
cachedAnimationController.stop();
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (lng.Config.animationsEnabled) {
|
|
467
|
+
view.lng[axis] = shiftPrevChildPos - active[axis];
|
|
468
|
+
targetPosition = view.lng[axis] + childSize * slice.shiftBy;
|
|
469
|
+
const settings = view.animationSettings;
|
|
470
|
+
if (settings !== shiftSettingsFrom) {
|
|
471
|
+
shiftSettings = {};
|
|
472
|
+
shiftSettingsFrom = settings;
|
|
473
|
+
}
|
|
474
|
+
for (const key in settings) {
|
|
475
|
+
(shiftSettings as Record<string, unknown>)[key] =
|
|
476
|
+
settings[key as keyof lng.AnimationSettings];
|
|
477
|
+
}
|
|
478
|
+
// The time since the last shift, up to the row's duration (250 by
|
|
479
|
+
// default). Inline, as the wrap delta below: a helper with one call
|
|
480
|
+
// site would be a closure per press under terser's default
|
|
481
|
+
// reduce_funcs.
|
|
482
|
+
const now = performance.now();
|
|
483
|
+
const sinceLast = now - lastNavTime;
|
|
484
|
+
lastNavTime = now;
|
|
485
|
+
const settingsDuration = settings?.duration;
|
|
486
|
+
const duration = settingsDuration === undefined ? 250 : settingsDuration;
|
|
487
|
+
shiftSettings.duration = sinceLast < duration ? sinceLast : duration;
|
|
488
|
+
shiftProps[axis] = targetPosition;
|
|
489
|
+
cachedAnimationController = view
|
|
490
|
+
.animate(shiftProps, shiftSettings)
|
|
491
|
+
.start();
|
|
492
|
+
} else {
|
|
493
|
+
view.lng[axis] =
|
|
494
|
+
shiftPrevChildPos - active[axis] + childSize * slice.shiftBy;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
402
498
|
const onSelectedChanged: lngp.OnSelectedChanged = function (
|
|
403
499
|
_idx,
|
|
404
500
|
elm,
|
|
@@ -420,59 +516,45 @@ function createVirtual<T>(
|
|
|
420
516
|
|
|
421
517
|
const rawDelta = idx - (lastIdx ?? 0);
|
|
422
518
|
const windowLen = elm?.children?.length ?? props.displaySize + bufferSize();
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
519
|
+
const wrap = effectiveWrap();
|
|
520
|
+
// With wrap, the shorter way round the window.
|
|
521
|
+
let delta = rawDelta;
|
|
522
|
+
if (wrap) {
|
|
523
|
+
if (!windowLen) {
|
|
524
|
+
delta = 0;
|
|
525
|
+
} else {
|
|
526
|
+
const half = windowLen / 2;
|
|
527
|
+
if (delta > half) {
|
|
528
|
+
delta -= windowLen;
|
|
529
|
+
} else if (delta < -half) {
|
|
530
|
+
delta += windowLen;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const next = s.untrack(cursor) + delta;
|
|
536
|
+
const c = wrap ? utils.mod(next, total) : utils.clamp(next, 0, total - 1);
|
|
537
|
+
setCursor(c);
|
|
433
538
|
|
|
434
|
-
const newState = computeSlice(
|
|
435
|
-
setSlice(newState);
|
|
539
|
+
const newState = computeSlice(c, delta);
|
|
436
540
|
elm.selected = newState.selected;
|
|
437
541
|
|
|
438
542
|
if (!wrapUnlocked() && rawDelta > 0) setWrapUnlocked(true);
|
|
439
543
|
|
|
440
544
|
if (
|
|
441
545
|
props.onEndReachedThreshold !== undefined &&
|
|
442
|
-
|
|
546
|
+
c >= itemCount() - props.onEndReachedThreshold
|
|
443
547
|
) {
|
|
444
548
|
props.onEndReached?.();
|
|
445
549
|
}
|
|
446
550
|
|
|
447
551
|
if (newState.shiftBy === 0) return;
|
|
448
552
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (
|
|
456
|
-
cachedAnimationController &&
|
|
457
|
-
cachedAnimationController.state === 'running'
|
|
458
|
-
) {
|
|
459
|
-
cachedAnimationController.stop();
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
if (lng.Config.animationsEnabled) {
|
|
463
|
-
this.lng[axis] = prevChildPos - active[axis];
|
|
464
|
-
targetPosition = this.lng[axis] + childSize * slice().shiftBy;
|
|
465
|
-
cachedAnimationController = this.animate(
|
|
466
|
-
{ [axis]: targetPosition },
|
|
467
|
-
{
|
|
468
|
-
...this.animationSettings,
|
|
469
|
-
duration: getAdaptiveDuration(this.animationSettings?.duration),
|
|
470
|
-
},
|
|
471
|
-
).start();
|
|
472
|
-
} else {
|
|
473
|
-
this.lng[axis] = (prevChildPos - active[axis]) + childSize * slice().shiftBy;
|
|
474
|
-
}
|
|
475
|
-
});
|
|
553
|
+
// `elm` is the row (`this`): navigation calls it on itself.
|
|
554
|
+
shiftView = elm;
|
|
555
|
+
shiftActive = active;
|
|
556
|
+
shiftPrevChildPos = (targetPosition ?? this[axis]) + active[axis];
|
|
557
|
+
queueMicrotask(applyShift);
|
|
476
558
|
};
|
|
477
559
|
|
|
478
560
|
const updateSelected = ([sel, _items]: [number?, any?]) => {
|
|
@@ -480,11 +562,10 @@ function createVirtual<T>(
|
|
|
480
562
|
const safeSel = utils.clamp(sel, 0, itemCount() - 1);
|
|
481
563
|
const item = items()[safeSel];
|
|
482
564
|
setCursor(safeSel);
|
|
483
|
-
const
|
|
484
|
-
setSlice(newState);
|
|
565
|
+
const shiftBy = computeSlice(safeSel, 0).shiftBy;
|
|
485
566
|
|
|
486
567
|
queueMicrotask(() => {
|
|
487
|
-
viewRef.updateLayout();
|
|
568
|
+
if (layoutPending) viewRef.updateLayout();
|
|
488
569
|
const activeIndex = viewRef.children.findIndex((x) => x.item === item);
|
|
489
570
|
if (activeIndex === -1) return;
|
|
490
571
|
viewRef.selected = activeIndex;
|
|
@@ -492,9 +573,9 @@ function createVirtual<T>(
|
|
|
492
573
|
viewRef.children[activeIndex]?.setFocus();
|
|
493
574
|
}
|
|
494
575
|
|
|
495
|
-
if (
|
|
576
|
+
if (shiftBy === 0) return;
|
|
496
577
|
|
|
497
|
-
const childSize = computeSize(slice
|
|
578
|
+
const childSize = computeSize(slice.selected);
|
|
498
579
|
// Original Position is offset to support scrollToIndex
|
|
499
580
|
originalPosition = originalPosition ?? viewRef.lng[axis];
|
|
500
581
|
targetPosition = targetPosition ?? viewRef.lng[axis];
|
|
@@ -517,7 +598,7 @@ function createVirtual<T>(
|
|
|
517
598
|
}
|
|
518
599
|
// offset just for wrap so we keep one item before
|
|
519
600
|
queueMicrotask(() => {
|
|
520
|
-
const childSize = computeSize(slice
|
|
601
|
+
const childSize = computeSize(slice.selected);
|
|
521
602
|
viewRef.lng[axis] = (viewRef.lng[axis] || 0) + childSize * -1;
|
|
522
603
|
// Original Position is offset to support scrollToIndex
|
|
523
604
|
originalPosition = viewRef.lng[axis];
|
|
@@ -536,13 +617,18 @@ function createVirtual<T>(
|
|
|
536
617
|
c = Math.max(0, itemCount() - 1);
|
|
537
618
|
setCursor(c);
|
|
538
619
|
}
|
|
539
|
-
|
|
540
|
-
setSlice(newState);
|
|
541
|
-
viewRef.selected = newState.selected;
|
|
620
|
+
viewRef.selected = computeSlice(c, 0).selected;
|
|
542
621
|
}),
|
|
543
622
|
);
|
|
544
623
|
|
|
545
|
-
|
|
624
|
+
// Clears layoutPending: the row's flex pass has run since the window
|
|
625
|
+
// changed. The app's onLayout still runs, read when called.
|
|
626
|
+
function onLayout(this: lng.ElementNode, target: lng.ElementNode) {
|
|
627
|
+
layoutPending = false;
|
|
628
|
+
return props.onLayout?.call(this, target);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
const view = (
|
|
546
632
|
<view
|
|
547
633
|
transitionLeft={isRow ? defaultTransitionBack : undefined}
|
|
548
634
|
transitionRight={isRow ? defaultTransitionForward : undefined}
|
|
@@ -555,10 +641,10 @@ function createVirtual<T>(
|
|
|
555
641
|
}, props.ref)}
|
|
556
642
|
wrap={effectiveWrap()}
|
|
557
643
|
selected={selected()}
|
|
558
|
-
cursor={cursor()}
|
|
559
644
|
forwardFocus={/* @once */ lngp.navigableForwardFocus}
|
|
560
645
|
scrollToIndex={/* @once */ scrollToIndex}
|
|
561
646
|
onSelectedChanged={/* @once */ onSelectedChanged}
|
|
647
|
+
onLayout={/* @once */ onLayout}
|
|
562
648
|
style={
|
|
563
649
|
/* @once */ lng.combineStyles(
|
|
564
650
|
props.style,
|
|
@@ -575,9 +661,17 @@ function createVirtual<T>(
|
|
|
575
661
|
)
|
|
576
662
|
}
|
|
577
663
|
>
|
|
578
|
-
<List each={
|
|
664
|
+
<List each={sliceItems()}>{props.children}</List>
|
|
579
665
|
</view>
|
|
580
666
|
);
|
|
667
|
+
|
|
668
|
+
// `cursor` has an effect of its own: in the spread above, a cursor change
|
|
669
|
+
// (every press) re-ran every prop of the spread.
|
|
670
|
+
s.createRenderEffect(() => {
|
|
671
|
+
viewRef.cursor = cursor();
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
return view;
|
|
581
675
|
}
|
|
582
676
|
|
|
583
677
|
export function VirtualRow<T>(props: VirtualProps<T>) {
|