@onekeyfe/react-native-native-list 3.0.179-alpha.303 → 3.0.179-alpha.304

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
@@ -2,6 +2,7 @@ import UIKit
2
2
 
3
3
  /// The activity template's bounded rich presentation; all values are caller-formatted.
4
4
  final class NativeListActivityDetailsView: UIStackView {
5
+ var fonts = NativeListFontFamilies()
5
6
  var onAction: ((String, UIView, String, Int) -> Void)?
6
7
  private let main = UIStackView()
7
8
  private let visual = NativeListLeadingVisual()
@@ -58,7 +59,10 @@ final class NativeListActivityDetailsView: UIStackView {
58
59
 
59
60
  /// Mirrors bind(): the same resolved texts, stack spacings and column widths, so the
60
61
  /// automatic height matches the rendered stacks.
61
- static func measure(_ data: [String: Any], width: CGFloat) -> CGFloat {
62
+ static func measure(_ data: [String: Any], width: CGFloat, fonts: NativeListFontFamilies)
63
+ -> CGFloat
64
+ {
65
+ sizingButton.titleLabel?.font = nativeListFont(ofSize: 14, weight: .medium, fonts: fonts)
62
66
  let style = data.dictionary("style") ?? [:]
63
67
  let table = data.string("presentation") == "table"
64
68
  let image = style.dictionary("image") ?? [:]
@@ -72,9 +76,10 @@ final class NativeListActivityDetailsView: UIStackView {
72
76
 
73
77
  let amounts = data.dictionaries("amounts").map { amount -> (width: CGFloat, height: CGFloat) in
74
78
  let primary = NativeListResolvedText(amount.string("text"), style: style.dictionary("primaryAmount"),
75
- size: 16, weight: .medium, color: .label, lineHeight: 24, lines: 1, tabular: true)
79
+ size: 16, weight: .medium, color: .label, lineHeight: 24, lines: 1, tabular: true,
80
+ fonts: fonts)
76
81
  let secondary = NativeListResolvedText(amount.string("secondaryText"), style: style.dictionary("secondaryAmount"),
77
- size: 14, color: .label, lineHeight: 20, lines: 1)
82
+ size: 14, color: .label, lineHeight: 20, lines: 1, fonts: fonts)
78
83
  let visual: CGFloat = amount.dictionary("leading") == nil ? 0 : 20
79
84
  return (
80
85
  (visual > 0 ? visual + 6 : 0) + max(primary.measureWidth(), secondary.measureWidth()),
@@ -89,9 +94,15 @@ final class NativeListActivityDetailsView: UIStackView {
89
94
  var feeHeight: CGFloat = 0
90
95
  if let feeData = data.dictionary("fee") {
91
96
  let secondaryStyle = style.dictionary("secondaryAmount")
92
- let label = NativeListResolvedText(feeData.string("label"), style: secondaryStyle, size: 12, color: .label, lineHeight: 16, lines: 1)
93
- let primary = NativeListResolvedText(feeData.string("primary"), style: secondaryStyle, size: 14, color: .label, lineHeight: 20, lines: 1)
94
- let secondary = NativeListResolvedText(feeData.string("secondary"), style: secondaryStyle, size: 12, color: .label, lineHeight: 16, lines: 1)
97
+ let label = NativeListResolvedText(
98
+ feeData.string("label"), style: secondaryStyle, size: 12, color: .label, lineHeight: 16,
99
+ lines: 1, fonts: fonts)
100
+ let primary = NativeListResolvedText(
101
+ feeData.string("primary"), style: secondaryStyle, size: 14, color: .label, lineHeight: 20,
102
+ lines: 1, fonts: fonts)
103
+ let secondary = NativeListResolvedText(
104
+ feeData.string("secondary"), style: secondaryStyle, size: 12, color: .label, lineHeight: 16,
105
+ lines: 1, fonts: fonts)
95
106
  let lineWidth = primary.measureWidth() + secondary.measureWidth() +
96
107
  (primary.text.isEmpty || secondary.text.isEmpty ? 0 : 4)
97
108
  feeWidth = max(label.measureWidth(), lineWidth)
@@ -108,14 +119,14 @@ final class NativeListActivityDetailsView: UIStackView {
108
119
  }
109
120
 
110
121
  let title = NativeListResolvedText(data.string("title"), style: style.dictionary("title"), size: 16,
111
- weight: .medium, color: .label, lineHeight: 24, lines: 1)
122
+ weight: .medium, color: .label, lineHeight: 24, lines: 1, fonts: fonts)
112
123
  let titleHeight = max(
113
124
  title.measure(width: .greatestFiniteMagnitude),
114
125
  data.dictionaries("badges").isEmpty ? 0 : 16)
115
126
  let description = NativeListResolvedText(data.string("description"), style: style.dictionary("description"),
116
- size: 14, color: .label, lineHeight: 20, lines: 2)
127
+ size: 14, color: .label, lineHeight: 20, lines: 2, fonts: fonts)
117
128
  let status = NativeListResolvedText(data.string("status"), style: style.dictionary("status"),
118
- size: 12, color: .label, lineHeight: 16, lines: 1)
129
+ size: 12, color: .label, lineHeight: 16, lines: 1, fonts: fonts)
119
130
  var identityHeight = titleHeight
120
131
  for text in [description, status] where !text.text.isEmpty {
121
132
  identityHeight += lineGap + text.measure(width: max(1, identityWidth))
@@ -132,7 +143,8 @@ final class NativeListActivityDetailsView: UIStackView {
132
143
  return max(imageHeight, identityHeight, amountsHeight, feeHeight) + actionsHeight + verticalPadding * 2
133
144
  }
134
145
 
135
- func bind(_ item: NativeListItem, theme: [String: Any]?) {
146
+ func bind(_ item: NativeListItem, theme: [String: Any]?, fonts: NativeListFontFamilies) {
147
+ self.fonts = fonts
136
148
  let data = item.data
137
149
  let style = data.dictionary("style") ?? [:]
138
150
  let image = style.dictionary("image") ?? [:]
@@ -151,13 +163,19 @@ final class NativeListActivityDetailsView: UIStackView {
151
163
  if table { dimensions.append(amounts.widthAnchor.constraint(equalTo: identity.widthAnchor)) }
152
164
  NSLayoutConstraint.activate(dimensions)
153
165
  visual.bind(data.dictionary("leading") ?? [:], style: image, key: item.key, theme: theme,
154
- isUnread: false, secondaryVisual: data.dictionary("secondaryLeading"))
166
+ isUnread: false, secondaryVisual: data.dictionary("secondaryLeading"), fonts: fonts)
155
167
  NativeListResolvedText(data.string("title"), style: style.dictionary("title"), size: 16,
156
- weight: .medium, color: nativeListColor(theme, "primaryText", "#202020"), lineHeight: 24, lines: 1).bind(title)
168
+ weight: .medium, color: nativeListColor(theme, "primaryText", "#202020"), lineHeight: 24,
169
+ lines: 1, fonts: fonts
170
+ ).bind(title)
157
171
  NativeListResolvedText(data.string("description"), style: style.dictionary("description"), size: 14,
158
- color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20, lines: 2).bind(descriptionLabel)
172
+ color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20, lines: 2,
173
+ fonts: fonts
174
+ ).bind(descriptionLabel)
159
175
  NativeListResolvedText(data.string("status"), style: style.dictionary("status"), size: 12,
160
- color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 16, lines: 1).bind(status)
176
+ color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 16, lines: 1,
177
+ fonts: fonts
178
+ ).bind(status)
161
179
  descriptionKey = data.string("descriptionActionKey")
162
180
  descriptionLabel.isUserInteractionEnabled = !descriptionKey.isEmpty
163
181
  descriptionLabel.accessibilityTraits = descriptionKey.isEmpty ? .staticText : .button
@@ -167,7 +185,8 @@ final class NativeListActivityDetailsView: UIStackView {
167
185
  let tone = descriptor.string("tone")
168
186
  let tint = nativeListActivityTone(tone, theme: theme)
169
187
  NativeListResolvedText(" \(descriptor.string("text")) ", style: nil, size: 12,
170
- weight: .medium, color: tint, lineHeight: 16, lines: 1).bind(label)
188
+ weight: .medium, color: tint, lineHeight: 16, lines: 1, fonts: fonts
189
+ ).bind(label)
171
190
  label.backgroundColor = tint.withAlphaComponent(0.1)
172
191
  label.layer.cornerRadius = 4; label.clipsToBounds = true
173
192
  label.setContentCompressionResistancePriority(.required, for: .horizontal)
@@ -182,17 +201,23 @@ final class NativeListActivityDetailsView: UIStackView {
182
201
  let view = NativeListActivityAmountView(); amountViews.append(view); amounts.addArrangedSubview(view)
183
202
  }
184
203
  for (index, descriptor) in descriptors.enumerated() {
185
- amountViews[index].bind(descriptor, key: "\(item.key):\(descriptor.string("key"))", style: style, theme: theme, table: table)
204
+ amountViews[index].bind(descriptor, key: "\(item.key):\(descriptor.string("key"))", style: style, theme: theme, table: table, fonts: fonts)
186
205
  }
187
206
  let feeData = data.dictionary("fee")
188
207
  fee.isHidden = feeData == nil
189
208
  fee.alpha = feeData?.bool("hidden") == true ? 0 : 1
190
209
  NativeListResolvedText(feeData?.string("label") ?? "", style: style.dictionary("secondaryAmount"),
191
- size: 12, color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 16, lines: 1).bind(feeLabel)
210
+ size: 12, color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 16, lines: 1,
211
+ fonts: fonts
212
+ ).bind(feeLabel)
192
213
  NativeListResolvedText(feeData?.string("primary") ?? "", style: style.dictionary("secondaryAmount"),
193
- size: 14, color: nativeListColor(theme, "primaryText", "#202020"), lineHeight: 20, lines: 1).bind(feePrimary)
214
+ size: 14, color: nativeListColor(theme, "primaryText", "#202020"), lineHeight: 20, lines: 1,
215
+ fonts: fonts
216
+ ).bind(feePrimary)
194
217
  NativeListResolvedText(feeData?.string("secondary") ?? "", style: style.dictionary("secondaryAmount"),
195
- size: 12, color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 16, lines: 1).bind(feeSecondary)
218
+ size: 12, color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 16, lines: 1,
219
+ fonts: fonts
220
+ ).bind(feeSecondary)
196
221
  for button in buttons { actions.removeArrangedSubview(button); button.removeFromSuperview() }
197
222
  buttons = []
198
223
  nativeListActivitySegments(feePrimary, feeData?.dictionaries("primaryTextSegments") ?? [])
@@ -204,7 +229,7 @@ final class NativeListActivityDetailsView: UIStackView {
204
229
  for (index, descriptor) in actionData.enumerated() {
205
230
  let button = UIButton(type: .system); button.tag = index
206
231
  button.setTitle(descriptor.string("label"), for: .normal)
207
- button.titleLabel?.font = nativeListFont(ofSize: 14, weight: .medium)
232
+ button.titleLabel?.font = nativeListFont(ofSize: 14, weight: .medium, fonts: fonts)
208
233
  button.setTitleColor(nativeListActivityTone(descriptor.string("tone"), theme: theme), for: .normal)
209
234
  button.backgroundColor = nativeListColor(theme, "strongBackground", "#F0F0F0")
210
235
  button.layer.cornerRadius = 8
@@ -240,6 +265,7 @@ private func nativeListActivityTone(_ tone: String, theme: [String: Any]?) -> UI
240
265
  }
241
266
 
242
267
  private final class NativeListActivityAmountView: UIStackView {
268
+ var fonts = NativeListFontFamilies()
243
269
  private let visual = NativeListLeadingVisual()
244
270
  private let labels = UIStackView()
245
271
  private let primary = NativeListTextLabel()
@@ -253,20 +279,33 @@ private final class NativeListActivityAmountView: UIStackView {
253
279
  NSLayoutConstraint.activate([visual.widthAnchor.constraint(equalToConstant: 20), visual.heightAnchor.constraint(equalToConstant: 20)])
254
280
  }
255
281
  required init(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
256
- func bind(_ data: [String: Any], key: String, style: [String: Any], theme: [String: Any]?, table: Bool) {
282
+ func bind(
283
+ _ data: [String: Any], key: String, style: [String: Any], theme: [String: Any]?, table: Bool,
284
+ fonts: NativeListFontFamilies
285
+ ) {
286
+ self.fonts = fonts
257
287
  let leading = data.dictionary("leading")
258
288
  visual.isHidden = leading == nil
259
- if let leading { visual.bind(leading, style: ["width": 20, "height": 20], key: key, theme: theme, isUnread: false) } else { visual.recycle() }
289
+ if let leading {
290
+ visual.bind(
291
+ leading, style: ["width": 20, "height": 20], key: key, theme: theme, isUnread: false,
292
+ fonts: fonts)
293
+ } else {
294
+ visual.recycle()
295
+ }
260
296
  var primaryStyle = style.dictionary("primaryAmount") ?? [:]
261
297
  if primaryStyle["alignment"] == nil { primaryStyle["alignment"] = table ? "start" : "end" }
262
298
  let resolved = NativeListResolvedText(data.string("text"), style: primaryStyle, size: 16,
263
- weight: .medium, color: nativeListActivityTone(data.string("tone"), theme: theme), lineHeight: 24, lines: 1, tabular: true)
299
+ weight: .medium, color: nativeListActivityTone(data.string("tone"), theme: theme),
300
+ lineHeight: 24, lines: 1, tabular: true, fonts: fonts)
264
301
  resolved.bind(primary)
265
302
  nativeListActivitySegments(primary, data.dictionaries("textSegments"))
266
303
  var secondaryStyle = style.dictionary("secondaryAmount") ?? [:]
267
304
  if secondaryStyle["alignment"] == nil { secondaryStyle["alignment"] = table ? "start" : "end" }
268
305
  NativeListResolvedText(data.string("secondaryText"), style: secondaryStyle, size: 14,
269
- color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20, lines: 1).bind(secondary)
306
+ color: nativeListColor(theme, "secondaryText", "#646464"), lineHeight: 20, lines: 1,
307
+ fonts: fonts
308
+ ).bind(secondary)
270
309
  nativeListActivitySegments(secondary, data.dictionaries("secondaryTextSegments"))
271
310
  }
272
311
  func recycle() { visual.recycle() }
@@ -2,9 +2,12 @@ import UIKit
2
2
 
3
3
  final class NativeListActivityCell: 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
- if item.data["amounts"] != nil { return NativeListActivityDetailsView.measure(item.data, width: width) }
8
+ if item.data["amounts"] != nil {
9
+ return NativeListActivityDetailsView.measure(item.data, width: width, fonts: fonts)
10
+ }
8
11
  return item.data.dictionaries("footerActions").isEmpty ? 60 : 100
9
12
  }
10
13
 
@@ -56,7 +59,7 @@ final class NativeListActivityCell: NativeListRendererCell {
56
59
  actions.spacing = 8
57
60
  for (index, button) in buttons.enumerated() {
58
61
  button.tag = index
59
- button.titleLabel?.font = nativeListFont(ofSize: 12, weight: .medium)
62
+ button.titleLabel?.font = nativeListFont(ofSize: 12, weight: .medium, fonts: fonts)
60
63
  button.layer.cornerRadius = 8
61
64
  button.contentEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
62
65
  button.addTarget(self, action: #selector(pressed(_:)), for: .touchUpInside)
@@ -73,6 +76,9 @@ final class NativeListActivityCell: NativeListRendererCell {
73
76
  _ item: NativeListItem, theme: [String: Any]?, layout: String,
74
77
  checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String
75
78
  ) {
79
+ buttons.forEach {
80
+ $0.titleLabel?.font = nativeListFont(ofSize: 12, weight: .medium, fonts: fonts)
81
+ }
76
82
  let data = item.data
77
83
  let rich = data["amounts"] != nil
78
84
  details.isHidden = !rich
@@ -85,7 +91,7 @@ final class NativeListActivityCell: NativeListRendererCell {
85
91
  let vp = CGFloat(style.double("verticalPadding", default: 8))
86
92
  contentInsets = UIEdgeInsets(top: vp, left: hp, bottom: vp, right: hp)
87
93
  visual.recycle()
88
- details.bind(item, theme: theme)
94
+ details.bind(item, theme: theme, fonts: fonts)
89
95
  return
90
96
  }
91
97
  details.recycle()
@@ -115,7 +121,7 @@ final class NativeListActivityCell: NativeListRendererCell {
115
121
  if let leading = data.dictionary("leading") {
116
122
  visual.bind(
117
123
  leading, style: image, key: item.key, theme: theme, isUnread: false,
118
- secondaryVisual: data.dictionary("secondaryLeading"))
124
+ secondaryVisual: data.dictionary("secondaryLeading"), fonts: fonts)
119
125
  } else {
120
126
  // Legacy kept an empty leading slot (no placeholder disc) when no visual was given.
121
127
  visual.clear()
@@ -126,7 +132,8 @@ final class NativeListActivityCell: NativeListRendererCell {
126
132
  ) {
127
133
  NativeListResolvedText(
128
134
  value, style: style.dictionary(slot), size: size, weight: weight, color: color,
129
- lineHeight: line, lines: lines
135
+ lineHeight: line, lines: lines,
136
+ fonts: fonts
130
137
  ).bind(view)
131
138
  }
132
139
  bind(
@@ -139,11 +146,11 @@ final class NativeListActivityCell: NativeListRendererCell {
139
146
  bind(
140
147
  status, failed ? "" : data.string("status"), "status", size: 12,
141
148
  color: nativeListColor(theme, "secondaryText", "#646464"),
142
- line: nativeListFont(ofSize: 12).lineHeight)
149
+ line: nativeListFont(ofSize: 12, fonts: fonts).lineHeight)
143
150
  bind(
144
151
  failure, failed ? " Failed " : "", "status", size: 12, weight: .medium,
145
152
  color: nativeListColor(theme, "negative", "#CE2C31"),
146
- line: nativeListFont(ofSize: 12, weight: .medium).lineHeight)
153
+ line: nativeListFont(ofSize: 12, weight: .medium, fonts: fonts).lineHeight)
147
154
  failure.backgroundColor = nativeListColor(theme, "criticalBackground", "#F3000D14")
148
155
  failure.layer.cornerRadius = 4
149
156
  failure.clipsToBounds = true
@@ -163,12 +170,14 @@ final class NativeListActivityCell: NativeListRendererCell {
163
170
  button.rowTextOffsetY = 0
164
171
  let resolved = NativeListResolvedText(
165
172
  value, style: nil, size: index == 0 ? 16 : 14, weight: index == 0 ? .medium : .regular,
166
- color: color, lineHeight: index == 0 ? 24 : 20, lines: 1, tabular: true)
173
+ color: color, lineHeight: index == 0 ? 24 : 20, lines: 1, tabular: true, fonts: fonts)
167
174
  button.setAttributedTitle(
168
175
  resolved.attributed(direction: button.effectiveUserInterfaceLayoutDirection), for: .normal)
169
176
  button.titleLabel?.font = resolved.font
170
177
  button.isHidden = value.isEmpty
171
- if let text = style.dictionary(slot) { NativeListTextStyles.applyStyledButton(button, text) }
178
+ if let text = style.dictionary(slot) {
179
+ NativeListTextStyles.applyStyledButton(button, text, fonts: fonts)
180
+ }
172
181
  }
173
182
  let descriptors = Array(data.dictionaries("footerActions").prefix(3))
174
183
  actions.isHidden = descriptors.isEmpty
@@ -2,7 +2,8 @@ import UIKit
2
2
 
3
3
  final class NativeListDataRowCell: 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
8
  let secondary = item.data.dictionaries("columns").contains {
8
9
  !$0.string("secondaryText").isEmpty
@@ -64,7 +65,7 @@ final class NativeListDataRowCell: NativeListRendererCell {
64
65
  root.setCustomSpacing(layout == "table" ? 8 : root.spacing, after: favorite)
65
66
  visual.isHidden = data.dictionary("leading") == nil
66
67
  if let leading = data.dictionary("leading") {
67
- visual.bind(leading, style: image, key: item.key, theme: theme, isUnread: false)
68
+ visual.bind(leading, style: image, key: item.key, theme: theme, isUnread: false, fonts: fonts)
68
69
  } else {
69
70
  visual.recycle()
70
71
  }
@@ -83,7 +84,7 @@ final class NativeListDataRowCell: NativeListRendererCell {
83
84
  accessoryStyle["value"] = style.dictionary("index")
84
85
  accessories.bind(
85
86
  item, descriptors: descriptors, theme: theme, style: accessoryStyle,
86
- checkboxState: checkboxState)
87
+ checkboxState: checkboxState, fonts: fonts)
87
88
  accessories.isHidden = descriptors.isEmpty
88
89
  NSLayoutConstraint.deactivate(rowConstraints)
89
90
  rowConstraints = [
@@ -101,11 +102,13 @@ final class NativeListDataRowCell: NativeListRendererCell {
101
102
  }
102
103
  let badges = index == 0 ? data.dictionaries("badges") : []
103
104
  if layout == "table" {
104
- cell.bind(column: values[index], badges: badges, theme: theme)
105
+ cell.bind(column: values[index], badges: badges, theme: theme, fonts: fonts)
105
106
  } else {
106
- cell.bindLinear(column: values[index], badges: badges, theme: theme, style: style)
107
+ cell.bindLinear(column: values[index], badges: badges, theme: theme, style: style, fonts: fonts)
108
+ }
109
+ cell.applyStyle(style) { label, style in
110
+ NativeListTextStyles.applyStyledText(label, style, fonts: fonts)
107
111
  }
108
- cell.applyStyle(style, text: NativeListTextStyles.applyStyledText)
109
112
  if index > 0 {
110
113
  rowConstraints.append(
111
114
  cell.widthAnchor.constraint(
@@ -202,7 +205,8 @@ private final class NativeListTableColumnView: UIStackView {
202
205
  func bind(
203
206
  column: [String: Any],
204
207
  badges: [[String: Any]],
205
- theme: [String: Any]?
208
+ theme: [String: Any]?,
209
+ fonts: NativeListFontFamilies
206
210
  ) {
207
211
  reset()
208
212
  let textAlignment: NSTextAlignment
@@ -220,12 +224,12 @@ private final class NativeListTableColumnView: UIStackView {
220
224
  primaryLabel.textAlignment = textAlignment
221
225
  secondaryLeadingLabel.textAlignment = textAlignment
222
226
  secondaryLabel.textAlignment = textAlignment
223
- primaryLabel.font = nativeListFont(ofSize: 14, weight: .medium)
224
- secondaryLeadingLabel.font = nativeListFont(ofSize: 12)
225
- secondaryLabel.font = nativeListFont(ofSize: 12)
227
+ primaryLabel.font = nativeListFont(ofSize: 14, weight: .medium, fonts: fonts)
228
+ secondaryLeadingLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
229
+ secondaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
226
230
  primaryLabel.attributedText = line(
227
231
  column.string("text"),
228
- font: nativeListFont(ofSize: 14, weight: .medium),
232
+ font: nativeListFont(ofSize: 14, weight: .medium, fonts: fonts),
229
233
  color: textColor(column.string("tone"), theme: theme),
230
234
  height: 20
231
235
  )
@@ -234,7 +238,7 @@ private final class NativeListTableColumnView: UIStackView {
234
238
  let label = NativeListInsetLabel()
235
239
  label.horizontalInset = 6
236
240
  label.text = badge.string("text")
237
- label.font = nativeListFont(ofSize: 10)
241
+ label.font = nativeListFont(ofSize: 10, fonts: fonts)
238
242
  label.textColor = nativeListColor(theme, "info", "#0D74CE")
239
243
  label.textAlignment = .center
240
244
  label.backgroundColor = UIColor(nativeListHex: "#008FF519", fallback: .systemBlue)
@@ -250,7 +254,7 @@ private final class NativeListTableColumnView: UIStackView {
250
254
  if !secondaryLeading.isEmpty {
251
255
  secondaryLeadingLabel.attributedText = line(
252
256
  secondaryLeading,
253
- font: nativeListFont(ofSize: 12),
257
+ font: nativeListFont(ofSize: 12, fonts: fonts),
254
258
  color: nativeListColor(theme, "secondaryText", "#646464"),
255
259
  height: 16
256
260
  )
@@ -261,7 +265,7 @@ private final class NativeListTableColumnView: UIStackView {
261
265
  if !secondary.isEmpty {
262
266
  secondaryLabel.attributedText = line(
263
267
  secondary,
264
- font: nativeListFont(ofSize: 12),
268
+ font: nativeListFont(ofSize: 12, fonts: fonts),
265
269
  color: textColor(
266
270
  column.string("secondaryTone", default: "secondary"),
267
271
  theme: theme
@@ -280,7 +284,7 @@ private final class NativeListTableColumnView: UIStackView {
280
284
  /// alignment); `lines`/`truncate` and vertical alignment/offset act on the single label.
281
285
  func bindLinear(
282
286
  column: [String: Any], badges: [[String: Any]], theme: [String: Any]?,
283
- style: [String: Any] = [:]
287
+ style: [String: Any] = [:], fonts: NativeListFontFamilies
284
288
  ) {
285
289
  reset()
286
290
  linear = true
@@ -290,12 +294,12 @@ private final class NativeListTableColumnView: UIStackView {
290
294
  let secondaryStyle = style.dictionary("columnSecondary") ?? [:]
291
295
  func font(_ textStyle: [String: Any], size: CGFloat, weight: NativeListFontWeight) -> UIFont {
292
296
  guard textStyle["fontSize"] != nil || textStyle["fontWeight"] != nil else {
293
- return nativeListFont(ofSize: size, weight: weight)
297
+ return nativeListFont(ofSize: size, weight: weight, fonts: fonts)
294
298
  }
295
299
  return nativeListFont(
296
300
  ofSize: CGFloat(textStyle.double("fontSize", default: Double(size))),
297
301
  weight: NativeListTextStyles.marketFontWeight(
298
- textStyle.string("fontWeight"), fallback: weight))
302
+ textStyle.string("fontWeight"), fallback: weight), fonts: fonts)
299
303
  }
300
304
  func color(_ textStyle: [String: Any], _ fallback: UIColor) -> UIColor {
301
305
  (textStyle["color"] as? String).map { UIColor(nativeListHex: $0, fallback: fallback) }
@@ -351,7 +355,7 @@ private final class NativeListTableColumnView: UIStackView {
351
355
  NSAttributedString(
352
356
  string: " \(badge.string("text")) ",
353
357
  attributes: [
354
- .font: nativeListFont(ofSize: 12, weight: .medium),
358
+ .font: nativeListFont(ofSize: 12, weight: .medium, fonts: fonts),
355
359
  .foregroundColor: nativeListColor(theme, "info", "#0D74CE"),
356
360
  .backgroundColor: UIColor(nativeListHex: "#008FF519", fallback: .systemBlue),
357
361
  ]))
@@ -377,7 +381,7 @@ private final class NativeListTableColumnView: UIStackView {
377
381
  attributed.append(NSAttributedString(string: "\n\(secondary)", attributes: attributes))
378
382
  lines = min(3, lines + max(1, secondaryStyle.int("lines", default: 1)))
379
383
  }
380
- primaryLabel.font = nativeListFont(ofSize: 12)
384
+ primaryLabel.font = nativeListFont(ofSize: 12, fonts: fonts)
381
385
  primaryLabel.numberOfLines = lines
382
386
  primaryLabel.attributedText = attributed
383
387
  let truncation =
@@ -9,16 +9,7 @@ enum NativeListFontWeight {
9
9
  case semibold
10
10
  case bold
11
11
 
12
- fileprivate var postScriptName: String {
13
- switch self {
14
- case .regular: return "Roobert-Regular"
15
- case .medium: return "Roobert-Medium"
16
- case .semibold: return "Roobert-SemiBold"
17
- case .bold: return "Roobert-Bold"
18
- }
19
- }
20
-
21
- fileprivate var systemWeight: UIFont.Weight {
12
+ var systemWeight: UIFont.Weight {
22
13
  switch self {
23
14
  case .regular: return .regular
24
15
  case .medium: return .medium
@@ -39,40 +30,58 @@ private enum NativeListResources {
39
30
  }
40
31
  return Bundle(for: NativeListResourceToken.self)
41
32
  }()
33
+ }
34
+
35
+ struct NativeListFontFamilies: Equatable {
36
+ let names: [String: String]
37
+ init(names: [String: String] = [:]) { self.names = names }
42
38
 
43
- static let registerFonts: Void = {
44
- ["Regular", "Medium", "SemiBold", "Bold"].forEach { weight in
45
- let directURL = bundle.url(forResource: "Roobert-\(weight)", withExtension: "ttf")
46
- let nestedURL = bundle.url(
47
- forResource: "Roobert-\(weight)",
48
- withExtension: "ttf",
49
- subdirectory: "fonts"
50
- )
51
- guard let url = directURL ?? nestedURL else { return }
52
- CTFontManagerRegisterFontsForURL(url as CFURL, .process, nil)
39
+ init?(json: String) {
40
+ guard let data = json.data(using: .utf8),
41
+ let value = try? JSONSerialization.jsonObject(with: data) as? [String: Any]
42
+ else { return nil }
43
+ let weights: Set<String> = ["regular", "medium", "semibold", "bold"]
44
+ var names: [String: String] = [:]
45
+ for (key, value) in value {
46
+ guard weights.contains(key), let name = value as? String, !name.isEmpty,
47
+ name.utf16.count <= 128,
48
+ !name.unicodeScalars.contains(where: { $0.value < 32 || $0.value == 127 })
49
+ else { return nil }
50
+ names[key] = name
53
51
  }
54
- }()
52
+ self.names = names
53
+ }
54
+
55
+ func font(ofSize size: CGFloat, weight: NativeListFontWeight) -> UIFont {
56
+ let key: String
57
+ switch weight {
58
+ case .regular: key = "regular"
59
+ case .medium: key = "medium"
60
+ case .semibold: key = "semibold"
61
+ case .bold: key = "bold"
62
+ }
63
+ return names[key].flatMap { UIFont(name: $0, size: size) }
64
+ ?? UIFont.systemFont(ofSize: size, weight: weight.systemWeight)
65
+ }
55
66
  }
56
67
 
57
- func nativeListFont(ofSize size: CGFloat, weight: NativeListFontWeight = .regular) -> UIFont {
58
- _ = NativeListResources.registerFonts
59
- return UIFont(name: weight.postScriptName, size: size)
60
- ?? UIFont.systemFont(ofSize: size, weight: weight.systemWeight)
68
+ func nativeListFont(
69
+ ofSize size: CGFloat, weight: NativeListFontWeight = .regular,
70
+ fonts: NativeListFontFamilies = NativeListFontFamilies()
71
+ ) -> UIFont {
72
+ fonts.font(ofSize: size, weight: weight)
61
73
  }
62
74
 
63
75
  func nativeListTabularFont(
64
- ofSize size: CGFloat,
65
- weight: NativeListFontWeight = .regular
76
+ ofSize size: CGFloat, weight: NativeListFontWeight = .regular,
77
+ fonts: NativeListFontFamilies = NativeListFontFamilies()
66
78
  ) -> UIFont {
67
- let font = nativeListFont(ofSize: size, weight: weight)
79
+ let font = fonts.font(ofSize: size, weight: weight)
68
80
  let settings: [[UIFontDescriptor.FeatureKey: Int]] = [[
69
- .type: kNumberSpacingType,
70
- .selector: kMonospacedNumbersSelector,
81
+ .type: kNumberSpacingType, .selector: kMonospacedNumbersSelector
71
82
  ]]
72
- let descriptor = font.fontDescriptor.addingAttributes([
73
- .featureSettings: settings,
74
- ])
75
- return UIFont(descriptor: descriptor, size: size)
83
+ return UIFont(
84
+ descriptor: font.fontDescriptor.addingAttributes([.featureSettings: settings]), size: size)
76
85
  }
77
86
 
78
87
  func nativeListIcon(named name: String) -> UIImage? {