@onekeyfe/react-native-native-list 6.8.0-3 → 6.8.0-30

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 (62) hide show
  1. package/android/build.gradle +3 -0
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +18 -4
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +12 -1
  4. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +166 -36
  5. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +3 -2
  6. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +8 -1
  7. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +6 -3
  8. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +21 -4
  9. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +24 -3
  10. package/android/src/main/java/com/onekey/nativelist/NativeListRowUpdates.kt +34 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +11 -4
  12. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +71 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +126 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +84 -9
  15. package/android/src/main/res/values/native_scroll_coordinator_ids.xml +1 -0
  16. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentitySubtitleBindingTest.kt +177 -0
  17. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +2 -0
  18. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +130 -0
  19. package/docs/ROW_TEMPLATES.md +8 -1
  20. package/docs/SPEC.md +312 -5
  21. package/docs/STYLE_SPEC.md +7 -1
  22. package/ios/NativeListAccessoryStack.swift +22 -0
  23. package/ios/NativeListActivityDetailsView.swift +45 -1
  24. package/ios/NativeListDataRowRenderer.swift +12 -5
  25. package/ios/NativeListIdentityRenderer.swift +145 -66
  26. package/ios/NativeListLeadingVisual.swift +8 -0
  27. package/ios/NativeListMarketRenderer.swift +6 -2
  28. package/ios/NativeListModels.swift +7 -0
  29. package/ios/NativeListResolvedText.swift +9 -7
  30. package/ios/NativeListSectionHeaderRenderer.swift +9 -43
  31. package/ios/NativeListTextStyles.swift +72 -12
  32. package/ios/NativeListTitleSegmentLayout.swift +72 -0
  33. package/ios/NativeListTitleSegmentsLabel.swift +92 -0
  34. package/ios/RNCNativeListView.swift +203 -45
  35. package/ios/tests/NativeListActivityPresentationTests.swift +137 -0
  36. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +155 -0
  37. package/ios/tests/NativeListLifecycleTests.swift +298 -24
  38. package/ios/tests/NativeListMediaVisibilityTests.swift +2 -1
  39. package/lib/module/models.js +2 -0
  40. package/lib/module/validation.js +96 -13
  41. package/lib/module/web/NativeListWebEngine.js +427 -100
  42. package/lib/module/web/templates/ActivityRowRenderer.js +1 -1
  43. package/lib/module/web/templates/IdentityRowRenderer.js +134 -3
  44. package/lib/module/web/templates/MarketRowRenderer.js +2 -0
  45. package/lib/module/web/templates/MediaTileRowRenderer.js +1 -0
  46. package/lib/module/web/templates/RowElements.js +2 -2
  47. package/lib/module/web/templates/RowText.js +2 -0
  48. package/lib/typescript/src/models.d.ts +35 -1
  49. package/lib/typescript/src/web/NativeListWebEngine.d.ts +17 -2
  50. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +6 -2
  51. package/lib/typescript/src/web/templates/RowVisual.d.ts +1 -1
  52. package/package.json +1 -1
  53. package/src/models.ts +38 -0
  54. package/src/validation.ts +196 -6
  55. package/src/web/NativeListWebEngine.ts +671 -112
  56. package/src/web/templates/ActivityRowRenderer.ts +1 -1
  57. package/src/web/templates/IdentityRowRenderer.ts +208 -3
  58. package/src/web/templates/MarketRowRenderer.ts +2 -0
  59. package/src/web/templates/MediaTileRowRenderer.ts +1 -0
  60. package/src/web/templates/RowElements.ts +3 -2
  61. package/src/web/templates/RowText.ts +6 -0
  62. package/src/web/templates/RowVisual.ts +2 -1
@@ -598,7 +598,7 @@ function bindHistory(
598
598
  v.descriptionPrefix.style.cssText = `${ellipsis}flex-shrink:0;max-width:${
599
599
  actionText ? `calc(100% - ${descriptionActionReserve})` : '100%'
600
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:${
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;letter-spacing:inherit;display:${
602
602
  actionText ? 'block' : 'none'
603
603
  };`;
604
604
  v.descriptionAction.textContent = actionText;
@@ -1,4 +1,4 @@
1
- import { applyTextWeight } from './RowText';
1
+ import { applyTextWeight, fontWeight } from './RowText';
2
2
  import { applyTabularNumbers, hasExplicitRowHeight } from './RowElements';
3
3
  import type {
4
4
  IdentityRow,
@@ -30,6 +30,81 @@ function toneColor(
30
30
  if (tone === 'secondary') return 'var(--nl-secondary)';
31
31
  return fallback === 'secondary' ? 'var(--nl-secondary)' : 'var(--nl-primary)';
32
32
  }
33
+ // Hidden from sight, still read: the runs themselves are hidden from
34
+ // assistive technology in favor of `title`.
35
+ const VISUALLY_HIDDEN: Partial<CSSStyleDeclaration> = {
36
+ position: 'absolute',
37
+ width: '1px',
38
+ height: '1px',
39
+ overflow: 'hidden',
40
+ clip: 'rect(0 0 0 0)',
41
+ whiteSpace: 'nowrap',
42
+ };
43
+ function appendTitleRuns(
44
+ document: Document,
45
+ target: HTMLElement,
46
+ row: IdentityRow
47
+ ): void {
48
+ const runs = createElement(
49
+ document,
50
+ 'span',
51
+ 'ok-native-list-identity-title-runs'
52
+ );
53
+ runs.setAttribute('aria-hidden', 'true');
54
+ Object.assign(runs.style, {
55
+ display: 'flex',
56
+ flex: '1 1 auto',
57
+ minWidth: '0',
58
+ maxWidth: '100%',
59
+ overflow: 'hidden',
60
+ });
61
+ row.titleSegments?.forEach((segment) => {
62
+ const run = createElement(
63
+ document,
64
+ 'span',
65
+ 'ok-native-list-identity-title-run',
66
+ // A run is one line on every platform: `white-space: pre` would turn a
67
+ // hard break into a second line here.
68
+ segment.text.replace(/\r\n|[\r\n]/g, ' ')
69
+ );
70
+ // Only the shrinking run gives up width; a cap is a share of the line.
71
+ Object.assign(run.style, {
72
+ flex: segment.shrink ? '0 1 auto' : '0 0 auto',
73
+ minWidth: segment.shrink ? '0' : '',
74
+ maxWidth:
75
+ segment.maxWidthRatio === undefined
76
+ ? ''
77
+ : `${segment.maxWidthRatio * 100}%`,
78
+ overflow: 'hidden',
79
+ textOverflow: 'ellipsis',
80
+ whiteSpace: 'pre',
81
+ });
82
+ if (segment.tone)
83
+ run.style.color =
84
+ segment.tone === 'secondary'
85
+ ? 'var(--nl-secondary)'
86
+ : 'var(--nl-primary)';
87
+ if (segment.fontWeight === 'medium') {
88
+ run.style.fontWeight = '500';
89
+ run.style.fontFamily = 'var(--nl-font-medium)';
90
+ } else if (segment.fontWeight === 'regular') {
91
+ run.style.fontWeight = '400';
92
+ run.style.fontFamily = 'var(--nl-font-regular)';
93
+ }
94
+ setData(run, 'tone', segment.tone);
95
+ runs.appendChild(run);
96
+ });
97
+ const spoken = createElement(
98
+ document,
99
+ 'span',
100
+ 'ok-native-list-identity-title-spoken',
101
+ row.title
102
+ );
103
+ Object.assign(spoken.style, VISUALLY_HIDDEN);
104
+ target.replaceChildren(runs, spoken);
105
+ target.style.display = 'flex';
106
+ target.style.minWidth = '0';
107
+ }
33
108
  function appendAccessories(
34
109
  parent: HTMLElement,
35
110
  document: Document,
@@ -44,6 +119,16 @@ function appendAccessories(
44
119
  'ok-native-list-accessories'
45
120
  );
46
121
 
122
+ // ListItem's rename + drag pair sits in <XStack gap="$6">; iOS and Android
123
+ // lay the same pair out natively.
124
+ if (
125
+ accessories.length === 2 &&
126
+ accessories[0].kind === 'icon' &&
127
+ accessories[0].name === 'PencilOutline' &&
128
+ accessories[1].kind === 'drag'
129
+ )
130
+ container.style.gap = '24px';
131
+
47
132
  if (
48
133
  row &&
49
134
  hasExplicitRowHeight(row) &&
@@ -111,9 +196,21 @@ function createIdentityRow(
111
196
  row.leadingAction.name,
112
197
  row.leadingAction.actionKey,
113
198
  row.leadingAction.disabled,
114
- row.leadingAction.tintColor
199
+ row.leadingAction.tintColor,
200
+ row.leadingAction.accessibilityLabel
115
201
  );
116
202
  markActionAnchorSource(action, 'leadingAction');
203
+ // ListItem.IconButton geometry, as on iOS and Android: the medium tertiary
204
+ // frame overhangs its 24-point slot by 7 on each side.
205
+ action.classList.add('ok-native-list-tertiary-icon');
206
+ const glyph = createElement(
207
+ document,
208
+ 'span',
209
+ 'ok-native-list-action-glyph'
210
+ );
211
+ glyph.dataset.nativeListAnchorGlyph = '';
212
+ glyph.append(...action.childNodes);
213
+ action.append(glyph);
117
214
  body.appendChild(action);
118
215
  }
119
216
  const visual = primitives.visual(
@@ -195,6 +292,18 @@ function createIdentityRow(
195
292
  fragment.appendChild(document.createTextNode(row.title.slice(offset)));
196
293
  textTarget.prepend(fragment);
197
294
  }
295
+ // The runs replace the plain title, except where `title` itself is
296
+ // highlighted or shown in the wallet sidebar.
297
+ const hasTitleRuns =
298
+ !!row.titleSegments?.length &&
299
+ presentation !== 'walletSidebar' &&
300
+ !row.titleMatch?.length;
301
+ if (hasTitleRuns) {
302
+ const textTarget =
303
+ titleElement.querySelector<HTMLElement>('[data-nl-slot="title"]') ??
304
+ titleElement;
305
+ appendTitleRuns(document, textTarget, row);
306
+ }
198
307
  if (row.subtitleSegments?.length) {
199
308
  column.querySelector('.ok-native-list-secondary')?.remove();
200
309
  const segments = createElement(
@@ -391,6 +500,69 @@ function createIdentityRow(
391
500
  badges.style.minWidth = '0';
392
501
  }
393
502
  }
503
+ if (hasTitleRuns) {
504
+ // The runs fill what the title line leaves, so a ratio is a share of
505
+ // that width and title accessories sit at the line's end.
506
+ const runs = titleElement.querySelector<HTMLElement>(
507
+ '.ok-native-list-identity-title-runs'
508
+ );
509
+ for (
510
+ let node = runs?.parentElement;
511
+ node && node !== titleElement;
512
+ node = node.parentElement
513
+ ) {
514
+ node.style.display = 'flex';
515
+ node.style.flex = '1 1 auto';
516
+ node.style.minWidth = '0';
517
+ }
518
+ titleElement.style.display = 'flex';
519
+ titleElement.style.alignItems = 'center';
520
+ }
521
+ if (row.titleLeadingIcon && presentation !== 'walletSidebar') {
522
+ const descriptor = row.titleLeadingIcon;
523
+ if (titleElement.hasAttribute('data-nl-slot')) {
524
+ // Keep the glyph out of the title slot that text styles apply to.
525
+ const titleText = tagSlot(
526
+ createElement(document, 'span', 'ok-native-list-identity-title-text'),
527
+ 'title'
528
+ );
529
+ while (titleElement.firstChild)
530
+ titleText.appendChild(titleElement.firstChild);
531
+ if (hasTitleRuns) {
532
+ titleText.style.display = 'flex';
533
+ // Created after the loop above gave the runs' ancestors their share:
534
+ // without it a ratio would be a share of the text's own width.
535
+ titleText.style.flex = '1 1 auto';
536
+ titleText.style.minWidth = '0';
537
+ }
538
+ titleElement.removeAttribute('data-nl-slot');
539
+ titleElement.appendChild(titleText);
540
+ }
541
+ // A label makes the passive glyph an image with that name.
542
+ const icon = primitives.iconAction(
543
+ descriptor.name,
544
+ undefined,
545
+ undefined,
546
+ descriptor.tintColor,
547
+ descriptor.accessibilityLabel
548
+ );
549
+ icon.className = 'ok-native-list-identity-title-leading-icon';
550
+ if (!descriptor.accessibilityLabel)
551
+ icon.setAttribute('aria-hidden', 'true');
552
+ // The slot is 16px. Host artwork comes at 24px, and a name without
553
+ // artwork leaves the slot empty rather than a text glyph.
554
+ const artwork = icon.querySelector('svg');
555
+ if (artwork) {
556
+ artwork.setAttribute('width', '16');
557
+ artwork.setAttribute('height', '16');
558
+ } else icon.textContent = '';
559
+ titleElement.style.display = 'flex';
560
+ titleElement.style.alignItems = 'center';
561
+ // 6px to the title, whatever gap the title line already has.
562
+ const lineGap = Number.parseFloat(titleElement.style.gap || '0') || 0;
563
+ icon.style.marginInlineEnd = `${Math.max(0, 6 - lineGap)}px`;
564
+ titleElement.prepend(icon);
565
+ }
394
566
  if (presentation === 'walletSidebar' && row.badges?.length) {
395
567
  const badges = createElement(
396
568
  document,
@@ -403,6 +575,7 @@ function createIdentityRow(
403
575
  column.appendChild(badges);
404
576
  }
405
577
  for (const key of ['title', 'subtitle'] as const) {
578
+ if (key === 'title' && hasTitleRuns) continue;
406
579
  const lines = row.style?.[key]?.lines ?? row[`${key}Lines`];
407
580
  if (lines !== undefined)
408
581
  column
@@ -559,10 +732,42 @@ function applyIdentityStyle(body: HTMLElement, row: IdentityRow) {
559
732
  body
560
733
  .querySelectorAll<HTMLElement>('[data-nl-slot="' + key + '"]')
561
734
  .forEach((element) => {
562
- applyTextStyleToSlot(element, slotStyle);
735
+ if (
736
+ key === 'title' &&
737
+ element.querySelector('.ok-native-list-identity-title-runs')
738
+ )
739
+ applyTitleStyleToRuns(element, slotStyle);
740
+ else applyTextStyleToSlot(element, slotStyle);
563
741
  });
564
742
  });
565
743
  }
744
+ // With runs, `style.title` only sets what a run inherits: a run that names its
745
+ // tone or weight keeps it, and the runs stay on one line whatever `lines` says.
746
+ function applyTitleStyleToRuns(
747
+ slot: HTMLElement,
748
+ style: NativeListTextStyle
749
+ ): void {
750
+ if (style.fontSize !== undefined)
751
+ slot.style.fontSize = String(style.fontSize) + 'px';
752
+ if (style.lineHeight !== undefined)
753
+ slot.style.lineHeight = String(style.lineHeight) + 'px';
754
+ if (style.fontWeight !== undefined)
755
+ applyTextWeight(slot, String(fontWeight(style.fontWeight, 400)));
756
+ if (style.color !== undefined) slot.style.color = style.color;
757
+ if (style.tabularNumbers !== undefined)
758
+ slot.style.fontVariantNumeric = style.tabularNumbers
759
+ ? 'tabular-nums'
760
+ : 'proportional-nums';
761
+ if (style.letterSpacing !== undefined)
762
+ slot.style.letterSpacing = String(style.letterSpacing) + 'px';
763
+ // Paint only, as for a plain title: the line keeps its place in the layout.
764
+ if (style.offsetY !== undefined) {
765
+ const runs = slot.querySelector<HTMLElement>(
766
+ '.ok-native-list-identity-title-runs'
767
+ );
768
+ if (runs) runs.style.transform = `translateY(${style.offsetY}px)`;
769
+ }
770
+ }
566
771
  type Views = {
567
772
  visual?: {
568
773
  key: string;
@@ -66,6 +66,8 @@ function applyMarketTextStyle(
66
66
  String(fontWeight(style?.fontWeight, defaults.weight))
67
67
  );
68
68
  element.style.color = style?.color ?? '';
69
+ element.style.letterSpacing = '';
70
+ element.style.fontVariantNumeric = '';
69
71
  element.style.textAlign = style?.alignment ?? defaults.alignment;
70
72
  element.style.whiteSpace = (style?.lines ?? 1) > 1 ? 'normal' : 'nowrap';
71
73
  element.style.display = '';
@@ -460,6 +460,7 @@ function bindGallery(
460
460
  }
461
461
  v.badge.textContent = row.badge?.text ?? '';
462
462
  if (row.badge) {
463
+ v.badge.style.cssText = '';
463
464
  Object.assign(v.badge.style, {
464
465
  position: 'absolute',
465
466
  right: '0',
@@ -102,8 +102,9 @@ export function createBadge(
102
102
  // Selector digits retain their font family, including explicit button fonts.
103
103
  export function applyTabularNumbers(body: HTMLElement): void {
104
104
  body.style.fontVariantNumeric = 'tabular-nums';
105
- body.querySelectorAll<HTMLElement>('span,button').forEach((text) => {
106
- text.style.fontVariantNumeric = 'tabular-nums';
105
+ body.querySelectorAll('button').forEach((button) => {
106
+ if (!button.style.fontVariantNumeric)
107
+ button.style.fontVariantNumeric = 'inherit';
107
108
  });
108
109
  }
109
110
 
@@ -150,6 +150,12 @@ export function applyTextStyleToSlot(
150
150
  if (style.fontWeight !== undefined)
151
151
  applyTextWeight(element, String(fontWeight(style.fontWeight, 400)));
152
152
  if (style.color !== undefined) element.style.color = style.color;
153
+ if (style.tabularNumbers !== undefined)
154
+ element.style.fontVariantNumeric = style.tabularNumbers
155
+ ? 'tabular-nums'
156
+ : 'proportional-nums';
157
+ if (style.letterSpacing !== undefined)
158
+ element.style.letterSpacing = String(style.letterSpacing) + 'px';
153
159
  // Explicit overrides also apply to rich text runs, but never to sibling badges.
154
160
  // Subscript segments keep their legacy size relative to the field size.
155
161
  element.querySelectorAll<HTMLElement>('span').forEach((run) => {
@@ -13,7 +13,8 @@ export type RowPrimitives = Readonly<{
13
13
  name: string,
14
14
  actionKey: string | undefined,
15
15
  disabled?: boolean,
16
- tintColor?: string
16
+ tintColor?: string,
17
+ accessibilityLabel?: string
17
18
  ) => HTMLElement;
18
19
  accessory: (
19
20
  rowKey: string,