@onekeyfe/react-native-native-list 6.7.0-alpha.466 → 6.8.0-10

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.
Files changed (46) hide show
  1. package/README.md +312 -379
  2. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +15 -6
  3. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
  4. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +66 -31
  5. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +32 -11
  6. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +60 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +5 -1
  8. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +75 -0
  9. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +25 -19
  10. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -0
  11. package/docs/ROW_TEMPLATES.md +11 -4
  12. package/docs/SPEC.md +296 -20
  13. package/docs/STYLE_SPEC.md +12 -0
  14. package/ios/NativeListActivityDetailsView.swift +13 -5
  15. package/ios/NativeListMediaPlaceholderView.swift +189 -0
  16. package/ios/NativeListMediaPreviewSlot.swift +122 -61
  17. package/ios/NativeListMediaTileRenderer.swift +13 -13
  18. package/ios/NativeListResolvedText.swift +15 -4
  19. package/ios/NativeListTextLabel.swift +106 -0
  20. package/ios/RNCNativeListView.swift +129 -32
  21. package/ios/tests/NativeListActivityPresentationTests.swift +270 -0
  22. package/ios/tests/NativeListLifecycleTests.swift +369 -40
  23. package/ios/tests/NativeListMediaVisibilityTests.swift +41 -7
  24. package/lib/module/NativeList.js +17 -4
  25. package/lib/module/NativeList.web.js +3 -1
  26. package/lib/module/validation.js +53 -4
  27. package/lib/module/web/NativeListGeneratedIcons.js +1 -0
  28. package/lib/module/web/NativeListWebEngine.js +13 -11
  29. package/lib/module/web/templates/ActivityRowRenderer.js +29 -23
  30. package/lib/module/web/templates/DataRowRenderer.js +54 -1
  31. package/lib/module/web/templates/IdentityRowRenderer.js +3 -1
  32. package/lib/module/web/templates/MediaTileRowRenderer.js +84 -15
  33. package/lib/typescript/src/models.d.ts +18 -1
  34. package/package.json +1 -1
  35. package/scripts/generate-icons.test.mjs +1 -0
  36. package/scripts/native-list-icons.json +1 -1
  37. package/src/NativeList.tsx +25 -4
  38. package/src/NativeList.web.tsx +1 -1
  39. package/src/models.ts +18 -0
  40. package/src/validation.ts +96 -1
  41. package/src/web/NativeListGeneratedIcons.ts +1 -0
  42. package/src/web/NativeListWebEngine.ts +16 -11
  43. package/src/web/templates/ActivityRowRenderer.ts +42 -32
  44. package/src/web/templates/DataRowRenderer.ts +76 -1
  45. package/src/web/templates/IdentityRowRenderer.ts +3 -3
  46. package/src/web/templates/MediaTileRowRenderer.ts +90 -15
@@ -168,9 +168,10 @@ type HistoryViews = {
168
168
  title: HTMLElement;
169
169
  badges: HTMLElement;
170
170
  description: HTMLElement;
171
- descriptionTime: HTMLElement;
172
- descriptionDot: HTMLElement;
173
- descriptionAddress: HTMLButtonElement;
171
+ /** Description text before the action, or nothing. */
172
+ descriptionPrefix: HTMLElement;
173
+ /** Description text that opens the action; the whole text without one. */
174
+ descriptionAction: HTMLButtonElement;
174
175
  amounts: HTMLElement;
175
176
  amountRows: Map<string, AmountViews>;
176
177
  fee: HTMLElement;
@@ -196,6 +197,8 @@ const isHistory = (row: ActivityRow) =>
196
197
  row.presentation !== undefined || row.amounts !== undefined;
197
198
  const ellipsis =
198
199
  'min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';
200
+ /** Width a description prefix always leaves for the action text after it. */
201
+ const descriptionActionReserve = '3em';
199
202
  function valueText(
200
203
  node: HTMLElement,
201
204
  text: string | undefined,
@@ -221,14 +224,13 @@ function createHistory(body: HTMLElement, primitives: RowPrimitives) {
221
224
  const badges = node('badges');
222
225
  const description = node('description');
223
226
  description.dataset.nlSlot = 'description';
224
- const descriptionTime = createElement(document, 'span');
225
- const descriptionDot = createElement(document, 'span', undefined, '•');
226
- const descriptionAddress = createElement(
227
+ const descriptionPrefix = createElement(document, 'span');
228
+ const descriptionAction = createElement(
227
229
  document,
228
230
  'button'
229
231
  ) as HTMLButtonElement;
230
- descriptionAddress.type = 'button';
231
- description.append(descriptionTime, descriptionDot, descriptionAddress);
232
+ descriptionAction.type = 'button';
233
+ description.append(descriptionPrefix, descriptionAction);
232
234
  const amounts = node('amounts');
233
235
  const fee = node('fee');
234
236
  const feeLabel = node('fee-label');
@@ -252,9 +254,8 @@ function createHistory(body: HTMLElement, primitives: RowPrimitives) {
252
254
  title,
253
255
  badges,
254
256
  description,
255
- descriptionTime,
256
- descriptionDot,
257
- descriptionAddress,
257
+ descriptionPrefix,
258
+ descriptionAction,
258
259
  amounts,
259
260
  amountRows: new Map(),
260
261
  fee,
@@ -579,29 +580,38 @@ function bindHistory(
579
580
  ellipsis +
580
581
  'display:flex;max-width:100%;color:var(--nl-secondary);font-family:inherit;font-size:14px;line-height:20px;font-weight:400;font-variant-numeric:tabular-nums;';
581
582
  applyTextWeight(v.description, 400);
582
- const split = row.description?.indexOf(' • ') ?? -1;
583
- v.descriptionTime.textContent =
584
- split >= 0 ? row.description!.slice(0, split) : '';
585
- v.descriptionTime.style.display = split >= 0 ? 'inline' : 'none';
586
- v.descriptionTime.style.flexShrink = '0';
587
- v.descriptionDot.style.cssText = `flex-shrink:0;margin:0 4px;display:${
588
- split >= 0 ? 'inline' : 'none'
589
- }`;
590
- v.descriptionAddress.style.cssText =
591
- ellipsis +
592
- 'appearance:none;display:block;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;';
593
- v.descriptionAddress.textContent =
594
- split >= 0 ? row.description!.slice(split + 3) : row.description ?? '';
583
+ // The caller states where the action text starts; the string is not parsed.
584
+ const description = row.description ?? '';
585
+ const actionStart = row.descriptionActionKey
586
+ ? Math.min(Math.max(row.descriptionActionStart ?? 0, 0), description.length)
587
+ : 0;
588
+ const actionText = description.slice(actionStart);
589
+ const boundAction =
590
+ row.descriptionActionKey && actionText ? row.descriptionActionKey : '';
591
+ // `pre` keeps the space a prefix ends with; a line break stays a space.
592
+ v.descriptionPrefix.textContent = description
593
+ .slice(0, actionStart)
594
+ .replace(/\r\n|[\r\n]/g, ' ');
595
+ // The prefix keeps its width and the action truncates first, as the tail of
596
+ // the one native label does. A prefix wider than the row is capped instead,
597
+ // or it would squeeze the action to nothing and leave no pointer target.
598
+ v.descriptionPrefix.style.cssText = `${ellipsis}flex-shrink:0;max-width:${
599
+ actionText ? `calc(100% - ${descriptionActionReserve})` : '100%'
600
+ };white-space:pre;display:${actionStart > 0 ? 'block' : 'none'}`;
601
+ v.descriptionAction.style.cssText = `${ellipsis}appearance:none;max-width:100%;border:0;padding:0;background:transparent;text-align:left;color:inherit;font:inherit;font-variant-numeric:inherit;display:${
602
+ actionText ? 'block' : 'none'
603
+ };`;
604
+ v.descriptionAction.textContent = actionText;
595
605
  v.description.style.display = row.description ? 'flex' : 'none';
596
- v.descriptionAddress.tabIndex = row.descriptionActionKey ? 0 : -1;
597
- if (row.descriptionActionKey) {
598
- v.descriptionAddress.dataset.nativeListAction = row.descriptionActionKey;
599
- markActionAnchorSource(v.descriptionAddress, 'description');
600
- v.descriptionAddress.style.cursor = 'pointer';
606
+ v.descriptionAction.tabIndex = boundAction ? 0 : -1;
607
+ if (boundAction) {
608
+ v.descriptionAction.dataset.nativeListAction = boundAction;
609
+ markActionAnchorSource(v.descriptionAction, 'description');
610
+ v.descriptionAction.style.cursor = 'pointer';
601
611
  } else {
602
- delete v.descriptionAddress.dataset.nativeListAction;
603
- delete v.descriptionAddress.dataset.nativeListAnchorSource;
604
- v.descriptionAddress.style.cursor = 'inherit';
612
+ delete v.descriptionAction.dataset.nativeListAction;
613
+ delete v.descriptionAction.dataset.nativeListAnchorSource;
614
+ v.descriptionAction.style.cursor = 'inherit';
605
615
  }
606
616
  if (row.style?.description)
607
617
  primitives.textStyle(v.description, row.style.description);
@@ -11,6 +11,7 @@ type ColumnViews = {
11
11
  body: HTMLElement;
12
12
  primaryLine: HTMLElement;
13
13
  primary: HTMLElement;
14
+ leadingBadge: HTMLElement;
14
15
  titleIcons: HTMLElement;
15
16
  badges: HTMLElement;
16
17
  secondaryLine: HTMLElement;
@@ -43,6 +44,22 @@ function bind(body: HTMLElement, row: DataRow, primitives: RowPrimitives) {
43
44
  body.removeAttribute('data-nl-container-background');
44
45
  body.removeAttribute('data-nl-container-border');
45
46
  const style = row.style;
47
+ const isTokenTable =
48
+ row.index === undefined &&
49
+ !row.favorite &&
50
+ !row.checkbox &&
51
+ row.columns.length === 4 &&
52
+ row.columns[0]?.key === 'asset' &&
53
+ row.columns[1]?.key === 'balance' &&
54
+ row.columns[2]?.key === 'price' &&
55
+ row.columns[3]?.key === 'swapSpacer';
56
+ if (isTokenTable) {
57
+ // Match the legacy four equal columns, including the icon in the first.
58
+ body.style.display = 'grid';
59
+ body.style.gridTemplateColumns = 'repeat(4, minmax(0, 1fr))';
60
+ body.style.gap = '0';
61
+ }
62
+
46
63
  if (style?.horizontalPadding !== undefined)
47
64
  body.style.paddingInline = `${style.horizontalPadding}px`;
48
65
  if (style?.verticalPadding !== undefined)
@@ -80,6 +97,9 @@ function bind(body: HTMLElement, row: DataRow, primitives: RowPrimitives) {
80
97
  style?.image?.height ?? 40,
81
98
  (style?.leadingGap ?? 12) - 12
82
99
  );
100
+ if (v.visual) v.visual.style.gridArea = isTokenTable ? '1 / 1' : '';
101
+ v.trailing.style.gridArea = isTokenTable ? '1 / 4' : '';
102
+ v.trailing.style.justifySelf = isTokenTable ? 'end' : '';
83
103
  v.columns.forEach((cell, index) => {
84
104
  const column = row.columns[index];
85
105
  cell.body.hidden = !column;
@@ -92,6 +112,15 @@ function bind(body: HTMLElement, row: DataRow, primitives: RowPrimitives) {
92
112
  cell.body.hidden = false;
93
113
  cell.body.style.flex = String(column.weight ?? 1);
94
114
  cell.body.style.display = 'flex';
115
+ if (isTokenTable) {
116
+ cell.body.style.gridArea = `1 / ${index + 1}`;
117
+ if (index === 0 && v.visual) {
118
+ cell.body.style.marginInlineStart = `${
119
+ (style?.image?.width ?? 40) + (style?.leadingGap ?? 12)
120
+ }px`;
121
+ }
122
+ }
123
+
95
124
  cell.body.dataset.align = column.alignment ?? 'start';
96
125
  if (style?.lineGap !== undefined)
97
126
  cell.body.style.rowGap = `${style.lineGap}px`;
@@ -109,6 +138,45 @@ function bind(body: HTMLElement, row: DataRow, primitives: RowPrimitives) {
109
138
  fontWeight(style?.columns?.fontWeight, 500)
110
139
  );
111
140
  if (style?.columns) primitives.textStyle(cell.primary, style.columns);
141
+ const leadingBadge = column.webLeadingBadge;
142
+ cell.leadingBadge.hidden = !leadingBadge;
143
+ cell.leadingBadge.style.cssText = '';
144
+ cell.leadingBadge.textContent = leadingBadge?.text ?? '';
145
+ if (leadingBadge) {
146
+ // The line spans the column so the badge cap is a share of the column
147
+ // rather than of the line's own content; justifyContent then carries
148
+ // the column alignment the shrink-to-fit line got from its cell.
149
+ cell.primaryLine.style.alignSelf = 'stretch';
150
+ cell.primaryLine.style.justifyContent =
151
+ column.alignment === 'end'
152
+ ? 'flex-end'
153
+ : column.alignment === 'center'
154
+ ? 'center'
155
+ : 'flex-start';
156
+ cell.primaryLine.style.gap = '8px';
157
+ // A long label truncates at half the column; the primary text keeps the
158
+ // rest and truncates after it, so neither can leave the column.
159
+ cell.leadingBadge.style.display = 'block';
160
+ cell.leadingBadge.style.boxSizing = 'border-box';
161
+ cell.leadingBadge.style.flexShrink = '0';
162
+ cell.leadingBadge.style.maxWidth = '50%';
163
+ cell.leadingBadge.style.overflow = 'hidden';
164
+ cell.leadingBadge.style.textOverflow = 'ellipsis';
165
+ cell.leadingBadge.style.whiteSpace = 'nowrap';
166
+ cell.leadingBadge.style.padding = '2px 6px';
167
+ cell.leadingBadge.style.borderRadius = '4px';
168
+ cell.leadingBadge.style.fontSize = '12px';
169
+ cell.leadingBadge.style.lineHeight = '16px';
170
+ cell.leadingBadge.style.fontWeight = '400';
171
+ cell.leadingBadge.style.fontFamily = 'var(--nl-font-regular)';
172
+ cell.leadingBadge.style.color = leadingBadge.textColor;
173
+ cell.leadingBadge.style.backgroundColor = leadingBadge.backgroundColor;
174
+ cell.leadingBadge.style.pointerEvents = 'none';
175
+ cell.primary.style.minWidth = '0';
176
+ cell.primary.style.overflow = 'hidden';
177
+ cell.primary.style.textOverflow = 'ellipsis';
178
+ cell.primary.style.whiteSpace = 'nowrap';
179
+ }
112
180
  cell.titleIcons.replaceChildren();
113
181
  if (column.titleIcon || column.secondaryTitleIcon) {
114
182
  cell.primary.style.minWidth = '0';
@@ -210,10 +278,16 @@ function create(document: Document, row: DataRow, primitives: RowPrimitives) {
210
278
  'ok-native-list-data-primary'
211
279
  );
212
280
  const primary = tagSlot(createElement(document, 'span'), 'columns');
281
+ const leadingBadge = createElement(
282
+ document,
283
+ 'span',
284
+ 'ok-native-list-data-leading-badge'
285
+ );
286
+ leadingBadge.hidden = true;
213
287
  const titleIcons = createElement(document, 'span');
214
288
  titleIcons.style.display = 'contents';
215
289
  const badges = createElement(document, 'span');
216
- primaryLine.append(primary, titleIcons, badges);
290
+ primaryLine.append(leadingBadge, primary, titleIcons, badges);
217
291
  const secondaryLine = createElement(
218
292
  document,
219
293
  'span',
@@ -232,6 +306,7 @@ function create(document: Document, row: DataRow, primitives: RowPrimitives) {
232
306
  body: cell,
233
307
  primaryLine,
234
308
  primary,
309
+ leadingBadge,
235
310
  titleIcons,
236
311
  badges,
237
312
  secondaryLine,
@@ -505,10 +505,10 @@ function applyIdentityStyle(body: HTMLElement, row: IdentityRow) {
505
505
  }
506
506
  if (box.trailingGap !== undefined) {
507
507
  const gap = String(box.trailingGap) + 'px';
508
+ // The accessory row only. A value pair is one accessory whose two lines
509
+ // are a flex column, so a gap there would push the lines apart.
508
510
  body
509
- .querySelectorAll<HTMLElement>(
510
- '.ok-native-list-accessories, .ok-native-list-amounts'
511
- )
511
+ .querySelectorAll<HTMLElement>('.ok-native-list-accessories')
512
512
  .forEach((trailing) => {
513
513
  trailing.style.gap = gap;
514
514
  });
@@ -1,4 +1,3 @@
1
- import { createNamedIcon } from '@onekeyfe/react-native-image/icon/dom';
2
1
  import type { MediaTileRow, NativeListTextStyle } from '../../models';
3
2
  import type { RowPrimitives } from './RowVisual';
4
3
 
@@ -192,6 +191,78 @@ type GalleryViews = {
192
191
  leave: () => void;
193
192
  };
194
193
  const galleries = new WeakMap<HTMLElement, GalleryViews>();
194
+ type MediaPlaceholderState = 'loading' | 'failed';
195
+ type MediaPlaceholderPhase = MediaPlaceholderState | 'loaded';
196
+ const SVG_NS = 'http://www.w3.org/2000/svg';
197
+ let glyphMaskId = 0;
198
+
199
+ /**
200
+ * Placeholder glyphs share one 24pt geometry with the iOS and Android renderers:
201
+ * a rounded frame with a sun and a ridge; the failed glyph adds a slash and cuts
202
+ * a gap into the frame around it.
203
+ */
204
+ function createMediaGlyph(document: Document, state: MediaPlaceholderState) {
205
+ const svg = document.createElementNS(SVG_NS, 'svg');
206
+ svg.setAttribute('viewBox', '0 0 24 24');
207
+ svg.setAttribute('fill', 'none');
208
+ svg.setAttribute('stroke', 'currentColor');
209
+ svg.setAttribute('stroke-width', '1.5');
210
+ svg.setAttribute('stroke-linecap', 'round');
211
+ svg.setAttribute('stroke-linejoin', 'round');
212
+ svg.setAttribute('aria-hidden', 'true');
213
+ const shape = (tag: string, attributes: Record<string, string>) => {
214
+ const node = document.createElementNS(SVG_NS, tag);
215
+ Object.entries(attributes).forEach(([key, value]) =>
216
+ node.setAttribute(key, value)
217
+ );
218
+ return node;
219
+ };
220
+ const picture = shape('g', {});
221
+ picture.append(
222
+ shape('rect', { x: '3', y: '3', width: '18', height: '18', rx: '4' }),
223
+ shape('circle', { cx: '9', cy: '9', r: '1.6' }),
224
+ shape('path', { d: 'M5 20.5L14.5 11L21 17.5' })
225
+ );
226
+ if (state === 'failed') {
227
+ glyphMaskId += 1;
228
+ const id = `ok-native-list-media-cut-${glyphMaskId}`;
229
+ const mask = shape('mask', { id, maskUnits: 'userSpaceOnUse' });
230
+ mask.append(
231
+ shape('rect', {
232
+ x: '0',
233
+ y: '0',
234
+ width: '24',
235
+ height: '24',
236
+ fill: '#fff',
237
+ stroke: 'none',
238
+ }),
239
+ shape('path', {
240
+ d: 'M2.6 -0.6L24.6 21.4L21.4 24.6L-0.6 2.6Z',
241
+ fill: '#000',
242
+ stroke: 'none',
243
+ })
244
+ );
245
+ picture.setAttribute('mask', `url(#${id})`);
246
+ svg.append(mask, picture, shape('path', { d: 'M3 3L21 21' }));
247
+ } else svg.append(picture);
248
+ const wrap = document.createElement('div');
249
+ wrap.className = 'ok-native-list-media-glyph';
250
+ wrap.dataset.glyph = state;
251
+ wrap.append(svg);
252
+ return wrap;
253
+ }
254
+
255
+ const SWEEP_PERIOD_MS = 1600;
256
+
257
+ function setPlaceholderState(v: GalleryViews, state: MediaPlaceholderPhase) {
258
+ v.fallback.dataset.state = state;
259
+ if (state === 'loading')
260
+ // Keep every loading tile on one sweep phase, including recycled rows.
261
+ v.fallback.style.setProperty(
262
+ '--nl-media-sweep-delay',
263
+ `-${Math.round(performance.now() % SWEEP_PERIOD_MS)}ms`
264
+ );
265
+ }
195
266
  const isGalleryMedia = (row: MediaTileRow) =>
196
267
  row.variant === 'gallery' && (!row.image || (!!row.media && !row.imageState));
197
268
 
@@ -221,18 +292,12 @@ function initGallery(body: HTMLElement, primitives: RowPrimitives) {
221
292
  };
222
293
  const frame = element('ok-native-list-media-image');
223
294
  const fallback = element('ok-native-list-media-fallback');
224
- const svg = createNamedIcon(document, 'ImageSquareWavesOutline');
225
- fallback.append(svg);
226
- Object.assign(fallback.style, {
227
- position: 'absolute',
228
- inset: '0',
229
- display: 'flex',
230
- alignItems: 'center',
231
- justifyContent: 'center',
232
- color: 'var(--nl-disabled)',
233
- borderRadius: '10px',
234
- background: 'var(--nl-strong)',
235
- });
295
+ fallback.append(
296
+ element('ok-native-list-media-hatch'),
297
+ element('ok-native-list-media-sheen'),
298
+ createMediaGlyph(document, 'loading'),
299
+ createMediaGlyph(document, 'failed')
300
+ );
236
301
  const metadata = element('ok-native-list-media-meta');
237
302
  const subtitleLine = element('ok-native-list-media-subtitle-row');
238
303
  const subtitle = element('ok-native-list-media-subtitle');
@@ -320,10 +385,17 @@ function bindGallery(
320
385
  v.fallback.style.visibility = 'visible';
321
386
  const epoch = v.epoch;
322
387
  const source = row.imageState ? undefined : row.media?.source;
388
+ setPlaceholderState(
389
+ v,
390
+ source?.uri && row.media?.probeOrder.length ? 'loading' : 'failed'
391
+ );
323
392
  const probe = (attempt: number) => {
324
393
  if (v.epoch !== epoch) return;
325
394
  const kind = row.media?.probeOrder[attempt];
326
- if (!source?.uri || !kind) return;
395
+ if (!source?.uri || !kind) {
396
+ setPlaceholderState(v, 'failed');
397
+ return;
398
+ }
327
399
  const media = body.ownerDocument.createElement(
328
400
  kind === 'video' ? 'video' : 'img'
329
401
  );
@@ -369,8 +441,11 @@ function bindGallery(
369
441
  probe(attempt + 1);
370
442
  };
371
443
  const ready = () => {
372
- if (v.epoch === epoch && v.media === media)
444
+ if (v.epoch === epoch && v.media === media) {
373
445
  v.fallback.style.visibility = 'hidden';
446
+ // Stops the sweep animation behind the picture.
447
+ setPlaceholderState(v, 'loaded');
448
+ }
374
449
  };
375
450
  if (media.tagName === 'VIDEO') media.onloadeddata = ready;
376
451
  else media.onload = ready;