@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
package/src/validation.ts CHANGED
@@ -282,6 +282,8 @@ function assertTextStyle(
282
282
  'alignment',
283
283
  'verticalAlignment',
284
284
  'offsetY',
285
+ 'letterSpacing',
286
+ 'tabularNumbers',
285
287
  ...additionalKeys,
286
288
  ],
287
289
  path,
@@ -333,6 +335,17 @@ function assertTextStyle(
333
335
  fail(`${path}.verticalAlignment`, 'must be top, center, or bottom');
334
336
  }
335
337
  assertBoundedStyleNumber(style.offsetY, `${path}.offsetY`, -8, 8);
338
+ assertBoundedStyleNumber(
339
+ style.letterSpacing,
340
+ `${path}.letterSpacing`,
341
+ -4,
342
+ 10
343
+ );
344
+ if (
345
+ style.tabularNumbers !== undefined &&
346
+ typeof style.tabularNumbers !== 'boolean'
347
+ )
348
+ fail(`${path}.tabularNumbers`, 'must be a boolean');
336
349
  }
337
350
 
338
351
  function assertBoxStyle(style: RowBoxStyle, path: string): void {
@@ -1344,6 +1357,110 @@ function assertButtonGroup(
1344
1357
  });
1345
1358
  }
1346
1359
 
1360
+ const MAX_TITLE_SEGMENTS = 4;
1361
+ const HEX_COLOR_PATTERN = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
1362
+
1363
+ function assertTitleSegments(value: unknown, path: string): void {
1364
+ if (
1365
+ !Array.isArray(value) ||
1366
+ value.length === 0 ||
1367
+ value.length > MAX_TITLE_SEGMENTS
1368
+ )
1369
+ fail(path, `must hold 1...${MAX_TITLE_SEGMENTS} segments`);
1370
+ let shrinking = 0;
1371
+ // Array.from also visits holes, so a sparse list is rejected here and the
1372
+ // production sanitizer drops it before protocol validation walks it.
1373
+ Array.from(value as readonly unknown[]).forEach((item, index) => {
1374
+ const segmentPath = `${path}[${index}]`;
1375
+ const segment = protocolObject(item, segmentPath);
1376
+ assertUnknownKeys(
1377
+ segment,
1378
+ ['text', 'tone', 'fontWeight', 'shrink', 'maxWidthRatio'],
1379
+ segmentPath,
1380
+ 'title segment key'
1381
+ );
1382
+ const { text, tone, fontWeight, shrink, maxWidthRatio } = segment;
1383
+ if (typeof text !== 'string' || !text.trim())
1384
+ fail(`${segmentPath}.text`, 'must be non-blank');
1385
+ assertText(text, `${segmentPath}.text`);
1386
+ if (tone !== undefined && tone !== 'primary' && tone !== 'secondary')
1387
+ fail(`${segmentPath}.tone`, 'must be primary or secondary');
1388
+ if (
1389
+ fontWeight !== undefined &&
1390
+ fontWeight !== 'regular' &&
1391
+ fontWeight !== 'medium'
1392
+ )
1393
+ fail(`${segmentPath}.fontWeight`, 'must be regular or medium');
1394
+ if (shrink !== undefined && typeof shrink !== 'boolean')
1395
+ fail(`${segmentPath}.shrink`, 'must be a boolean');
1396
+ if (shrink) shrinking += 1;
1397
+ if (
1398
+ maxWidthRatio !== undefined &&
1399
+ (typeof maxWidthRatio !== 'number' ||
1400
+ !Number.isFinite(maxWidthRatio) ||
1401
+ maxWidthRatio <= 0 ||
1402
+ maxWidthRatio > 1)
1403
+ )
1404
+ fail(`${segmentPath}.maxWidthRatio`, 'must be finite within (0, 1]');
1405
+ });
1406
+ if (shrinking > 1) fail(path, 'allows at most one shrinking segment');
1407
+ }
1408
+
1409
+ function assertTitleLeadingIcon(value: unknown, path: string): void {
1410
+ const icon = protocolObject(value, path);
1411
+ assertUnknownKeys(
1412
+ icon,
1413
+ ['name', 'tintColor', 'accessibilityLabel'],
1414
+ path,
1415
+ 'title leading icon key'
1416
+ );
1417
+ const { name, tintColor, accessibilityLabel } = icon;
1418
+ if (typeof name !== 'string' || !name.trim())
1419
+ fail(`${path}.name`, 'must be non-blank');
1420
+ if (
1421
+ tintColor !== undefined &&
1422
+ (typeof tintColor !== 'string' || !HEX_COLOR_PATTERN.test(tintColor))
1423
+ )
1424
+ fail(`${path}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
1425
+ if (
1426
+ accessibilityLabel !== undefined &&
1427
+ typeof accessibilityLabel !== 'string'
1428
+ )
1429
+ fail(`${path}.accessibilityLabel`, 'must be a string');
1430
+ }
1431
+
1432
+ function assertIdentityTitleRuns(
1433
+ row: Pick<
1434
+ IdentityRow,
1435
+ 'titleSegments' | 'titleLeadingIcon' | 'titleMatch' | 'presentation'
1436
+ >,
1437
+ path: string
1438
+ ): void {
1439
+ if (row.titleSegments !== undefined) {
1440
+ assertTitleSegments(row.titleSegments, `${path}.titleSegments`);
1441
+ // titleMatch ranges index `title`, which the runs replace on screen.
1442
+ if (row.titleMatch?.length)
1443
+ fail(`${path}.titleMatch`, 'cannot be combined with titleSegments');
1444
+ if (row.presentation === 'walletSidebar')
1445
+ fail(`${path}.titleSegments`, 'is not supported with walletSidebar');
1446
+ }
1447
+ if (row.titleLeadingIcon !== undefined) {
1448
+ assertTitleLeadingIcon(row.titleLeadingIcon, `${path}.titleLeadingIcon`);
1449
+ if (row.presentation === 'walletSidebar')
1450
+ fail(`${path}.titleLeadingIcon`, 'is not supported with walletSidebar');
1451
+ }
1452
+ }
1453
+
1454
+ /** Production keeps decorative title runs only when they pass the rules. */
1455
+ function passesTitleRunRules(check: () => void): boolean {
1456
+ try {
1457
+ check();
1458
+ return true;
1459
+ } catch {
1460
+ return false;
1461
+ }
1462
+ }
1463
+
1347
1464
  // A passive label: its text and two caller colors, with no action or style slot.
1348
1465
  function assertWebLeadingBadge(value: unknown, path: string): void {
1349
1466
  if (value === undefined) return;
@@ -1518,6 +1635,15 @@ function assertLeadingVisual(
1518
1635
  !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(visual.fallbackTextColor))
1519
1636
  )
1520
1637
  fail(`${path}.fallbackTextColor`, 'must be a hex color');
1638
+ if (
1639
+ 'borderWidth' in visual &&
1640
+ visual.borderWidth !== undefined &&
1641
+ (typeof visual.borderWidth !== 'number' ||
1642
+ !Number.isFinite(visual.borderWidth) ||
1643
+ visual.borderWidth <= 0 ||
1644
+ visual.borderWidth > 4)
1645
+ )
1646
+ fail(`${path}.borderWidth`, 'must be within (0, 4]');
1521
1647
  if (
1522
1648
  visual.fallbackIcon?.size !== undefined &&
1523
1649
  (!Number.isFinite(visual.fallbackIcon.size) ||
@@ -1870,6 +1996,7 @@ function assertRow(
1870
1996
  );
1871
1997
  });
1872
1998
  assertIdentityExtras(row, path);
1999
+ assertIdentityTitleRuns(row, path);
1873
2000
  assertText(row.subtitle, `${path}.subtitle`);
1874
2001
  // OneKey patch: selector text segments truncate independently.
1875
2002
  row.subtitleSegments?.forEach((segment, segmentIndex) => {
@@ -2463,11 +2590,14 @@ const ROW_FIELDS: Readonly<Record<string, readonly string[]>> = {
2463
2590
  'titleIcon',
2464
2591
  'secondaryTitleIcon',
2465
2592
  'titleImage',
2593
+ 'titleSegments',
2594
+ 'titleLeadingIcon',
2466
2595
  'subtitle',
2467
2596
  'tertiary',
2468
2597
  'tertiaryTone',
2469
2598
  'titleLines',
2470
2599
  'subtitleLines',
2600
+ 'collapseEmptyTrailing',
2471
2601
  'badges',
2472
2602
  'trailing',
2473
2603
  'draggable',
@@ -2641,10 +2771,13 @@ const PATCH_FIELDS: Readonly<Record<string, readonly string[]>> = {
2641
2771
  'titleIcon',
2642
2772
  'secondaryTitleIcon',
2643
2773
  'titleImage',
2774
+ 'titleSegments',
2775
+ 'titleLeadingIcon',
2644
2776
  'subtitle',
2645
2777
  'tertiary',
2646
2778
  'tertiaryTone',
2647
2779
  'subtitleLines',
2780
+ 'collapseEmptyTrailing',
2648
2781
  'badges',
2649
2782
  'trailing',
2650
2783
  ],
@@ -2773,6 +2906,7 @@ function protocolKey(value: unknown, path: string): void {
2773
2906
  const PROTOCOL_ARRAY_FIELDS = new Set([
2774
2907
  'columns',
2775
2908
  'titleSuffixes',
2909
+ 'titleSegments',
2776
2910
  'cells',
2777
2911
  'points',
2778
2912
  'images',
@@ -2807,6 +2941,7 @@ const PROTOCOL_NUMBER_FIELDS = new Set([
2807
2941
  'opacity',
2808
2942
  'offsetY',
2809
2943
  'offsetX',
2944
+ 'letterSpacing',
2810
2945
  'cornerRadius',
2811
2946
  'borderWidth',
2812
2947
  'horizontalPadding',
@@ -2919,7 +3054,7 @@ function assertProtocolFields(
2919
3054
  PROTOCOL_NUMBER_FIELDS.has(field) &&
2920
3055
  typeof item === 'number' &&
2921
3056
  item < 0 &&
2922
- !['offsetX', 'offsetY'].includes(field)
3057
+ !['offsetX', 'offsetY', 'letterSpacing'].includes(field)
2923
3058
  )
2924
3059
  fail(fieldPath, 'must be non-negative');
2925
3060
  if (
@@ -2930,7 +3065,10 @@ function assertProtocolFields(
2930
3065
  fail(fieldPath, 'must be regular, medium, semibold, or bold');
2931
3066
  if (field === 'buttonStyle' && item !== 'tertiary')
2932
3067
  fail(fieldPath, 'must be tertiary');
2933
- if (field === 'hideLeading' && typeof item !== 'boolean')
3068
+ if (
3069
+ (field === 'hideLeading' || field === 'collapseEmptyTrailing') &&
3070
+ typeof item !== 'boolean'
3071
+ )
2934
3072
  fail(fieldPath, 'must be boolean');
2935
3073
  if (
2936
3074
  field === 'key' ||
@@ -3014,7 +3152,10 @@ function assertRowProtocol(row: RowModel, path: string): void {
3014
3152
  if (row.height !== undefined && row.height < 0)
3015
3153
  fail(`${path}.height`, 'must be non-negative');
3016
3154
  if (row.type === 'identity') {
3017
- if (isDevelopment()) assertIdentityExtras(row, path);
3155
+ if (isDevelopment()) {
3156
+ assertIdentityExtras(row, path);
3157
+ assertIdentityTitleRuns(row, path);
3158
+ }
3018
3159
  if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes))
3019
3160
  fail(`${path}.titleSuffixes`, 'must be an array');
3020
3161
  row.titleSuffixes?.forEach((suffix, index) => {
@@ -3138,6 +3279,17 @@ function assertRowProtocol(row: RowModel, path: string): void {
3138
3279
 
3139
3280
  function assertSnapshotProtocol(snapshot: NativeListSnapshot): void {
3140
3281
  protocolObject(snapshot, 'snapshot');
3282
+ const reorderActivation = snapshot.capabilities?.reorderActivation;
3283
+ if (
3284
+ reorderActivation !== undefined &&
3285
+ reorderActivation !== 'row' &&
3286
+ reorderActivation !== 'handle'
3287
+ ) {
3288
+ fail(
3289
+ 'snapshot.capabilities.reorderActivation',
3290
+ "must be 'row' or 'handle'"
3291
+ );
3292
+ }
3141
3293
  if (snapshot.disclosure !== undefined) {
3142
3294
  protocolObject(snapshot.disclosure, 'snapshot.disclosure');
3143
3295
  if (typeof snapshot.disclosure.expanded !== 'boolean')
@@ -3280,6 +3432,7 @@ const VISUAL_FIELDS = [
3280
3432
  'overlays',
3281
3433
  'borderStyle',
3282
3434
  'borderColor',
3435
+ 'borderWidth',
3283
3436
  'cornerIcon',
3284
3437
  ];
3285
3438
  const TEXT_STYLE_FIELDS = [
@@ -3293,6 +3446,8 @@ const TEXT_STYLE_FIELDS = [
3293
3446
  'alignment',
3294
3447
  'verticalAlignment',
3295
3448
  'offsetY',
3449
+ 'letterSpacing',
3450
+ 'tabularNumbers',
3296
3451
  ];
3297
3452
  const ACCESSORY_FIELDS: Readonly<Record<string, readonly string[]>> = {
3298
3453
  value: ['kind', 'text', 'secondary', 'textSegments'],
@@ -3618,6 +3773,14 @@ const NESTED_DECORATION_FIELDS: Readonly<Record<string, readonly string[]>> = {
3618
3773
 
3619
3774
  function sanitizeDecoration(value: unknown, field: string): unknown {
3620
3775
  if (value === undefined || value === null) return undefined;
3776
+ if (field === 'titleSegments')
3777
+ return passesTitleRunRules(() => assertTitleSegments(value, field))
3778
+ ? value
3779
+ : undefined;
3780
+ if (field === 'titleLeadingIcon')
3781
+ return passesTitleRunRules(() => assertTitleLeadingIcon(value, field))
3782
+ ? value
3783
+ : undefined;
3621
3784
  // All or nothing: a badge without valid text and both colors is dropped, and
3622
3785
  // only its three declared fields are kept.
3623
3786
  if (field === 'webLeadingBadge') {
@@ -3679,6 +3842,9 @@ function sanitizeDecoration(value: unknown, field: string): unknown {
3679
3842
  : items.filter((item) => item !== undefined);
3680
3843
  }
3681
3844
  if (!isRecord(value)) return value;
3845
+ const isLeadingVisual = ['leading', 'visual', 'secondaryLeading'].includes(
3846
+ field
3847
+ );
3682
3848
  let object = value;
3683
3849
  if (field === 'titleImage') {
3684
3850
  const image = sanitizeImage(value.image);
@@ -3702,7 +3868,7 @@ function sanitizeDecoration(value: unknown, field: string): unknown {
3702
3868
  ) {
3703
3869
  if (typeof value.name !== 'string' || !value.name.trim()) return undefined;
3704
3870
  object = pickFields(value, ICON_FIELDS);
3705
- } else if (['leading', 'visual', 'secondaryLeading'].includes(field)) {
3871
+ } else if (isLeadingVisual) {
3706
3872
  object = pickFields(value, VISUAL_FIELDS);
3707
3873
  } else if (field === 'media') {
3708
3874
  object = pickFields(value, ['source', 'probeOrder']);
@@ -3801,6 +3967,24 @@ function sanitizeDecoration(value: unknown, field: string): unknown {
3801
3967
  const next: Record<string, unknown> = {};
3802
3968
  for (const [key, item] of Object.entries(object)) {
3803
3969
  if (item === undefined || item === null) continue;
3970
+ if (
3971
+ isLeadingVisual &&
3972
+ key === 'borderWidth' &&
3973
+ (typeof item !== 'number' ||
3974
+ !Number.isFinite(item) ||
3975
+ item <= 0 ||
3976
+ item > 4)
3977
+ )
3978
+ continue;
3979
+ if (
3980
+ key === 'letterSpacing' &&
3981
+ (typeof item !== 'number' ||
3982
+ !Number.isFinite(item) ||
3983
+ item < -4 ||
3984
+ item > 10)
3985
+ )
3986
+ continue;
3987
+ if (key === 'tabularNumbers' && typeof item !== 'boolean') continue;
3804
3988
  if (
3805
3989
  (/color$/i.test(key) || /background$/i.test(key)) &&
3806
3990
  (typeof item !== 'string' || !/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(item))
@@ -3865,7 +4049,7 @@ function sanitizeDecoration(value: unknown, field: string): unknown {
3865
4049
  typeof item !== 'object' &&
3866
4050
  typeof item === 'number' &&
3867
4051
  (!Number.isFinite(item) ||
3868
- (item < 0 && !['offsetX', 'offsetY'].includes(key)))
4052
+ (item < 0 && !['offsetX', 'offsetY', 'letterSpacing'].includes(key)))
3869
4053
  )
3870
4054
  continue;
3871
4055
  if (
@@ -4382,6 +4566,8 @@ function assertPatchChanges(patch: PatchValues, index: number): void {
4382
4566
  );
4383
4567
  });
4384
4568
  assertIdentityExtras(patch.changes, path);
4569
+ // A null clear never reaches here; a replacement follows the row rules.
4570
+ assertIdentityTitleRuns(patch.changes, path);
4385
4571
  assertText(patch.changes.subtitle, `${path}.subtitle`);
4386
4572
  assertText(patch.changes.tertiary, `${path}.tertiary`);
4387
4573
  if (
@@ -4672,7 +4858,11 @@ function normalizePatch(patch: RowPatch, index: number): RowPatch | undefined {
4672
4858
  ? sanitizeMarketMetrics(normalized)
4673
4859
  : sanitizeDecoration(normalized, field);
4674
4860
  if (canonical !== undefined) changes[field] = canonical;
4675
- else if (field === 'titleImage') changes[field] = null;
4861
+ // A rejected title decoration clears the old one instead of leaving it drawn.
4862
+ else if (
4863
+ ['titleImage', 'titleSegments', 'titleLeadingIcon'].includes(field)
4864
+ )
4865
+ changes[field] = null;
4676
4866
  }
4677
4867
  if (
4678
4868
  patch.type === 'market' &&