@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
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
- import { createNamedIcon } from '@onekeyfe/react-native-image/icon/dom';
4
3
  const views = new WeakMap();
5
4
  function bindLegacy(body, row, primitives) {
6
5
  const v = views.get(body);
@@ -123,6 +122,79 @@ function recycleLegacy(body) {
123
122
  v.imageKey = v.networkKey = '';
124
123
  }
125
124
  const galleries = new WeakMap();
125
+ const SVG_NS = 'http://www.w3.org/2000/svg';
126
+ let glyphMaskId = 0;
127
+
128
+ /**
129
+ * Placeholder glyphs share one 24pt geometry with the iOS and Android renderers:
130
+ * a rounded frame with a sun and a ridge; the failed glyph adds a slash and cuts
131
+ * a gap into the frame around it.
132
+ */
133
+ function createMediaGlyph(document, state) {
134
+ const svg = document.createElementNS(SVG_NS, 'svg');
135
+ svg.setAttribute('viewBox', '0 0 24 24');
136
+ svg.setAttribute('fill', 'none');
137
+ svg.setAttribute('stroke', 'currentColor');
138
+ svg.setAttribute('stroke-width', '1.5');
139
+ svg.setAttribute('stroke-linecap', 'round');
140
+ svg.setAttribute('stroke-linejoin', 'round');
141
+ svg.setAttribute('aria-hidden', 'true');
142
+ const shape = (tag, attributes) => {
143
+ const node = document.createElementNS(SVG_NS, tag);
144
+ Object.entries(attributes).forEach(([key, value]) => node.setAttribute(key, value));
145
+ return node;
146
+ };
147
+ const picture = shape('g', {});
148
+ picture.append(shape('rect', {
149
+ x: '3',
150
+ y: '3',
151
+ width: '18',
152
+ height: '18',
153
+ rx: '4'
154
+ }), shape('circle', {
155
+ cx: '9',
156
+ cy: '9',
157
+ r: '1.6'
158
+ }), shape('path', {
159
+ d: 'M5 20.5L14.5 11L21 17.5'
160
+ }));
161
+ if (state === 'failed') {
162
+ glyphMaskId += 1;
163
+ const id = `ok-native-list-media-cut-${glyphMaskId}`;
164
+ const mask = shape('mask', {
165
+ id,
166
+ maskUnits: 'userSpaceOnUse'
167
+ });
168
+ mask.append(shape('rect', {
169
+ x: '0',
170
+ y: '0',
171
+ width: '24',
172
+ height: '24',
173
+ fill: '#fff',
174
+ stroke: 'none'
175
+ }), shape('path', {
176
+ d: 'M2.6 -0.6L24.6 21.4L21.4 24.6L-0.6 2.6Z',
177
+ fill: '#000',
178
+ stroke: 'none'
179
+ }));
180
+ picture.setAttribute('mask', `url(#${id})`);
181
+ svg.append(mask, picture, shape('path', {
182
+ d: 'M3 3L21 21'
183
+ }));
184
+ } else svg.append(picture);
185
+ const wrap = document.createElement('div');
186
+ wrap.className = 'ok-native-list-media-glyph';
187
+ wrap.dataset.glyph = state;
188
+ wrap.append(svg);
189
+ return wrap;
190
+ }
191
+ const SWEEP_PERIOD_MS = 1600;
192
+ function setPlaceholderState(v, state) {
193
+ v.fallback.dataset.state = state;
194
+ if (state === 'loading')
195
+ // Keep every loading tile on one sweep phase, including recycled rows.
196
+ v.fallback.style.setProperty('--nl-media-sweep-delay', `-${Math.round(performance.now() % SWEEP_PERIOD_MS)}ms`);
197
+ }
126
198
  const isGalleryMedia = row => row.variant === 'gallery' && (!row.image || !!row.media && !row.imageState);
127
199
  function clearGalleryMedia(v) {
128
200
  v.epoch += 1;
@@ -149,18 +221,7 @@ function initGallery(body, primitives) {
149
221
  };
150
222
  const frame = element('ok-native-list-media-image');
151
223
  const fallback = element('ok-native-list-media-fallback');
152
- const svg = createNamedIcon(document, 'ImageSquareWavesOutline');
153
- fallback.append(svg);
154
- Object.assign(fallback.style, {
155
- position: 'absolute',
156
- inset: '0',
157
- display: 'flex',
158
- alignItems: 'center',
159
- justifyContent: 'center',
160
- color: 'var(--nl-disabled)',
161
- borderRadius: '10px',
162
- background: 'var(--nl-strong)'
163
- });
224
+ fallback.append(element('ok-native-list-media-hatch'), element('ok-native-list-media-sheen'), createMediaGlyph(document, 'loading'), createMediaGlyph(document, 'failed'));
164
225
  const metadata = element('ok-native-list-media-meta');
165
226
  const subtitleLine = element('ok-native-list-media-subtitle-row');
166
227
  const subtitle = element('ok-native-list-media-subtitle');
@@ -240,10 +301,14 @@ function bindGallery(body, row, primitives) {
240
301
  v.fallback.style.visibility = 'visible';
241
302
  const epoch = v.epoch;
242
303
  const source = row.imageState ? undefined : row.media?.source;
304
+ setPlaceholderState(v, source?.uri && row.media?.probeOrder.length ? 'loading' : 'failed');
243
305
  const probe = attempt => {
244
306
  if (v.epoch !== epoch) return;
245
307
  const kind = row.media?.probeOrder[attempt];
246
- if (!source?.uri || !kind) return;
308
+ if (!source?.uri || !kind) {
309
+ setPlaceholderState(v, 'failed');
310
+ return;
311
+ }
247
312
  const media = body.ownerDocument.createElement(kind === 'video' ? 'video' : 'img');
248
313
  v.frame.style.borderRadius = kind === 'video' ? '0' : '10px';
249
314
  Object.assign(media.style, {
@@ -284,7 +349,11 @@ function bindGallery(body, row, primitives) {
284
349
  probe(attempt + 1);
285
350
  };
286
351
  const ready = () => {
287
- if (v.epoch === epoch && v.media === media) v.fallback.style.visibility = 'hidden';
352
+ if (v.epoch === epoch && v.media === media) {
353
+ v.fallback.style.visibility = 'hidden';
354
+ // Stops the sweep animation behind the picture.
355
+ setPlaceholderState(v, 'loaded');
356
+ }
288
357
  };
289
358
  if (media.tagName === 'VIDEO') media.onloadeddata = ready;else media.onload = ready;
290
359
  v.media = media;
@@ -394,18 +394,6 @@ export type RowBase = Readonly<{
394
394
  accessibilityLabel?: string;
395
395
  separator?: boolean;
396
396
  }>;
397
- /** One run of an identity title line; see docs/SPEC.md. */
398
- export type IdentityTitleSegment = Readonly<{
399
- text: string;
400
- /** Omitted: the title color. */
401
- tone?: 'primary' | 'secondary';
402
- /** Omitted: the title weight. */
403
- fontWeight?: 'regular' | 'medium';
404
- /** The one run that gives up width when the line is too narrow. */
405
- shrink?: boolean;
406
- /** Caps the run at this fraction of the title line, within (0, 1]. */
407
- maxWidthRatio?: number;
408
- }>;
409
397
  export type IdentityRow = RowBase & Readonly<{
410
398
  type: 'identity';
411
399
  /** Opt in to content-based height; explicit row/container height still wins. */
@@ -440,14 +428,6 @@ export type IdentityRow = RowBase & Readonly<{
440
428
  }>;
441
429
  /** Web-only additional help icon after titleIcon. */
442
430
  secondaryTitleIcon?: IdentityRow['titleIcon'];
443
- /** Runs drawn in place of `title`, which stays the spoken label. */
444
- titleSegments?: readonly IdentityTitleSegment[];
445
- /** 16-point glyph before the title; decorative unless labelled. */
446
- titleLeadingIcon?: Readonly<{
447
- name: string;
448
- tintColor?: string;
449
- accessibilityLabel?: string;
450
- }>;
451
431
  /** Circular image after title icons; image dimensions must be square, 1...40. */
452
432
  titleImage?: Readonly<{
453
433
  image: ImageSource;
@@ -513,6 +493,14 @@ export type ActivityRow = RowBase & Readonly<{
513
493
  hidden?: boolean;
514
494
  }>;
515
495
  descriptionActionKey?: string;
496
+ /**
497
+ * UTF-16 offset into `description` where the text that opens
498
+ * `descriptionActionKey` starts; the text before it stays plain. An integer
499
+ * in `0...description.length`: `0`, the default, makes the whole
500
+ * description the action and `description.length` leaves no action text.
501
+ * Ignored without `descriptionActionKey`.
502
+ */
503
+ descriptionActionStart?: number;
516
504
  footerActions?: readonly FooterAction[];
517
505
  style?: ActivityRowStyle;
518
506
  }>;
@@ -900,7 +888,7 @@ export type PatchClearableChanges<Row, Keys extends keyof Row> = Readonly<{
900
888
  export type RowPatch = Readonly<{
901
889
  type: 'identity';
902
890
  key: string;
903
- changes: PatchClearableChanges<IdentityRow, CommonPatchFields | 'title' | 'titleSuffixes' | 'titleIcon' | 'secondaryTitleIcon' | 'titleImage' | 'titleSegments' | 'titleLeadingIcon' | 'subtitle' | 'subtitleLines' | 'contentHeight' | 'longPressActionKey' | 'tertiary' | 'tertiaryTone' | 'badges' | 'trailing' | 'leading' | 'leadingAction' | 'titleMatch' | 'titleActionKey' | 'titleActionOnHover' | 'subtitleSegments'>;
891
+ changes: PatchClearableChanges<IdentityRow, CommonPatchFields | 'title' | 'titleSuffixes' | 'titleIcon' | 'secondaryTitleIcon' | 'titleImage' | 'subtitle' | 'subtitleLines' | 'contentHeight' | 'longPressActionKey' | 'tertiary' | 'tertiaryTone' | 'badges' | 'trailing' | 'leading' | 'leadingAction' | 'titleMatch' | 'titleActionKey' | 'titleActionOnHover' | 'subtitleSegments'>;
904
892
  }> | Readonly<{
905
893
  type: 'rail';
906
894
  key: string;
@@ -908,7 +896,7 @@ export type RowPatch = Readonly<{
908
896
  }> | Readonly<{
909
897
  type: 'activity';
910
898
  key: string;
911
- changes: PatchClearableChanges<ActivityRow, CommonPatchFields | 'title' | 'description' | 'status' | 'amounts' | 'badges' | 'presentation' | 'fee' | 'descriptionActionKey' | 'primaryAmount' | 'secondaryAmount' | 'leading' | 'hideLeading' | 'secondaryLeading' | 'footerActions'>;
899
+ changes: PatchClearableChanges<ActivityRow, CommonPatchFields | 'title' | 'description' | 'status' | 'amounts' | 'badges' | 'presentation' | 'fee' | 'descriptionActionKey' | 'descriptionActionStart' | 'primaryAmount' | 'secondaryAmount' | 'leading' | 'hideLeading' | 'secondaryLeading' | 'footerActions'>;
912
900
  }> | Readonly<{
913
901
  type: 'message';
914
902
  key: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "6.7.0-alpha.475",
3
+ "version": "6.8.0-2",
4
4
  "description": "Template-driven native RecyclerView and UICollectionView for React Native",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",
@@ -185,10 +185,21 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
185
185
  }
186
186
  const expandedEpoch = disclosureSlotMounts.current.expandedEpoch;
187
187
  const toggleEpoch = disclosureSlotMounts.current.toggleEpoch;
188
+ const iosHeaderPresent = Platform.OS === 'ios' && listHeader != null;
188
189
  const [slotMeasurements, setSlotMeasurements] = useState({
189
190
  heights: [0, 0, 0, 0, 0, 0],
190
191
  readyEpochs: [-1, -1, -1, -1, -1, -1],
192
+ iosHeaderPresent,
193
+ headerEpoch: 0,
191
194
  });
195
+ if (slotMeasurements.iosHeaderPresent !== iosHeaderPresent) {
196
+ setSlotMeasurements({
197
+ ...slotMeasurements,
198
+ iosHeaderPresent,
199
+ headerEpoch: slotMeasurements.headerEpoch + 1,
200
+ });
201
+ }
202
+ const headerEpoch = slotMeasurements.headerEpoch;
192
203
  const hasSidecar = listSidecar !== undefined;
193
204
  const sidecarWidth = sidecarLayout?.width;
194
205
  const sidecarGap = sidecarLayout?.gap;
@@ -321,7 +332,12 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
321
332
  parseInt(String(Platform.Version), 10) >= 26 &&
322
333
  (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') &&
323
334
  topOverlay != null;
324
- const containerSlotHeightsJson = JSON.stringify(slotHeights);
335
+ const containerSlotHeightsJson = JSON.stringify(
336
+ Platform.OS === 'ios' &&
337
+ (!iosHeaderPresent || slotMeasurements.readyEpochs[0] !== headerEpoch)
338
+ ? [iosHeaderPresent ? null : 0, ...slotHeights.slice(1)]
339
+ : slotHeights
340
+ );
325
341
  const defaultSlotInset =
326
342
  snapshot.layout.contentPaddingHorizontal ??
327
343
  snapshot.layout.contentPadding ??
@@ -351,6 +367,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
351
367
  return;
352
368
  }
353
369
  setSlotMeasurements((previous) => {
370
+ if (index === 0 && epoch !== previous.headerEpoch) return previous;
354
371
  if (
355
372
  previous.heights[index] === height &&
356
373
  previous.readyEpochs[index] === epoch
@@ -361,7 +378,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
361
378
  const readyEpochs = [...previous.readyEpochs];
362
379
  heights[index] = height;
363
380
  readyEpochs[index] = epoch;
364
- return { heights, readyEpochs };
381
+ return { ...previous, heights, readyEpochs };
365
382
  });
366
383
  };
367
384
  const sidecarLayoutJson = sidecarLayout
@@ -835,7 +852,11 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
835
852
  >
836
853
  {slotContents.map((content, index) => (
837
854
  <View
838
- key={index}
855
+ key={
856
+ index === 0 && Platform.OS === 'ios'
857
+ ? `header-${headerEpoch}`
858
+ : index
859
+ }
839
860
  collapsable={false}
840
861
  style={{
841
862
  position: 'absolute',
@@ -849,7 +870,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
849
870
  recordSlotLayout(
850
871
  index,
851
872
  Math.ceil(event.nativeEvent.layout.height),
852
- 0
873
+ index === 0 ? headerEpoch : 0
853
874
  );
854
875
  }
855
876
  }}
@@ -617,7 +617,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
617
617
  pointerEvents={slotState.disclosurePresent ? 'auto' : 'none'}
618
618
  style={
619
619
  slotState.disclosurePresent
620
- ? undefined
620
+ ? { marginHorizontal: -padding }
621
621
  : collapsedExpandedContentStyle
622
622
  }
623
623
  >
package/src/models.ts CHANGED
@@ -513,19 +513,6 @@ export type RowBase = Readonly<{
513
513
  separator?: boolean;
514
514
  }>;
515
515
 
516
- /** One run of an identity title line; see docs/SPEC.md. */
517
- export type IdentityTitleSegment = Readonly<{
518
- text: string;
519
- /** Omitted: the title color. */
520
- tone?: 'primary' | 'secondary';
521
- /** Omitted: the title weight. */
522
- fontWeight?: 'regular' | 'medium';
523
- /** The one run that gives up width when the line is too narrow. */
524
- shrink?: boolean;
525
- /** Caps the run at this fraction of the title line, within (0, 1]. */
526
- maxWidthRatio?: number;
527
- }>;
528
-
529
516
  export type IdentityRow = RowBase &
530
517
  Readonly<{
531
518
  type: 'identity';
@@ -557,14 +544,6 @@ export type IdentityRow = RowBase &
557
544
  }>;
558
545
  /** Web-only additional help icon after titleIcon. */
559
546
  secondaryTitleIcon?: IdentityRow['titleIcon'];
560
- /** Runs drawn in place of `title`, which stays the spoken label. */
561
- titleSegments?: readonly IdentityTitleSegment[];
562
- /** 16-point glyph before the title; decorative unless labelled. */
563
- titleLeadingIcon?: Readonly<{
564
- name: string;
565
- tintColor?: string;
566
- accessibilityLabel?: string;
567
- }>;
568
547
  /** Circular image after title icons; image dimensions must be square, 1...40. */
569
548
  titleImage?: Readonly<{
570
549
  image: ImageSource;
@@ -637,6 +616,14 @@ export type ActivityRow = RowBase &
637
616
  hidden?: boolean;
638
617
  }>;
639
618
  descriptionActionKey?: string;
619
+ /**
620
+ * UTF-16 offset into `description` where the text that opens
621
+ * `descriptionActionKey` starts; the text before it stays plain. An integer
622
+ * in `0...description.length`: `0`, the default, makes the whole
623
+ * description the action and `description.length` leaves no action text.
624
+ * Ignored without `descriptionActionKey`.
625
+ */
626
+ descriptionActionStart?: number;
640
627
  footerActions?: readonly FooterAction[];
641
628
  style?: ActivityRowStyle;
642
629
  }>;
@@ -1114,8 +1101,6 @@ export type RowPatch =
1114
1101
  | 'titleIcon'
1115
1102
  | 'secondaryTitleIcon'
1116
1103
  | 'titleImage'
1117
- | 'titleSegments'
1118
- | 'titleLeadingIcon'
1119
1104
  | 'subtitle'
1120
1105
  | 'subtitleLines'
1121
1106
  | 'contentHeight'
@@ -1154,6 +1139,7 @@ export type RowPatch =
1154
1139
  | 'presentation'
1155
1140
  | 'fee'
1156
1141
  | 'descriptionActionKey'
1142
+ | 'descriptionActionStart'
1157
1143
  | 'primaryAmount'
1158
1144
  | 'secondaryAmount'
1159
1145
  | 'leading'
package/src/validation.ts CHANGED
@@ -1344,108 +1344,6 @@ function assertButtonGroup(
1344
1344
  });
1345
1345
  }
1346
1346
 
1347
- const MAX_TITLE_SEGMENTS = 4;
1348
- const HEX_COLOR_PATTERN = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
1349
-
1350
- function assertTitleSegments(value: unknown, path: string): void {
1351
- if (
1352
- !Array.isArray(value) ||
1353
- value.length === 0 ||
1354
- value.length > MAX_TITLE_SEGMENTS
1355
- )
1356
- fail(path, `must hold 1...${MAX_TITLE_SEGMENTS} segments`);
1357
- let shrinking = 0;
1358
- value.forEach((item: unknown, index) => {
1359
- const segmentPath = `${path}[${index}]`;
1360
- const segment = protocolObject(item, segmentPath);
1361
- assertUnknownKeys(
1362
- segment,
1363
- ['text', 'tone', 'fontWeight', 'shrink', 'maxWidthRatio'],
1364
- segmentPath,
1365
- 'title segment key'
1366
- );
1367
- const { text, tone, fontWeight, shrink, maxWidthRatio } = segment;
1368
- if (typeof text !== 'string' || !text.trim())
1369
- fail(`${segmentPath}.text`, 'must be non-blank');
1370
- assertText(text, `${segmentPath}.text`);
1371
- if (tone !== undefined && tone !== 'primary' && tone !== 'secondary')
1372
- fail(`${segmentPath}.tone`, 'must be primary or secondary');
1373
- if (
1374
- fontWeight !== undefined &&
1375
- fontWeight !== 'regular' &&
1376
- fontWeight !== 'medium'
1377
- )
1378
- fail(`${segmentPath}.fontWeight`, 'must be regular or medium');
1379
- if (shrink !== undefined && typeof shrink !== 'boolean')
1380
- fail(`${segmentPath}.shrink`, 'must be a boolean');
1381
- if (shrink) shrinking += 1;
1382
- if (
1383
- maxWidthRatio !== undefined &&
1384
- (typeof maxWidthRatio !== 'number' ||
1385
- !Number.isFinite(maxWidthRatio) ||
1386
- maxWidthRatio <= 0 ||
1387
- maxWidthRatio > 1)
1388
- )
1389
- fail(`${segmentPath}.maxWidthRatio`, 'must be finite within (0, 1]');
1390
- });
1391
- if (shrinking > 1) fail(path, 'allows at most one shrinking segment');
1392
- }
1393
-
1394
- function assertTitleLeadingIcon(value: unknown, path: string): void {
1395
- const icon = protocolObject(value, path);
1396
- assertUnknownKeys(
1397
- icon,
1398
- ['name', 'tintColor', 'accessibilityLabel'],
1399
- path,
1400
- 'title leading icon key'
1401
- );
1402
- const { name, tintColor, accessibilityLabel } = icon;
1403
- if (typeof name !== 'string' || !name.trim())
1404
- fail(`${path}.name`, 'must be non-blank');
1405
- if (
1406
- tintColor !== undefined &&
1407
- (typeof tintColor !== 'string' || !HEX_COLOR_PATTERN.test(tintColor))
1408
- )
1409
- fail(`${path}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
1410
- if (
1411
- accessibilityLabel !== undefined &&
1412
- typeof accessibilityLabel !== 'string'
1413
- )
1414
- fail(`${path}.accessibilityLabel`, 'must be a string');
1415
- }
1416
-
1417
- function assertIdentityTitleRuns(
1418
- row: Pick<
1419
- IdentityRow,
1420
- 'titleSegments' | 'titleLeadingIcon' | 'titleMatch' | 'presentation'
1421
- >,
1422
- path: string
1423
- ): void {
1424
- if (row.titleSegments !== undefined) {
1425
- assertTitleSegments(row.titleSegments, `${path}.titleSegments`);
1426
- // titleMatch ranges index `title`, which the runs replace on screen.
1427
- if (row.titleMatch?.length)
1428
- fail(`${path}.titleMatch`, 'cannot be combined with titleSegments');
1429
- if (row.presentation === 'walletSidebar')
1430
- fail(`${path}.titleSegments`, 'is not supported with walletSidebar');
1431
- }
1432
- if (row.titleLeadingIcon !== undefined) {
1433
- assertTitleLeadingIcon(row.titleLeadingIcon, `${path}.titleLeadingIcon`);
1434
- if (row.presentation === 'walletSidebar')
1435
- fail(`${path}.titleLeadingIcon`, 'is not supported with walletSidebar');
1436
- }
1437
- }
1438
-
1439
- /** Production keeps decorative title runs only when they pass the rules. */
1440
- function passesTitleRunRules(check: () => void): boolean {
1441
- try {
1442
- check();
1443
- return true;
1444
- } catch {
1445
- return false;
1446
- }
1447
- }
1448
-
1449
1347
  function assertIdentityExtras(
1450
1348
  row: Pick<
1451
1349
  IdentityRow,
@@ -1723,6 +1621,11 @@ function assertVisual(row: RowModel, path: string): void {
1723
1621
  });
1724
1622
  }
1725
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
+
1726
1629
  function assertActivity(row: Partial<ActivityRow>, path: string): void {
1727
1630
  if (row.hideLeading !== undefined && typeof row.hideLeading !== 'boolean')
1728
1631
  fail(`${path}.hideLeading`, 'must be boolean');
@@ -1735,6 +1638,11 @@ function assertActivity(row: Partial<ActivityRow>, path: string): void {
1735
1638
  fail(`${path}.presentation`, 'must be stacked or table');
1736
1639
  if (row.descriptionActionKey !== undefined)
1737
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');
1738
1646
  if ((row.amounts?.length ?? 0) > 32)
1739
1647
  fail(`${path}.amounts`, 'supports at most 32 amount lines');
1740
1648
  const amountKeys = new Set<string>();
@@ -1936,7 +1844,6 @@ function assertRow(
1936
1844
  );
1937
1845
  });
1938
1846
  assertIdentityExtras(row, path);
1939
- assertIdentityTitleRuns(row, path);
1940
1847
  assertText(row.subtitle, `${path}.subtitle`);
1941
1848
  // OneKey patch: selector text segments truncate independently.
1942
1849
  row.subtitleSegments?.forEach((segment, segmentIndex) => {
@@ -2002,6 +1909,13 @@ function assertRow(
2002
1909
  break;
2003
1910
  case 'activity':
2004
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
+ );
2005
1919
  break;
2006
1920
  case 'message':
2007
1921
  if (
@@ -2519,8 +2433,6 @@ const ROW_FIELDS: Readonly<Record<string, readonly string[]>> = {
2519
2433
  'titleIcon',
2520
2434
  'secondaryTitleIcon',
2521
2435
  'titleImage',
2522
- 'titleSegments',
2523
- 'titleLeadingIcon',
2524
2436
  'subtitle',
2525
2437
  'tertiary',
2526
2438
  'tertiaryTone',
@@ -2554,6 +2466,7 @@ const ROW_FIELDS: Readonly<Record<string, readonly string[]>> = {
2554
2466
  'presentation',
2555
2467
  'fee',
2556
2468
  'descriptionActionKey',
2469
+ 'descriptionActionStart',
2557
2470
  'footerActions',
2558
2471
  ],
2559
2472
  message: [
@@ -2698,8 +2611,6 @@ const PATCH_FIELDS: Readonly<Record<string, readonly string[]>> = {
2698
2611
  'titleIcon',
2699
2612
  'secondaryTitleIcon',
2700
2613
  'titleImage',
2701
- 'titleSegments',
2702
- 'titleLeadingIcon',
2703
2614
  'subtitle',
2704
2615
  'tertiary',
2705
2616
  'tertiaryTone',
@@ -2723,6 +2634,7 @@ const PATCH_FIELDS: Readonly<Record<string, readonly string[]>> = {
2723
2634
  'amounts',
2724
2635
  'fee',
2725
2636
  'descriptionActionKey',
2637
+ 'descriptionActionStart',
2726
2638
  'footerActions',
2727
2639
  ],
2728
2640
  message: [
@@ -2831,7 +2743,6 @@ function protocolKey(value: unknown, path: string): void {
2831
2743
  const PROTOCOL_ARRAY_FIELDS = new Set([
2832
2744
  'columns',
2833
2745
  'titleSuffixes',
2834
- 'titleSegments',
2835
2746
  'cells',
2836
2747
  'points',
2837
2748
  'images',
@@ -3073,10 +2984,7 @@ function assertRowProtocol(row: RowModel, path: string): void {
3073
2984
  if (row.height !== undefined && row.height < 0)
3074
2985
  fail(`${path}.height`, 'must be non-negative');
3075
2986
  if (row.type === 'identity') {
3076
- if (isDevelopment()) {
3077
- assertIdentityExtras(row, path);
3078
- assertIdentityTitleRuns(row, path);
3079
- }
2987
+ if (isDevelopment()) assertIdentityExtras(row, path);
3080
2988
  if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes))
3081
2989
  fail(`${path}.titleSuffixes`, 'must be an array');
3082
2990
  row.titleSuffixes?.forEach((suffix, index) => {
@@ -3673,14 +3581,6 @@ const NESTED_DECORATION_FIELDS: Readonly<Record<string, readonly string[]>> = {
3673
3581
 
3674
3582
  function sanitizeDecoration(value: unknown, field: string): unknown {
3675
3583
  if (value === undefined || value === null) return undefined;
3676
- if (field === 'titleSegments')
3677
- return passesTitleRunRules(() => assertTitleSegments(value, field))
3678
- ? value
3679
- : undefined;
3680
- if (field === 'titleLeadingIcon')
3681
- return passesTitleRunRules(() => assertTitleLeadingIcon(value, field))
3682
- ? value
3683
- : undefined;
3684
3584
  if (
3685
3585
  !Array.isArray(value) &&
3686
3586
  [
@@ -4050,6 +3950,11 @@ function sanitizeRowForProduction(row: RowModel): RowModel {
4050
3950
  delete next[field];
4051
3951
  continue;
4052
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
+ }
4053
3958
  if (field === 'parent' && isRecord(value))
4054
3959
  next[field] = sanitizeRowForProduction(value as unknown as RowModel);
4055
3960
  else if (field === 'children' && Array.isArray(value))
@@ -4981,6 +4886,16 @@ function mergeAndValidateSingleRow(
4981
4886
  )
4982
4887
  changes.subtitle = null;
4983
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;
4984
4899
  const merged = { ...previous } as unknown as Record<string, unknown>;
4985
4900
  for (const [field, value] of Object.entries(changes)) {
4986
4901
  if (value === null) delete merged[field];