@onekeyfe/react-native-native-list 6.8.0-25 → 6.8.0-27

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.
@@ -519,4 +519,141 @@ final class NativeListActivityPresentationTests: XCTestCase {
519
519
  rendered, accuracy: 1, name)
520
520
  }
521
521
  }
522
+
523
+ // OK-67497: History rows with a risk badge ("High risk") must keep the badge right
524
+ // after the title, like the identity title row (OK-66041). The title line used to
525
+ // stretch the title across the identity column, pushing badges to the amount column.
526
+ func testTitleBadgesFollowTheTitleTextAndSurviveRebind() throws {
527
+ func data(title: String, badges: Bool) -> [String: Any] {
528
+ var value: [String: Any] = [
529
+ "type": "activity", "key": "receive", "title": title, "description": "0xc168f7...62f46d",
530
+ "leading": ["kind": "icon", "name": "ArrowBottomOutline"],
531
+ "amounts": [["key": "usdt", "text": "+1,250 USDT", "secondaryText": "$1,250.13"]],
532
+ ]
533
+ if badges { value["badges"] = [["key": "risk", "text": "High risk", "tone": "warning"]] }
534
+ return value
535
+ }
536
+ let details = NativeListActivityDetailsView()
537
+ let container = UIView(frame: CGRect(x: 0, y: 0, width: 390, height: 200))
538
+ details.translatesAutoresizingMaskIntoConstraints = false
539
+ container.addSubview(details)
540
+ NSLayoutConstraint.activate([
541
+ details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
542
+ details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
543
+ details.topAnchor.constraint(equalTo: container.topAnchor),
544
+ ])
545
+ let title = try XCTUnwrap(Mirror(reflecting: details).children.first { $0.label == "title" }?.value as? UILabel)
546
+ let titleLine = try XCTUnwrap(Mirror(reflecting: details).children.first { $0.label == "titleLine" }?.value as? UIStackView)
547
+ func badge() throws -> UILabel {
548
+ let views = try XCTUnwrap(Mirror(reflecting: details).children.first { $0.label == "badgeViews" }?.value as? [UILabel])
549
+ return try XCTUnwrap(views.first)
550
+ }
551
+ // Direct bind skips NativeListRendererCell.bind, which marks the host dirty.
552
+ // Without setNeedsLayout a later layoutIfNeeded keeps the previous frames.
553
+ func layout(_ host: UIView) {
554
+ host.setNeedsLayout()
555
+ host.layoutIfNeeded()
556
+ }
557
+
558
+ details.bind(try NativeListItem(data: data(title: "Receive", badges: true)), theme: nil, fonts: NativeListFontFamilies())
559
+ layout(container)
560
+ let amountsColumn = try XCTUnwrap(details.arrangedSubviews.first as? UIStackView).arrangedSubviews[2]
561
+ func widestText(_ view: UIView) -> CGFloat {
562
+ if view.isHidden { return 0 }
563
+ let own = (view as? UILabel).map {
564
+ ($0.text ?? "").isEmpty ? 0 : $0.intrinsicContentSize.width
565
+ } ?? 0
566
+ return view.subviews.reduce(own) { max($0, widestText($1)) }
567
+ }
568
+ XCTAssertEqual(amountsColumn.bounds.width, widestText(amountsColumn), accuracy: 1,
569
+ "stacked amounts keep their text width and leave the row's slack to the identity column")
570
+ XCTAssertEqual(title.bounds.width, title.intrinsicContentSize.width, accuracy: 1,
571
+ "title must keep its intrinsic width instead of stretching across the title line")
572
+ var titleFrame = title.convert(title.bounds, to: titleLine)
573
+ var badgeFrame = try badge().convert(try badge().bounds, to: titleLine)
574
+ XCTAssertEqual(badgeFrame.minX, titleFrame.maxX + 4, accuracy: 1, "badge follows the title with titleBadgeGap")
575
+ // Before the fix the title stretched across the line and the badge ended flush with it.
576
+ XCTAssertGreaterThan(titleLine.bounds.width - badgeFrame.maxX, 20,
577
+ "the line's slack stays after the badge instead of before it")
578
+
579
+ // A long title truncates in front of the badge; the badge stays whole inside the line.
580
+ details.bind(try NativeListItem(data: data(title: String(repeating: "Contract interaction ", count: 6), badges: true)),
581
+ theme: nil, fonts: NativeListFontFamilies())
582
+ layout(container)
583
+ titleFrame = title.convert(title.bounds, to: titleLine)
584
+ badgeFrame = try badge().convert(try badge().bounds, to: titleLine)
585
+ XCTAssertEqual(badgeFrame.minX, titleFrame.maxX + 4, accuracy: 1)
586
+ XCTAssertLessThanOrEqual(badgeFrame.maxX, titleLine.bounds.width + 0.5)
587
+ XCTAssertEqual(try badge().bounds.width, try badge().intrinsicContentSize.width, accuracy: 1)
588
+
589
+ // Rebinding without badges gives the title the whole line again.
590
+ details.bind(try NativeListItem(data: data(title: String(repeating: "Contract interaction ", count: 6), badges: false)),
591
+ theme: nil, fonts: NativeListFontFamilies())
592
+ layout(container)
593
+ XCTAssertEqual(title.convert(title.bounds, to: titleLine).maxX, titleLine.bounds.width, accuracy: 1)
594
+
595
+ // Without badges a short title still spans the line, so `alignment: center` keeps
596
+ // centering it on a recycled row exactly as on a fresh one.
597
+ var centered = data(title: "Receive", badges: false)
598
+ centered["style"] = ["title": ["alignment": "center"]]
599
+ details.bind(try NativeListItem(data: centered), theme: nil, fonts: NativeListFontFamilies())
600
+ layout(container)
601
+ XCTAssertEqual(title.bounds.width, titleLine.bounds.width, accuracy: 1)
602
+ XCTAssertEqual(title.textAlignment, .center)
603
+ let fresh = NativeListActivityDetailsView()
604
+ let freshContainer = UIView(frame: container.frame)
605
+ fresh.translatesAutoresizingMaskIntoConstraints = false
606
+ freshContainer.addSubview(fresh)
607
+ NSLayoutConstraint.activate([
608
+ fresh.leadingAnchor.constraint(equalTo: freshContainer.leadingAnchor),
609
+ fresh.trailingAnchor.constraint(equalTo: freshContainer.trailingAnchor),
610
+ fresh.topAnchor.constraint(equalTo: freshContainer.topAnchor),
611
+ ])
612
+ fresh.bind(try NativeListItem(data: centered), theme: nil, fonts: NativeListFontFamilies())
613
+ layout(freshContainer)
614
+ let freshTitle = try XCTUnwrap(Mirror(reflecting: fresh).children.first { $0.label == "title" }?.value as? UILabel)
615
+ XCTAssertEqual(title.frame, freshTitle.frame, "recycled and fresh rows lay out the title the same way")
616
+ }
617
+
618
+ // Amount labels share the stacked column's width. A short amount (hugging) must not
619
+ // squeeze a longer one (compression), whatever the order or number of lines.
620
+ func testStackedAmountsKeepTheLongestTextWhole() throws {
621
+ let details = NativeListActivityDetailsView()
622
+ let container = UIView(frame: CGRect(x: 0, y: 0, width: 390, height: 2000))
623
+ details.translatesAutoresizingMaskIntoConstraints = false
624
+ container.addSubview(details)
625
+ NSLayoutConstraint.activate([
626
+ details.leadingAnchor.constraint(equalTo: container.leadingAnchor),
627
+ details.trailingAnchor.constraint(equalTo: container.trailingAnchor),
628
+ details.topAnchor.constraint(equalTo: container.topAnchor),
629
+ ])
630
+ func labels(_ view: UIView) -> [UILabel] {
631
+ if view.isHidden { return [] }
632
+ return ((view as? UILabel).map { [$0] } ?? []) + view.subviews.flatMap(labels)
633
+ }
634
+ let long = ["key": "long", "text": "+123,456.78 USDT", "secondaryText": "$1"]
635
+ let cases: [(String, [[String: Any]])] = [
636
+ ("long first", [long, ["key": "short", "text": "1", "secondaryText": "$1"]]),
637
+ ("long last", [["key": "short", "text": "1", "secondaryText": "$1"], long]),
638
+ ("six lines", (0..<6).map { $0 == 3 ? long : ["key": "s\($0)", "text": "\($0)", "secondaryText": "$1"] }),
639
+ ("32 lines", (0..<32).map { $0 == 31 ? long : ["key": "s\($0)", "text": "\($0)", "secondaryText": "$1"] }),
640
+ ]
641
+ for (name, amounts) in cases {
642
+ details.bind(try NativeListItem(data: [
643
+ "type": "activity", "key": "tx", "title": "Receive", "description": "0xc168f7...62f46d",
644
+ "leading": ["kind": "icon", "name": "ArrowBottomOutline"], "hideLeading": true,
645
+ "amounts": amounts,
646
+ ]), theme: nil, fonts: NativeListFontFamilies())
647
+ container.setNeedsLayout()
648
+ container.layoutIfNeeded()
649
+ let column = try XCTUnwrap(details.arrangedSubviews.first as? UIStackView).arrangedSubviews[2]
650
+ let texts = labels(column).filter { !($0.text ?? "").isEmpty }
651
+ let widest = texts.map(\.intrinsicContentSize.width).max() ?? 0
652
+ XCTAssertEqual(column.bounds.width, widest, accuracy: 1, name)
653
+ for label in texts {
654
+ XCTAssertGreaterThanOrEqual(label.bounds.width + 0.5, label.intrinsicContentSize.width,
655
+ "\(name): \(label.text ?? "") is not truncated")
656
+ }
657
+ }
658
+ }
522
659
  }
@@ -78,4 +78,159 @@ final class NativeListIdentityTitleIconLayoutTests: XCTestCase {
78
78
  XCTAssertGreaterThan(badgeFrame.minX, iconFrame.maxX)
79
79
  XCTAssertLessThanOrEqual(badgeFrame.maxX, cell.bounds.width)
80
80
  }
81
+
82
+ // An address book row: a plain title after the 16pt `titleLeadingIcon`. A
83
+ // long name truncates after the glyph instead of squeezing it to nothing.
84
+ func testLongPlainTitleTruncatesAfterTheLeadingIcon() throws {
85
+ let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
86
+ let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
87
+ window.addSubview(cell)
88
+ let leadingIcon = try child(cell, "titleLeadingIconView", as: UIImageView.self)
89
+ let titleLabel = try child(cell, "titleLabel", as: UILabel.self)
90
+ let item = try NativeListItem(data: [
91
+ "key": "book", "type": "identity",
92
+ "title": "A very long address book name that cannot possibly fit on one line",
93
+ "height": 60,
94
+ "leading": ["kind": "token", "fallbackIcon": ["name": "CryptoCoinOutline"]],
95
+ "titleLeadingIcon": ["name": "BookOpenOutline"],
96
+ "subtitle": "0x1234...abcd",
97
+ ])
98
+ cell.bind(item: item, theme: nil, layout: "linear", selected: false,
99
+ checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
100
+ cell.layoutIfNeeded()
101
+
102
+ let iconFrame = leadingIcon.convert(leadingIcon.bounds, to: cell)
103
+ let labelFrame = titleLabel.convert(titleLabel.bounds, to: cell)
104
+ XCTAssertFalse(leadingIcon.isHidden)
105
+ XCTAssertEqual(leadingIcon.bounds.width, 16, accuracy: 0.5,
106
+ "the leading glyph keeps its 16pt width")
107
+ XCTAssertEqual(labelFrame.minX, iconFrame.maxX + 6, accuracy: 1,
108
+ "the title follows the glyph with the 6pt gap")
109
+ XCTAssertLessThan(titleLabel.bounds.width, titleLabel.intrinsicContentSize.width,
110
+ "the title truncates instead of the glyph")
111
+ XCTAssertLessThanOrEqual(labelFrame.maxX, cell.bounds.width)
112
+ }
113
+
114
+ // A wallet sidebar row keeps the plain title even when a production row
115
+ // carries runs and a leading glyph, also after the cell drew both for a
116
+ // recipient row.
117
+ func testWalletSidebarRowIgnoresTitleRunsAndLeadingIcon() throws {
118
+ let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 68))
119
+ let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
120
+ window.addSubview(cell)
121
+ let titleLabel = try child(cell, "titleLabel", as: UILabel.self)
122
+ let runs = try child(cell, "titleSegmentsLabel", as: UIView.self)
123
+ let leadingIcon = try child(cell, "titleLeadingIconView", as: UIImageView.self)
124
+ let decorations: [String: Any] = [
125
+ "titleSegments": [
126
+ ["text": "Main", "shrink": true],
127
+ ["text": " / ", "tone": "secondary"],
128
+ ["text": "Account 1"],
129
+ ],
130
+ "titleLeadingIcon": ["name": "BookOpenOutline"],
131
+ ]
132
+ func bind(_ data: [String: Any]) throws {
133
+ var row: [String: Any] = [
134
+ "key": "wallet", "type": "identity", "title": "Main / Account 1", "height": 68,
135
+ ]
136
+ data.forEach { row[$0.key] = $0.value }
137
+ cell.bind(item: try NativeListItem(data: row), theme: nil, layout: "linear",
138
+ selected: false, checkboxState: { _, _, fallback in fallback },
139
+ fonts: NativeListFontFamilies())
140
+ cell.layoutIfNeeded()
141
+ }
142
+
143
+ try bind(decorations)
144
+ XCTAssertFalse(runs.isHidden)
145
+ XCTAssertFalse(leadingIcon.isHidden)
146
+
147
+ try bind(decorations.merging(["presentation": "walletSidebar"]) { $1 })
148
+ XCTAssertTrue(runs.isHidden, "wallet sidebar rows draw no runs")
149
+ XCTAssertTrue(leadingIcon.isHidden, "wallet sidebar rows draw no leading glyph")
150
+ XCTAssertFalse(titleLabel.isHidden)
151
+ XCTAssertEqual(titleLabel.text, "Main / Account 1")
152
+ }
153
+
154
+ // `titleMatch` keeps the plain highlighted title on screen, so an
155
+ // auto-height row is measured for that title and its `titleLines`, not for
156
+ // one line of runs.
157
+ func testHighlightedTitleIsMeasuredWithItsOwnLines() throws {
158
+ func height(_ data: [String: Any]) throws -> CGFloat {
159
+ var row: [String: Any] = [
160
+ "key": "match", "type": "identity", "contentHeight": "auto",
161
+ "title": "A very long recipient name that needs a second line to show",
162
+ "titleLines": 2, "titleMatch": [["start": 0, "end": 6]],
163
+ "subtitle": "0x1234...abcd",
164
+ ]
165
+ data.forEach { row[$0.key] = $0.value }
166
+ return try XCTUnwrap(NativeListIdentityCell.measure(
167
+ try NativeListItem(data: row), width: 240, theme: nil, layout: "linear",
168
+ fonts: NativeListFontFamilies()))
169
+ }
170
+ let runs: [[String: Any]] = [["text": "A very long", "shrink": true], ["text": " recipient"]]
171
+
172
+ let plain = try height([:])
173
+ XCTAssertEqual(try height(["titleSegments": runs]), plain, accuracy: 0.5)
174
+ XCTAssertGreaterThan(plain, try height(["titleLines": 1]))
175
+ }
176
+
177
+ private func autoHeight(_ data: [String: Any], width: CGFloat) throws -> CGFloat {
178
+ var row: [String: Any] = [
179
+ "key": "auto", "type": "identity", "contentHeight": "auto",
180
+ "title": "A very long recipient name that needs more than one line to show in full",
181
+ "titleLines": 3, "subtitle": "0x1234...abcd",
182
+ ]
183
+ data.forEach { row[$0.key] = $0.value }
184
+ return try XCTUnwrap(NativeListIdentityCell.measure(
185
+ try NativeListItem(data: row), width: width, theme: nil, layout: "linear",
186
+ fonts: NativeListFontFamilies()))
187
+ }
188
+
189
+ // The leading glyph and its gap take 22 points from the title, so the row
190
+ // measures like a plain row that much narrower, at every wrapping boundary.
191
+ func testAutoHeightCountsTheLeadingIconInTheTitleWidth() throws {
192
+ let icon: [String: Any] = ["name": "BookOpenOutline"]
193
+ for width in stride(from: CGFloat(200), through: 320, by: 6) {
194
+ XCTAssertEqual(
195
+ try autoHeight(["titleLeadingIcon": icon], width: width),
196
+ try autoHeight([:], width: width - 22), accuracy: 0.5, "width \(width)")
197
+ }
198
+ }
199
+
200
+ // Runs are one line, so `style.title.lines` must not reserve more for them.
201
+ func testRunsAreMeasuredAsOneLineWhateverTheTitleStyleAsksFor() throws {
202
+ let runs: [[String: Any]] = [["text": "A very long", "shrink": true], ["text": " recipient"]]
203
+ let twoLines: [String: Any] = ["title": ["lines": 2]]
204
+
205
+ let oneLine = try autoHeight(["titleSegments": runs, "titleLines": 1], width: 240)
206
+ XCTAssertEqual(
207
+ try autoHeight(["titleSegments": runs, "style": twoLines], width: 240), oneLine, accuracy: 0.5)
208
+ XCTAssertGreaterThan(try autoHeight(["style": twoLines], width: 240), oneLine)
209
+ }
210
+
211
+ // `style.title.offsetY` moves the runs as it moves a plain title, and a
212
+ // later row without it starts from zero again.
213
+ func testRunsTakeTheTitleOpticalOffset() throws {
214
+ let cell = NativeListIdentityCell(frame: CGRect(x: 0, y: 0, width: 320, height: 60))
215
+ let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
216
+ window.addSubview(cell)
217
+ let runsLabel = try child(cell, "titleSegmentsLabel", as: NativeListTitleSegmentsLabel.self)
218
+ func bind(_ style: [String: Any]?) throws {
219
+ var row: [String: Any] = [
220
+ "key": "runs", "type": "identity", "title": "Wallet / Account", "height": 60,
221
+ "titleSegments": [["text": "Wallet", "shrink": true], ["text": " / Account"]],
222
+ ]
223
+ if let style { row["style"] = style }
224
+ cell.bind(item: try NativeListItem(data: row), theme: nil, layout: "linear", selected: false,
225
+ checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
226
+ cell.layoutIfNeeded()
227
+ }
228
+
229
+ try bind(["title": ["offsetY": 3]])
230
+ XCTAssertFalse(runsLabel.isHidden)
231
+ XCTAssertEqual(runsLabel.offsetY, 3, accuracy: 0.01)
232
+
233
+ try bind(nil)
234
+ XCTAssertEqual(runsLabel.offsetY, 0, accuracy: 0.01)
235
+ }
81
236
  }
@@ -39,6 +39,8 @@ export const ROW_BOX_STYLE_KEYS_BY_TYPE = {
39
39
 
40
40
  // OneKey patch: preserve compact very-small-balance digit runs.
41
41
 
42
+ /** One run of an identity title line; see docs/SPEC.md. */
43
+
42
44
  /** Native Market quote row. All values are already localized/formatted strings. */
43
45
 
44
46
  /** Compact KPI card for dashboards and grids. */
@@ -704,6 +704,68 @@ function assertButtonGroup(row, path) {
704
704
  }
705
705
  });
706
706
  }
707
+ const MAX_TITLE_SEGMENTS = 4;
708
+ const HEX_COLOR_PATTERN = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
709
+ function assertTitleSegments(value, path) {
710
+ if (!Array.isArray(value) || value.length === 0 || value.length > MAX_TITLE_SEGMENTS) fail(path, `must hold 1...${MAX_TITLE_SEGMENTS} segments`);
711
+ let shrinking = 0;
712
+ // Array.from also visits holes, so a sparse list is rejected here and the
713
+ // production sanitizer drops it before protocol validation walks it.
714
+ Array.from(value).forEach((item, index) => {
715
+ const segmentPath = `${path}[${index}]`;
716
+ const segment = protocolObject(item, segmentPath);
717
+ assertUnknownKeys(segment, ['text', 'tone', 'fontWeight', 'shrink', 'maxWidthRatio'], segmentPath, 'title segment key');
718
+ const {
719
+ text,
720
+ tone,
721
+ fontWeight,
722
+ shrink,
723
+ maxWidthRatio
724
+ } = segment;
725
+ if (typeof text !== 'string' || !text.trim()) fail(`${segmentPath}.text`, 'must be non-blank');
726
+ assertText(text, `${segmentPath}.text`);
727
+ if (tone !== undefined && tone !== 'primary' && tone !== 'secondary') fail(`${segmentPath}.tone`, 'must be primary or secondary');
728
+ if (fontWeight !== undefined && fontWeight !== 'regular' && fontWeight !== 'medium') fail(`${segmentPath}.fontWeight`, 'must be regular or medium');
729
+ if (shrink !== undefined && typeof shrink !== 'boolean') fail(`${segmentPath}.shrink`, 'must be a boolean');
730
+ if (shrink) shrinking += 1;
731
+ if (maxWidthRatio !== undefined && (typeof maxWidthRatio !== 'number' || !Number.isFinite(maxWidthRatio) || maxWidthRatio <= 0 || maxWidthRatio > 1)) fail(`${segmentPath}.maxWidthRatio`, 'must be finite within (0, 1]');
732
+ });
733
+ if (shrinking > 1) fail(path, 'allows at most one shrinking segment');
734
+ }
735
+ function assertTitleLeadingIcon(value, path) {
736
+ const icon = protocolObject(value, path);
737
+ assertUnknownKeys(icon, ['name', 'tintColor', 'accessibilityLabel'], path, 'title leading icon key');
738
+ const {
739
+ name,
740
+ tintColor,
741
+ accessibilityLabel
742
+ } = icon;
743
+ if (typeof name !== 'string' || !name.trim()) fail(`${path}.name`, 'must be non-blank');
744
+ if (tintColor !== undefined && (typeof tintColor !== 'string' || !HEX_COLOR_PATTERN.test(tintColor))) fail(`${path}.tintColor`, 'must be #RRGGBB or #RRGGBBAA');
745
+ if (accessibilityLabel !== undefined && typeof accessibilityLabel !== 'string') fail(`${path}.accessibilityLabel`, 'must be a string');
746
+ }
747
+ function assertIdentityTitleRuns(row, path) {
748
+ if (row.titleSegments !== undefined) {
749
+ assertTitleSegments(row.titleSegments, `${path}.titleSegments`);
750
+ // titleMatch ranges index `title`, which the runs replace on screen.
751
+ if (row.titleMatch?.length) fail(`${path}.titleMatch`, 'cannot be combined with titleSegments');
752
+ if (row.presentation === 'walletSidebar') fail(`${path}.titleSegments`, 'is not supported with walletSidebar');
753
+ }
754
+ if (row.titleLeadingIcon !== undefined) {
755
+ assertTitleLeadingIcon(row.titleLeadingIcon, `${path}.titleLeadingIcon`);
756
+ if (row.presentation === 'walletSidebar') fail(`${path}.titleLeadingIcon`, 'is not supported with walletSidebar');
757
+ }
758
+ }
759
+
760
+ /** Production keeps decorative title runs only when they pass the rules. */
761
+ function passesTitleRunRules(check) {
762
+ try {
763
+ check();
764
+ return true;
765
+ } catch {
766
+ return false;
767
+ }
768
+ }
707
769
 
708
770
  // A passive label: its text and two caller colors, with no action or style slot.
709
771
  function assertWebLeadingBadge(value, path) {
@@ -954,6 +1016,7 @@ function assertRow(row, index, path = `rows[${index}]`) {
954
1016
  if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
955
1017
  });
956
1018
  assertIdentityExtras(row, path);
1019
+ assertIdentityTitleRuns(row, path);
957
1020
  assertText(row.subtitle, `${path}.subtitle`);
958
1021
  // OneKey patch: selector text segments truncate independently.
959
1022
  row.subtitleSegments?.forEach((segment, segmentIndex) => {
@@ -1251,7 +1314,7 @@ function assertSnapshotContract(snapshot) {
1251
1314
  }
1252
1315
  const COMMON_ROW_FIELDS = ['height', 'heightRounding', 'testID', 'opacity', 'backgroundColor', 'backgroundFullWidth', 'pressDisabled', 'key', 'revision', 'sectionKey', 'groupId', 'groupPosition', 'size', 'density', 'disabled', 'selected', 'accessibilityLabel', 'separator', 'type', 'style'];
1253
1316
  const ROW_FIELDS = {
1254
- identity: [...COMMON_ROW_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'presentation', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'titleLines', 'subtitleLines', 'collapseEmptyTrailing', 'badges', 'trailing', 'draggable'],
1317
+ identity: [...COMMON_ROW_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'presentation', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'titleSegments', 'titleLeadingIcon', 'subtitle', 'tertiary', 'tertiaryTone', 'titleLines', 'subtitleLines', 'collapseEmptyTrailing', 'badges', 'trailing', 'draggable'],
1255
1318
  walletGroup: [...COMMON_ROW_FIELDS, 'parent', 'children', 'draggable'],
1256
1319
  rail: [...COMMON_ROW_FIELDS, 'visual', 'title', 'status', 'badge', 'draggable'],
1257
1320
  activity: [...COMMON_ROW_FIELDS, 'leading', 'hideLeading', 'secondaryLeading', 'title', 'description', 'status', 'primaryAmount', 'secondaryAmount', 'amounts', 'badges', 'presentation', 'fee', 'descriptionActionKey', 'descriptionActionStart', 'footerActions'],
@@ -1267,7 +1330,7 @@ const ROW_FIELDS = {
1267
1330
  };
1268
1331
  const COMMON_PATCH_FIELDS = ['height', 'heightRounding', 'opacity', 'pressDisabled', 'revision', 'disabled', 'selected', 'accessibilityLabel', 'separator', 'style'];
1269
1332
  const PATCH_FIELDS = {
1270
- identity: [...COMMON_PATCH_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'subtitle', 'tertiary', 'tertiaryTone', 'subtitleLines', 'collapseEmptyTrailing', 'badges', 'trailing'],
1333
+ identity: [...COMMON_PATCH_FIELDS, 'contentHeight', 'longPressActionKey', 'titleMatch', 'titleActionKey', 'titleActionOnHover', 'subtitleSegments', 'leading', 'leadingAction', 'title', 'titleSuffixes', 'titleIcon', 'secondaryTitleIcon', 'titleImage', 'titleSegments', 'titleLeadingIcon', 'subtitle', 'tertiary', 'tertiaryTone', 'subtitleLines', 'collapseEmptyTrailing', 'badges', 'trailing'],
1271
1334
  rail: [...COMMON_PATCH_FIELDS, 'title', 'visual', 'status', 'badge'],
1272
1335
  activity: [...COMMON_PATCH_FIELDS, 'presentation', 'leading', 'title', 'badges', 'status', 'hideLeading', 'secondaryLeading', 'description', 'primaryAmount', 'secondaryAmount', 'amounts', 'fee', 'descriptionActionKey', 'descriptionActionStart', 'footerActions'],
1273
1336
  message: [...COMMON_PATCH_FIELDS, 'presentation', 'title', 'unread', 'body', 'bodyLines', 'time', 'thumbnail'],
@@ -1287,7 +1350,7 @@ function protocolObject(value, path) {
1287
1350
  function protocolKey(value, path) {
1288
1351
  if (typeof value !== 'string' || value.trim().length === 0) fail(path, 'must be a non-blank string');
1289
1352
  }
1290
- const PROTOCOL_ARRAY_FIELDS = new Set(['columns', 'titleSuffixes', 'cells', 'points', 'images', 'overlays', 'badges', 'trailing', 'footerActions', 'buttons', 'amounts', 'metrics', 'children', 'subtitleSegments', 'titleMatch', 'selectedKeys', 'segments', 'hoverSecondary', 'hoverImages', 'secondaryBadges', 'fallbackUris', 'probeOrder', 'priceSegments', 'textSegments', 'secondaryTextSegments', 'primaryTextSegments']);
1353
+ const PROTOCOL_ARRAY_FIELDS = new Set(['columns', 'titleSuffixes', 'titleSegments', 'cells', 'points', 'images', 'overlays', 'badges', 'trailing', 'footerActions', 'buttons', 'amounts', 'metrics', 'children', 'subtitleSegments', 'titleMatch', 'selectedKeys', 'segments', 'hoverSecondary', 'hoverImages', 'secondaryBadges', 'fallbackUris', 'probeOrder', 'priceSegments', 'textSegments', 'secondaryTextSegments', 'primaryTextSegments']);
1291
1354
  const PROTOCOL_NUMBER_FIELDS = new Set(['leadingContentMaxWidthRatio', 'height', 'width', 'fontSize', 'lineHeight', 'opacity', 'offsetY', 'offsetX', 'letterSpacing', 'cornerRadius', 'borderWidth', 'horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'titleBadgeGap', 'trailingGap', 'start', 'end', 'padding', 'offset', 'overscan', 'minWidth', 'flex', 'paddingStart', 'paddingEnd', 'changeWidth', 'changeHeight', 'changeCornerRadius', 'contentTrailingGap', 'subtitleTrailingPadding', 'partGap', 'contentPadding', 'contentPaddingHorizontal', 'contentPaddingTop', 'contentPaddingBottom', 'itemSpacing', 'gridColumns']);
1292
1355
 
1293
1356
  /** Validate only shapes that renderers dereference, not display budgets. */
@@ -1358,7 +1421,10 @@ function assertRowProtocol(row, path) {
1358
1421
  }
1359
1422
  if (row.height !== undefined && row.height < 0) fail(`${path}.height`, 'must be non-negative');
1360
1423
  if (row.type === 'identity') {
1361
- if (isDevelopment()) assertIdentityExtras(row, path);
1424
+ if (isDevelopment()) {
1425
+ assertIdentityExtras(row, path);
1426
+ assertIdentityTitleRuns(row, path);
1427
+ }
1362
1428
  if (row.titleSuffixes !== undefined && !Array.isArray(row.titleSuffixes)) fail(`${path}.titleSuffixes`, 'must be an array');
1363
1429
  row.titleSuffixes?.forEach((suffix, index) => {
1364
1430
  protocolObject(suffix, `${path}.titleSuffixes[${index}]`);
@@ -1617,6 +1683,8 @@ const NESTED_DECORATION_FIELDS = {
1617
1683
  };
1618
1684
  function sanitizeDecoration(value, field) {
1619
1685
  if (value === undefined || value === null) return undefined;
1686
+ if (field === 'titleSegments') return passesTitleRunRules(() => assertTitleSegments(value, field)) ? value : undefined;
1687
+ if (field === 'titleLeadingIcon') return passesTitleRunRules(() => assertTitleLeadingIcon(value, field)) ? value : undefined;
1620
1688
  // All or nothing: a badge without valid text and both colors is dropped, and
1621
1689
  // only its three declared fields are kept.
1622
1690
  if (field === 'webLeadingBadge') {
@@ -1959,6 +2027,8 @@ function assertPatchChanges(patch, index) {
1959
2027
  if (suffix.maxWidth !== undefined && (!Number.isFinite(suffix.maxWidth) || suffix.maxWidth < 0 || suffix.maxWidth > 4096)) fail(`${path}.titleSuffixes[${index}].maxWidth`, 'must be finite within 0...4096');
1960
2028
  });
1961
2029
  assertIdentityExtras(patch.changes, path);
2030
+ // A null clear never reaches here; a replacement follows the row rules.
2031
+ assertIdentityTitleRuns(patch.changes, path);
1962
2032
  assertText(patch.changes.subtitle, `${path}.subtitle`);
1963
2033
  assertText(patch.changes.tertiary, `${path}.tertiary`);
1964
2034
  if (patch.changes.tertiaryTone !== undefined && !['secondary', 'info'].includes(patch.changes.tertiaryTone)) {
@@ -2152,7 +2222,9 @@ function normalizePatch(patch, index) {
2152
2222
  continue;
2153
2223
  }
2154
2224
  const canonical = isDevelopment() ? normalized : patch.type === 'market' && field === 'metrics' ? sanitizeMarketMetrics(normalized) : sanitizeDecoration(normalized, field);
2155
- if (canonical !== undefined) changes[field] = canonical;else if (field === 'titleImage') changes[field] = null;
2225
+ if (canonical !== undefined) changes[field] = canonical;
2226
+ // A rejected title decoration clears the old one instead of leaving it drawn.
2227
+ else if (['titleImage', 'titleSegments', 'titleLeadingIcon'].includes(field)) changes[field] = null;
2156
2228
  }
2157
2229
  if (patch.type === 'market' && Array.isArray(changes.priceSegments) && changes.priceSegments.length > 0 && (typeof changes.price !== 'string' || !changes.price.trim())) fail(`${path}.changes.price`, 'is required when priceSegments is updated');
2158
2230
  if (!isDevelopment()) {
@@ -482,7 +482,7 @@ export const WEB_LIST_CSS = `
482
482
  .ok-native-list-icon-button.ok-native-list-tertiary-icon{box-sizing:border-box;flex:0 0 38px;width:38px;height:38px;margin:-7px;padding:6px;border:1px solid transparent;border-radius:9999px;color:var(--nl-icon-subdued);background:transparent}.ok-native-list-icon-button.ok-native-list-tertiary-icon:hover:not(:disabled){background:var(--nl-hover)}.ok-native-list-icon-button.ok-native-list-tertiary-icon:active:not(:disabled){background:var(--nl-pressed)}.ok-native-list-icon-button.ok-native-list-tertiary-icon:disabled{opacity:.4;cursor:default}
483
483
  .ok-native-list-action-glyph{display:inline-flex;width:24px;height:24px;align-items:center;justify-content:center}
484
484
  .ok-native-list-icon-button.ok-native-list-tertiary-icon:focus-visible:not(:disabled){outline:2px solid var(--nl-accent)}
485
- .ok-native-list-identity-title-icon{flex:0 0 20px;width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon);font-size:20px}.ok-native-list-identity-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
485
+ .ok-native-list-identity-title-icon{flex:0 0 20px;width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon);font-size:20px}.ok-native-list-identity-title-leading-icon{flex:0 0 16px;width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;color:var(--nl-icon-subdued);font-size:16px}.ok-native-list-identity-title-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
486
486
  .ok-native-list-account-row .ok-native-list-visual,.ok-native-list-account-action-row .ok-native-list-visual{width:32px;height:32px;flex-basis:32px}.ok-native-list-account-row .ok-native-list-visual>img,.ok-native-list-account-row .ok-native-list-visual-main,.ok-native-list-account-action-row .ok-native-list-visual>img,.ok-native-list-account-action-row .ok-native-list-visual-main{width:32px;height:32px}.ok-native-list-account-row .ok-native-list-visual>.ok-native-list-visual-corner{width:20px;height:20px;padding:2px}.ok-native-list-account-action-row .ok-native-list-visual{border-radius:8px!important}.ok-native-list-wallet-row .ok-native-list-title{color:var(--nl-secondary);font-size:12px;line-height:16px;font-weight:400;font-family:var(--nl-font-regular)}.ok-native-list-item[data-native-list-selected="true"]>.ok-native-list-wallet-row .ok-native-list-title{color:var(--nl-primary)}.ok-native-list-account-row .ok-native-list-title{font-size:16px;line-height:20px;font-weight:400;font-family:var(--nl-font-regular)}.ok-native-list-account-row .ok-native-list-secondary{font-size:14px;line-height:20px;font-weight:400;font-family:var(--nl-font-regular)}
487
487
  .ok-native-list-flex{display:flex;flex:1;min-width:0;flex-direction:column;justify-content:center}.ok-native-list-title{font-size:15px;line-height:20px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--nl-font-semibold)}.ok-native-list-secondary{font-size:13px;line-height:18px;color:var(--nl-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ok-native-list-tertiary{color:var(--nl-secondary)}.ok-native-list-info{color:var(--nl-info)}
488
488
  .ok-native-list-identity-row .ok-native-list-title,.ok-native-list-identity-row .ok-native-list-amounts>span:first-child{font-size:16px;line-height:20px}.ok-native-list-identity-row .ok-native-list-secondary{font-size:14px;line-height:20px}
@@ -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);