@geastack/elements 0.1.6 → 0.1.8
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/README.md +33 -2
- package/package.json +1 -1
- package/ui/virtual_list.cpp +42 -8
package/README.md
CHANGED
|
@@ -13,11 +13,42 @@ npm install @geastack/elements
|
|
|
13
13
|
`CameraController` types are re-exported from `@geastack/core`.
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
+
import { Component, Store, type VirtualListElement } from '@geastack/core'
|
|
16
17
|
import { VirtualList } from '@geastack/elements'
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
import { Text } from '@geastack/engine'
|
|
19
|
+
|
|
20
|
+
class ListScroll extends Store {
|
|
21
|
+
scrollTop = 0
|
|
22
|
+
sync() {
|
|
23
|
+
const list = document.getElementById('rows') as VirtualListElement | null
|
|
24
|
+
if (list) this.scrollTop = list.scrollTop
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const scroll = new ListScroll()
|
|
28
|
+
|
|
29
|
+
export class App extends Component {
|
|
30
|
+
template() {
|
|
31
|
+
return (
|
|
32
|
+
<VirtualList
|
|
33
|
+
id="rows"
|
|
34
|
+
itemCount={1000}
|
|
35
|
+
itemHeight={48}
|
|
36
|
+
scrollTop={scroll.scrollTop}
|
|
37
|
+
onScroll={() => scroll.sync()}
|
|
38
|
+
itemTemplate={(index) => <Text>{`Row ${index}`}</Text>}
|
|
39
|
+
/>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
19
43
|
```
|
|
20
44
|
|
|
45
|
+
`VirtualList` renders a native `<virtual-list>` scrolling over
|
|
46
|
+
`itemCount * itemHeight` and recycles a fixed pool of row slots. The app owns
|
|
47
|
+
`scrollTop`: read it from the element in `onScroll` and pass it back in.
|
|
48
|
+
`itemTemplate(index, top)` renders the row at `index`; `slotCount`, `overscan`,
|
|
49
|
+
`class`, `itemClass` and the touch handlers are optional
|
|
50
|
+
(`components/VirtualList.d.ts`).
|
|
51
|
+
|
|
21
52
|
The native backends are compiled into a target through `@geastack/core`'s
|
|
22
53
|
source manifest; apps only import the components.
|
|
23
54
|
|
package/package.json
CHANGED
package/ui/virtual_list.cpp
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#include "internal.h"
|
|
3
|
+
#include "input_retirement.h"
|
|
3
4
|
|
|
4
5
|
#include "tree_state.h"
|
|
5
6
|
|
|
@@ -174,6 +175,19 @@ void VirtualListRenderer::configureAttribute(int node, const char *name, const c
|
|
|
174
175
|
n.render.layout_dirty = 1;
|
|
175
176
|
#if GEA_CSS_SCROLLING
|
|
176
177
|
n.render.non_scroll_dirty = 1;
|
|
178
|
+
#endif
|
|
179
|
+
Tree::instance().markNodeDisplayCommandsDirty(node);
|
|
180
|
+
} else if (sameName(name, "content-height") || sameName(name, "contentHeight")) {
|
|
181
|
+
// Rows of different heights: the app sums them and the list scrolls
|
|
182
|
+
// over that instead of item-count times the first slot's height.
|
|
183
|
+
const int next = parseIntAttribute(value, list.contentHeight);
|
|
184
|
+
if (next == list.contentHeight) return;
|
|
185
|
+
list.contentHeight = next;
|
|
186
|
+
Node &n = state.nodes[node];
|
|
187
|
+
n.render.dirty = 1;
|
|
188
|
+
n.render.layout_dirty = 1;
|
|
189
|
+
#if GEA_CSS_SCROLLING
|
|
190
|
+
n.render.non_scroll_dirty = 1;
|
|
177
191
|
#endif
|
|
178
192
|
Tree::instance().markNodeDisplayCommandsDirty(node);
|
|
179
193
|
}
|
|
@@ -202,6 +216,7 @@ int VirtualListRenderer::virtualContentHeight(int node, int rowHeight)
|
|
|
202
216
|
// recomputing ITEM_HEIGHT and hand-syncing it to the CSS.
|
|
203
217
|
if (rowHeight > 0) ensureRareData(node).ensureVirtualList().rowHeight = static_cast<int32_t>(rowHeight);
|
|
204
218
|
const NodeRareData *rd = rareDataFor(node);
|
|
219
|
+
if (rd && rd->virtualList && rd->virtualList->contentHeight > 0) return rd->virtualList->contentHeight;
|
|
205
220
|
const int count = rd && rd->virtualList ? rd->virtualList->itemCount : 0;
|
|
206
221
|
if (count <= 0 || rowHeight <= 0) return 0;
|
|
207
222
|
const int64_t raw = static_cast<int64_t>(count) * static_cast<int64_t>(rowHeight);
|
|
@@ -291,6 +306,7 @@ void Tree::setScrollLeft(int node, int scrollLeft)
|
|
|
291
306
|
if (node < 0 || node >= nodeCount()) return;
|
|
292
307
|
Node &n = treeState().nodes[node];
|
|
293
308
|
if (!isViewLikeNodeType(n.type) || !scrollsOverflowX(n.computedStyle()) || n.type == NodeType::VirtualList) return;
|
|
309
|
+
if (animateSnapPageScroll(node, true, scrollLeft)) return;
|
|
294
310
|
const int maxX = ViewRenderer::scrollMaxX(n);
|
|
295
311
|
if (scrollLeft < 0) scrollLeft = 0;
|
|
296
312
|
if (scrollLeft > maxX) scrollLeft = maxX;
|
|
@@ -317,6 +333,7 @@ void Tree::setScrollTop(int node, int scrollTop)
|
|
|
317
333
|
return;
|
|
318
334
|
}
|
|
319
335
|
if (!isViewLikeNodeType(n.type) || !scrollsOverflowY(n.computedStyle())) return;
|
|
336
|
+
if (animateSnapPageScroll(node, false, scrollTop)) return;
|
|
320
337
|
const int maxY = ViewRenderer::scrollMaxY(n);
|
|
321
338
|
if (scrollTop < 0) scrollTop = 0;
|
|
322
339
|
if (scrollTop > maxY) scrollTop = maxY;
|
|
@@ -343,39 +360,56 @@ void Tree::scrollIntoView(int node)
|
|
|
343
360
|
#endif
|
|
344
361
|
}
|
|
345
362
|
|
|
363
|
+
void Tree::scrollIntoViewKeepingPadding(int node)
|
|
364
|
+
{
|
|
365
|
+
#if GEA_CSS_SCROLLING
|
|
366
|
+
scrollIntoView(node);
|
|
367
|
+
if (treeState().pendingScrollIntoViewNode == node) treeState().pendingScrollIntoViewKeepsPadding = true;
|
|
368
|
+
#else
|
|
369
|
+
(void)node;
|
|
370
|
+
#endif
|
|
371
|
+
}
|
|
372
|
+
|
|
346
373
|
void Tree::applyPendingScrollIntoView()
|
|
347
374
|
{
|
|
348
375
|
#if GEA_CSS_SCROLLING
|
|
349
376
|
auto &state = treeState();
|
|
350
377
|
const int node = state.pendingScrollIntoViewNode;
|
|
351
378
|
if (node < 0) return;
|
|
352
|
-
|
|
379
|
+
const bool keepPadding = state.pendingScrollIntoViewKeepsPadding;
|
|
380
|
+
auto finish = [&state] {
|
|
353
381
|
state.pendingScrollIntoViewNode = -1;
|
|
382
|
+
state.pendingScrollIntoViewKeepsPadding = false;
|
|
383
|
+
};
|
|
384
|
+
if (node >= state.nodeCount || !state.nodeActive[node]) {
|
|
385
|
+
finish();
|
|
354
386
|
return;
|
|
355
387
|
}
|
|
356
388
|
const int scroller = nearestScrollableAncestorY(state, node);
|
|
357
389
|
if (scroller < 0) return;
|
|
358
390
|
|
|
359
391
|
const Node &container = state.nodes[scroller];
|
|
392
|
+
const int padTop = keepPadding ? container.computedStyle().padding[0] : 0;
|
|
393
|
+
const int padBottom = keepPadding ? container.computedStyle().padding[2] : 0;
|
|
360
394
|
const int viewportTop = container.layout.scroll_y;
|
|
361
395
|
const int viewportBottom = viewportTop + container.layout.height;
|
|
362
396
|
int targetTop = 0;
|
|
363
397
|
int targetBottom = 0;
|
|
364
398
|
if (!targetContentBoundsY(state, scroller, node, &targetTop, &targetBottom)) {
|
|
365
|
-
|
|
399
|
+
finish();
|
|
366
400
|
return;
|
|
367
401
|
}
|
|
368
402
|
|
|
369
403
|
int next = container.layout.scroll_y;
|
|
370
|
-
if (targetTop < viewportTop) {
|
|
371
|
-
next = targetTop;
|
|
372
|
-
} else if (targetBottom > viewportBottom) {
|
|
373
|
-
next = targetBottom - container.layout.height;
|
|
404
|
+
if (targetTop - padTop < viewportTop) {
|
|
405
|
+
next = targetTop - padTop;
|
|
406
|
+
} else if (targetBottom + padBottom > viewportBottom) {
|
|
407
|
+
next = targetBottom + padBottom - container.layout.height;
|
|
374
408
|
} else {
|
|
375
|
-
|
|
409
|
+
finish();
|
|
376
410
|
return;
|
|
377
411
|
}
|
|
378
|
-
|
|
412
|
+
finish();
|
|
379
413
|
setScrollTop(scroller, next);
|
|
380
414
|
#else
|
|
381
415
|
|