@geastack/elements 0.1.2 → 0.1.4

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.
@@ -1,4 +1,4 @@
1
- import type { ClassValue, TouchEventHandler } from '@geastack/core'
1
+ import type { ClassValue, Event, TouchEventHandler } from '@geastack/core'
2
2
 
3
3
  export type VirtualListItemTemplate = (index: number, top: number) => any
4
4
 
@@ -15,6 +15,7 @@ export interface VirtualListProps {
15
15
  onTouchStart?: TouchEventHandler
16
16
  onTouchMove?: TouchEventHandler
17
17
  onTouchEnd?: TouchEventHandler
18
+ onScroll?: (event: Event) => void
18
19
  }
19
20
 
20
21
  export default function VirtualList(props: VirtualListProps): any
@@ -1,4 +1,4 @@
1
- import type { ClassValue, TouchEventHandler } from '@geastack/core'
1
+ import type { ClassValue, Event, TouchEventHandler } from '@geastack/core'
2
2
 
3
3
  // A windowing list backed by the native <virtual-list> element. The element is
4
4
  // an ordinary overflow:scroll container that scrolls over a virtual content
@@ -25,6 +25,7 @@ export interface VirtualListProps {
25
25
  onTouchStart?: TouchEventHandler
26
26
  onTouchMove?: TouchEventHandler
27
27
  onTouchEnd?: TouchEventHandler
28
+ onScroll?: (event: Event) => void
28
29
  }
29
30
 
30
31
  const SLOT_COUNT = 16
@@ -94,7 +95,8 @@ export default function VirtualList({
94
95
  itemTemplate,
95
96
  onTouchStart,
96
97
  onTouchMove,
97
- onTouchEnd
98
+ onTouchEnd,
99
+ onScroll
98
100
  }: VirtualListProps) {
99
101
  const rowOverscan = overscan === undefined ? 2 : overscan
100
102
  return (
@@ -105,6 +107,7 @@ export default function VirtualList({
105
107
  onTouchStart={onTouchStart}
106
108
  onTouchMove={onTouchMove}
107
109
  onTouchEnd={onTouchEnd}
110
+ onScroll={onScroll}
108
111
  >
109
112
  <VirtualListSlot slotIndex={0} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
110
113
  <VirtualListSlot slotIndex={1} scrollTop={scrollTop} itemHeight={itemHeight} overscan={rowOverscan} itemCount={itemCount} itemClass={itemClass} itemTemplate={itemTemplate} />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/elements",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Non-core GeaStack JSX elements and native element backends.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -41,6 +41,6 @@
41
41
  },
42
42
  "sideEffects": false,
43
43
  "dependencies": {
44
- "@geastack/core": "^0.1.0"
44
+ "@geastack/core": "^0.1.34"
45
45
  }
46
46
  }
@@ -21,6 +21,18 @@ namespace gea::embedded::ui {
21
21
 
22
22
  namespace {
23
23
 
24
+ void dispatchScrollEvent(int node)
25
+ {
26
+ Tree &tree = Tree::instance();
27
+ if (!tree.hasListenersForType("scroll")) return;
28
+ gea::framework::events::PointerEvent event{};
29
+ event.type = gea::framework::events::PointerEventType::Scroll;
30
+ event.targetId = node;
31
+ event.bubbles = false;
32
+ event.cancelable = false;
33
+ tree.dispatchEvent(event);
34
+ }
35
+
24
36
  int parseIntAttribute(const char *value, int fallback)
25
37
  {
26
38
  if (!value || !value[0]) return fallback;
@@ -60,7 +72,7 @@ int clampScrollTop(const Node &n, int scrollTop)
60
72
  bool canScrollY(int node, const Node &n)
61
73
  {
62
74
  if (n.type == NodeType::VirtualList) return VirtualListRenderer::scrollMaxY(node) > 0;
63
- if (!isViewLikeNodeType(n.type) || !scrollsOverflowY(n.style)) return false;
75
+ if (!isViewLikeNodeType(n.type) || !scrollsOverflowY(n.computedStyle())) return false;
64
76
  return ViewRenderer::scrollMaxY(n) > 0;
65
77
  }
66
78
 
@@ -80,12 +92,12 @@ bool targetContentBoundsY(const TreeState &state, int scroller, int target, int
80
92
  int y = 0;
81
93
  for (int current = target; current >= 0 && current != scroller; current = state.nodes[current].parent) {
82
94
  const Node &node = state.nodes[current];
83
- if (!state.nodeActive[current] || node.style.display == kDisplayNone) return false;
95
+ if (!state.nodeActive[current] || node.computedStyle().display == kDisplayNone) return false;
84
96
  y += node.layout.y;
85
97
 
86
98
  const int parent = node.parent;
87
99
  if (parent < 0 || parent >= state.nodeCount) return false;
88
- if (parent != scroller && state.nodes[parent].style.overflow == 2 && scrollsOverflowY(state.nodes[parent].style)) {
100
+ if (parent != scroller && state.nodes[parent].computedStyle().overflow == 2 && scrollsOverflowY(state.nodes[parent].computedStyle())) {
89
101
  y -= state.nodes[parent].layout.scroll_y;
90
102
  }
91
103
  }
@@ -129,22 +141,29 @@ bool scrollResolvedNodeIntoView(TreeState &state, int node)
129
141
 
130
142
  void VirtualListRenderer::init(int node)
131
143
  {
144
+ #if GEA_CSS_SCROLLING
132
145
  if (node < 0 || node >= kMaxNodes) return;
133
146
  auto &state = treeState();
134
- ensureRareData(node).virtualList.itemCount = 0;
147
+ ensureRareData(node).ensureVirtualList().itemCount = 0;
135
148
  // Behave like any overflow:scroll container so the generic scroll, clip and
136
149
  // scrollbar paths drive the list. The app's CSS may also set this; forcing
137
150
  // it here keeps a bare <virtual-list> scrollable.
138
- state.nodes[node].style.overflow = 2;
139
- state.nodes[node].style.overflow_x = 0;
140
- state.nodes[node].style.overflow_y = 2;
151
+ state.nodes[node].mutableStyle().overflow = 2;
152
+ #if GEA_CSS_OVERFLOW_AXES
153
+ state.nodes[node].mutableStyle().overflow_x = 0;
154
+ state.nodes[node].mutableStyle().overflow_y = 2;
155
+ #endif
156
+ #else
157
+ (void)node;
158
+ #endif
141
159
  }
142
160
 
143
161
  void VirtualListRenderer::configureAttribute(int node, const char *name, const char *value)
144
162
  {
163
+ #if GEA_CSS_SCROLLING
145
164
  auto &state = treeState();
146
165
  if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return;
147
- auto &list = ensureRareData(node).virtualList;
166
+ auto &list = ensureRareData(node).ensureVirtualList();
148
167
 
149
168
  if (sameName(name, "item-count") || sameName(name, "itemCount")) {
150
169
  const int next = parseIntAttribute(value, list.itemCount);
@@ -153,9 +172,14 @@ void VirtualListRenderer::configureAttribute(int node, const char *name, const c
153
172
  Node &n = state.nodes[node];
154
173
  n.render.dirty = 1;
155
174
  n.render.layout_dirty = 1;
175
+ #if GEA_CSS_SCROLLING
156
176
  n.render.non_scroll_dirty = 1;
177
+ #endif
157
178
  Tree::instance().markNodeDisplayCommandsDirty(node);
158
179
  }
180
+ #else
181
+ (void)node; (void)name; (void)value;
182
+ #endif
159
183
  }
160
184
 
161
185
  int VirtualListRenderer::itemCount(int node)
@@ -163,11 +187,12 @@ int VirtualListRenderer::itemCount(int node)
163
187
  const auto &state = treeState();
164
188
  if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
165
189
  const NodeRareData *rd = rareDataFor(node);
166
- return rd ? rd->virtualList.itemCount : 0;
190
+ return rd && rd->virtualList ? rd->virtualList->itemCount : 0;
167
191
  }
168
192
 
169
193
  int VirtualListRenderer::virtualContentHeight(int node, int rowHeight)
170
194
  {
195
+ #if GEA_CSS_SCROLLING
171
196
  auto &state = treeState();
172
197
  if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
173
198
  // Cache the measured row height (the first slot child's rendered CSS layout
@@ -175,12 +200,15 @@ int VirtualListRenderer::virtualContentHeight(int node, int rowHeight)
175
200
  // and position/window its recycled slots from the SAME value the native
176
201
  // scroll geometry uses — one source of truth, instead of the app
177
202
  // recomputing ITEM_HEIGHT and hand-syncing it to the CSS.
178
- if (rowHeight > 0) ensureRareData(node).virtualList.rowHeight = static_cast<int32_t>(rowHeight);
203
+ if (rowHeight > 0) ensureRareData(node).ensureVirtualList().rowHeight = static_cast<int32_t>(rowHeight);
179
204
  const NodeRareData *rd = rareDataFor(node);
180
- const int count = rd ? rd->virtualList.itemCount : 0;
205
+ const int count = rd && rd->virtualList ? rd->virtualList->itemCount : 0;
181
206
  if (count <= 0 || rowHeight <= 0) return 0;
182
207
  const int64_t raw = static_cast<int64_t>(count) * static_cast<int64_t>(rowHeight);
183
208
  return raw > 0x3fffffffLL ? 0x3fffffff : static_cast<int>(raw);
209
+ #else
210
+ (void)node; (void)rowHeight; return 0;
211
+ #endif
184
212
  }
185
213
 
186
214
  int VirtualListRenderer::rowHeight(int node)
@@ -188,7 +216,7 @@ int VirtualListRenderer::rowHeight(int node)
188
216
  const auto &state = treeState();
189
217
  if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return 0;
190
218
  const NodeRareData *rd = rareDataFor(node);
191
- return rd ? rd->virtualList.rowHeight : 0;
219
+ return rd && rd->virtualList ? rd->virtualList->rowHeight : 0;
192
220
  }
193
221
 
194
222
  int VirtualListRenderer::scrollTop(int node)
@@ -216,6 +244,7 @@ int VirtualListRenderer::scrollMaxY(int node)
216
244
 
217
245
  bool VirtualListRenderer::setScrollTop(int node, int scrollTop)
218
246
  {
247
+ #if GEA_CSS_SCROLLING
219
248
  auto &state = treeState();
220
249
  if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return false;
221
250
  Node &n = state.nodes[node];
@@ -225,15 +254,23 @@ bool VirtualListRenderer::setScrollTop(int node, int scrollTop)
225
254
  n.render.dirty = 1;
226
255
  n.render.layout_dirty = 1;
227
256
  Tree::instance().markScrollDirty(node);
257
+ dispatchScrollEvent(node);
228
258
  return true;
259
+ #else
260
+ (void)node; (void)scrollTop; return false;
261
+ #endif
229
262
  }
230
263
 
231
264
  void VirtualListRenderer::captureSnapshot(int node)
232
265
  {
266
+ #if GEA_CSS_SCROLLING
233
267
  auto &state = treeState();
234
268
  if (node < 0 || node >= state.nodeCount || state.nodes[node].type != NodeType::VirtualList) return;
235
269
  Node &n = state.nodes[node];
236
270
  n.layout.previous_scroll_y = n.layout.scroll_y;
271
+ #else
272
+ (void)node;
273
+ #endif
237
274
  }
238
275
 
239
276
  int Tree::scrollTop(int node) const
@@ -250,9 +287,10 @@ int Tree::scrollLeft(int node) const
250
287
 
251
288
  void Tree::setScrollLeft(int node, int scrollLeft)
252
289
  {
290
+ #if GEA_CSS_SCROLLING
253
291
  if (node < 0 || node >= nodeCount()) return;
254
292
  Node &n = treeState().nodes[node];
255
- if (!isViewLikeNodeType(n.type) || !scrollsOverflowX(n.style) || n.type == NodeType::VirtualList) return;
293
+ if (!isViewLikeNodeType(n.type) || !scrollsOverflowX(n.computedStyle()) || n.type == NodeType::VirtualList) return;
256
294
  const int maxX = ViewRenderer::scrollMaxX(n);
257
295
  if (scrollLeft < 0) scrollLeft = 0;
258
296
  if (scrollLeft > maxX) scrollLeft = maxX;
@@ -260,15 +298,25 @@ void Tree::setScrollLeft(int node, int scrollLeft)
260
298
  n.layout.scroll_x = static_cast<int32_t>(scrollLeft);
261
299
  n.render.dirty = 1;
262
300
  n.render.layout_dirty = 1;
301
+ #if GEA_CSS_SCROLLING
263
302
  n.render.non_scroll_dirty = 1;
303
+ #endif
264
304
  markScrollDirty(node);
305
+ #else
306
+ (void)node; (void)scrollLeft;
307
+ #endif
265
308
  }
266
309
 
267
310
  void Tree::setScrollTop(int node, int scrollTop)
268
311
  {
312
+ #if GEA_CSS_SCROLLING
269
313
  if (node < 0 || node >= nodeCount()) return;
270
314
  Node &n = treeState().nodes[node];
271
- if (!isViewLikeNodeType(n.type) || (n.type != NodeType::VirtualList && !scrollsOverflowY(n.style))) return;
315
+ if (n.type == NodeType::VirtualList) {
316
+ VirtualListRenderer::setScrollTop(node, scrollTop);
317
+ return;
318
+ }
319
+ if (!isViewLikeNodeType(n.type) || !scrollsOverflowY(n.computedStyle())) return;
272
320
  const int maxY = ViewRenderer::scrollMaxY(n);
273
321
  if (scrollTop < 0) scrollTop = 0;
274
322
  if (scrollTop > maxY) scrollTop = maxY;
@@ -277,19 +325,27 @@ void Tree::setScrollTop(int node, int scrollTop)
277
325
  n.render.dirty = 1;
278
326
  n.render.layout_dirty = 1;
279
327
  markScrollDirty(node);
328
+ #else
329
+ (void)node; (void)scrollTop;
330
+ #endif
280
331
  }
281
332
 
282
333
  void Tree::scrollIntoView(int node)
283
334
  {
335
+ #if GEA_CSS_SCROLLING
284
336
  auto &state = treeState();
285
337
  if (node < 0 || node >= state.nodeCount || !state.nodeActive[node]) return;
286
338
  state.pendingScrollIntoViewNode = node;
287
339
  scrollResolvedNodeIntoView(state, node);
288
340
  markDisplayListContentDirty();
341
+ #else
342
+ (void)node;
343
+ #endif
289
344
  }
290
345
 
291
346
  void Tree::applyPendingScrollIntoView()
292
347
  {
348
+ #if GEA_CSS_SCROLLING
293
349
  auto &state = treeState();
294
350
  const int node = state.pendingScrollIntoViewNode;
295
351
  if (node < 0) return;
@@ -321,6 +377,9 @@ void Tree::applyPendingScrollIntoView()
321
377
  }
322
378
  state.pendingScrollIntoViewNode = -1;
323
379
  setScrollTop(scroller, next);
380
+ #else
381
+
382
+ #endif
324
383
  }
325
384
 
326
385
  } // namespace gea::embedded::ui