@geastack/elements 0.1.7 → 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 +14 -0
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
|
@@ -175,6 +175,19 @@ void VirtualListRenderer::configureAttribute(int node, const char *name, const c
|
|
|
175
175
|
n.render.layout_dirty = 1;
|
|
176
176
|
#if GEA_CSS_SCROLLING
|
|
177
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;
|
|
178
191
|
#endif
|
|
179
192
|
Tree::instance().markNodeDisplayCommandsDirty(node);
|
|
180
193
|
}
|
|
@@ -203,6 +216,7 @@ int VirtualListRenderer::virtualContentHeight(int node, int rowHeight)
|
|
|
203
216
|
// recomputing ITEM_HEIGHT and hand-syncing it to the CSS.
|
|
204
217
|
if (rowHeight > 0) ensureRareData(node).ensureVirtualList().rowHeight = static_cast<int32_t>(rowHeight);
|
|
205
218
|
const NodeRareData *rd = rareDataFor(node);
|
|
219
|
+
if (rd && rd->virtualList && rd->virtualList->contentHeight > 0) return rd->virtualList->contentHeight;
|
|
206
220
|
const int count = rd && rd->virtualList ? rd->virtualList->itemCount : 0;
|
|
207
221
|
if (count <= 0 || rowHeight <= 0) return 0;
|
|
208
222
|
const int64_t raw = static_cast<int64_t>(count) * static_cast<int64_t>(rowHeight);
|