@onekeyfe/react-native-native-list 6.7.0-alpha.475 → 6.8.0-2

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 (50) 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/NativeListIdentityRenderer.kt +3 -87
  4. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPlaceholderView.kt +244 -0
  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/NativeListPrimitives.kt +3 -6
  8. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +5 -1
  9. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +75 -0
  10. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +25 -19
  11. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListDescriptionTouchPolicyTest.kt +153 -0
  12. package/docs/ROW_TEMPLATES.md +9 -11
  13. package/docs/SPEC.md +188 -108
  14. package/docs/STYLE_SPEC.md +7 -0
  15. package/ios/NativeListActivityDetailsView.swift +13 -5
  16. package/ios/NativeListIdentityRenderer.swift +6 -94
  17. package/ios/NativeListMediaPlaceholderView.swift +189 -0
  18. package/ios/NativeListMediaTileRenderer.swift +13 -13
  19. package/ios/NativeListResolvedText.swift +15 -4
  20. package/ios/NativeListTextLabel.swift +106 -0
  21. package/ios/RNCNativeListView.swift +50 -7
  22. package/ios/tests/NativeListActivityPresentationTests.swift +270 -0
  23. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +0 -95
  24. package/ios/tests/NativeListLifecycleTests.swift +176 -16
  25. package/ios/tests/NativeListMediaVisibilityTests.swift +16 -7
  26. package/lib/module/NativeList.js +17 -4
  27. package/lib/module/NativeList.web.js +3 -1
  28. package/lib/module/models.js +0 -2
  29. package/lib/module/validation.js +23 -72
  30. package/lib/module/web/NativeListWebEngine.js +13 -11
  31. package/lib/module/web/templates/ActivityRowRenderer.js +29 -23
  32. package/lib/module/web/templates/DataRowRenderer.js +16 -0
  33. package/lib/module/web/templates/IdentityRowRenderer.js +3 -92
  34. package/lib/module/web/templates/MediaTileRowRenderer.js +84 -15
  35. package/lib/typescript/src/models.d.ts +10 -22
  36. package/package.json +1 -1
  37. package/src/NativeList.tsx +25 -4
  38. package/src/NativeList.web.tsx +1 -1
  39. package/src/models.ts +9 -23
  40. package/src/validation.ts +35 -120
  41. package/src/web/NativeListWebEngine.ts +16 -11
  42. package/src/web/templates/ActivityRowRenderer.ts +42 -32
  43. package/src/web/templates/DataRowRenderer.ts +28 -0
  44. package/src/web/templates/IdentityRowRenderer.ts +3 -141
  45. package/src/web/templates/MediaTileRowRenderer.ts +90 -15
  46. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +0 -49
  47. package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +0 -105
  48. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +0 -80
  49. package/ios/NativeListTitleSegmentLayout.swift +0 -45
  50. package/ios/NativeListTitleSegmentsLabel.swift +0 -80
@@ -418,6 +418,15 @@ function effectiveRows(snapshot: NativeListSnapshot): readonly RowModel[] {
418
418
  return snapshot.emptyState ? [snapshot.emptyState] : [];
419
419
  }
420
420
 
421
+ function isDarkBackground(color: string | undefined) {
422
+ const rgb = color ? /^#([0-9a-f]{6})/i.exec(color)?.[1] : undefined;
423
+ if (!rgb) return false;
424
+ const red = Number.parseInt(rgb.slice(0, 2), 16);
425
+ const green = Number.parseInt(rgb.slice(2, 4), 16);
426
+ const blue = Number.parseInt(rgb.slice(4, 6), 16);
427
+ return red * 299 + green * 587 + blue * 114 < 128_000;
428
+ }
429
+
421
430
  function resolvedTheme(snapshot: NativeListSnapshot): NativeListTheme {
422
431
  return { ...defaultTheme, ...snapshot.theme };
423
432
  }
@@ -843,7 +852,7 @@ export const WEB_LIST_CSS = `
843
852
  .ok-native-list-trailing-button{appearance:none;box-sizing:border-box;flex:0 0 auto;padding:4px 10px;border:1px solid transparent;border-radius:9999px;background:var(--nl-button-bg,var(--nl-strong));color:var(--nl-button-text,var(--nl-primary));font:500 14px/20px var(--nl-font-medium);white-space:nowrap;cursor:default}.ok-native-list-trailing-button:hover:not(:disabled){background:var(--nl-button-hover,var(--nl-strong))}.ok-native-list-trailing-button:active:not(:disabled){background:var(--nl-button-pressed,var(--nl-pressed))}.ok-native-list-trailing-button:focus-visible{outline:2px solid var(--nl-button-focus,var(--nl-accent))}.ok-native-list-trailing-button:disabled{opacity:.4;cursor:default}
844
853
  .ok-native-list-icon-button.ok-native-list-tertiary-icon{box-sizing:border-box;flex:0 0 38px;width:38px;height:38px;margin:-7px;padding:6px;border:1px solid transparent;border-radius:9999px;color:var(--nl-icon-subdued);background:transparent}.ok-native-list-icon-button.ok-native-list-tertiary-icon:hover:not(:disabled){background:var(--nl-hover)}.ok-native-list-icon-button.ok-native-list-tertiary-icon:active:not(:disabled){background:var(--nl-pressed)}.ok-native-list-icon-button.ok-native-list-tertiary-icon:disabled{opacity:.4;cursor:default}
845
854
  .ok-native-list-icon-button.ok-native-list-tertiary-icon:focus-visible:not(:disabled){outline:2px solid var(--nl-accent)}
846
- .ok-native-list-identity-title-icon{flex:0 0 20px;width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon);font-size:20px}.ok-native-list-identity-title-leading-icon{flex:0 0 16px;width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:16px}.ok-native-list-identity-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
855
+ .ok-native-list-identity-title-icon{flex:0 0 20px;width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon);font-size:20px}.ok-native-list-identity-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
847
856
  .ok-native-list-account-row .ok-native-list-visual,.ok-native-list-account-action-row .ok-native-list-visual{width:32px;height:32px;flex-basis:32px}.ok-native-list-account-row .ok-native-list-visual>img,.ok-native-list-account-row .ok-native-list-visual-main,.ok-native-list-account-action-row .ok-native-list-visual>img,.ok-native-list-account-action-row .ok-native-list-visual-main{width:32px;height:32px}.ok-native-list-account-row .ok-native-list-visual>.ok-native-list-visual-corner{width:20px;height:20px;padding:2px}.ok-native-list-account-action-row .ok-native-list-visual{border-radius:8px!important}.ok-native-list-wallet-row .ok-native-list-title{color:var(--nl-secondary);font-size:12px;line-height:16px;font-weight:400;font-family:var(--nl-font-regular)}.ok-native-list-item[data-native-list-selected="true"]>.ok-native-list-wallet-row .ok-native-list-title{color:var(--nl-primary)}.ok-native-list-account-row .ok-native-list-title{font-size:16px;line-height:20px;font-weight:400;font-family:var(--nl-font-regular)}.ok-native-list-account-row .ok-native-list-secondary{font-size:14px;line-height:20px;font-weight:400;font-family:var(--nl-font-regular)}
848
857
  .ok-native-list-flex{display:flex;flex:1;min-width:0;flex-direction:column;justify-content:center}.ok-native-list-title{font-size:15px;line-height:20px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-semibold)}.ok-native-list-secondary{font-size:13px;line-height:18px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-tertiary{color:var(--nl-secondary)}.ok-native-list-info{color:var(--nl-info)}
849
858
  .ok-native-list-identity-row .ok-native-list-title,.ok-native-list-identity-row .ok-native-list-amounts>span:first-child{font-size:16px;line-height:20px}.ok-native-list-identity-row .ok-native-list-secondary{font-size:14px;line-height:20px}
@@ -860,7 +869,7 @@ export const WEB_LIST_CSS = `
860
869
  .ok-native-list-account-action-row{justify-content:flex-start;gap:12px;padding:0 12px}.ok-native-list-account-action-row .ok-native-list-action-title{color:var(--nl-secondary);font-size:16px;line-height:24px;font-weight:400;font-family:var(--nl-font-regular)}
861
870
  .ok-native-list-system{justify-content:center;padding:8px 12px;background:var(--nl-bg);color:var(--nl-secondary);cursor:default}.ok-native-list-system[data-variant="retry"],.ok-native-list-system[data-variant="noMatch"],.ok-native-list-system[data-variant="end"]{justify-content:flex-start}.ok-native-list-system[data-variant="retry"]{cursor:pointer}
862
871
  .ok-native-list-rail{padding:4px;gap:6px;border-radius:8px}.ok-native-list-rail .ok-native-list-visual{width:20px;height:20px;flex-basis:20px}.ok-native-list-rail .ok-native-list-visual>img,.ok-native-list-rail .ok-native-list-visual-main{width:20px;height:20px}.ok-native-list-rail-title{font-size:12px;font-weight:500;white-space:nowrap;font-family:var(--nl-font-medium)}
863
- .ok-native-list-media{display:block;padding:0 5px;background:transparent;border-radius:16px}.ok-native-list-media-image{display:block;width:100%;aspect-ratio:1;border-radius:10px;background:var(--nl-strong);object-fit:cover}.ok-native-list-media-image[data-state="empty"]{background:transparent}.ok-native-list-media-image[data-state="error"]{display:flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:24px}.ok-native-list-media-meta{padding-top:7px}.ok-native-list-media-subtitle-row{display:flex;align-items:center;gap:6px}.ok-native-list-media-subtitle{flex:1;min-width:0;font-size:12px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-media-network{width:14px;height:14px;border-radius:50%}.ok-native-list-media-title{font-size:16px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-medium)}.ok-native-list-media-close{position:absolute;right:9px;top:4px;border:0;background:color-mix(in srgb,var(--nl-inverse) 72%,transparent);color:var(--nl-inverse-text);width:24px;height:24px;border-radius:50%;cursor:pointer;font:18px/20px var(--nl-font-regular)}
872
+ .ok-native-list-media{display:block;padding:0 5px;background:transparent;border-radius:16px}.ok-native-list-media-image{display:block;width:100%;aspect-ratio:1;border-radius:10px;background:var(--nl-strong);object-fit:cover}.ok-native-list-media-image[data-state="empty"]{background:transparent}.ok-native-list-media-image[data-state="error"]{display:flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:24px}.ok-native-list-media-meta{padding-top:7px}.ok-native-list-media-subtitle-row{display:flex;align-items:center;gap:6px}.ok-native-list-media-subtitle{flex:1;min-width:0;font-size:12px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-media-network{width:14px;height:14px;border-radius:50%}.ok-native-list-media-title{font-size:16px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-medium)}.ok-native-list-media-fallback{position:absolute;inset:0;overflow:hidden;border-radius:10px;background:var(--nl-strong);color:color-mix(in srgb,var(--nl-disabled) 70%,transparent)}.ok-native-list-media-fallback::after{content:"";position:absolute;inset:0;border-radius:inherit;box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--nl-separator) 60%,transparent);pointer-events:none}.ok-native-list-media-sheen,.ok-native-list-media-hatch,.ok-native-list-media-glyph{position:absolute;inset:0;pointer-events:none}.ok-native-list-media-glyph{display:none;align-items:center;justify-content:center}.ok-native-list-media-glyph svg{width:28%;max-width:44px;height:auto}.ok-native-list-media-fallback[data-state="loading"] .ok-native-list-media-glyph[data-glyph="loading"],.ok-native-list-media-fallback[data-state="failed"] .ok-native-list-media-glyph[data-glyph="failed"]{display:flex}.ok-native-list-media-sheen{display:none;overflow:hidden}.ok-native-list-media-fallback[data-state="loading"] .ok-native-list-media-sheen{display:block}.ok-native-list-media-sheen::before{content:"";position:absolute;top:-50%;bottom:-50%;left:0;width:60%;background:linear-gradient(100deg,transparent 0%,var(--nl-media-shine,rgba(255,255,255,.75)) 50%,transparent 100%);transform:translateX(-135%) skewX(-12deg);animation:ok-native-list-media-sweep 1.6s cubic-bezier(.4,0,.2,1) infinite;animation-delay:var(--nl-media-sweep-delay,0s)}@keyframes ok-native-list-media-sweep{0%{transform:translateX(-135%) skewX(-12deg)}70%,100%{transform:translateX(220%) skewX(-12deg)}}.ok-native-list-media-hatch{display:none;background-image:repeating-linear-gradient(135deg,color-mix(in srgb,var(--nl-primary) 4.5%,transparent) 0 1px,transparent 1px 7px);-webkit-mask-image:radial-gradient(circle at 50% 50%,transparent 0 22%,#000 70%);mask-image:radial-gradient(circle at 50% 50%,transparent 0 22%,#000 70%)}.ok-native-list-media-fallback[data-state="failed"] .ok-native-list-media-hatch{display:block}@media(prefers-reduced-motion:reduce){.ok-native-list-media-sheen::before{animation:none;transform:translateX(60%) skewX(-12deg);opacity:.6}}.ok-native-list-media-close{position:absolute;right:9px;top:4px;border:0;background:color-mix(in srgb,var(--nl-inverse) 72%,transparent);color:var(--nl-inverse-text);width:24px;height:24px;border-radius:50%;cursor:pointer;font:18px/20px var(--nl-font-regular)}
864
873
  .ok-native-list-metric{display:flex;flex-direction:column;align-items:flex-start;padding:12px;border-radius:12px;gap:5px;background:var(--nl-row)}.ok-native-list-metric-value{font-size:22px;line-height:28px;font-weight:700;font-family:var(--nl-font-bold)}.ok-native-list-composite{display:flex;flex-direction:column;align-items:stretch;padding:14px;border-radius:12px;gap:12px;background:var(--nl-subdued)}.ok-native-list-composite-heading{font-size:14px;letter-spacing:1px;color:var(--nl-secondary)}.ok-native-list-composite-row{display:flex;gap:12px}.ok-native-list-composite-cell{flex:1;min-width:0}.ok-native-list-composite-cell[data-shaded="true"]{padding:10px;border-radius:10px;background:color-mix(in srgb,var(--nl-primary) 5%,transparent)}.ok-native-list-composite-value{font-size:18px;font-weight:600;font-family:var(--nl-font-semibold)}.ok-native-list-divider{height:1px;background:var(--nl-separator)}.ok-native-list-progress{height:4px;border-radius:2px;overflow:hidden;background:var(--nl-negative)}.ok-native-list-progress>span{display:block;height:100%;border-radius:2px;background:var(--nl-positive)}
865
874
  .ok-native-list-data{padding:6px 12px}.ok-native-list-index{flex:0 0 28px;color:var(--nl-secondary);font-size:13px}.ok-native-list-favorite{flex:0 0 24px;color:var(--nl-icon-subdued);font-size:22px}.ok-native-list-favorite[data-active="true"]{color:var(--nl-accent)}.ok-native-list-data-cell{display:flex;flex-direction:column;min-width:0}.ok-native-list-data-cell[data-align="center"]{align-items:center}.ok-native-list-data-cell[data-align="end"]{align-items:flex-end}.ok-native-list-data-primary{display:flex;align-items:center;gap:5px;max-width:100%;font-size:16px;font-weight:500;white-space:nowrap;font-family:var(--nl-font-medium)}.ok-native-list-unread{width:7px;height:7px;flex:0 0 7px;border-radius:50%;background:var(--nl-accent)}.ok-native-list-thumbnail{width:64px;height:64px;border-radius:10px;object-fit:cover}
866
875
  .ok-native-list-item[data-native-list-row-press-enabled="true"]:active>.ok-native-list-history{background:var(--nl-selected)}
@@ -1311,15 +1320,8 @@ function createVisual(
1311
1320
  'span',
1312
1321
  'ok-native-list-image-skeleton'
1313
1322
  );
1314
- const background = resolvedTheme(context.snapshot).background;
1315
- const rgb = /^#([0-9a-f]{6})/i.exec(background)?.[1];
1316
- if (rgb) {
1317
- const red = Number.parseInt(rgb.slice(0, 2), 16);
1318
- const green = Number.parseInt(rgb.slice(2, 4), 16);
1319
- const blue = Number.parseInt(rgb.slice(4, 6), 16);
1320
- if (red * 299 + green * 587 + blue * 114 < 128_000)
1321
- skeleton.dataset.dark = 'true';
1322
- }
1323
+ if (isDarkBackground(resolvedTheme(context.snapshot).background))
1324
+ skeleton.dataset.dark = 'true';
1323
1325
  frame.appendChild(skeleton);
1324
1326
  image.addEventListener('load', () => skeleton.remove(), { once: true });
1325
1327
  image.addEventListener('error', () => skeleton.remove(), { once: true });
@@ -3165,6 +3167,9 @@ export class NativeListWebEngine {
3165
3167
  '--nl-inverse': theme.inverseBackground,
3166
3168
  '--nl-inverse-text': theme.inverseText,
3167
3169
  '--nl-info': theme.info,
3170
+ '--nl-media-shine': isDarkBackground(theme.background)
3171
+ ? 'rgba(255,255,255,0.07)'
3172
+ : 'rgba(255,255,255,0.75)',
3168
3173
  };
3169
3174
  Object.entries(values).forEach(([name, value]) => {
3170
3175
  if (!value) return;
@@ -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);
@@ -43,6 +43,22 @@ function bind(body: HTMLElement, row: DataRow, primitives: RowPrimitives) {
43
43
  body.removeAttribute('data-nl-container-background');
44
44
  body.removeAttribute('data-nl-container-border');
45
45
  const style = row.style;
46
+ const isTokenTable =
47
+ row.index === undefined &&
48
+ !row.favorite &&
49
+ !row.checkbox &&
50
+ row.columns.length === 4 &&
51
+ row.columns[0]?.key === 'asset' &&
52
+ row.columns[1]?.key === 'balance' &&
53
+ row.columns[2]?.key === 'price' &&
54
+ row.columns[3]?.key === 'swapSpacer';
55
+ if (isTokenTable) {
56
+ // Match the legacy four equal columns, including the icon in the first.
57
+ body.style.display = 'grid';
58
+ body.style.gridTemplateColumns = 'repeat(4, minmax(0, 1fr))';
59
+ body.style.gap = '0';
60
+ }
61
+
46
62
  if (style?.horizontalPadding !== undefined)
47
63
  body.style.paddingInline = `${style.horizontalPadding}px`;
48
64
  if (style?.verticalPadding !== undefined)
@@ -80,6 +96,9 @@ function bind(body: HTMLElement, row: DataRow, primitives: RowPrimitives) {
80
96
  style?.image?.height ?? 40,
81
97
  (style?.leadingGap ?? 12) - 12
82
98
  );
99
+ if (v.visual) v.visual.style.gridArea = isTokenTable ? '1 / 1' : '';
100
+ v.trailing.style.gridArea = isTokenTable ? '1 / 4' : '';
101
+ v.trailing.style.justifySelf = isTokenTable ? 'end' : '';
83
102
  v.columns.forEach((cell, index) => {
84
103
  const column = row.columns[index];
85
104
  cell.body.hidden = !column;
@@ -92,6 +111,15 @@ function bind(body: HTMLElement, row: DataRow, primitives: RowPrimitives) {
92
111
  cell.body.hidden = false;
93
112
  cell.body.style.flex = String(column.weight ?? 1);
94
113
  cell.body.style.display = 'flex';
114
+ if (isTokenTable) {
115
+ cell.body.style.gridArea = `1 / ${index + 1}`;
116
+ if (index === 0 && v.visual) {
117
+ cell.body.style.marginInlineStart = `${
118
+ (style?.image?.width ?? 40) + (style?.leadingGap ?? 12)
119
+ }px`;
120
+ }
121
+ }
122
+
95
123
  cell.body.dataset.align = column.alignment ?? 'start';
96
124
  if (style?.lineGap !== undefined)
97
125
  cell.body.style.rowGap = `${style.lineGap}px`;
@@ -30,79 +30,6 @@ 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
- segment.text
67
- );
68
- // Only the shrinking run gives up width; a cap is a share of the line.
69
- Object.assign(run.style, {
70
- flex: segment.shrink ? '0 1 auto' : '0 0 auto',
71
- minWidth: segment.shrink ? '0' : '',
72
- maxWidth:
73
- segment.maxWidthRatio === undefined
74
- ? ''
75
- : `${segment.maxWidthRatio * 100}%`,
76
- overflow: 'hidden',
77
- textOverflow: 'ellipsis',
78
- whiteSpace: 'pre',
79
- });
80
- if (segment.tone)
81
- run.style.color =
82
- segment.tone === 'secondary'
83
- ? 'var(--nl-secondary)'
84
- : 'var(--nl-primary)';
85
- if (segment.fontWeight === 'medium') {
86
- run.style.fontWeight = '500';
87
- run.style.fontFamily = 'var(--nl-font-medium)';
88
- } else if (segment.fontWeight === 'regular') {
89
- run.style.fontWeight = '400';
90
- run.style.fontFamily = 'var(--nl-font-regular)';
91
- }
92
- setData(run, 'tone', segment.tone);
93
- runs.appendChild(run);
94
- });
95
- const spoken = createElement(
96
- document,
97
- 'span',
98
- 'ok-native-list-identity-title-spoken',
99
- row.title
100
- );
101
- Object.assign(spoken.style, VISUALLY_HIDDEN);
102
- target.replaceChildren(runs, spoken);
103
- target.style.display = 'flex';
104
- target.style.minWidth = '0';
105
- }
106
33
  function appendAccessories(
107
34
  parent: HTMLElement,
108
35
  document: Document,
@@ -268,18 +195,6 @@ function createIdentityRow(
268
195
  fragment.appendChild(document.createTextNode(row.title.slice(offset)));
269
196
  textTarget.prepend(fragment);
270
197
  }
271
- // The runs replace the plain title, except where `title` itself is
272
- // highlighted or shown in the wallet sidebar.
273
- const hasTitleRuns =
274
- !!row.titleSegments?.length &&
275
- presentation !== 'walletSidebar' &&
276
- !row.titleMatch?.length;
277
- if (hasTitleRuns) {
278
- const textTarget =
279
- titleElement.querySelector<HTMLElement>('[data-nl-slot="title"]') ??
280
- titleElement;
281
- appendTitleRuns(document, textTarget, row);
282
- }
283
198
  if (row.subtitleSegments?.length) {
284
199
  column.querySelector('.ok-native-list-secondary')?.remove();
285
200
  const segments = createElement(
@@ -476,58 +391,6 @@ function createIdentityRow(
476
391
  badges.style.minWidth = '0';
477
392
  }
478
393
  }
479
- if (hasTitleRuns) {
480
- // The runs fill what the title line leaves, so a ratio is a share of
481
- // that width and title accessories sit at the line's end.
482
- const runs = titleElement.querySelector<HTMLElement>(
483
- '.ok-native-list-identity-title-runs'
484
- );
485
- for (
486
- let node = runs?.parentElement;
487
- node && node !== titleElement;
488
- node = node.parentElement
489
- ) {
490
- node.style.display = 'flex';
491
- node.style.flex = '1 1 auto';
492
- node.style.minWidth = '0';
493
- }
494
- titleElement.style.display = 'flex';
495
- titleElement.style.alignItems = 'center';
496
- }
497
- if (row.titleLeadingIcon && presentation !== 'walletSidebar') {
498
- const descriptor = row.titleLeadingIcon;
499
- if (titleElement.hasAttribute('data-nl-slot')) {
500
- // Keep the glyph out of the title slot that text styles apply to.
501
- const titleText = tagSlot(
502
- createElement(document, 'span', 'ok-native-list-identity-title-text'),
503
- 'title'
504
- );
505
- while (titleElement.firstChild)
506
- titleText.appendChild(titleElement.firstChild);
507
- if (hasTitleRuns) {
508
- titleText.style.display = 'flex';
509
- titleText.style.minWidth = '0';
510
- }
511
- titleElement.removeAttribute('data-nl-slot');
512
- titleElement.appendChild(titleText);
513
- }
514
- const icon = primitives.iconAction(
515
- descriptor.name,
516
- undefined,
517
- undefined,
518
- descriptor.tintColor
519
- );
520
- icon.className = 'ok-native-list-identity-title-leading-icon';
521
- if (descriptor.accessibilityLabel)
522
- icon.setAttribute('aria-label', descriptor.accessibilityLabel);
523
- else icon.setAttribute('aria-hidden', 'true');
524
- titleElement.style.display = 'flex';
525
- titleElement.style.alignItems = 'center';
526
- // 6px to the title, whatever gap the title line already has.
527
- const lineGap = Number.parseFloat(titleElement.style.gap || '0') || 0;
528
- icon.style.marginInlineEnd = `${Math.max(0, 6 - lineGap)}px`;
529
- titleElement.prepend(icon);
530
- }
531
394
  if (presentation === 'walletSidebar' && row.badges?.length) {
532
395
  const badges = createElement(
533
396
  document,
@@ -540,7 +403,6 @@ function createIdentityRow(
540
403
  column.appendChild(badges);
541
404
  }
542
405
  for (const key of ['title', 'subtitle'] as const) {
543
- if (key === 'title' && hasTitleRuns) continue;
544
406
  const lines = row.style?.[key]?.lines ?? row[`${key}Lines`];
545
407
  if (lines !== undefined)
546
408
  column
@@ -643,10 +505,10 @@ function applyIdentityStyle(body: HTMLElement, row: IdentityRow) {
643
505
  }
644
506
  if (box.trailingGap !== undefined) {
645
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.
646
510
  body
647
- .querySelectorAll<HTMLElement>(
648
- '.ok-native-list-accessories, .ok-native-list-amounts'
649
- )
511
+ .querySelectorAll<HTMLElement>('.ok-native-list-accessories')
650
512
  .forEach((trailing) => {
651
513
  trailing.style.gap = gap;
652
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;
@@ -1,49 +0,0 @@
1
- package com.margelo.nitro.nativelist
2
-
3
- /**
4
- * Widths for identity title runs (docs/SPEC.md, "Identity title segments and
5
- * leading title icon"). A run's base width is its natural width under its cap;
6
- * the one shrinking run takes what the others leave; runs that do not shrink
7
- * and still overflow are cut from the end of the line.
8
- */
9
- internal fun nativeListTitleSegmentWidths(
10
- natural: List<Float>,
11
- shrink: List<Boolean>,
12
- maxWidthRatio: List<Float?>,
13
- available: Float,
14
- ): List<Float> {
15
- val line = available.coerceAtLeast(0f)
16
- val widths =
17
- natural.indices
18
- .map { index ->
19
- val width = natural[index].coerceAtLeast(0f)
20
- val ratio = maxWidthRatio.getOrNull(index)
21
- if (ratio == null) width else minOf(width, ratio * line)
22
- }
23
- .toMutableList()
24
- val shrinking = shrink.indexOf(true)
25
- if (shrinking in widths.indices) {
26
- val others = widths.indices.filter { it != shrinking }.sumOf { widths[it].toDouble() }.toFloat()
27
- widths[shrinking] = minOf(widths[shrinking], line - others).coerceAtLeast(0f)
28
- }
29
- var overflow = widths.sum() - line
30
- var index = widths.lastIndex
31
- while (overflow > 0f && index >= 0) {
32
- val cut = minOf(widths[index], overflow)
33
- widths[index] -= cut
34
- overflow -= cut
35
- index -= 1
36
- }
37
- return widths
38
- }
39
-
40
- /** Wallet sidebar rows keep the plain title: no runs and no leading glyph (docs/SPEC.md). */
41
- internal fun nativeListAllowsTitleDecorations(presentation: String): Boolean =
42
- presentation != "walletSidebar"
43
-
44
- /**
45
- * Whether the runs replace `title`: not where `title` itself is highlighted
46
- * (`titleMatch` indexes it), and never on a wallet sidebar row.
47
- */
48
- internal fun nativeListShowsTitleRuns(presentation: String, runCount: Int, matchCount: Int): Boolean =
49
- runCount > 0 && matchCount == 0 && nativeListAllowsTitleDecorations(presentation)