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

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