@ng-native/components 0.27.0 → 0.29.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 +116 -11
- package/android/src/main/java/dev/ngnative/components/ContextMenuPopup.kt +61 -19
- package/android/src/main/java/dev/ngnative/components/MenusModule.kt +22 -0
- package/android/src/main/java/dev/ngnative/components/Shortcut.kt +13 -4
- package/dist/context-menu.d.ts +14 -6
- package/dist/context-menu.js +30 -28
- package/dist/context-menu.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/menu.d.ts +17 -8
- package/dist/menu.js +22 -36
- package/dist/menu.js.map +1 -1
- package/dist/modal.d.ts +6 -2
- package/dist/modal.js.map +1 -1
- package/dist/native-button.d.ts +31 -2
- package/dist/native-button.js +104 -6
- package/dist/native-button.js.map +1 -1
- package/dist/press-menu.d.ts +60 -0
- package/dist/press-menu.js +116 -0
- package/dist/press-menu.js.map +1 -0
- package/dist/pressable.d.ts +3 -0
- package/dist/pressable.js +7 -1
- package/dist/pressable.js.map +1 -1
- package/dist/reanimated.js +27 -3
- package/dist/reanimated.js.map +1 -1
- package/dist/scroll-view.d.ts +3 -1
- package/dist/scroll-view.js +7 -2
- package/dist/scroll-view.js.map +1 -1
- package/dist/settled-updates.d.ts +55 -0
- package/dist/settled-updates.js +77 -0
- package/dist/settled-updates.js.map +1 -0
- package/dist/sidebar-item.d.ts +18 -3
- package/dist/sidebar-item.js +29 -3
- package/dist/sidebar-item.js.map +1 -1
- package/dist/sidebar.js +4 -3
- package/dist/sidebar.js.map +1 -1
- package/dist/split-view.d.ts +23 -2
- package/dist/split-view.js +32 -5
- package/dist/split-view.js.map +1 -1
- package/dist/stand-ins/reanimated.d.ts +5 -0
- package/dist/stand-ins/reanimated.js +7 -0
- package/dist/stand-ins/reanimated.js.map +1 -1
- package/dist/sticky-headers.d.ts +19 -0
- package/dist/sticky-headers.js +67 -10
- package/dist/sticky-headers.js.map +1 -1
- package/dist/sticky-rows.d.ts +123 -26
- package/dist/sticky-rows.js +285 -71
- package/dist/sticky-rows.js.map +1 -1
- package/dist/svg-icon.d.ts +23 -0
- package/dist/svg-icon.js +53 -0
- package/dist/svg-icon.js.map +1 -0
- package/dist/tray-icon.d.ts +7 -1
- package/dist/tray-icon.js +15 -3
- package/dist/tray-icon.js.map +1 -1
- package/dist/virtual-list-sticky-level.d.ts +33 -0
- package/dist/virtual-list-sticky-level.js +58 -0
- package/dist/virtual-list-sticky-level.js.map +1 -0
- package/dist/virtual-list-sticky.d.ts +19 -0
- package/dist/virtual-list-sticky.js +13 -0
- package/dist/virtual-list-sticky.js.map +1 -0
- package/dist/virtual-list.d.ts +29 -7
- package/dist/virtual-list.js +127 -59
- package/dist/virtual-list.js.map +1 -1
- package/dist/worklet-style.d.ts +11 -0
- package/dist/worklet-style.js +15 -1
- package/dist/worklet-style.js.map +1 -1
- package/dist/worklets.d.ts +5 -1
- package/dist/worklets.js.map +1 -1
- package/dist/written-props.js +3 -0
- package/dist/written-props.js.map +1 -1
- package/ios/NgNativeButtonComponentView.mm +8 -4
- package/ios/NgNativeButtonMetrics.h +9 -2
- package/ios/NgNativeButtonMetrics.mm +33 -4
- package/ios/NgNativeButtonShadowNode.h +2 -0
- package/ios/NgNativeButtonShadowNode.mm +5 -1
- package/ios/NgNativeMenus.mm +42 -2
- package/ios/NgNativePressMenu.h +28 -0
- package/ios/NgNativePressMenu.mm +45 -0
- package/package.json +3 -3
package/dist/sticky-rows.js
CHANGED
|
@@ -1,36 +1,66 @@
|
|
|
1
1
|
import { computed, signal } from '@angular/core';
|
|
2
2
|
import { pinnedRange, } from '@ng-native/fabric';
|
|
3
3
|
import { STICKY_SETTLE_MS } from "./sticky-headers.js";
|
|
4
|
+
const NONE = [];
|
|
5
|
+
/** A range native moves a view nowhere along. */
|
|
6
|
+
const STILL = { input: [0, 1], output: [0, 0] };
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
8
|
+
* The zIndex of a level 0 row where rows have levels, each level further in one under it. Fixed,
|
|
9
|
+
* not counted from the levels the list holds: a deeper level arriving would otherwise commit new
|
|
10
|
+
* props on every sticky row, and a view native is moving goes back to its place for a frame.
|
|
11
|
+
* Levels this deep and deeper share a zIndex of 1.
|
|
12
|
+
*/
|
|
13
|
+
const FRONT = 100;
|
|
14
|
+
/**
|
|
15
|
+
* `<virtual-list>`'s sticky rows: which hold the leading edge, the style that pins each, the
|
|
6
16
|
* header's pinned style, and, where the host moves views by the scroll on the native side, what
|
|
7
17
|
* native is moving. The list's own share of `stickyIndices` and `stickyHeader`, as `StickyHeaders`
|
|
8
18
|
* is `<scroll-view>`'s.
|
|
9
19
|
*
|
|
20
|
+
* Rows pin at levels, when `virtualListStickyLevel` gives them: a row holds the edge under the
|
|
21
|
+
* rows of the levels further out than its own, and the next row at its level or further out pushes
|
|
22
|
+
* it off. Without levels every sticky row is at level 0, each pushed off by the next.
|
|
23
|
+
*
|
|
10
24
|
* Pinning is not native: RN's `ScrollView.js` translates a sticky child against the scroll offset
|
|
11
25
|
* in JavaScript, and a row here follows the offset the same way while it is the current one, by
|
|
12
26
|
* its `top` when absolutely positioned and by a transform when in flow. Where native can move a
|
|
13
|
-
* view by the scroll, each sticky row instead stays at its own place in the
|
|
14
|
-
* translates it on every frame the list scrolls, as RN's `ScrollViewStickyHeader`
|
|
15
|
-
* translate committed from each scroll event lands a frame or more late, and on a fast
|
|
16
|
-
* row shudders and comes away from the edge.
|
|
27
|
+
* view by the scroll, each sticky row, and a pinned header, instead stays at its own place in the
|
|
28
|
+
* list and native translates it on every frame the list scrolls, as RN's `ScrollViewStickyHeader`
|
|
29
|
+
* does; a translate committed from each scroll event lands a frame or more late, and on a fast
|
|
30
|
+
* fling the row shudders and comes away from the edge.
|
|
17
31
|
*/
|
|
18
32
|
export class StickyRows {
|
|
19
|
-
/** Whether native moves sticky rows. */
|
|
33
|
+
/** Whether native moves sticky rows and the pinned header. */
|
|
20
34
|
native;
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Where the scroll view is along its axis, header and all: 0 until native says otherwise, since
|
|
37
|
+
* Android sends no scroll event until the list moves.
|
|
38
|
+
*/
|
|
39
|
+
along = signal(0, /* @ts-ignore */
|
|
40
|
+
...(ngDevMode ? [{ debugName: "along" }] : /* istanbul ignore next */ []));
|
|
41
|
+
/** The leading edge of the viewport in content space, past the header at its current size. */
|
|
42
|
+
offset = computed(() => this.along() - this.list.headerHeight(), /* @ts-ignore */
|
|
43
|
+
...(ngDevMode ? [{ debugName: "offset" }] : /* istanbul ignore next */ []));
|
|
25
44
|
engine;
|
|
26
45
|
node;
|
|
27
46
|
list;
|
|
28
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Where the scroll view is once scrolling pauses, header and all, which the settled translate of
|
|
49
|
+
* a native-moved row is from.
|
|
50
|
+
*/
|
|
29
51
|
settled = signal(0, /* @ts-ignore */
|
|
30
52
|
...(ngDevMode ? [{ debugName: "settled" }] : /* istanbul ignore next */ []));
|
|
31
53
|
settleTimer;
|
|
32
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* What native is moving, by row view: the axis with the transform kept beside the translate,
|
|
56
|
+
* and the range it moves the row by.
|
|
57
|
+
*/
|
|
33
58
|
drives = new Map();
|
|
59
|
+
/**
|
|
60
|
+
* What native moves the header by, once it has been pinned. Kept, moving it nowhere, when it no
|
|
61
|
+
* longer is: native goes on drawing a translate it set after its drive is gone.
|
|
62
|
+
*/
|
|
63
|
+
headerDrive = null;
|
|
34
64
|
/** The list scrolled itself, and native has not drawn its sticky rows there yet. */
|
|
35
65
|
jumped = false;
|
|
36
66
|
/** Native has reported reaching the target, so this pass's drives are the last to need telling. */
|
|
@@ -43,6 +73,10 @@ export class StickyRows {
|
|
|
43
73
|
reported;
|
|
44
74
|
/** Where native's latest event of all said it was, header and all. */
|
|
45
75
|
nativeAt = 0;
|
|
76
|
+
/** The axis the list scrolled along when native said so, until then none. */
|
|
77
|
+
nativeAxis;
|
|
78
|
+
/** No scroll event has come for `STICKY_SETTLE_MS`, so none is on its way to draw a new graph. */
|
|
79
|
+
resting = true;
|
|
46
80
|
/**
|
|
47
81
|
* Scroll end events still to come, one for each jump that moved native, as iOS sends one. Kept
|
|
48
82
|
* across jumps: one that landed has its end still to come, and must not be taken for the next's.
|
|
@@ -58,56 +92,132 @@ export class StickyRows {
|
|
|
58
92
|
this.native = engine.drivesScroll;
|
|
59
93
|
}
|
|
60
94
|
/** Whether the scroll offset is needed as a signal, which only pinning needs. */
|
|
61
|
-
pinning = computed(() => this.list.header() || this.
|
|
95
|
+
pinning = computed(() => this.list.header() || this.rows().size > 0, /* @ts-ignore */
|
|
62
96
|
...(ngDevMode ? [{ debugName: "pinning" }] : /* istanbul ignore next */ []));
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Each sticky row's level, in list order: the rows of `stickyIndices` at level 0, and with a
|
|
99
|
+
* level function every row it gives one. A sticky index given for rows not there yet pins
|
|
100
|
+
* nothing and pushes nothing off until its row arrives.
|
|
101
|
+
*/
|
|
102
|
+
levels = computed(() => {
|
|
103
|
+
const indices = this.list.indices();
|
|
104
|
+
const levelOf = this.list.levels?.levelOf();
|
|
105
|
+
const items = this.list.items();
|
|
106
|
+
const levels = [];
|
|
107
|
+
if (!levelOf) {
|
|
108
|
+
for (const index of indices)
|
|
109
|
+
if (index < items.length)
|
|
110
|
+
levels.push([index, 0]);
|
|
111
|
+
return levels;
|
|
112
|
+
}
|
|
113
|
+
const outermost = new Set(indices);
|
|
114
|
+
items.forEach((item, index) => {
|
|
115
|
+
const level = outermost.has(index) ? 0 : levelOf(item, index);
|
|
116
|
+
if (level !== null)
|
|
117
|
+
levels.push([index, level]);
|
|
118
|
+
});
|
|
119
|
+
return levels;
|
|
67
120
|
}, /* @ts-ignore */
|
|
68
|
-
...(ngDevMode ? [{ debugName: "
|
|
121
|
+
...(ngDevMode ? [{ debugName: "levels" }] : /* istanbul ignore next */ []));
|
|
122
|
+
/** Each sticky row, with the rows it pins under and the one that pushes it off. */
|
|
123
|
+
rows = computed(() => {
|
|
124
|
+
const rows = new Map();
|
|
125
|
+
// The rows a row here would pin under: each deeper than the one before it.
|
|
126
|
+
const open = [];
|
|
127
|
+
for (const [index, level] of this.levels()) {
|
|
128
|
+
while (open.length > 0 && rows.get(open.at(-1)).level >= level) {
|
|
129
|
+
rows.get(open.pop()).next = index;
|
|
130
|
+
}
|
|
131
|
+
rows.set(index, { level, above: [...open], next: undefined });
|
|
132
|
+
open.push(index);
|
|
133
|
+
}
|
|
134
|
+
return rows;
|
|
135
|
+
}, /* @ts-ignore */
|
|
136
|
+
...(ngDevMode ? [{ debugName: "rows" }] : /* istanbul ignore next */ []));
|
|
69
137
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
138
|
+
* For each sticky row in list order, the least offset that reaches it or a row after it. Where a
|
|
139
|
+
* row starts to hold never comes before where the row before it does, unless a negative `rowGap`
|
|
140
|
+
* overlaps the rows, and this stays in order either way, so `pinned` can halve over it.
|
|
141
|
+
*/
|
|
142
|
+
reach = computed(() => {
|
|
143
|
+
const order = this.levels();
|
|
144
|
+
const reach = new Array(order.length);
|
|
145
|
+
let least = Infinity;
|
|
146
|
+
for (let at = order.length - 1; at >= 0; at--) {
|
|
147
|
+
least = Math.min(least, this.startOf(order[at][0]));
|
|
148
|
+
reach[at] = least;
|
|
149
|
+
}
|
|
150
|
+
return reach;
|
|
151
|
+
}, /* @ts-ignore */
|
|
152
|
+
...(ngDevMode ? [{ debugName: "reach" }] : /* istanbul ignore next */ []));
|
|
153
|
+
/**
|
|
154
|
+
* The sticky rows currently holding the leading edge, outermost first: the last one the offset
|
|
155
|
+
* has reached, under the rows it pins under. Empty when the list has scrolled back above the
|
|
156
|
+
* first of them.
|
|
72
157
|
*/
|
|
73
158
|
pinned = computed(() => {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
return
|
|
159
|
+
const order = this.levels();
|
|
160
|
+
if (order.length === 0)
|
|
161
|
+
return NONE;
|
|
77
162
|
const offset = this.offset();
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
163
|
+
// The last row the offset has reached is the last whose `reach` it has, found by halving.
|
|
164
|
+
const reach = this.reach();
|
|
165
|
+
let low = 0;
|
|
166
|
+
let high = order.length;
|
|
167
|
+
while (low < high) {
|
|
168
|
+
const middle = (low + high) >> 1;
|
|
169
|
+
if (reach[middle] <= offset)
|
|
170
|
+
low = middle + 1;
|
|
82
171
|
else
|
|
83
|
-
|
|
172
|
+
high = middle;
|
|
84
173
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
174
|
+
if (low === 0)
|
|
175
|
+
return NONE;
|
|
176
|
+
const pinned = order[low - 1][0];
|
|
177
|
+
return [...this.rows().get(pinned).above, pinned];
|
|
178
|
+
}, { ...(ngDevMode ? { debugName: "pinned" } : /* istanbul ignore next */ {}), equal: (a, b) => a.length === b.length && a.every((index, at) => index === b[at]) });
|
|
88
179
|
/**
|
|
89
180
|
* The header's translation while it is pinned: the scroll position, held back at zero by an
|
|
90
|
-
* overscroll and at the first sticky row, which pushes it off.
|
|
181
|
+
* overscroll and at the first sticky row, which pushes it off. Where native moves it, the
|
|
182
|
+
* translate native had reached when scrolling paused, as for a sticky row.
|
|
91
183
|
*/
|
|
92
184
|
headerStyle = computed(() => {
|
|
93
185
|
const flip = this.list.flipText();
|
|
94
186
|
if (!this.list.header())
|
|
95
187
|
return flip ? { transform: flip } : undefined;
|
|
96
|
-
const along = this.
|
|
97
|
-
const
|
|
98
|
-
const limit = first === undefined ? Infinity : this.list.topOf(first);
|
|
99
|
-
const shift = Math.min(Math.max(0, along), limit);
|
|
188
|
+
const along = this.native ? this.settled() : this.along();
|
|
189
|
+
const shift = Math.min(Math.max(0, along), this.headerLimit());
|
|
100
190
|
const move = shift > 0 ? `${this.list.horizontal() ? 'translateX' : 'translateY'}(${shift}px)` : '';
|
|
101
191
|
const transform = [move, flip ?? ''].filter(Boolean).join(' ');
|
|
102
192
|
return transform ? { zIndex: 1, transform } : { zIndex: 1 };
|
|
103
193
|
}, /* @ts-ignore */
|
|
104
194
|
...(ngDevMode ? [{ debugName: "headerStyle" }] : /* istanbul ignore next */ []));
|
|
105
|
-
/**
|
|
106
|
-
|
|
107
|
-
|
|
195
|
+
/**
|
|
196
|
+
* A pinned row in flow, moved by a transform from `at`, where flow put it, to where it holds:
|
|
197
|
+
* under the rows it pins under, until the next row at its level or further out pushes it off.
|
|
198
|
+
*/
|
|
199
|
+
flowStyle(index, at) {
|
|
200
|
+
const holds = Math.min(this.offset(), this.stopOf(index)) + this.above(index);
|
|
201
|
+
const shift = Math.max(0, holds - at);
|
|
108
202
|
const move = `${this.list.horizontal() ? 'translateX' : 'translateY'}(${shift}px)`;
|
|
109
203
|
const flip = this.list.flipText();
|
|
110
|
-
return {
|
|
204
|
+
return {
|
|
205
|
+
...this.list.flowSpacing(),
|
|
206
|
+
zIndex: this.zIndexOf(index),
|
|
207
|
+
transform: flip ? `${move} ${flip}` : move,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* A pinned row placed by its `top`: under the rows it pins under, until the next row at its
|
|
212
|
+
* level or further out reaches it there and pushes it off.
|
|
213
|
+
*/
|
|
214
|
+
slotStyle(index) {
|
|
215
|
+
const at = Math.min(this.offset(), this.stopOf(index)) + this.above(index);
|
|
216
|
+
return {
|
|
217
|
+
...this.list.slotStyle(index),
|
|
218
|
+
[this.list.horizontal() ? 'left' : 'top']: at,
|
|
219
|
+
zIndex: this.zIndexOf(index),
|
|
220
|
+
};
|
|
111
221
|
}
|
|
112
222
|
/**
|
|
113
223
|
* A sticky row native moves: at its own place, with the translate native had reached when
|
|
@@ -118,9 +228,10 @@ export class StickyRows {
|
|
|
118
228
|
const style = this.list.measuring()
|
|
119
229
|
? { ...this.list.flowSpacing() }
|
|
120
230
|
: { ...this.list.slotStyle(index) };
|
|
121
|
-
style['zIndex'] =
|
|
122
|
-
const
|
|
123
|
-
const
|
|
231
|
+
style['zIndex'] = this.zIndexOf(index);
|
|
232
|
+
const start = this.startOf(index);
|
|
233
|
+
const settled = this.settled() - this.list.headerHeight();
|
|
234
|
+
const shift = Math.min(Math.max(0, settled - start), this.stopOf(index) - start);
|
|
124
235
|
const move = shift > 0 ? `${horizontal ? 'translateX' : 'translateY'}(${shift}px)` : '';
|
|
125
236
|
const transform = [move, this.list.flipText() ?? ''].filter(Boolean).join(' ');
|
|
126
237
|
if (transform)
|
|
@@ -133,7 +244,7 @@ export class StickyRows {
|
|
|
133
244
|
* back. Apart from that, `kind`, the row's `itemType`.
|
|
134
245
|
*/
|
|
135
246
|
recyclingType(index, kind) {
|
|
136
|
-
if (!this.
|
|
247
|
+
if (!this.rows().has(index))
|
|
137
248
|
return kind;
|
|
138
249
|
let type = this.typeOfKind.get(kind);
|
|
139
250
|
if (!type) {
|
|
@@ -147,26 +258,33 @@ export class StickyRows {
|
|
|
147
258
|
isType(type) {
|
|
148
259
|
return this.types.has(type);
|
|
149
260
|
}
|
|
150
|
-
/** The list scrolled, to `
|
|
151
|
-
scrolled(
|
|
261
|
+
/** The list scrolled, to `along` in the scroll view. */
|
|
262
|
+
scrolled(along) {
|
|
152
263
|
this.nativeAt = along;
|
|
264
|
+
this.nativeAxis = this.list.horizontal() ? 'x' : 'y';
|
|
153
265
|
if (this.jumped) {
|
|
154
266
|
this.reported = along;
|
|
155
267
|
// An event from before the jump, or on the way, is not where it lands.
|
|
156
268
|
if (Math.abs(along - this.jumpedTo) <= 1)
|
|
157
269
|
this.landed = true;
|
|
158
270
|
}
|
|
159
|
-
// A pinned row follows the scroll continuously, so
|
|
160
|
-
//
|
|
161
|
-
// moves no row in or out of the window costs none.
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.leading.set(offset);
|
|
271
|
+
// A pinned row follows the scroll continuously, so the offset is a signal. Nothing reads it
|
|
272
|
+
// until a row or the header is pinned, so without them this stays out of change detection,
|
|
273
|
+
// and a fling that moves no row in or out of the window costs none. It is kept all the same:
|
|
274
|
+
// a row that turns sticky in a scrolled list is pinned where the list is, not where it was.
|
|
275
|
+
this.along.set(along);
|
|
165
276
|
if (!this.native)
|
|
166
277
|
return;
|
|
167
|
-
// See `STICKY_SETTLE_MS`.
|
|
168
278
|
clearTimeout(this.settleTimer);
|
|
169
|
-
this.
|
|
279
|
+
this.resting = false;
|
|
280
|
+
const settle = () => {
|
|
281
|
+
this.resting = true;
|
|
282
|
+
this.settled.set(along);
|
|
283
|
+
};
|
|
284
|
+
if (!this.pinning())
|
|
285
|
+
return settle();
|
|
286
|
+
// See `STICKY_SETTLE_MS`.
|
|
287
|
+
this.settleTimer = setTimeout(settle, STICKY_SETTLE_MS);
|
|
170
288
|
}
|
|
171
289
|
/** The list is scrolling itself, to `to` in the scroll view, where native has not drawn yet. */
|
|
172
290
|
jumping(to, animated) {
|
|
@@ -199,12 +317,12 @@ export class StickyRows {
|
|
|
199
317
|
this.landed = true;
|
|
200
318
|
}
|
|
201
319
|
/**
|
|
202
|
-
* Hand each rendered sticky row's view to native to move, and let go of the rest
|
|
203
|
-
*
|
|
204
|
-
* drive to make or let go.
|
|
320
|
+
* Hand each rendered sticky row's view to native to move, and let go of the rest, and the
|
|
321
|
+
* header's view, `header`, while it is pinned. `views` are the rendered rows' views in the same
|
|
322
|
+
* order as `rows`. Each is only asked for where there is a drive to make or let go.
|
|
205
323
|
*/
|
|
206
|
-
drive(rows, views) {
|
|
207
|
-
if (!this.pinning() && this.drives.size === 0)
|
|
324
|
+
drive(rows, views, header) {
|
|
325
|
+
if (!this.pinning() && this.drives.size === 0 && !this.headerDrive)
|
|
208
326
|
return;
|
|
209
327
|
const rendered = views();
|
|
210
328
|
const axis = this.list.horizontal() ? 'x' : 'y';
|
|
@@ -228,14 +346,22 @@ export class StickyRows {
|
|
|
228
346
|
if (!view || !next)
|
|
229
347
|
return;
|
|
230
348
|
live.add(view);
|
|
231
|
-
|
|
349
|
+
// The axis too: a list turned horizontal moves its sticky rows along x.
|
|
350
|
+
const statics = axis + JSON.stringify(next.statics);
|
|
351
|
+
const range = JSON.stringify(next.range);
|
|
232
352
|
const held = this.drives.get(view);
|
|
233
|
-
if (held?.statics === statics)
|
|
234
|
-
|
|
353
|
+
if (held?.statics === statics) {
|
|
354
|
+
const drawn = held.range === range && held.drawn;
|
|
355
|
+
const at = drawn ? from : this.drawnFrom(axis, from);
|
|
356
|
+
held.range = range;
|
|
357
|
+
held.drawn = drawn || at !== undefined;
|
|
358
|
+
return held.drive.update(next.range, at);
|
|
359
|
+
}
|
|
235
360
|
held?.drive.stop();
|
|
236
|
-
const
|
|
361
|
+
const told = this.drawnFrom(axis, from);
|
|
362
|
+
const drive = this.engine.driveByScroll(view, this.node, axis, next.range, next.statics, told);
|
|
237
363
|
if (drive)
|
|
238
|
-
this.drives.set(view, { drive, statics });
|
|
364
|
+
this.drives.set(view, { drive, statics, range, drawn: told !== undefined });
|
|
239
365
|
});
|
|
240
366
|
for (const [view, held] of this.drives) {
|
|
241
367
|
if (live.has(view))
|
|
@@ -243,30 +369,118 @@ export class StickyRows {
|
|
|
243
369
|
held.drive.stop();
|
|
244
370
|
this.drives.delete(view);
|
|
245
371
|
}
|
|
372
|
+
this.driveHeader(header, axis, from);
|
|
246
373
|
if (this.landed)
|
|
247
374
|
this.jumped = this.landed = false;
|
|
248
375
|
}
|
|
376
|
+
/**
|
|
377
|
+
* Hand the header to native to move while it is pinned, by the scroll view's offset until the
|
|
378
|
+
* first sticky row pushes it off. Unpinned, it is moved nowhere.
|
|
379
|
+
*/
|
|
380
|
+
driveHeader(view, axis, from) {
|
|
381
|
+
const pinned = this.list.header();
|
|
382
|
+
if (!pinned && !this.headerDrive)
|
|
383
|
+
return;
|
|
384
|
+
const range = pinned ? this.headerRange() : STILL;
|
|
385
|
+
const held = this.headerDrive;
|
|
386
|
+
const moved = JSON.stringify(range);
|
|
387
|
+
const at = this.headerFrom(pinned, moved, axis, from);
|
|
388
|
+
const statics = this.list.flip() ?? [];
|
|
389
|
+
// The axis too: a list turned horizontal moves the header along x.
|
|
390
|
+
const key = axis + JSON.stringify(statics);
|
|
391
|
+
if (held?.statics === key) {
|
|
392
|
+
held.pinned = pinned;
|
|
393
|
+
held.range = moved;
|
|
394
|
+
return held.drive.update(range, at);
|
|
395
|
+
}
|
|
396
|
+
held?.drive.stop();
|
|
397
|
+
const drive = this.engine.driveByScroll(view(), this.node, axis, range, statics, held ? (at ?? this.drawnFrom(axis, from)) : at);
|
|
398
|
+
this.headerDrive = drive && { drive, statics: key, pinned, range: moved };
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Where native is told the scroll view is for the header's drive, `pinned` and moved by the range
|
|
402
|
+
* `moved`. Pinned, let go, or moved by a new range at rest, native has no new scroll event to draw
|
|
403
|
+
* it from: it is told where it last said it was. Mid-scroll the next event draws it, and what
|
|
404
|
+
* native last said trails it, and what it said along the other axis says nothing of `axis`. After a
|
|
405
|
+
* jump, `from`, where the list scrolled itself.
|
|
406
|
+
*/
|
|
407
|
+
headerFrom(pinned, moved, axis, from) {
|
|
408
|
+
const held = this.headerDrive;
|
|
409
|
+
const changed = held?.pinned !== pinned || (this.resting && held.range !== moved);
|
|
410
|
+
if (!changed)
|
|
411
|
+
return from;
|
|
412
|
+
return from ?? (this.nativeAxis === axis ? this.nativeAt : undefined);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Where native is told the scroll view is for a drive made, or moved by a new range, along
|
|
416
|
+
* `axis`. Native draws a graph when the offset changes, and at rest no scroll event comes to draw
|
|
417
|
+
* it: it is told where native last said it was, unless that was along the other axis. Mid-scroll
|
|
418
|
+
* the next event draws it. After a jump, `from`.
|
|
419
|
+
*/
|
|
420
|
+
drawnFrom(axis, from) {
|
|
421
|
+
return from ?? (this.resting && this.nativeAxis === axis ? this.nativeAt : undefined);
|
|
422
|
+
}
|
|
423
|
+
/** How native moves the pinned header. A first sticky row at the very top holds it in place. */
|
|
424
|
+
headerRange() {
|
|
425
|
+
const limit = this.headerLimit();
|
|
426
|
+
return limit > 0 ? pinnedRange(0, limit) : STILL;
|
|
427
|
+
}
|
|
428
|
+
/** How far the header moves before the first sticky row pushes it off: to that row's top. */
|
|
429
|
+
headerLimit() {
|
|
430
|
+
const [first] = this.rows().keys();
|
|
431
|
+
return first === undefined ? Infinity : this.list.topOf(first);
|
|
432
|
+
}
|
|
249
433
|
destroy() {
|
|
250
434
|
clearTimeout(this.settleTimer);
|
|
251
435
|
for (const held of this.drives.values())
|
|
252
436
|
held.drive.stop();
|
|
437
|
+
this.headerDrive?.drive.stop();
|
|
253
438
|
}
|
|
254
|
-
/**
|
|
439
|
+
/** The size of the rows a sticky row pins under, which is how far from the edge it holds. */
|
|
440
|
+
above(index) {
|
|
441
|
+
let size = 0;
|
|
442
|
+
for (const over of this.rows().get(index)?.above ?? NONE)
|
|
443
|
+
size += this.list.heightOf(over);
|
|
444
|
+
return size;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* A deeper row is drawn under the rows it pins under, and every sticky row over the rest. See
|
|
448
|
+
* `FRONT`. Without levels a sticky row's zIndex is 1, as it was before there were any.
|
|
449
|
+
*/
|
|
450
|
+
zIndexOf(index) {
|
|
451
|
+
if (!this.list.levels?.levelOf())
|
|
452
|
+
return 1;
|
|
453
|
+
return Math.max(1, FRONT - (this.rows().get(index)?.level ?? 0));
|
|
454
|
+
}
|
|
455
|
+
/** The offset a sticky row starts to hold from: where its top meets the rows it pins under. */
|
|
456
|
+
startOf(index) {
|
|
457
|
+
return this.list.topOf(index) - this.above(index);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* The offset a sticky row stops holding at, pushed off by the next: where that row's top meets
|
|
461
|
+
* this row's far edge.
|
|
462
|
+
*/
|
|
255
463
|
stopOf(index) {
|
|
256
|
-
const next = this.
|
|
257
|
-
|
|
464
|
+
const next = this.rows().get(index)?.next;
|
|
465
|
+
if (next === undefined)
|
|
466
|
+
return Infinity;
|
|
467
|
+
return this.list.topOf(next) - this.list.heightOf(index) - this.above(index);
|
|
258
468
|
}
|
|
259
469
|
/**
|
|
260
470
|
* How native moves a rendered row, or null when it does not: along the scroll view's own
|
|
261
|
-
* offset, which counts the header, from the row
|
|
471
|
+
* offset, which counts the header, from where the row meets the rows it pins under until the
|
|
472
|
+
* next sticky row pushes it off. A row the next one follows with no space between them holds
|
|
473
|
+
* nowhere, so native moves it nowhere: it is not let go, since native keeps the translate it
|
|
474
|
+
* had moved a row by.
|
|
262
475
|
*/
|
|
263
476
|
driveOf(row) {
|
|
264
|
-
if (!this.native || row.parked || !this.
|
|
477
|
+
if (!this.native || row.parked || !this.rows().has(row.index))
|
|
265
478
|
return null;
|
|
266
479
|
const header = this.list.headerHeight();
|
|
267
|
-
const start = header + this.
|
|
480
|
+
const start = header + this.startOf(row.index);
|
|
481
|
+
const stop = header + this.stopOf(row.index);
|
|
268
482
|
return {
|
|
269
|
-
range: pinnedRange(start,
|
|
483
|
+
range: stop > start ? pinnedRange(start, stop) : { input: [start, start + 1], output: [0, 0] },
|
|
270
484
|
statics: this.list.flip() ?? [],
|
|
271
485
|
};
|
|
272
486
|
}
|