@onekeyfe/react-native-native-list 3.0.179 → 6.7.0-1

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 (111) hide show
  1. package/LICENSE +36 -0
  2. package/README.md +32 -3
  3. package/android/build.gradle +0 -1
  4. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +22 -1
  5. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +8 -8
  6. package/android/src/main/java/com/onekey/nativelist/NativeListActionRenderer.kt +5 -5
  7. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +4 -4
  8. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -6
  9. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +6 -1
  10. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +11 -11
  11. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +20 -20
  12. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +5 -4
  13. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +7 -7
  14. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +5 -5
  15. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +8 -7
  16. package/android/src/main/java/com/onekey/nativelist/NativeListMetricCardRenderer.kt +14 -14
  17. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +28 -15
  18. package/android/src/main/java/com/onekey/nativelist/NativeListRailRenderer.kt +4 -4
  19. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +3 -3
  20. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +3 -2
  21. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +5 -4
  22. package/android/src/main/java/com/onekey/nativelist/NativeListRowHost.kt +1 -1
  23. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +20 -20
  24. package/android/src/main/java/com/onekey/nativelist/NativeListSystemRenderer.kt +3 -3
  25. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +104 -18
  26. package/android/src/main/java/com/onekey/nativelist/NativeListWalletGroupRenderer.kt +6 -5
  27. package/docs/SPEC.md +69 -0
  28. package/docs/STYLE_SPEC.md +12 -2
  29. package/ios/HybridNativeList.swift +18 -6
  30. package/ios/NativeListAccessoryStack.swift +14 -10
  31. package/ios/NativeListActionRenderer.swift +7 -4
  32. package/ios/NativeListActivityDetailsView.swift +63 -24
  33. package/ios/NativeListActivityRenderer.swift +19 -10
  34. package/ios/NativeListDataRowRenderer.swift +23 -19
  35. package/ios/NativeListDesignAssets.swift +43 -34
  36. package/ios/NativeListIdentityRenderer.swift +23 -19
  37. package/ios/NativeListLeadingVisual.swift +9 -4
  38. package/ios/NativeListMarketRenderer.swift +19 -11
  39. package/ios/NativeListMediaTileRenderer.swift +11 -7
  40. package/ios/NativeListMessageRenderer.swift +20 -10
  41. package/ios/NativeListMetricCardRenderer.swift +16 -12
  42. package/ios/NativeListRailRenderer.swift +9 -7
  43. package/ios/NativeListRendererCell.swift +6 -4
  44. package/ios/NativeListRendererRegistry.swift +8 -3
  45. package/ios/NativeListResolvedText.swift +3 -3
  46. package/ios/NativeListRowHost.swift +7 -2
  47. package/ios/NativeListSectionHeaderRenderer.swift +22 -19
  48. package/ios/NativeListSystemRenderer.swift +18 -16
  49. package/ios/NativeListTextStyles.swift +18 -12
  50. package/ios/NativeListWalletGroupRenderer.swift +6 -4
  51. package/ios/RNCNativeListView.swift +38 -5
  52. package/ios/tests/NativeListActivityPresentationTests.swift +5 -3
  53. package/ios/tests/NativeListLifecycleTests.swift +77 -2
  54. package/lib/module/NativeList.js +3 -0
  55. package/lib/module/NativeList.web.js +8 -1
  56. package/lib/module/fonts.js +44 -0
  57. package/lib/module/index.js +1 -0
  58. package/lib/module/web/NativeListWebEngine.js +48 -24
  59. package/lib/module/web/templates/ActionRowRenderer.js +2 -1
  60. package/lib/module/web/templates/IdentityRowRenderer.js +4 -3
  61. package/lib/module/web/templates/MarketRowRenderer.js +2 -1
  62. package/lib/module/web/templates/RowText.js +13 -3
  63. package/lib/module/web/templates/SectionHeaderRowRenderer.js +3 -2
  64. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  65. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  66. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  67. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  68. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  69. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  70. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  71. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  72. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  73. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  74. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  75. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  76. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  77. package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
  78. package/lib/typescript/src/fonts.d.ts +10 -0
  79. package/lib/typescript/src/index.d.ts +2 -0
  80. package/lib/typescript/src/web/NativeListWebEngine.d.ts +4 -1
  81. package/lib/typescript/src/web/templates/RowText.d.ts +1 -0
  82. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
  83. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
  84. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
  85. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
  86. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
  87. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
  88. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
  89. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
  90. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
  91. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
  92. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
  93. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
  94. package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
  95. package/package.json +4 -5
  96. package/react-native-native-list.podspec +0 -1
  97. package/src/NativeList.nitro.ts +1 -0
  98. package/src/NativeList.tsx +3 -0
  99. package/src/NativeList.web.tsx +10 -1
  100. package/src/fonts.ts +64 -0
  101. package/src/index.ts +3 -0
  102. package/src/web/NativeListWebEngine.ts +53 -24
  103. package/src/web/templates/ActionRowRenderer.ts +2 -1
  104. package/src/web/templates/IdentityRowRenderer.ts +4 -3
  105. package/src/web/templates/MarketRowRenderer.ts +4 -2
  106. package/src/web/templates/RowText.ts +15 -3
  107. package/src/web/templates/SectionHeaderRowRenderer.ts +6 -3
  108. package/common/fonts/Roobert-Bold.ttf +0 -0
  109. package/common/fonts/Roobert-Medium.ttf +0 -0
  110. package/common/fonts/Roobert-Regular.ttf +0 -0
  111. package/common/fonts/Roobert-SemiBold.ttf +0 -0
@@ -94,7 +94,8 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
94
94
  !["summary", "gallery"].contains(item.data.string("variant"))
95
95
  }
96
96
  override class func measure(
97
- _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String
97
+ _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
98
+ fonts: NativeListFontFamilies
98
99
  ) -> CGFloat? {
99
100
  if layout == "table" { return 28 }
100
101
  if item.data.string("presentation") == "networkSelector" { return 47 }
@@ -210,7 +211,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
210
211
  label.rowVerticalAlignment = nil
211
212
  }
212
213
  titleLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
213
- subtitleLabel.font = nativeListFont(ofSize: 14)
214
+ subtitleLabel.font = nativeListFont(ofSize: 14, fonts: fonts)
214
215
  subtitleLabel.textColor = nativeListColor(theme, "secondaryText", "#646464")
215
216
  mainStack.alignment = .fill
216
217
  mainStack.spacing = 2
@@ -221,7 +222,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
221
222
  let value = accessoryButtons[0]
222
223
  value.setTitle(nil, for: .normal)
223
224
  value.setAttributedTitle(nil, for: .normal)
224
- value.titleLabel?.font = nativeListFont(ofSize: 16, weight: .medium)
225
+ value.titleLabel?.font = nativeListFont(ofSize: 16, weight: .medium, fonts: fonts)
225
226
  value.titleLabel?.numberOfLines = 1
226
227
  value.titleLabel?.lineBreakMode = .byTruncatingTail
227
228
  value.contentHorizontalAlignment = .center
@@ -275,13 +276,13 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
275
276
  private func applyTextStyle(_ item: NativeListItem) {
276
277
  let style = item.data.dictionary("style") ?? [:]
277
278
  if let title = style.dictionary("title") {
278
- NativeListTextStyles.applyStyledText(titleLabel, title)
279
+ NativeListTextStyles.applyStyledText(titleLabel, title, fonts: fonts)
279
280
  }
280
281
  if let subtitle = style.dictionary("subtitle") {
281
- NativeListTextStyles.applyStyledText(subtitleLabel, subtitle)
282
+ NativeListTextStyles.applyStyledText(subtitleLabel, subtitle, fonts: fonts)
282
283
  }
283
284
  if let value = style.dictionary("value") {
284
- NativeListTextStyles.applyStyledButton(accessoryButtons[0], value)
285
+ NativeListTextStyles.applyStyledButton(accessoryButtons[0], value, fonts: fonts)
285
286
  }
286
287
  }
287
288
  override func bindSelectionContent(
@@ -305,8 +306,8 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
305
306
  _ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
306
307
  ) {
307
308
  checkboxControl.bind(
308
- item, descriptors: [descriptor], theme: currentTheme, style: [:], checkboxState: checkboxState
309
- )
309
+ item, descriptors: [descriptor], theme: currentTheme, style: [:], checkboxState: checkboxState,
310
+ fonts: fonts)
310
311
  }
311
312
  override func recycleContent() {
312
313
  checkboxControl.reset()
@@ -382,8 +383,8 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
382
383
  : isGallery || layout == "sectioned" ? .semibold : .regular
383
384
  titleLabel.font = nativeListFont(
384
385
  ofSize: isGallery ? 18 : isSummary ? 16 : isTable ? 11 : isHistory ? 12 : 14,
385
- weight: isHistory ? .semibold : headerWeight
386
- )
386
+ weight: isHistory ? .semibold : headerWeight,
387
+ fonts: fonts)
387
388
  titleLabel.textColor = nativeListColor(
388
389
  theme,
389
390
  isSummary || isGallery ? "primaryText" : "secondaryText",
@@ -421,7 +422,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
421
422
  if layout == "linear" {
422
423
  // TokenManager's section title is a plain body label with mt=10,
423
424
  // unlike the reusable 36-point SectionHeader used by sectioned lists.
424
- titleLabel.font = nativeListFont(ofSize: 14)
425
+ titleLabel.font = nativeListFont(ofSize: 14, fonts: fonts)
425
426
  topInset = 10
426
427
  bottomInset = 0
427
428
  }
@@ -482,11 +483,12 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
482
483
  color: nativeListColor(theme, "secondaryText", "#646464")
483
484
  )
484
485
  accessoryButtons[0].titleLabel?.font = nativeListFont(
485
- ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular)
486
+ ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular, fonts: fonts)
486
487
  setButtonLine(
487
488
  accessoryButtons[0],
488
489
  text: item.data.string("value"),
489
- font: nativeListFont(ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular),
490
+ font: nativeListFont(
491
+ ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular, fonts: fonts),
490
492
  color: nativeListColor(theme, "secondaryText", "#646464"),
491
493
  lineHeight: 24
492
494
  )
@@ -497,7 +499,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
497
499
  trailingStack.axis = .horizontal
498
500
  trailingStack.alignment = .center
499
501
  trailingStack.spacing = 4
500
- accessoryButtons[0].titleLabel?.font = nativeListFont(ofSize: 11)
502
+ accessoryButtons[0].titleLabel?.font = nativeListFont(ofSize: 11, fonts: fonts)
501
503
  accessoryButtons[0].setTitleColor(
502
504
  nativeListColor(theme, "secondaryText", "#646464"),
503
505
  for: .normal
@@ -535,12 +537,12 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
535
537
  bottomInset = -8
536
538
  accessoryButtons[0].titleLabel?.font = nativeListTabularFont(
537
539
  ofSize: 16,
538
- weight: .medium
539
- )
540
+ weight: .medium,
541
+ fonts: fonts)
540
542
  setButtonLine(
541
543
  accessoryButtons[0],
542
544
  text: item.data.string("value"),
543
- font: nativeListTabularFont(ofSize: 16, weight: .medium),
545
+ font: nativeListTabularFont(ofSize: 16, weight: .medium, fonts: fonts),
544
546
  color: nativeListColor(theme, "primaryText", "#202020"),
545
547
  lineHeight: 24
546
548
  )
@@ -641,7 +643,7 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
641
643
  }
642
644
  for segment in segments {
643
645
  attributes[.font] = nativeListTabularFont(
644
- ofSize: segment.string("style") == "subscript" ? 10 : 16, weight: .medium)
646
+ ofSize: segment.string("style") == "subscript" ? 10 : 16, weight: .medium, fonts: fonts)
645
647
  value.append(NSAttributedString(string: segment.string("text"), attributes: attributes))
646
648
  }
647
649
  button.setAttributedTitle(value, for: .normal)
@@ -679,7 +681,8 @@ final class NativeListSectionHeaderCell: NativeListRendererCell {
679
681
  setButtonLine(
680
682
  valueButton,
681
683
  text: value,
682
- font: nativeListFont(ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular),
684
+ font: nativeListFont(
685
+ ofSize: 16, weight: isExplicitNetworkHeader ? .medium : .regular, fonts: fonts),
683
686
  color: nativeListColor(currentTheme, "secondaryText", "#646464"),
684
687
  lineHeight: 24
685
688
  )
@@ -2,9 +2,10 @@ import UIKit
2
2
 
3
3
  final class NativeListSystemCell: NativeListRendererCell {
4
4
  override class func measure(
5
- _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String
5
+ _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
6
+ fonts: NativeListFontFamilies
6
7
  ) -> CGFloat? {
7
- return NativeListSystemRenderer.measure(item, width: width)
8
+ return NativeListSystemRenderer.measure(item, width: width, fonts: fonts)
8
9
  }
9
10
  override class func appliesSizePreset(_ item: NativeListItem) -> Bool {
10
11
  NativeListSystemRenderer.appliesSizePreset(item)
@@ -75,7 +76,8 @@ final class NativeListSystemCell: NativeListRendererCell {
75
76
  label.text = nil
76
77
  label.isHidden = true
77
78
  label.font = nativeListFont(
78
- ofSize: label === titleLabel ? 16 : 14, weight: label === titleLabel ? .medium : .regular)
79
+ ofSize: label === titleLabel ? 16 : 14, weight: label === titleLabel ? .medium : .regular,
80
+ fonts: fonts)
79
81
  label.textColor = nativeListColor(
80
82
  theme, label === titleLabel ? "primaryText" : "secondaryText",
81
83
  label === titleLabel ? "#202020" : "#646464")
@@ -90,7 +92,7 @@ final class NativeListSystemCell: NativeListRendererCell {
90
92
  button.setAttributedTitle(nil, for: .normal)
91
93
  button.setTitle(nil, for: .normal)
92
94
  button.isHidden = true
93
- button.titleLabel?.font = nativeListFont(ofSize: 16, weight: .medium)
95
+ button.titleLabel?.font = nativeListFont(ofSize: 16, weight: .medium, fonts: fonts)
94
96
  button.titleLabel?.numberOfLines = 1
95
97
  button.contentEdgeInsets = .zero
96
98
  button.contentHorizontalAlignment = .center
@@ -116,13 +118,13 @@ final class NativeListSystemCell: NativeListRendererCell {
116
118
  if style["trailingGap"] != nil { trailingStack.spacing = CGFloat(style.double("trailingGap")) }
117
119
  let warning = item.data.string("variant") == "warning"
118
120
  if warning, let text = style.dictionary("title") {
119
- NativeListTextStyles.applyStyledText(titleLabel, text)
121
+ NativeListTextStyles.applyStyledText(titleLabel, text, fonts: fonts)
120
122
  }
121
123
  if let text = style.dictionary("message") {
122
- NativeListTextStyles.applyStyledText(warning ? subtitleLabel : titleLabel, text)
124
+ NativeListTextStyles.applyStyledText(warning ? subtitleLabel : titleLabel, text, fonts: fonts)
123
125
  }
124
126
  if let text = style.dictionary("actionText") {
125
- NativeListTextStyles.applyStyledButton(button, text)
127
+ NativeListTextStyles.applyStyledButton(button, text, fonts: fonts)
126
128
  }
127
129
  contentInsets = UIEdgeInsets(
128
130
  top: topInset, left: leftInset, bottom: -bottomInset, right: -rightInset)
@@ -229,7 +231,7 @@ final class NativeListSystemCell: NativeListRendererCell {
229
231
  bottomInset = -(height - top - (message.isEmpty ? 30 : 61))
230
232
  if !message.isEmpty {
231
233
  show(titleLabel, message, lines: 2)
232
- titleLabel.font = nativeListTabularFont(ofSize: 16)
234
+ titleLabel.font = nativeListTabularFont(ofSize: 16, fonts: fonts)
233
235
  titleLabel.textColor = nativeListColor(theme, "secondaryText", "#646464")
234
236
  titleLabel.textAlignment = .center
235
237
  setLineHeight(titleLabel, text: message, lineHeight: 24)
@@ -240,7 +242,7 @@ final class NativeListSystemCell: NativeListRendererCell {
240
242
  button.backgroundColor = .clear
241
243
  button.layer.cornerRadius = 15
242
244
  setButtonLine(
243
- button, text: text, font: nativeListTabularFont(ofSize: 14, weight: .medium),
245
+ button, text: text, font: nativeListTabularFont(ofSize: 14, weight: .medium, fonts: fonts),
244
246
  color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20)
245
247
  let textWidth = button.intrinsicContentSize.width
246
248
  selectorConstraints.append(contentsOf: [
@@ -284,7 +286,7 @@ final class NativeListSystemCell: NativeListRendererCell {
284
286
  root.addArrangedSubview(mainStack)
285
287
  mainStack.alignment = .center
286
288
  mainStack.setContentHuggingPriority(.defaultLow, for: .horizontal)
287
- titleLabel.font = nativeListTabularFont(ofSize: 16)
289
+ titleLabel.font = nativeListTabularFont(ofSize: 16, fonts: fonts)
288
290
  titleLabel.textColor = nativeListColor(theme, "secondaryText", "#646464")
289
291
  titleLabel.textAlignment = .center
290
292
  show(titleLabel, item.data.string("message"), lines: 1)
@@ -324,9 +326,9 @@ final class NativeListSystemCell: NativeListRendererCell {
324
326
  topInset = 14
325
327
  bottomInset = -14
326
328
  mainStack.spacing = 4
327
- titleLabel.font = nativeListFont(ofSize: 14, weight: .medium)
329
+ titleLabel.font = nativeListFont(ofSize: 14, weight: .medium, fonts: fonts)
328
330
  titleLabel.numberOfLines = 0
329
- subtitleLabel.font = nativeListFont(ofSize: 14)
331
+ subtitleLabel.font = nativeListFont(ofSize: 14, fonts: fonts)
330
332
  subtitleLabel.numberOfLines = 0
331
333
  show(titleLabel, item.data.string("title"), lines: 0)
332
334
  show(subtitleLabel, item.data.string("message"), lines: 0)
@@ -375,7 +377,7 @@ final class NativeListSystemCell: NativeListRendererCell {
375
377
  mainStack.alignment = variant == "loading" || alignsToStart ? .leading : .center
376
378
  if alignsToStart {
377
379
  mainStack.setContentHuggingPriority(.defaultLow, for: .horizontal)
378
- titleLabel.font = nativeListFont(ofSize: 14)
380
+ titleLabel.font = nativeListFont(ofSize: 14, fonts: fonts)
379
381
  titleLabel.textColor = nativeListColor(theme, "secondaryText", "#646464")
380
382
  setLineHeight(titleLabel, text: titleLabel.text ?? "", lineHeight: 20)
381
383
  }
@@ -388,7 +390,7 @@ final class NativeListSystemCell: NativeListRendererCell {
388
390
  setButtonLine(
389
391
  accessoryButtons[0],
390
392
  text: "Retry",
391
- font: nativeListFont(ofSize: 14, weight: .medium),
393
+ font: nativeListFont(ofSize: 14, weight: .medium, fonts: fonts),
392
394
  color: nativeListColor(theme, "primaryText", "#202020"),
393
395
  lineHeight: 20
394
396
  )
@@ -512,7 +514,7 @@ enum NativeListSystemRenderer {
512
514
  static func appliesSizePreset(_ item: NativeListItem) -> Bool {
513
515
  !["warning", "spacer"].contains(item.data.string("variant"))
514
516
  }
515
- static func measure(_ item: NativeListItem, width: CGFloat) -> CGFloat {
517
+ static func measure(_ item: NativeListItem, width: CGFloat, fonts: NativeListFontFamilies) -> CGFloat {
516
518
  if item.type == "system", item.data.string("variant") == "spacer" {
517
519
  return CGFloat(item.data.int("height"))
518
520
  }
@@ -536,7 +538,7 @@ enum NativeListSystemRenderer {
536
538
  .font: nativeListFont(
537
539
  ofSize: fontSize,
538
540
  weight: NativeListTextStyles.marketFontWeight(
539
- textStyle?.string("fontWeight") ?? "", fallback: weight)),
541
+ textStyle?.string("fontWeight") ?? "", fallback: weight), fonts: fonts),
540
542
  .paragraphStyle: paragraph,
541
543
  ], context: nil
542
544
  ).height / lineHeight)
@@ -3,21 +3,23 @@ import UIKit
3
3
 
4
4
  // Apply semantic overrides after a renderer has restored its resolved defaults.
5
5
  enum NativeListTextStyles {
6
- static func applyStyledText(_ label: UILabel, _ style: [String: Any]) {
6
+ static func applyStyledText(
7
+ _ label: UILabel, _ style: [String: Any], fonts: NativeListFontFamilies
8
+ ) {
7
9
  let text = label.attributedText?.string ?? label.text ?? ""
8
10
  guard !text.isEmpty, !style.isEmpty else { return }
9
11
  let originalText = label.attributedText
10
12
  let textLabel = label as? NativeListTextLabel
11
13
  let baseFont =
12
14
  (originalText?.attribute(.font, at: 0, effectiveRange: nil) as? UIFont) ?? label.font
13
- ?? nativeListFont(ofSize: 14)
15
+ ?? nativeListFont(ofSize: 14, fonts: fonts)
14
16
  let size = CGFloat(style.double("fontSize", default: Double(baseFont.pointSize)))
15
17
  let font: UIFont
16
18
  if let weightName = style["fontWeight"] as? String {
17
19
  font = nativeListFont(
18
20
  ofSize: size,
19
- weight: marketFontWeight(weightName, fallback: .regular)
20
- )
21
+ weight: marketFontWeight(weightName, fallback: .regular),
22
+ fonts: fonts)
21
23
  } else {
22
24
  font = baseFont.withSize(size)
23
25
  }
@@ -53,7 +55,7 @@ enum NativeListTextStyles {
53
55
  paragraph.lineBreakMode = label.lineBreakMode
54
56
  }
55
57
  var attributes: [NSAttributedString.Key: Any] = [:]
56
- applyStyledFont(attributed, style, fallback: baseFont)
58
+ applyStyledFont(attributed, style, fallback: baseFont, fonts: fonts)
57
59
  if style["color"] != nil { attributes[.foregroundColor] = color }
58
60
  if style["alignment"] != nil || style["lines"] != nil || style["truncate"] != nil
59
61
  || style["lineHeight"] != nil
@@ -74,7 +76,9 @@ enum NativeListTextStyles {
74
76
  label.attributedText = attributed
75
77
  }
76
78
 
77
- static func applyStyledButton(_ button: UIButton, _ style: [String: Any]) {
79
+ static func applyStyledButton(
80
+ _ button: UIButton, _ style: [String: Any], fonts: NativeListFontFamilies
81
+ ) {
78
82
  let text =
79
83
  button.attributedTitle(for: .normal)?.string
80
84
  ?? button.title(for: .normal)
@@ -84,14 +88,14 @@ enum NativeListTextStyles {
84
88
  let accessory = button as? NativeListAccessoryButton
85
89
  let baseFont =
86
90
  (originalText?.attribute(.font, at: 0, effectiveRange: nil) as? UIFont) ?? button.titleLabel?
87
- .font ?? nativeListFont(ofSize: 14)
91
+ .font ?? nativeListFont(ofSize: 14, fonts: fonts)
88
92
  let size = CGFloat(style.double("fontSize", default: Double(baseFont.pointSize)))
89
93
  let font: UIFont
90
94
  if let weightName = style["fontWeight"] as? String {
91
95
  font = nativeListFont(
92
96
  ofSize: size,
93
- weight: marketFontWeight(weightName, fallback: .regular)
94
- )
97
+ weight: marketFontWeight(weightName, fallback: .regular),
98
+ fonts: fonts)
95
99
  } else {
96
100
  font = baseFont.withSize(size)
97
101
  }
@@ -116,7 +120,7 @@ enum NativeListTextStyles {
116
120
  : alignmentName == "end" ? .trailing : .center
117
121
  }
118
122
  var attributes: [NSAttributedString.Key: Any] = [:]
119
- applyStyledFont(attributed, style, fallback: baseFont)
123
+ applyStyledFont(attributed, style, fallback: baseFont, fonts: fonts)
120
124
  if style["color"] != nil { attributes[.foregroundColor] = color }
121
125
  if style["alignment"] != nil || style["lineHeight"] != nil || style["lines"] != nil
122
126
  || style["truncate"] != nil
@@ -153,7 +157,8 @@ enum NativeListTextStyles {
153
157
  }
154
158
 
155
159
  static func applyStyledFont(
156
- _ text: NSMutableAttributedString, _ style: [String: Any], fallback: UIFont
160
+ _ text: NSMutableAttributedString, _ style: [String: Any], fallback: UIFont,
161
+ fonts: NativeListFontFamilies
157
162
  ) {
158
163
  guard style["fontSize"] != nil || style["fontWeight"] != nil else { return }
159
164
  text.enumerateAttribute(.font, in: NSRange(location: 0, length: text.length)) {
@@ -164,7 +169,8 @@ enum NativeListTextStyles {
164
169
  style["fontWeight"] == nil
165
170
  ? original.withSize(size)
166
171
  : nativeListFont(
167
- ofSize: size, weight: marketFontWeight(style.string("fontWeight"), fallback: .regular))
172
+ ofSize: size, weight: marketFontWeight(style.string("fontWeight"), fallback: .regular),
173
+ fonts: fonts)
168
174
  text.addAttribute(.font, value: font, range: range)
169
175
  }
170
176
  }
@@ -55,7 +55,8 @@ final class NativeListWalletGroupCell: NativeListRendererCell, UIGestureRecogniz
55
55
  }
56
56
  override class func appliesSizePreset(_ item: NativeListItem) -> Bool { false }
57
57
  override class func measure(
58
- _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String
58
+ _ item: NativeListItem, width: CGFloat, theme: [String: Any]?, layout: String,
59
+ fonts: NativeListFontFamilies
59
60
  ) -> CGFloat? {
60
61
  let members = memberItems(item)
61
62
  return members.reduce(
@@ -76,7 +77,7 @@ final class NativeListWalletGroupCell: NativeListRendererCell, UIGestureRecogniz
76
77
  dragBadge.translatesAutoresizingMaskIntoConstraints = false
77
78
  dragBadge.horizontalInset = 6
78
79
  dragBadge.textAlignment = .center
79
- dragBadge.font = nativeListTabularFont(ofSize: 12, weight: .semibold)
80
+ dragBadge.font = nativeListTabularFont(ofSize: 12, weight: .semibold, fonts: fonts)
80
81
  dragBadge.layer.cornerRadius = 12
81
82
  dragBadge.layer.masksToBounds = true
82
83
  dragBadge.layer.borderWidth = 1
@@ -101,6 +102,7 @@ final class NativeListWalletGroupCell: NativeListRendererCell, UIGestureRecogniz
101
102
  _ item: NativeListItem, theme: [String: Any]?, layout: String,
102
103
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
103
104
  ) {
105
+ dragBadge.font = nativeListTabularFont(ofSize: 12, weight: .semibold, fonts: fonts)
104
106
  members = Self.memberItems(item)
105
107
  let keys = Set(members.map(\.key))
106
108
  for key in Array(memberViews.keys) where !keys.contains(key) {
@@ -134,7 +136,7 @@ final class NativeListWalletGroupCell: NativeListRendererCell, UIGestureRecogniz
134
136
  view.cell.listStyle = listStyle
135
137
  view.cell.bind(
136
138
  item: member, theme: theme, layout: layout, selected: member.data.bool("selected"),
137
- checkboxState: checkboxState)
139
+ checkboxState: checkboxState, fonts: fonts)
138
140
  root.insertArrangedSubview(view.cell, at: index)
139
141
  }
140
142
  if let parent = members.first {
@@ -153,7 +155,7 @@ final class NativeListWalletGroupCell: NativeListRendererCell, UIGestureRecogniz
153
155
  compactCell?.listStyle = listStyle
154
156
  compactCell?.bind(
155
157
  item: parent, theme: theme, layout: layout, selected: parent.data.bool("selected"),
156
- checkboxState: checkboxState)
158
+ checkboxState: checkboxState, fonts: fonts)
157
159
  }
158
160
  let count = members.dropFirst().filter { ($0.data["draggable"] as? Bool) != false }.count
159
161
  dragBadge.text = count > 0 ? "+\(count)" : nil
@@ -4,6 +4,26 @@ import UIKit
4
4
  import UniformTypeIdentifiers
5
5
 
6
6
  final class NativeListView: UIView {
7
+ private var fonts = NativeListFontFamilies()
8
+
9
+ func setFontFamiliesJson(_ json: String) {
10
+ guard let next = NativeListFontFamilies(json: json), next != fonts else { return }
11
+ fonts = next
12
+ if interactiveReorderSource != nil { cancelInteractiveReorderForStructuralUpdate() }
13
+ sectionIndexView.refreshFonts(fonts)
14
+ sectionIndexPreview.refreshFonts(fonts)
15
+ invalidateActionAnchor(reason: "layout")
16
+ configureFooterIfPresent()
17
+ var snapshot = dataSource.snapshot()
18
+ snapshot.reconfigureItems(snapshot.itemIdentifiers)
19
+ dataSource.apply(snapshot, animatingDifferences: false)
20
+ flowLayout.invalidateLayout()
21
+ setNeedsLayout()
22
+ }
23
+
24
+ private func configureFooterIfPresent() {
25
+ if let config { configureFooter(config) }
26
+ }
7
27
  private var refreshEmittedForDrag = false
8
28
  private var minimumDragOffset: CGFloat = 0
9
29
  private var containerSlotHeights: [CGFloat] = [0, 0, 0]
@@ -1666,7 +1686,8 @@ final class NativeListView: UIView {
1666
1686
  selected: item.data.bool("selected") || config.selectedKeys.contains(item.key),
1667
1687
  checkboxState: { [weak self] item, target, fallback in
1668
1688
  self?.resolveCheckboxState(item: item, target: target, fallback: fallback) ?? fallback
1669
- }
1689
+ },
1690
+ fonts: fonts
1670
1691
  )
1671
1692
  if item.key == interactiveReorderCompactKey {
1672
1693
  cell.setWalletGroupReorderCompact(true)
@@ -2029,7 +2050,9 @@ final class NativeListView: UIView {
2029
2050
  ? floor((availableWidth - CGFloat((config?.gridColumns ?? 2) - 1) * (config?.itemSpacing ?? 0)) / CGFloat(config?.gridColumns ?? 2))
2030
2051
  : availableWidth
2031
2052
  let rowWidth = allocatedWidth ?? (config?.orientation == "horizontal" ? 280 : columnWidth)
2032
- if let height = NativeListRendererRegistry.measure(item, width: rowWidth, theme: config?.theme, layout: config?.layout ?? "linear") {
2053
+ if let height = NativeListRendererRegistry.measure(
2054
+ item, width: rowWidth, theme: config?.theme, layout: config?.layout ?? "linear", fonts: fonts)
2055
+ {
2033
2056
  return max(0, height + (NativeListRendererRegistry.appliesSizePreset(item) ? (item.data.string("size") == "small" ? -8 : item.data.string("size") == "large" ? 12 : 0) : 0))
2034
2057
  }
2035
2058
  return 56
@@ -2411,7 +2434,7 @@ extension NativeListView: UICollectionViewDelegateFlowLayout {
2411
2434
  }
2412
2435
 
2413
2436
  private func railWidth(_ item: NativeListItem) -> CGFloat {
2414
- NativeListRailRenderer.Resolved(item, theme: config?.theme).horizontalWidth
2437
+ NativeListRailRenderer.Resolved(item, theme: config?.theme, fonts: fonts).horizontalWidth
2415
2438
  }
2416
2439
 
2417
2440
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
@@ -2664,6 +2687,11 @@ private struct NativeListSectionIndexEntry {
2664
2687
  }
2665
2688
 
2666
2689
  private final class NativeListSectionIndexPreviewView: UIView {
2690
+ private var fonts = NativeListFontFamilies()
2691
+ func refreshFonts(_ fonts: NativeListFontFamilies) {
2692
+ self.fonts = fonts
2693
+ label.font = nativeListFont(ofSize: 30, fonts: fonts)
2694
+ }
2667
2695
  private let shapeLayer = CAShapeLayer()
2668
2696
  private let label = UILabel()
2669
2697
 
@@ -2679,7 +2707,7 @@ private final class NativeListSectionIndexPreviewView: UIView {
2679
2707
  layer.addSublayer(shapeLayer)
2680
2708
  label.textAlignment = .center
2681
2709
  label.adjustsFontForContentSizeCategory = true
2682
- label.font = nativeListFont(ofSize: 30)
2710
+ label.font = nativeListFont(ofSize: 30, fonts: fonts)
2683
2711
  label.isAccessibilityElement = false
2684
2712
  addSubview(label)
2685
2713
  }
@@ -2734,6 +2762,11 @@ private final class NativeListSectionIndexPreviewView: UIView {
2734
2762
  // OneKey patch: arbitrate index scrubbing against ancestor dismissal gestures.
2735
2763
  // private final class NativeListSectionIndexView: UIControl {
2736
2764
  private final class NativeListSectionIndexView: UIControl, UIGestureRecognizerDelegate {
2765
+ private var fonts = NativeListFontFamilies()
2766
+ func refreshFonts(_ fonts: NativeListFontFamilies) {
2767
+ self.fonts = fonts
2768
+ updateLabelStyles()
2769
+ }
2737
2770
  private static let edgePadding: CGFloat = 8
2738
2771
  private static let labelSize: CGFloat = 14
2739
2772
  private static let labelSpacing: CGFloat = 16
@@ -2951,7 +2984,7 @@ private final class NativeListSectionIndexView: UIControl, UIGestureRecognizerDe
2951
2984
  label.backgroundColor = active ? activeColor : .clear
2952
2985
  label.layer.cornerRadius = Self.labelSize / 2
2953
2986
  label.layer.masksToBounds = active
2954
- label.font = nativeListFont(ofSize: 10, weight: active ? .medium : .regular)
2987
+ label.font = nativeListFont(ofSize: 10, weight: active ? .medium : .regular, fonts: fonts)
2955
2988
  }
2956
2989
  }
2957
2990
  }
@@ -21,7 +21,7 @@ final class NativeListActivityPresentationTests: XCTestCase {
21
21
  ],
22
22
  ])
23
23
  let view = NativeListActivityDetailsView()
24
- view.bind(item, theme: nil)
24
+ view.bind(item, theme: nil, fonts: NativeListFontFamilies())
25
25
  func labels(in view: UIView) -> [UILabel] {
26
26
  (view as? UILabel).map { [$0] } ?? view.subviews.flatMap { labels(in: $0) }
27
27
  }
@@ -87,11 +87,13 @@ final class NativeListActivityPresentationTests: XCTestCase {
87
87
  view.trailingAnchor.constraint(equalTo: container.trailingAnchor),
88
88
  view.topAnchor.constraint(equalTo: container.topAnchor),
89
89
  ])
90
- view.bind(item, theme: nil)
90
+ view.bind(item, theme: nil, fonts: NativeListFontFamilies())
91
91
  container.layoutIfNeeded()
92
92
  container.layoutIfNeeded()
93
93
  let rendered = ceil(view.frame.height) + vertical * 2
94
- XCTAssertEqual(NativeListActivityDetailsView.measure(data, width: width), rendered, accuracy: 1, name)
94
+ XCTAssertEqual(
95
+ NativeListActivityDetailsView.measure(data, width: width, fonts: NativeListFontFamilies()),
96
+ rendered, accuracy: 1, name)
95
97
  }
96
98
  }
97
99
  }
@@ -76,7 +76,7 @@ final class NativeListLifecycleTests: XCTestCase {
76
76
  "style": ["title": ["color": "#FFAA00"]],
77
77
  ])
78
78
  cell.bind(item: item, theme: nil, layout: "sectioned", selected: false,
79
- checkboxState: { _, _, fallback in fallback })
79
+ checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
80
80
  }
81
81
  try bind(loading: true)
82
82
  let spinner = try XCTUnwrap(cell.root.arrangedSubviews.first as? UIActivityIndicatorView)
@@ -106,7 +106,7 @@ final class NativeListLifecycleTests: XCTestCase {
106
106
 
107
107
  func bind(_ item: NativeListItem) {
108
108
  cell.bind(item: item, theme: nil, layout: "linear", selected: false,
109
- checkboxState: { _, _, fallback in fallback })
109
+ checkboxState: { _, _, fallback in fallback }, fonts: NativeListFontFamilies())
110
110
  }
111
111
 
112
112
  bind(first)
@@ -166,6 +166,81 @@ final class NativeListLifecycleTests: XCTestCase {
166
166
  XCTAssertTrue(second.isHidden)
167
167
  }
168
168
 
169
+ func testFontResolversMeasureBindResetAndKeepIndependentInstances() throws {
170
+ let first = NativeListFontFamilies(names: ["regular": "Courier", "bold": "Courier-Bold"])
171
+ let second = NativeListFontFamilies(names: ["regular": "Georgia", "bold": "Georgia-Bold"])
172
+ XCTAssertNotNil(UIFont(name: "Courier", size: 16))
173
+ XCTAssertNotNil(UIFont(name: "Georgia", size: 16))
174
+ func resolve(_ fonts: NativeListFontFamilies) -> NativeListResolvedText {
175
+ NativeListResolvedText(
176
+ "WWWWiiii", style: nil, size: 16, color: .label,
177
+ lineHeight: 24, lines: 1, fonts: fonts)
178
+ }
179
+ let a = resolve(first)
180
+ let b = resolve(second)
181
+ let label = NativeListTextLabel()
182
+ a.bind(label)
183
+ XCTAssertEqual(label.font.fontName, a.font.fontName)
184
+ XCTAssertEqual(a.measureWidth(), ceil(a.attributed(direction: .leftToRight).size().width))
185
+ XCTAssertNotEqual(a.font.fontName, b.font.fontName)
186
+ XCTAssertNotEqual(a.measureWidth(), b.measureWidth())
187
+ b.bind(label)
188
+ XCTAssertEqual(label.font.fontName, "Georgia")
189
+ resolve(NativeListFontFamilies()).bind(label)
190
+ XCTAssertEqual(label.font.fontName, UIFont.systemFont(ofSize: 16).fontName)
191
+ XCTAssertEqual(a.font.fontName, "Courier")
192
+ }
193
+
194
+ func testUnstyledLeadingVisualAndFooterRebindConfiguredFonts() throws {
195
+ let first = NativeListFontFamilies(names: ["regular": "Courier", "bold": "Courier-Bold"])
196
+ let second = NativeListFontFamilies(names: ["regular": "Georgia", "bold": "Georgia-Bold"])
197
+ let visual = NativeListLeadingVisual()
198
+ for fonts in [first, second] {
199
+ visual.bind(
200
+ ["kind": "account", "fallbackText": "A"], style: [:], key: "a", theme: nil,
201
+ isUnread: false, fonts: fonts)
202
+ XCTAssertEqual(
203
+ visual.fallbackTextView.font.fontName, fonts.font(ofSize: 13, weight: .bold).fontName)
204
+ }
205
+ let view = NativeListView(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
206
+ view.setFontFamiliesJson("{\"regular\":\"Courier\",\"medium\":\"Courier\"}")
207
+ view.applySnapshotJson(
208
+ try snapshot(footer: [
209
+ "key": "footer", "type": "action", "title": "Continue", "actionKey": "continue",
210
+ ]))
211
+ let footer = try XCTUnwrap(footerCell(in: view))
212
+ func labels(_ view: UIView) -> [UILabel] {
213
+ (view as? UILabel).map { [$0] } ?? view.subviews.flatMap(labels)
214
+ }
215
+ XCTAssertEqual(labels(footer).first { $0.text == "Continue" }?.font.fontName, "Courier")
216
+ view.setFontFamiliesJson("{\"regular\":\"Georgia\",\"medium\":\"Georgia\"}")
217
+ XCTAssertEqual(labels(footer).first { $0.text == "Continue" }?.font.fontName, "Georgia")
218
+ XCTAssertEqual(footer.accessibilityLabel, "Continue")
219
+ }
220
+
221
+ func testNestedWalletMembersAndDragBadgeFollowEachBindMapping() throws {
222
+ let group = NativeListWalletGroupCell(frame: CGRect(x: 0, y: 0, width: 320, height: 200))
223
+ let item = try NativeListItem(data: [
224
+ "type": "walletGroup", "key": "group",
225
+ "parent": ["type": "identity", "key": "parent", "title": "Parent", "variant": "wallet"],
226
+ "children": [["type": "identity", "key": "child", "title": "Child", "variant": "wallet"]],
227
+ ])
228
+ func labels(_ view: UIView) -> [UILabel] {
229
+ (view as? UILabel).map { [$0] } ?? view.subviews.flatMap(labels)
230
+ }
231
+ for face in ["Courier", "Georgia"] {
232
+ let fonts = NativeListFontFamilies(names: ["regular": face, "medium": face, "semibold": face])
233
+ group.bind(
234
+ item: item, theme: nil, layout: "linear", selected: false,
235
+ checkboxState: { _, _, fallback in fallback }, fonts: fonts)
236
+ let rendered = labels(group)
237
+ let members = rendered.filter { ["Parent", "Child"].contains($0.text ?? "") }
238
+ XCTAssertGreaterThanOrEqual(members.count, 2)
239
+ XCTAssertTrue(members.allSatisfy { $0.font.fontName == face })
240
+ XCTAssertEqual(rendered.first { $0.text == "+1" }?.font.fontName, face)
241
+ }
242
+ }
243
+
169
244
  private func snapshot(footer: [String: Any]?) throws -> String {
170
245
  var value: [String: Any] = [
171
246
  "schemaVersion": 1, "generation": 1, "layout": ["kind": "linear"], "rows": [],
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ import { useNativeListFontFamiliesJson } from "./fonts.js";
3
4
  import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
4
5
  import { OneKeyImageCache, OneKeyImageCachePolicy } from '@onekeyfe/react-native-image';
5
6
  import { NativeAvatarPrefetchModel, NativeAvatarPrefetchQueue } from "./avatarPrefetch.js";
@@ -52,6 +53,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
52
53
  initialScrollViewOffset,
53
54
  ...viewProps
54
55
  }, forwardedRef) {
56
+ const fontFamiliesJson = useNativeListFontFamiliesJson();
55
57
  const [slotHeights, setSlotHeights] = useState([0, 0, 0]);
56
58
  const [topOverlayHeight, setTopOverlayHeight] = useState(0);
57
59
  const hasTopOverlay = Platform?.OS === 'ios' && parseInt(String(Platform.Version), 10) >= 26 && topScrollEdgeEffect === 'hard' && topOverlay != null;
@@ -320,6 +322,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
320
322
  return /*#__PURE__*/_jsxs(NativeListHost, {
321
323
  ...viewProps,
322
324
  ...nativeCallbacks,
325
+ fontFamiliesJson: fontFamiliesJson,
323
326
  snapshotJson: snapshotJson,
324
327
  containerSlotHeightsJson: containerSlotHeightsJson,
325
328
  topScrollEdgeHard: hasTopOverlay,