@onekeyfe/react-native-native-list 6.7.0-alpha.466 → 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 (42) 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 +8 -3
  12. package/docs/SPEC.md +258 -18
  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 +50 -7
  21. package/ios/tests/NativeListActivityPresentationTests.swift +270 -0
  22. package/ios/tests/NativeListLifecycleTests.swift +176 -16
  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 +19 -2
  27. package/lib/module/web/NativeListWebEngine.js +13 -11
  28. package/lib/module/web/templates/ActivityRowRenderer.js +29 -23
  29. package/lib/module/web/templates/DataRowRenderer.js +16 -0
  30. package/lib/module/web/templates/IdentityRowRenderer.js +3 -1
  31. package/lib/module/web/templates/MediaTileRowRenderer.js +84 -15
  32. package/lib/typescript/src/models.d.ts +9 -1
  33. package/package.json +1 -1
  34. package/src/NativeList.tsx +25 -4
  35. package/src/NativeList.web.tsx +1 -1
  36. package/src/models.ts +9 -0
  37. package/src/validation.ts +34 -0
  38. package/src/web/NativeListWebEngine.ts +16 -11
  39. package/src/web/templates/ActivityRowRenderer.ts +42 -32
  40. package/src/web/templates/DataRowRenderer.ts +28 -0
  41. package/src/web/templates/IdentityRowRenderer.ts +3 -3
  42. package/src/web/templates/MediaTileRowRenderer.ts +90 -15
package/src/validation.ts CHANGED
@@ -1621,6 +1621,11 @@ function assertVisual(row: RowModel, path: string): void {
1621
1621
  });
1622
1622
  }
1623
1623
 
1624
+ /** The type half of the `descriptionActionStart` contract; the range needs the row. */
1625
+ function isDescriptionActionStart(value: unknown): value is number {
1626
+ return Number.isSafeInteger(value) && (value as number) >= 0;
1627
+ }
1628
+
1624
1629
  function assertActivity(row: Partial<ActivityRow>, path: string): void {
1625
1630
  if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean')
1626
1631
  fail(`${path}.hideLeading`, 'must be boolean');
@@ -1633,6 +1638,11 @@ function assertActivity(row: Partial<ActivityRow>, path: string): void {
1633
1638
  fail(`${path}.presentation`, 'must be stacked or table');
1634
1639
  if (row.descriptionActionKey !== undefined)
1635
1640
  assertKey(row.descriptionActionKey, `${path}.descriptionActionKey`);
1641
+ if (
1642
+ row.descriptionActionStart !== undefined &&
1643
+ !isDescriptionActionStart(row.descriptionActionStart)
1644
+ )
1645
+ fail(`${path}.descriptionActionStart`, 'must be a non-negative integer');
1636
1646
  if ((row.amounts?.length ?? 0) > 32)
1637
1647
  fail(`${path}.amounts`, 'supports at most 32 amount lines');
1638
1648
  const amountKeys = new Set<string>();
@@ -1899,6 +1909,13 @@ function assertRow(
1899
1909
  break;
1900
1910
  case 'activity':
1901
1911
  assertActivity(row, path);
1912
+ // Checked on the complete row only: a patch may carry the offset
1913
+ // without the description it points into.
1914
+ if ((row.descriptionActionStart ?? 0) > (row.description?.length ?? 0))
1915
+ fail(
1916
+ `${path}.descriptionActionStart`,
1917
+ 'must not exceed the description length'
1918
+ );
1902
1919
  break;
1903
1920
  case 'message':
1904
1921
  if (
@@ -2449,6 +2466,7 @@ const ROW_FIELDS: Readonly<Record<string, readonly string[]>> = {
2449
2466
  'presentation',
2450
2467
  'fee',
2451
2468
  'descriptionActionKey',
2469
+ 'descriptionActionStart',
2452
2470
  'footerActions',
2453
2471
  ],
2454
2472
  message: [
@@ -2616,6 +2634,7 @@ const PATCH_FIELDS: Readonly<Record<string, readonly string[]>> = {
2616
2634
  'amounts',
2617
2635
  'fee',
2618
2636
  'descriptionActionKey',
2637
+ 'descriptionActionStart',
2619
2638
  'footerActions',
2620
2639
  ],
2621
2640
  message: [
@@ -3931,6 +3950,11 @@ function sanitizeRowForProduction(row: RowModel): RowModel {
3931
3950
  delete next[field];
3932
3951
  continue;
3933
3952
  }
3953
+ if (field === 'descriptionActionStart') {
3954
+ // Renderers clamp an offset past the text; anything else has no meaning.
3955
+ if (!isDescriptionActionStart(value)) delete next[field];
3956
+ continue;
3957
+ }
3934
3958
  if (field === 'parent' && isRecord(value))
3935
3959
  next[field] = sanitizeRowForProduction(value as unknown as RowModel);
3936
3960
  else if (field === 'children' && Array.isArray(value))
@@ -4862,6 +4886,16 @@ function mergeAndValidateSingleRow(
4862
4886
  )
4863
4887
  changes.subtitle = null;
4864
4888
  }
4889
+ // The offset points into one specific description string, so a patch that
4890
+ // replaces the description without restating it falls back to the default.
4891
+ if (
4892
+ previous.type === 'activity' &&
4893
+ 'description' in changes &&
4894
+ changes.description !== previous.description &&
4895
+ !('descriptionActionStart' in changes) &&
4896
+ previous.descriptionActionStart !== undefined
4897
+ )
4898
+ changes.descriptionActionStart = null;
4865
4899
  const merged = { ...previous } as unknown as Record<string, unknown>;
4866
4900
  for (const [field, value] of Object.entries(changes)) {
4867
4901
  if (value === null) delete merged[field];
@@ -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
  }
@@ -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)}
@@ -872,7 +881,7 @@ export const WEB_LIST_CSS = `
872
881
  .ok-native-list-index-preview{position:absolute;z-index:8;right:40px;top:50%;display:flex;width:48px;height:48px;align-items:center;justify-content:center;transform:translateY(-50%) scale(.92);border-radius:14px;background:var(--nl-inverse);color:var(--nl-inverse-text);font-size:22px;font-weight:600;opacity:0;pointer-events:none;transition:opacity .15s ease,transform .15s ease;font-family:var(--nl-font-semibold)}.ok-native-list-index-preview[data-visible="true"]{opacity:1;transform:translateY(-50%) scale(1)}
873
882
  .ok-native-list-row.ok-native-list-market-skeleton{padding:12px 20px;gap:0}.ok-native-list-skeleton-left{display:flex;align-items:center;gap:12px;flex:1}.ok-native-list-skeleton-text{display:flex;flex-direction:column;gap:4px}.ok-native-list-skeleton-right{display:flex;align-items:center;gap:8px}.ok-native-list-skeleton-mark{display:block;flex-shrink:0;border-radius:8px;animation:ok-native-list-skeleton 1.5s linear infinite alternate}@keyframes ok-native-list-skeleton{from{background-color:var(--nl-skeleton-base)}to{background-color:var(--nl-skeleton-highlight)}}.ok-native-list-market-spinner{display:block;width:20px;height:20px;flex-shrink:0;color:var(--nl-icon);animation:ok-native-list-spin .75s linear infinite}
874
883
  @media (prefers-reduced-motion:reduce){.ok-native-list-index-preview,.ok-native-list-refresh{transition:none}.ok-native-list-spinner,.ok-native-list-market-spinner{animation:none}.ok-native-list-skeleton-mark{animation:none;background:var(--nl-skeleton-base)}}
875
- .ok-native-list-footer{flex:0 0 auto;min-height:0}.ok-native-list-sticky{position:absolute;z-index:4;left:0;right:0;top:0;pointer-events:auto;box-shadow:0 1px 0 var(--nl-separator)}.ok-native-list-viewport-frame:has(>.ok-native-list-index-rail:not([hidden]))>.ok-native-list-viewport,.ok-native-list-viewport-frame[data-section-index-visible="true"]>.ok-native-list-viewport{scrollbar-width:none}.ok-native-list-viewport-frame:has(>.ok-native-list-index-rail:not([hidden]))>.ok-native-list-viewport::-webkit-scrollbar,.ok-native-list-viewport-frame[data-section-index-visible="true"]>.ok-native-list-viewport::-webkit-scrollbar{display:none}.ok-native-list-index-rail{position:absolute;z-index:6;top:0;right:0;bottom:0;width:${SECTION_INDEX_RAIL_WIDTH}px;touch-action:none;cursor:pointer;font-family:var(--nl-font-regular);font-synthesis:none}.ok-native-list-index-rail[hidden]{display:none}.ok-native-list-index-button{appearance:none;position:absolute;left:15px;display:flex;width:14px;height:14px;align-items:center;justify-content:center;padding:0;transform:translateY(-50%);border:0;border-radius:7px;background:transparent;color:var(--nl-disabled);font-size:10px;font-weight:400;line-height:1;cursor:pointer;opacity:.5;transition:opacity .15s ease;font-family:var(--nl-font-regular)}.ok-native-list-index-rail:hover .ok-native-list-index-button,.ok-native-list-index-rail:focus-within .ok-native-list-index-button,.ok-native-list-index-button[data-active="true"]{opacity:1}.ok-native-list-index-button[data-active="true"]{background:var(--nl-positive);color:var(--nl-inverse-text);font-weight:500;font-family:var(--nl-font-medium)}.ok-native-list-index-button:focus-visible{outline:2px solid var(--nl-positive);outline-offset:1px}
884
+ .ok-native-list-footer{flex:0 0 auto;min-height:0}.ok-native-list-sticky{position:absolute;z-index:4;left:0;right:0;top:0;pointer-events:auto}.ok-native-list-viewport-frame:has(>.ok-native-list-index-rail:not([hidden]))>.ok-native-list-viewport,.ok-native-list-viewport-frame[data-section-index-visible="true"]>.ok-native-list-viewport{scrollbar-width:none}.ok-native-list-viewport-frame:has(>.ok-native-list-index-rail:not([hidden]))>.ok-native-list-viewport::-webkit-scrollbar,.ok-native-list-viewport-frame[data-section-index-visible="true"]>.ok-native-list-viewport::-webkit-scrollbar{display:none}.ok-native-list-index-rail{position:absolute;z-index:6;top:0;right:0;bottom:0;width:${SECTION_INDEX_RAIL_WIDTH}px;touch-action:none;cursor:pointer;font-family:var(--nl-font-regular);font-synthesis:none}.ok-native-list-index-rail[hidden]{display:none}.ok-native-list-index-button{appearance:none;position:absolute;left:15px;display:flex;width:14px;height:14px;align-items:center;justify-content:center;padding:0;transform:translateY(-50%);border:0;border-radius:7px;background:transparent;color:var(--nl-disabled);font-size:10px;font-weight:400;line-height:1;cursor:pointer;opacity:.5;transition:opacity .15s ease;font-family:var(--nl-font-regular)}.ok-native-list-index-rail:hover .ok-native-list-index-button,.ok-native-list-index-rail:focus-within .ok-native-list-index-button,.ok-native-list-index-button[data-active="true"]{opacity:1}.ok-native-list-index-button[data-active="true"]{background:var(--nl-positive);color:var(--nl-inverse-text);font-weight:500;font-family:var(--nl-font-medium)}.ok-native-list-index-button:focus-visible{outline:2px solid var(--nl-positive);outline-offset:1px}
876
885
  .ok-native-list-refresh{position:absolute;z-index:7;left:50%;top:8px;display:flex;align-items:center;gap:6px;padding:6px 10px;border-radius:999px;background:var(--nl-inverse);color:var(--nl-inverse-text);font-size:12px;opacity:0;transform:translate(-50%,-16px);transition:opacity .15s ease,transform .15s ease;pointer-events:none}.ok-native-list-refresh[data-visible="true"]{opacity:1;transform:translate(-50%,0)}
877
886
  .ok-native-list-warning{height:auto;display:flex;flex-direction:column;align-items:stretch;gap:4px;padding:14px 12px;border-top:1px solid;border-bottom:1px solid;box-sizing:border-box;cursor:default}.ok-native-list-warning-title,.ok-native-list-warning-message{font-size:14px;line-height:20px;white-space:normal;overflow-wrap:anywhere}.ok-native-list-warning-title{font-weight:500;color:var(--nl-primary);font-family:var(--nl-font-medium)}.ok-native-list-warning-message{font-weight:400;color:var(--nl-secondary);font-family:var(--nl-font-regular)}
878
887
  .ok-native-list-subtitle-segments{display:flex;align-items:center;min-width:0;max-width:100%;height:20px}.ok-native-list-subtitle-segments>.ok-native-list-secondary{flex:0 1 auto;min-width:0}.ok-native-list-subtitle-dot{flex:0 0 4px;width:4px;height:4px;margin:0 6px;border-radius:50%;background:var(--nl-disabled)}.ok-native-list-wallet-row>.ok-native-list-flex{flex:0 1 auto;width:100%;align-items:center}.ok-native-list-wallet-badges{display:flex;gap:4px;justify-content:center;margin-top:4px;height:20px;max-width:100%}.ok-native-list-wallet-badges>.ok-native-list-badge{background:var(--nl-strong);color:var(--nl-secondary);font-size:12px;line-height:16px;height:20px;box-sizing:border-box;padding:2px 4px}.ok-native-list-visual-overlay{position:absolute;display:flex;align-items:center;justify-content:center;box-sizing:border-box;border-radius:50%;overflow:hidden;line-height:1;font-size:10px}.ok-native-list-visual-overlay img,.ok-native-list-visual-overlay svg{width:100%;height:100%;object-fit:contain}/* OneKey patch: selector controls follow their original semantic colors and geometry. */
@@ -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`;
@@ -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;