@onekeyfe/react-native-native-list 6.8.0-24 → 6.8.0-26
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.
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +12 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +96 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +6 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +71 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +126 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +130 -0
- package/docs/ROW_TEMPLATES.md +8 -1
- package/docs/SPEC.md +156 -6
- package/ios/NativeListActivityDetailsView.swift +45 -1
- package/ios/NativeListIdentityRenderer.swift +109 -8
- package/ios/NativeListTitleSegmentLayout.swift +72 -0
- package/ios/NativeListTitleSegmentsLabel.swift +92 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +137 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +155 -0
- package/lib/module/models.js +2 -0
- package/lib/module/validation.js +77 -5
- package/lib/module/web/NativeListWebEngine.js +227 -90
- package/lib/module/web/templates/IdentityRowRenderer.js +122 -2
- package/lib/typescript/src/models.d.ts +21 -1
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +9 -1
- package/package.json +1 -1
- package/src/models.ts +23 -0
- package/src/validation.ts +129 -2
- package/src/web/NativeListWebEngine.ts +309 -105
- package/src/web/templates/IdentityRowRenderer.ts +185 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { applyTextWeight } from "./RowText.js";
|
|
3
|
+
import { applyTextWeight, fontWeight } from "./RowText.js";
|
|
4
4
|
import { applyTabularNumbers, hasExplicitRowHeight } from "./RowElements.js";
|
|
5
5
|
import { createElement, setData, tagSlot, markActionAnchorSource, createTextColumn, createBadge } from "./RowElements.js";
|
|
6
6
|
import { applyTextLayout, applyTextStyleToSlot, applyValueSegments } from "./RowText.js";
|
|
@@ -11,6 +11,57 @@ function toneColor(tone, fallback) {
|
|
|
11
11
|
if (tone === 'secondary') return 'var(--nl-secondary)';
|
|
12
12
|
return fallback === 'secondary' ? 'var(--nl-secondary)' : 'var(--nl-primary)';
|
|
13
13
|
}
|
|
14
|
+
// Hidden from sight, still read: the runs themselves are hidden from
|
|
15
|
+
// assistive technology in favor of `title`.
|
|
16
|
+
const VISUALLY_HIDDEN = {
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
width: '1px',
|
|
19
|
+
height: '1px',
|
|
20
|
+
overflow: 'hidden',
|
|
21
|
+
clip: 'rect(0 0 0 0)',
|
|
22
|
+
whiteSpace: 'nowrap'
|
|
23
|
+
};
|
|
24
|
+
function appendTitleRuns(document, target, row) {
|
|
25
|
+
const runs = createElement(document, 'span', 'ok-native-list-identity-title-runs');
|
|
26
|
+
runs.setAttribute('aria-hidden', 'true');
|
|
27
|
+
Object.assign(runs.style, {
|
|
28
|
+
display: 'flex',
|
|
29
|
+
flex: '1 1 auto',
|
|
30
|
+
minWidth: '0',
|
|
31
|
+
maxWidth: '100%',
|
|
32
|
+
overflow: 'hidden'
|
|
33
|
+
});
|
|
34
|
+
row.titleSegments?.forEach(segment => {
|
|
35
|
+
const run = createElement(document, 'span', 'ok-native-list-identity-title-run',
|
|
36
|
+
// A run is one line on every platform: `white-space: pre` would turn a
|
|
37
|
+
// hard break into a second line here.
|
|
38
|
+
segment.text.replace(/\r\n|[\r\n]/g, ' '));
|
|
39
|
+
// Only the shrinking run gives up width; a cap is a share of the line.
|
|
40
|
+
Object.assign(run.style, {
|
|
41
|
+
flex: segment.shrink ? '0 1 auto' : '0 0 auto',
|
|
42
|
+
minWidth: segment.shrink ? '0' : '',
|
|
43
|
+
maxWidth: segment.maxWidthRatio === undefined ? '' : `${segment.maxWidthRatio * 100}%`,
|
|
44
|
+
overflow: 'hidden',
|
|
45
|
+
textOverflow: 'ellipsis',
|
|
46
|
+
whiteSpace: 'pre'
|
|
47
|
+
});
|
|
48
|
+
if (segment.tone) run.style.color = segment.tone === 'secondary' ? 'var(--nl-secondary)' : 'var(--nl-primary)';
|
|
49
|
+
if (segment.fontWeight === 'medium') {
|
|
50
|
+
run.style.fontWeight = '500';
|
|
51
|
+
run.style.fontFamily = 'var(--nl-font-medium)';
|
|
52
|
+
} else if (segment.fontWeight === 'regular') {
|
|
53
|
+
run.style.fontWeight = '400';
|
|
54
|
+
run.style.fontFamily = 'var(--nl-font-regular)';
|
|
55
|
+
}
|
|
56
|
+
setData(run, 'tone', segment.tone);
|
|
57
|
+
runs.appendChild(run);
|
|
58
|
+
});
|
|
59
|
+
const spoken = createElement(document, 'span', 'ok-native-list-identity-title-spoken', row.title);
|
|
60
|
+
Object.assign(spoken.style, VISUALLY_HIDDEN);
|
|
61
|
+
target.replaceChildren(runs, spoken);
|
|
62
|
+
target.style.display = 'flex';
|
|
63
|
+
target.style.minWidth = '0';
|
|
64
|
+
}
|
|
14
65
|
function appendAccessories(parent, document, primitives, row, accessories) {
|
|
15
66
|
if (!accessories?.length) return;
|
|
16
67
|
const container = createElement(document, 'span', 'ok-native-list-accessories');
|
|
@@ -97,6 +148,13 @@ function createIdentityRow(document, primitives, row) {
|
|
|
97
148
|
fragment.appendChild(document.createTextNode(row.title.slice(offset)));
|
|
98
149
|
textTarget.prepend(fragment);
|
|
99
150
|
}
|
|
151
|
+
// The runs replace the plain title, except where `title` itself is
|
|
152
|
+
// highlighted or shown in the wallet sidebar.
|
|
153
|
+
const hasTitleRuns = !!row.titleSegments?.length && presentation !== 'walletSidebar' && !row.titleMatch?.length;
|
|
154
|
+
if (hasTitleRuns) {
|
|
155
|
+
const textTarget = titleElement.querySelector('[data-nl-slot="title"]') ?? titleElement;
|
|
156
|
+
appendTitleRuns(document, textTarget, row);
|
|
157
|
+
}
|
|
100
158
|
if (row.subtitleSegments?.length) {
|
|
101
159
|
column.querySelector('.ok-native-list-secondary')?.remove();
|
|
102
160
|
const segments = createElement(document, 'span', 'ok-native-list-subtitle-segments');
|
|
@@ -222,12 +280,59 @@ function createIdentityRow(document, primitives, row) {
|
|
|
222
280
|
badges.style.minWidth = '0';
|
|
223
281
|
}
|
|
224
282
|
}
|
|
283
|
+
if (hasTitleRuns) {
|
|
284
|
+
// The runs fill what the title line leaves, so a ratio is a share of
|
|
285
|
+
// that width and title accessories sit at the line's end.
|
|
286
|
+
const runs = titleElement.querySelector('.ok-native-list-identity-title-runs');
|
|
287
|
+
for (let node = runs?.parentElement; node && node !== titleElement; node = node.parentElement) {
|
|
288
|
+
node.style.display = 'flex';
|
|
289
|
+
node.style.flex = '1 1 auto';
|
|
290
|
+
node.style.minWidth = '0';
|
|
291
|
+
}
|
|
292
|
+
titleElement.style.display = 'flex';
|
|
293
|
+
titleElement.style.alignItems = 'center';
|
|
294
|
+
}
|
|
295
|
+
if (row.titleLeadingIcon && presentation !== 'walletSidebar') {
|
|
296
|
+
const descriptor = row.titleLeadingIcon;
|
|
297
|
+
if (titleElement.hasAttribute('data-nl-slot')) {
|
|
298
|
+
// Keep the glyph out of the title slot that text styles apply to.
|
|
299
|
+
const titleText = tagSlot(createElement(document, 'span', 'ok-native-list-identity-title-text'), 'title');
|
|
300
|
+
while (titleElement.firstChild) titleText.appendChild(titleElement.firstChild);
|
|
301
|
+
if (hasTitleRuns) {
|
|
302
|
+
titleText.style.display = 'flex';
|
|
303
|
+
// Created after the loop above gave the runs' ancestors their share:
|
|
304
|
+
// without it a ratio would be a share of the text's own width.
|
|
305
|
+
titleText.style.flex = '1 1 auto';
|
|
306
|
+
titleText.style.minWidth = '0';
|
|
307
|
+
}
|
|
308
|
+
titleElement.removeAttribute('data-nl-slot');
|
|
309
|
+
titleElement.appendChild(titleText);
|
|
310
|
+
}
|
|
311
|
+
// A label makes the passive glyph an image with that name.
|
|
312
|
+
const icon = primitives.iconAction(descriptor.name, undefined, undefined, descriptor.tintColor, descriptor.accessibilityLabel);
|
|
313
|
+
icon.className = 'ok-native-list-identity-title-leading-icon';
|
|
314
|
+
if (!descriptor.accessibilityLabel) icon.setAttribute('aria-hidden', 'true');
|
|
315
|
+
// The slot is 16px. Host artwork comes at 24px, and a name without
|
|
316
|
+
// artwork leaves the slot empty rather than a text glyph.
|
|
317
|
+
const artwork = icon.querySelector('svg');
|
|
318
|
+
if (artwork) {
|
|
319
|
+
artwork.setAttribute('width', '16');
|
|
320
|
+
artwork.setAttribute('height', '16');
|
|
321
|
+
} else icon.textContent = '';
|
|
322
|
+
titleElement.style.display = 'flex';
|
|
323
|
+
titleElement.style.alignItems = 'center';
|
|
324
|
+
// 6px to the title, whatever gap the title line already has.
|
|
325
|
+
const lineGap = Number.parseFloat(titleElement.style.gap || '0') || 0;
|
|
326
|
+
icon.style.marginInlineEnd = `${Math.max(0, 6 - lineGap)}px`;
|
|
327
|
+
titleElement.prepend(icon);
|
|
328
|
+
}
|
|
225
329
|
if (presentation === 'walletSidebar' && row.badges?.length) {
|
|
226
330
|
const badges = createElement(document, 'span', 'ok-native-list-wallet-badges');
|
|
227
331
|
row.badges.forEach(badge => badges.appendChild(createBadge(document, badge)));
|
|
228
332
|
column.appendChild(badges);
|
|
229
333
|
}
|
|
230
334
|
for (const key of ['title', 'subtitle']) {
|
|
335
|
+
if (key === 'title' && hasTitleRuns) continue;
|
|
231
336
|
const lines = row.style?.[key]?.lines ?? row[`${key}Lines`];
|
|
232
337
|
if (lines !== undefined) column.querySelectorAll(`[data-nl-slot="${key}"]`).forEach(text => {
|
|
233
338
|
applyTextLayout(text, lines === 0 ? {} : {
|
|
@@ -314,10 +419,25 @@ function applyIdentityStyle(body, row) {
|
|
|
314
419
|
const slotStyle = style[key];
|
|
315
420
|
if (!slotStyle) return;
|
|
316
421
|
body.querySelectorAll('[data-nl-slot="' + key + '"]').forEach(element => {
|
|
317
|
-
applyTextStyleToSlot(element, slotStyle);
|
|
422
|
+
if (key === 'title' && element.querySelector('.ok-native-list-identity-title-runs')) applyTitleStyleToRuns(element, slotStyle);else applyTextStyleToSlot(element, slotStyle);
|
|
318
423
|
});
|
|
319
424
|
});
|
|
320
425
|
}
|
|
426
|
+
// With runs, `style.title` only sets what a run inherits: a run that names its
|
|
427
|
+
// tone or weight keeps it, and the runs stay on one line whatever `lines` says.
|
|
428
|
+
function applyTitleStyleToRuns(slot, style) {
|
|
429
|
+
if (style.fontSize !== undefined) slot.style.fontSize = String(style.fontSize) + 'px';
|
|
430
|
+
if (style.lineHeight !== undefined) slot.style.lineHeight = String(style.lineHeight) + 'px';
|
|
431
|
+
if (style.fontWeight !== undefined) applyTextWeight(slot, String(fontWeight(style.fontWeight, 400)));
|
|
432
|
+
if (style.color !== undefined) slot.style.color = style.color;
|
|
433
|
+
if (style.tabularNumbers !== undefined) slot.style.fontVariantNumeric = style.tabularNumbers ? 'tabular-nums' : 'proportional-nums';
|
|
434
|
+
if (style.letterSpacing !== undefined) slot.style.letterSpacing = String(style.letterSpacing) + 'px';
|
|
435
|
+
// Paint only, as for a plain title: the line keeps its place in the layout.
|
|
436
|
+
if (style.offsetY !== undefined) {
|
|
437
|
+
const runs = slot.querySelector('.ok-native-list-identity-title-runs');
|
|
438
|
+
if (runs) runs.style.transform = `translateY(${style.offsetY}px)`;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
321
441
|
const views = new WeakMap();
|
|
322
442
|
function bind(body, row, primitives) {
|
|
323
443
|
const v = views.get(body);
|
|
@@ -400,6 +400,18 @@ export type RowBase = Readonly<{
|
|
|
400
400
|
accessibilityLabel?: string;
|
|
401
401
|
separator?: boolean;
|
|
402
402
|
}>;
|
|
403
|
+
/** One run of an identity title line; see docs/SPEC.md. */
|
|
404
|
+
export type IdentityTitleSegment = Readonly<{
|
|
405
|
+
text: string;
|
|
406
|
+
/** Omitted: the title color. */
|
|
407
|
+
tone?: 'primary' | 'secondary';
|
|
408
|
+
/** Omitted: the title weight. */
|
|
409
|
+
fontWeight?: 'regular' | 'medium';
|
|
410
|
+
/** The one run that gives up width when the line is too narrow. */
|
|
411
|
+
shrink?: boolean;
|
|
412
|
+
/** Caps the run at this fraction of the title line, within (0, 1]. */
|
|
413
|
+
maxWidthRatio?: number;
|
|
414
|
+
}>;
|
|
403
415
|
export type IdentityRow = RowBase & Readonly<{
|
|
404
416
|
type: 'identity';
|
|
405
417
|
/** Opt in to content-based height; explicit row/container height still wins. */
|
|
@@ -434,6 +446,14 @@ export type IdentityRow = RowBase & Readonly<{
|
|
|
434
446
|
}>;
|
|
435
447
|
/** Web-only additional help icon after titleIcon. */
|
|
436
448
|
secondaryTitleIcon?: IdentityRow['titleIcon'];
|
|
449
|
+
/** Runs drawn in place of `title`, which stays the spoken label. */
|
|
450
|
+
titleSegments?: readonly IdentityTitleSegment[];
|
|
451
|
+
/** 16-point glyph before the title; decorative unless labelled. */
|
|
452
|
+
titleLeadingIcon?: Readonly<{
|
|
453
|
+
name: string;
|
|
454
|
+
tintColor?: string;
|
|
455
|
+
accessibilityLabel?: string;
|
|
456
|
+
}>;
|
|
437
457
|
/** Circular image after title icons; image dimensions must be square, 1...40. */
|
|
438
458
|
titleImage?: Readonly<{
|
|
439
459
|
image: ImageSource;
|
|
@@ -911,7 +931,7 @@ export type PatchClearableChanges<Row, Keys extends keyof Row> = Readonly<{
|
|
|
911
931
|
export type RowPatch = Readonly<{
|
|
912
932
|
type: 'identity';
|
|
913
933
|
key: string;
|
|
914
|
-
changes: PatchClearableChanges<IdentityRow, CommonPatchFields | 'title' | 'titleSuffixes' | 'titleIcon' | 'secondaryTitleIcon' | 'titleImage' | 'subtitle' | 'subtitleLines' | 'collapseEmptyTrailing' | 'contentHeight' | 'longPressActionKey' | 'tertiary' | 'tertiaryTone' | 'badges' | 'trailing' | 'leading' | 'leadingAction' | 'titleMatch' | 'titleActionKey' | 'titleActionOnHover' | 'subtitleSegments'>;
|
|
934
|
+
changes: PatchClearableChanges<IdentityRow, CommonPatchFields | 'title' | 'titleSuffixes' | 'titleIcon' | 'secondaryTitleIcon' | 'titleImage' | 'titleSegments' | 'titleLeadingIcon' | 'subtitle' | 'subtitleLines' | 'collapseEmptyTrailing' | 'contentHeight' | 'longPressActionKey' | 'tertiary' | 'tertiaryTone' | 'badges' | 'trailing' | 'leading' | 'leadingAction' | 'titleMatch' | 'titleActionKey' | 'titleActionOnHover' | 'subtitleSegments'>;
|
|
915
935
|
}> | Readonly<{
|
|
916
936
|
type: 'rail';
|
|
917
937
|
key: string;
|
|
@@ -191,6 +191,8 @@ export declare class NativeListWebEngine {
|
|
|
191
191
|
private applyValidatedSnapshot;
|
|
192
192
|
private cancelStructuralAnimation;
|
|
193
193
|
private handleStructuralUserScroll;
|
|
194
|
+
private wheelReachesScrollOwner;
|
|
195
|
+
private hasNegativeScrollOffsets;
|
|
194
196
|
private updateStructuralTailWindow;
|
|
195
197
|
private writeStructuralHeight;
|
|
196
198
|
private reactFooterElement;
|
|
@@ -201,7 +203,7 @@ export declare class NativeListWebEngine {
|
|
|
201
203
|
currentSnapshot(): NativeListSnapshot;
|
|
202
204
|
applyPatches(patches: readonly RowPatch[]): void;
|
|
203
205
|
reconcileSelection(keys: readonly string[]): void;
|
|
204
|
-
scrollToIndex(index: number, scroll: NormalizedPositionScroll): void;
|
|
206
|
+
scrollToIndex(index: number, scroll: NormalizedPositionScroll, behavior?: ScrollBehavior): void;
|
|
205
207
|
scrollToKey(key: string, scroll: NormalizedPositionScroll): void;
|
|
206
208
|
scrollToOffset(offset: number, animated: boolean): void;
|
|
207
209
|
scrollToEnd(animated: boolean): void;
|
|
@@ -223,6 +225,8 @@ export declare class NativeListWebEngine {
|
|
|
223
225
|
private updateAvatarWindow;
|
|
224
226
|
private renderWindow;
|
|
225
227
|
private positionElement;
|
|
228
|
+
private updateRowReorderability;
|
|
229
|
+
private canStartKeyboardReorder;
|
|
226
230
|
private renderElement;
|
|
227
231
|
private renderFooter;
|
|
228
232
|
private sectionIndexVisibleEntryIndices;
|
|
@@ -282,6 +286,7 @@ export declare class NativeListWebEngine {
|
|
|
282
286
|
private moveKeyboardReorder;
|
|
283
287
|
private finishKeyboardReorder;
|
|
284
288
|
private cancelKeyboardReorder;
|
|
289
|
+
private setReorderRows;
|
|
285
290
|
private focusMountedRow;
|
|
286
291
|
private handleExternalScroll;
|
|
287
292
|
private handleScroll;
|
|
@@ -300,6 +305,7 @@ export declare class NativeListWebEngine {
|
|
|
300
305
|
private updateRefreshIndicator;
|
|
301
306
|
private handleReorderPointerDown;
|
|
302
307
|
private canStartPointerReorder;
|
|
308
|
+
private pointerReorderSourceIndex;
|
|
303
309
|
private activatePointerReorder;
|
|
304
310
|
private captureReorderPointer;
|
|
305
311
|
private releaseReorderPointer;
|
|
@@ -320,6 +326,7 @@ export declare class NativeListWebEngine {
|
|
|
320
326
|
private runReorderMove;
|
|
321
327
|
private flushReorderMove;
|
|
322
328
|
private stopReorderMove;
|
|
329
|
+
private reorderPointerCoordinate;
|
|
323
330
|
private reorderIndexAtPointer;
|
|
324
331
|
private movePointerReorderTo;
|
|
325
332
|
private canReuseReorderLayout;
|
|
@@ -331,6 +338,7 @@ export declare class NativeListWebEngine {
|
|
|
331
338
|
private completePointerReorder;
|
|
332
339
|
private handleReorderPointerCancel;
|
|
333
340
|
private stopReorderAutoScroll;
|
|
341
|
+
private cancelPendingPointerReorder;
|
|
334
342
|
private cancelPointerReorder;
|
|
335
343
|
private remapMountedRows;
|
|
336
344
|
private updateReorderVisualState;
|
package/package.json
CHANGED
package/src/models.ts
CHANGED
|
@@ -519,6 +519,19 @@ export type RowBase = Readonly<{
|
|
|
519
519
|
separator?: boolean;
|
|
520
520
|
}>;
|
|
521
521
|
|
|
522
|
+
/** One run of an identity title line; see docs/SPEC.md. */
|
|
523
|
+
export type IdentityTitleSegment = Readonly<{
|
|
524
|
+
text: string;
|
|
525
|
+
/** Omitted: the title color. */
|
|
526
|
+
tone?: 'primary' | 'secondary';
|
|
527
|
+
/** Omitted: the title weight. */
|
|
528
|
+
fontWeight?: 'regular' | 'medium';
|
|
529
|
+
/** The one run that gives up width when the line is too narrow. */
|
|
530
|
+
shrink?: boolean;
|
|
531
|
+
/** Caps the run at this fraction of the title line, within (0, 1]. */
|
|
532
|
+
maxWidthRatio?: number;
|
|
533
|
+
}>;
|
|
534
|
+
|
|
522
535
|
export type IdentityRow = RowBase &
|
|
523
536
|
Readonly<{
|
|
524
537
|
type: 'identity';
|
|
@@ -550,6 +563,14 @@ export type IdentityRow = RowBase &
|
|
|
550
563
|
}>;
|
|
551
564
|
/** Web-only additional help icon after titleIcon. */
|
|
552
565
|
secondaryTitleIcon?: IdentityRow['titleIcon'];
|
|
566
|
+
/** Runs drawn in place of `title`, which stays the spoken label. */
|
|
567
|
+
titleSegments?: readonly IdentityTitleSegment[];
|
|
568
|
+
/** 16-point glyph before the title; decorative unless labelled. */
|
|
569
|
+
titleLeadingIcon?: Readonly<{
|
|
570
|
+
name: string;
|
|
571
|
+
tintColor?: string;
|
|
572
|
+
accessibilityLabel?: string;
|
|
573
|
+
}>;
|
|
553
574
|
/** Circular image after title icons; image dimensions must be square, 1...40. */
|
|
554
575
|
titleImage?: Readonly<{
|
|
555
576
|
image: ImageSource;
|
|
@@ -1124,6 +1145,8 @@ export type RowPatch =
|
|
|
1124
1145
|
| 'titleIcon'
|
|
1125
1146
|
| 'secondaryTitleIcon'
|
|
1126
1147
|
| 'titleImage'
|
|
1148
|
+
| 'titleSegments'
|
|
1149
|
+
| 'titleLeadingIcon'
|
|
1127
1150
|
| 'subtitle'
|
|
1128
1151
|
| 'subtitleLines'
|
|
1129
1152
|
| 'collapseEmptyTrailing'
|
package/src/validation.ts
CHANGED
|
@@ -1357,6 +1357,110 @@ function assertButtonGroup(
|
|
|
1357
1357
|
});
|
|
1358
1358
|
}
|
|
1359
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
|
+
|
|
1360
1464
|
// A passive label: its text and two caller colors, with no action or style slot.
|
|
1361
1465
|
function assertWebLeadingBadge(value: unknown, path: string): void {
|
|
1362
1466
|
if (value === undefined) return;
|
|
@@ -1892,6 +1996,7 @@ function assertRow(
|
|
|
1892
1996
|
);
|
|
1893
1997
|
});
|
|
1894
1998
|
assertIdentityExtras(row, path);
|
|
1999
|
+
assertIdentityTitleRuns(row, path);
|
|
1895
2000
|
assertText(row.subtitle, `${path}.subtitle`);
|
|
1896
2001
|
// OneKey patch: selector text segments truncate independently.
|
|
1897
2002
|
row.subtitleSegments?.forEach((segment, segmentIndex) => {
|
|
@@ -2485,6 +2590,8 @@ const ROW_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
2485
2590
|
'titleIcon',
|
|
2486
2591
|
'secondaryTitleIcon',
|
|
2487
2592
|
'titleImage',
|
|
2593
|
+
'titleSegments',
|
|
2594
|
+
'titleLeadingIcon',
|
|
2488
2595
|
'subtitle',
|
|
2489
2596
|
'tertiary',
|
|
2490
2597
|
'tertiaryTone',
|
|
@@ -2664,6 +2771,8 @@ const PATCH_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
2664
2771
|
'titleIcon',
|
|
2665
2772
|
'secondaryTitleIcon',
|
|
2666
2773
|
'titleImage',
|
|
2774
|
+
'titleSegments',
|
|
2775
|
+
'titleLeadingIcon',
|
|
2667
2776
|
'subtitle',
|
|
2668
2777
|
'tertiary',
|
|
2669
2778
|
'tertiaryTone',
|
|
@@ -2797,6 +2906,7 @@ function protocolKey(value: unknown, path: string): void {
|
|
|
2797
2906
|
const PROTOCOL_ARRAY_FIELDS = new Set([
|
|
2798
2907
|
'columns',
|
|
2799
2908
|
'titleSuffixes',
|
|
2909
|
+
'titleSegments',
|
|
2800
2910
|
'cells',
|
|
2801
2911
|
'points',
|
|
2802
2912
|
'images',
|
|
@@ -3042,7 +3152,10 @@ function assertRowProtocol(row: RowModel, path: string): void {
|
|
|
3042
3152
|
if (row.height !== undefined && row.height < 0)
|
|
3043
3153
|
fail(`${path}.height`, 'must be non-negative');
|
|
3044
3154
|
if (row.type === 'identity') {
|
|
3045
|
-
if (isDevelopment())
|
|
3155
|
+
if (isDevelopment()) {
|
|
3156
|
+
assertIdentityExtras(row, path);
|
|
3157
|
+
assertIdentityTitleRuns(row, path);
|
|
3158
|
+
}
|
|
3046
3159
|
if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes))
|
|
3047
3160
|
fail(`${path}.titleSuffixes`, 'must be an array');
|
|
3048
3161
|
row.titleSuffixes?.forEach((suffix, index) => {
|
|
@@ -3660,6 +3773,14 @@ const NESTED_DECORATION_FIELDS: Readonly<Record<string, readonly string[]>> = {
|
|
|
3660
3773
|
|
|
3661
3774
|
function sanitizeDecoration(value: unknown, field: string): unknown {
|
|
3662
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;
|
|
3663
3784
|
// All or nothing: a badge without valid text and both colors is dropped, and
|
|
3664
3785
|
// only its three declared fields are kept.
|
|
3665
3786
|
if (field === 'webLeadingBadge') {
|
|
@@ -4445,6 +4566,8 @@ function assertPatchChanges(patch: PatchValues, index: number): void {
|
|
|
4445
4566
|
);
|
|
4446
4567
|
});
|
|
4447
4568
|
assertIdentityExtras(patch.changes, path);
|
|
4569
|
+
// A null clear never reaches here; a replacement follows the row rules.
|
|
4570
|
+
assertIdentityTitleRuns(patch.changes, path);
|
|
4448
4571
|
assertText(patch.changes.subtitle, `${path}.subtitle`);
|
|
4449
4572
|
assertText(patch.changes.tertiary, `${path}.tertiary`);
|
|
4450
4573
|
if (
|
|
@@ -4735,7 +4858,11 @@ function normalizePatch(patch: RowPatch, index: number): RowPatch | undefined {
|
|
|
4735
4858
|
? sanitizeMarketMetrics(normalized)
|
|
4736
4859
|
: sanitizeDecoration(normalized, field);
|
|
4737
4860
|
if (canonical !== undefined) changes[field] = canonical;
|
|
4738
|
-
|
|
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;
|
|
4739
4866
|
}
|
|
4740
4867
|
if (
|
|
4741
4868
|
patch.type === 'market' &&
|