@onekeyfe/react-native-native-list 3.0.158 → 3.0.159

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 (199) hide show
  1. package/README.md +21 -5
  2. package/android/build.gradle +7 -0
  3. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +20 -0
  4. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +711 -0
  5. package/android/src/main/java/com/onekey/nativelist/NativeListActionRenderer.kt +169 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +179 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +264 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +20 -6
  9. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +53 -0
  10. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +487 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListEndAlignment.kt +5 -0
  12. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +820 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListImageSlot.kt +147 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +453 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +997 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +268 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +243 -0
  18. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +232 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListMetricCardRenderer.kt +551 -0
  20. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +27 -1
  21. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +475 -0
  22. package/android/src/main/java/com/onekey/nativelist/NativeListRailRenderer.kt +143 -0
  23. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +42 -0
  24. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +415 -0
  25. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +163 -0
  26. package/android/src/main/java/com/onekey/nativelist/NativeListRowHost.kt +70 -0
  27. package/android/src/main/java/com/onekey/nativelist/NativeListScrollPositionTracker.kt +59 -0
  28. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +763 -0
  29. package/android/src/main/java/com/onekey/nativelist/NativeListSystemRenderer.kt +464 -0
  30. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +25 -0
  31. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +432 -124
  32. package/android/src/main/java/com/onekey/nativelist/NativeListWalletGroupRenderer.kt +407 -0
  33. package/android/src/main/res/values/native_scroll_coordinator_ids.xml +5 -0
  34. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListEndAlignmentTest.kt +34 -0
  35. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListScrollPositionTrackerTest.kt +44 -0
  36. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListSelectorBackgroundColorTest.kt +34 -0
  37. package/docs/DESIGN.md +520 -9
  38. package/docs/MIGRATION_BASELINE.md +117 -0
  39. package/docs/ROW_TEMPLATES.md +404 -0
  40. package/docs/SPEC.md +621 -0
  41. package/docs/STYLE_SPEC.md +988 -0
  42. package/docs/images/list-capabilities.svg +39 -0
  43. package/docs/images/row-action.svg +17 -0
  44. package/docs/images/row-activity.svg +24 -0
  45. package/docs/images/row-data.svg +24 -0
  46. package/docs/images/row-identity.svg +25 -0
  47. package/docs/images/row-market.svg +23 -0
  48. package/docs/images/row-media-tile.svg +26 -0
  49. package/docs/images/row-message.svg +20 -0
  50. package/docs/images/row-metric-card.svg +33 -0
  51. package/docs/images/row-rail.svg +18 -0
  52. package/docs/images/row-section-header.svg +19 -0
  53. package/docs/images/row-style-regions.svg +30 -0
  54. package/docs/images/row-system.svg +30 -0
  55. package/docs/images/row-wallet-group.svg +26 -0
  56. package/ios/HybridNativeList.swift +30 -0
  57. package/ios/NativeListAccessoryStack.swift +680 -0
  58. package/ios/NativeListActionRenderer.swift +108 -0
  59. package/ios/NativeListActivityDetailsView.swift +291 -0
  60. package/ios/NativeListActivityRenderer.swift +201 -0
  61. package/ios/NativeListDataRowRenderer.swift +444 -0
  62. package/ios/NativeListIdentityRenderer.swift +685 -0
  63. package/ios/NativeListImageSlot.swift +140 -0
  64. package/ios/NativeListLeadingVisual.swift +372 -0
  65. package/ios/NativeListMarketRenderer.swift +698 -0
  66. package/ios/NativeListMediaPreviewSlot.swift +259 -0
  67. package/ios/NativeListMediaTileRenderer.swift +190 -0
  68. package/ios/NativeListMessageRenderer.swift +168 -0
  69. package/ios/NativeListMetricCardRenderer.swift +420 -0
  70. package/ios/NativeListModels.swift +36 -1
  71. package/ios/NativeListRailRenderer.swift +152 -0
  72. package/ios/NativeListRendererCell.swift +311 -0
  73. package/ios/NativeListRendererRegistry.swift +50 -0
  74. package/ios/NativeListResolvedText.swift +130 -0
  75. package/ios/NativeListRowHost.swift +63 -0
  76. package/ios/NativeListScrollPositionTracker.swift +30 -0
  77. package/ios/NativeListSectionHeaderRenderer.swift +734 -0
  78. package/ios/NativeListSystemRenderer.swift +568 -0
  79. package/ios/NativeListTextLabel.swift +42 -0
  80. package/ios/NativeListTextStyles.swift +236 -0
  81. package/ios/NativeListWalletGroupRenderer.swift +255 -0
  82. package/ios/RNCNativeListView.swift +282 -184
  83. package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
  84. package/ios/tests/NativeListLifecycleTests.swift +241 -0
  85. package/ios/tests/NativeListMediaVisibilityTests.swift +109 -0
  86. package/ios/tests/NativeListScrollPositionTrackerTests.swift +25 -0
  87. package/lib/module/NativeList.js +56 -3
  88. package/lib/module/NativeList.web.js +5 -0
  89. package/lib/module/models.js +54 -0
  90. package/lib/module/validation.js +386 -28
  91. package/lib/module/web/NativeListWebEngine.js +148 -936
  92. package/lib/module/web/templates/ActionRowRenderer.js +97 -0
  93. package/lib/module/web/templates/ActivityRowRenderer.js +95 -0
  94. package/lib/module/web/templates/DataRowRenderer.js +145 -0
  95. package/lib/module/web/templates/IdentityRowRenderer.js +289 -0
  96. package/lib/module/web/templates/MarketRowRenderer.js +310 -0
  97. package/lib/module/web/templates/MediaTileRowRenderer.js +132 -0
  98. package/lib/module/web/templates/MessageRowRenderer.js +165 -0
  99. package/lib/module/web/templates/MetricCardRowRenderer.js +172 -0
  100. package/lib/module/web/templates/RailRowRenderer.js +98 -0
  101. package/lib/module/web/templates/RowContainerStyle.js +100 -0
  102. package/lib/module/web/templates/RowElements.js +93 -0
  103. package/lib/module/web/templates/RowRendererRegistry.js +70 -0
  104. package/lib/module/web/templates/RowText.js +121 -0
  105. package/lib/module/web/templates/RowVisual.js +43 -0
  106. package/lib/module/web/templates/SectionHeaderRowRenderer.js +146 -0
  107. package/lib/module/web/templates/SystemRowRenderer.js +161 -0
  108. package/lib/module/web/templates/WalletGroupRowRenderer.js +96 -0
  109. package/lib/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  110. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
  111. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
  112. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
  113. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
  114. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
  115. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
  116. package/lib/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
  117. package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
  118. package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
  119. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
  120. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
  121. package/lib/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  122. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
  123. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
  124. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
  125. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
  126. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
  127. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
  128. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
  129. package/lib/typescript/src/NativeList.nitro.d.ts +3 -0
  130. package/lib/typescript/src/NativeList.types.d.ts +14 -1
  131. package/lib/typescript/src/models.d.ts +199 -18
  132. package/lib/typescript/src/web/NativeListWebEngine.d.ts +18 -16
  133. package/lib/typescript/src/web/templates/ActionRowRenderer.d.ts +15 -0
  134. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +15 -0
  135. package/lib/typescript/src/web/templates/DataRowRenderer.d.ts +15 -0
  136. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +16 -0
  137. package/lib/typescript/src/web/templates/MarketRowRenderer.d.ts +30 -0
  138. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +15 -0
  139. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +44 -0
  140. package/lib/typescript/src/web/templates/MetricCardRowRenderer.d.ts +15 -0
  141. package/lib/typescript/src/web/templates/RailRowRenderer.d.ts +28 -0
  142. package/lib/typescript/src/web/templates/RowContainerStyle.d.ts +9 -0
  143. package/lib/typescript/src/web/templates/RowElements.d.ts +38 -0
  144. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +83 -0
  145. package/lib/typescript/src/web/templates/RowText.d.ts +9 -0
  146. package/lib/typescript/src/web/templates/RowVisual.d.ts +20 -0
  147. package/lib/typescript/src/web/templates/SectionHeaderRowRenderer.d.ts +15 -0
  148. package/lib/typescript/src/web/templates/SystemRowRenderer.d.ts +16 -0
  149. package/lib/typescript/src/web/templates/WalletGroupRowRenderer.d.ts +20 -0
  150. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  151. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
  152. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
  153. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
  154. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
  155. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
  156. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
  157. package/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
  158. package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
  159. package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
  160. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
  161. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
  162. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  163. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
  164. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
  165. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
  166. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
  167. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
  168. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
  169. package/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
  170. package/package.json +7 -6
  171. package/react-native-native-list.podspec +6 -0
  172. package/scripts/enable-container-slots.mjs +58 -0
  173. package/scripts/enable-container-slots.test.mjs +58 -0
  174. package/src/NativeList.nitro.ts +3 -0
  175. package/src/NativeList.tsx +84 -2
  176. package/src/NativeList.types.ts +14 -1
  177. package/src/NativeList.web.tsx +5 -0
  178. package/src/models.ts +320 -20
  179. package/src/validation.ts +641 -49
  180. package/src/web/NativeListWebEngine.ts +361 -1932
  181. package/src/web/templates/ActionRowRenderer.ts +123 -0
  182. package/src/web/templates/ActivityRowRenderer.ts +159 -0
  183. package/src/web/templates/DataRowRenderer.ts +212 -0
  184. package/src/web/templates/IdentityRowRenderer.ts +527 -0
  185. package/src/web/templates/MarketRowRenderer.ts +467 -0
  186. package/src/web/templates/MediaTileRowRenderer.ts +182 -0
  187. package/src/web/templates/MessageRowRenderer.ts +306 -0
  188. package/src/web/templates/MetricCardRowRenderer.ts +337 -0
  189. package/src/web/templates/RailRowRenderer.ts +136 -0
  190. package/src/web/templates/RowContainerStyle.ts +131 -0
  191. package/src/web/templates/RowElements.ts +160 -0
  192. package/src/web/templates/RowRendererRegistry.ts +111 -0
  193. package/src/web/templates/RowText.ts +181 -0
  194. package/src/web/templates/RowVisual.ts +115 -0
  195. package/src/web/templates/SectionHeaderRowRenderer.ts +243 -0
  196. package/src/web/templates/SystemRowRenderer.ts +282 -0
  197. package/src/web/templates/WalletGroupRowRenderer.ts +131 -0
  198. package/android/src/main/java/com/onekey/nativelist/NativeListRowView.kt +0 -4538
  199. package/ios/NativeListCell.swift +0 -4300
@@ -0,0 +1,763 @@
1
+ package com.margelo.nitro.nativelist
2
+
3
+ import android.content.res.ColorStateList
4
+ import android.graphics.Paint
5
+ import android.graphics.drawable.GradientDrawable
6
+ import android.text.Spannable
7
+ import android.text.SpannableStringBuilder
8
+ import android.text.TextUtils
9
+ import android.text.style.AbsoluteSizeSpan
10
+ import android.text.style.ForegroundColorSpan
11
+ import android.util.TypedValue
12
+ import android.view.Gravity
13
+ import android.view.View
14
+ import android.view.ViewGroup
15
+ import android.widget.LinearLayout
16
+ import android.widget.ProgressBar
17
+ import android.widget.TextView
18
+ import androidx.core.widget.TextViewCompat
19
+ import com.facebook.react.uimanager.ThemedReactContext
20
+ import kotlin.math.roundToInt
21
+ import org.json.JSONArray
22
+ import org.json.JSONObject
23
+
24
+ internal class NativeListSectionHeaderRowView(context: ThemedReactContext) :
25
+ NativeListRendererRowView(context) {
26
+ private val mainColumn = LinearLayout(context)
27
+ private val titleLine = PackedTitleLineLayout(context)
28
+ private val title = DottedUnderlineTextView(context)
29
+ private val titleSpinner = ProgressBar(context, null, android.R.attr.progressBarStyleSmall).apply {
30
+ isIndeterminate = true
31
+ importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
32
+ }
33
+ private val subtitle = NativeListTextView(context)
34
+ private val trailingColumn = LinearLayout(context)
35
+ private val trailingViews = listOf(NativeListTextView(context))
36
+ private val checkboxControl = NativeListAccessoryStack(context)
37
+ private val headerTitleIcon = OneKeyIconView(context)
38
+ private val headerValueIcon = OneKeyIconView(context)
39
+ private var currentItem: NativeListItem? = null
40
+ private var currentTheme: JSONObject? = null
41
+ private var currentLayout = "linear"
42
+ private val selectorTextMetrics = mutableMapOf<TextView, Pair<Float, Int>>()
43
+ private val paintDefaults = mutableMapOf<TextView, Int>()
44
+ private val selectorAccessibilityDelegate =
45
+ object : View.AccessibilityDelegate() {
46
+ override fun onInitializeAccessibilityNodeInfo(
47
+ host: View,
48
+ info: android.view.accessibility.AccessibilityNodeInfo,
49
+ ) {
50
+ super.onInitializeAccessibilityNodeInfo(host, info)
51
+ info.viewIdResourceName = host.getTag(com.facebook.react.R.id.react_test_id) as? String
52
+ }
53
+ }
54
+
55
+ override fun usesSourceScale(item: NativeListItem, provided: Boolean) =
56
+ item.usesSelectorSourceScale || provided
57
+
58
+ override fun backgroundGroupPosition(
59
+ item: NativeListItem,
60
+ layout: String,
61
+ itemIndex: Int?,
62
+ selected: Boolean,
63
+ ) =
64
+ if (layout == "sectioned" && !item.json.optBoolean("selected")) ""
65
+ else item.json.optString("groupPosition")
66
+
67
+ override fun defaultHeight(item: NativeListItem, layout: String) =
68
+ when {
69
+ item.json.optString("presentation") == "networkSelector" -> 44
70
+ layout == "table" -> 28
71
+ item.json.optString("variant") == "summary" -> 80
72
+ item.json.optString("variant") == "gallery" -> 32
73
+ item.json.optString("variant") == "history" ->
74
+ if (item.json.optBoolean("titleLoading")) 20 else 16
75
+ item.json.optString("value").isNotEmpty() && item.json.optJSONObject("checkbox") != null -> 40
76
+ else -> 36
77
+ }
78
+
79
+ override fun minimumContentHeight(item: NativeListItem, layout: String, sizeDelta: Int) =
80
+ dp(
81
+ (defaultHeight(item, layout) +
82
+ if (item.json.optString("variant") in setOf("summary", "gallery")) 0 else sizeDelta)
83
+ .coerceAtLeast(0)
84
+ )
85
+
86
+ override fun modelHeight(item: NativeListItem, layout: String): Int? {
87
+ if (!item.json.has("height")) return null
88
+ if (item.json.optString("heightRounding") in setOf("floor", "nearest"))
89
+ return super.modelHeight(item, layout)
90
+ if (
91
+ item.json.optString("presentation") == "networkSelector" &&
92
+ item.json.optString("variant") != "summary" &&
93
+ item.json.optJSONObject("checkbox") == null
94
+ ) {
95
+ val px = item.json.optDouble("height") * resources.displayMetrics.density
96
+ return if (item.json.optString("titleActionKey").isEmpty()) px.toInt()
97
+ else
98
+ kotlin.math
99
+ .ceil(px * (if (sourceScale) 1.0 else NativeListScale.factor(resources).toDouble()))
100
+ .toInt()
101
+ }
102
+ return super.modelHeight(item, layout)
103
+ }
104
+
105
+ init {
106
+ mainColumn.orientation = VERTICAL
107
+ mainColumn.gravity = Gravity.CENTER_VERTICAL
108
+ titleLine.orientation = HORIZONTAL
109
+ titleLine.gravity = Gravity.CENTER_VERTICAL
110
+ titleLine.addView(title, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
111
+ mainColumn.addView(titleLine)
112
+ mainColumn.addView(subtitle)
113
+ trailingColumn.addView(trailingViews[0])
114
+ trailingColumn.addView(checkboxControl)
115
+ checkboxControl.onAction = { key, view, slot, target ->
116
+ emitAction(key, view, "trailingAccessory", slot, target)
117
+ }
118
+ }
119
+
120
+ private fun color(theme: JSONObject?, key: String, fallback: String) =
121
+ parseNativeListColor(theme?.optString(key, fallback) ?: fallback)
122
+
123
+ private fun safeColor(value: String?, fallback: Int) =
124
+ runCatching { parseNativeListColor(value ?: "") }.getOrDefault(fallback)
125
+
126
+ private fun roundedFill(color: Int, radius: Float) =
127
+ GradientDrawable().apply {
128
+ setColor(color)
129
+ cornerRadius =
130
+ if (sourceScale) radius * resources.displayMetrics.density
131
+ else NativeListScale.dp(resources, radius)
132
+ }
133
+
134
+ private fun sp(value: Float) = if (sourceScale) value else NativeListScale.font(resources, value)
135
+
136
+ private fun wrap() = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
137
+
138
+ private fun weighted() = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
139
+
140
+ private fun showText(view: TextView, text: String, lines: Int) {
141
+ view.text = text
142
+ view.maxLines = lines
143
+ view.visibility = if (text.isEmpty()) GONE else VISIBLE
144
+ }
145
+
146
+ private fun emitAction(
147
+ item: NativeListItem,
148
+ key: String,
149
+ target: NativeSelectionTarget?,
150
+ view: View,
151
+ source: String,
152
+ slot: Int? = null,
153
+ ) {
154
+ emitAction(key, view, source, slot, target)
155
+ }
156
+
157
+ override fun bindContent(
158
+ item: NativeListItem,
159
+ theme: JSONObject?,
160
+ layout: String,
161
+ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
162
+ ) {
163
+ selectorTextMetrics.clear()
164
+ currentItem = item
165
+ currentTheme = theme
166
+ currentLayout = layout
167
+ removeAllViews()
168
+ titleLine.removeView(headerTitleIcon)
169
+ trailingColumn.removeView(headerValueIcon)
170
+ paintDefaults.forEach { (view, flags) -> view.paintFlags = flags }
171
+ paintDefaults.clear()
172
+ orientation = HORIZONTAL
173
+ gravity = Gravity.CENTER_VERTICAL
174
+ setPadding(
175
+ dp(if (layout == "table") 16 else 12),
176
+ dp(8),
177
+ dp(if (layout == "table") 16 else 12),
178
+ dp(8),
179
+ )
180
+ titleLine.packsChildrenAtStart = false
181
+ titleLine.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
182
+ title.layoutParams = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
183
+ for (view in listOf(title, subtitle) + trailingViews) {
184
+ view.text = ""
185
+ view.visibility = GONE
186
+ view.setLineSpacing(0f, 1f)
187
+ view.maxLines = 1
188
+ view.ellipsize = null
189
+ view.setHorizontallyScrolling(false)
190
+ view.opticalOffsetY = 0f
191
+ view.gravity = Gravity.START
192
+ view.letterSpacing = 0f
193
+ view.fontFeatureSettings = "tnum"
194
+ view.includeFontPadding = false
195
+ view.background = null
196
+ view.setPadding(0, 0, 0, 0)
197
+ view.setOnClickListener(null)
198
+ view.isClickable = false
199
+ }
200
+ title.useSourceScale = sourceScale
201
+ title.showsDottedUnderline = false
202
+ subtitle.textSize = sp(14f)
203
+ subtitle.typeface = NativeListFonts.regular(context)
204
+ subtitle.setTextColor(color(theme, "secondaryText", "#0000009B"))
205
+ subtitle.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
206
+ trailingViews[0].apply {
207
+ typeface = NativeListFonts.medium(context)
208
+ textSize = sp(16f)
209
+ gravity = Gravity.END or Gravity.CENTER_VERTICAL
210
+ setTextColor(color(theme, "primaryText", "#000000DF"))
211
+ setTag(com.facebook.react.R.id.react_test_id, null)
212
+ layoutParams = wrap()
213
+ }
214
+ trailingColumn.orientation = VERTICAL
215
+ trailingColumn.gravity = Gravity.END or Gravity.CENTER_VERTICAL
216
+ checkboxControl.reset()
217
+ checkboxControl.visibility = GONE
218
+ checkboxControl.layoutParams = wrap()
219
+ headerTitleIcon.useSourceScale = sourceScale
220
+ headerValueIcon.useSourceScale = sourceScale
221
+ bindSectionHeader(item, theme, checkboxState)
222
+ val variant = item.json.optString("variant")
223
+ val network = item.json.optString("presentation") == "networkSelector"
224
+ title.textSize =
225
+ sp(
226
+ when {
227
+ network && variant != "summary" -> 14f
228
+ variant == "gallery" -> 18f
229
+ variant == "summary" -> 16f
230
+ layout == "table" -> 11f
231
+ variant == "history" -> 12f
232
+ else -> 14f
233
+ }
234
+ )
235
+ title.typeface =
236
+ when {
237
+ network &&
238
+ item.hasExplicitHeight &&
239
+ variant != "summary" &&
240
+ (item.json.optJSONObject("checkbox") != null ||
241
+ item.json.optString("titleActionKey").isEmpty()) -> NativeListFonts.semibold(context)
242
+ network -> NativeListFonts.medium(context)
243
+ layout == "table" -> NativeListFonts.regular(context)
244
+ variant == "summary" -> NativeListFonts.medium(context)
245
+ else -> NativeListFonts.semibold(context)
246
+ }
247
+ TextViewCompat.setLineHeight(
248
+ title,
249
+ dp(
250
+ when {
251
+ network && variant != "summary" -> 20
252
+ variant in setOf("gallery", "summary") -> 24
253
+ layout == "table" -> 14
254
+ variant == "history" -> 16
255
+ else -> 20
256
+ }
257
+ ),
258
+ )
259
+ if (layout == "table") TextViewCompat.setLineHeight(trailingViews[0], dp(14))
260
+ if (
261
+ network &&
262
+ item.hasExplicitHeight &&
263
+ variant != "summary" &&
264
+ item.json.optString("titleActionKey").isEmpty() &&
265
+ item.json.optJSONObject("checkbox") == null
266
+ ) {
267
+ val inset = (20 * resources.displayMetrics.density).toInt() - dp(8)
268
+ setPadding(inset, 0, inset, 0)
269
+ }
270
+ val style = item.json.optJSONObject("style") ?: JSONObject()
271
+ if (style.has("horizontalPadding")) {
272
+ val hp = stylePx(style.optDouble("horizontalPadding"))
273
+ setPadding(hp, paddingTop, hp, paddingBottom)
274
+ }
275
+ if (style.has("verticalPadding")) {
276
+ val vp = stylePx(style.optDouble("verticalPadding"))
277
+ setPadding(paddingLeft, vp, paddingRight, vp)
278
+ }
279
+ if (style.has("lineGap"))
280
+ (subtitle.layoutParams as LayoutParams).topMargin = stylePx(style.optDouble("lineGap"))
281
+ if (style.has("trailingGap")) {
282
+ var previous = false
283
+ for (i in 0 until trailingColumn.childCount) {
284
+ val child = trailingColumn.getChildAt(i)
285
+ if (child.visibility == GONE) continue
286
+ val params = child.layoutParams as LayoutParams
287
+ if (trailingColumn.orientation == HORIZONTAL)
288
+ params.marginStart = if (previous) stylePx(style.optDouble("trailingGap")) else 0
289
+ else params.topMargin = if (previous) stylePx(style.optDouble("trailingGap")) else 0
290
+ previous = true
291
+ }
292
+ }
293
+ applyTextStyle(item)
294
+ titleSpinner.indeterminateTintList = ColorStateList.valueOf(title.currentTextColor)
295
+ style
296
+ .optJSONObject("container")
297
+ ?.optString("contentVerticalAlignment")
298
+ ?.takeIf(String::isNotEmpty)
299
+ ?.let {
300
+ gravity =
301
+ when (it) {
302
+ "top" -> Gravity.TOP
303
+ "bottom" -> Gravity.BOTTOM
304
+ else -> Gravity.CENTER_VERTICAL
305
+ }
306
+ }
307
+ applySelectorTypography(item)
308
+ }
309
+
310
+ private fun applyTextStyle(item: NativeListItem) {
311
+ val style = item.json.optJSONObject("style") ?: return
312
+ for ((slot, view) in
313
+ listOf("title" to title, "subtitle" to subtitle, "value" to trailingViews[0])) style
314
+ .optJSONObject(slot)
315
+ ?.let { applyStyledText(view, it) }
316
+ }
317
+
318
+ private fun bindCheckbox(
319
+ item: NativeListItem,
320
+ data: JSONObject,
321
+ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
322
+ ) {
323
+ checkboxControl.bind(
324
+ item,
325
+ JSONArray().put(data),
326
+ currentTheme,
327
+ JSONObject(),
328
+ sourceScale,
329
+ checkboxState,
330
+ )
331
+ }
332
+
333
+ override fun bindSelectionContent(
334
+ item: NativeListItem,
335
+ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
336
+ ) {
337
+ currentItem = item
338
+ checkboxControl.updateSelection(item, checkboxState)
339
+ }
340
+
341
+ override fun bindStableSummary(item: NativeListItem) {
342
+ if (item.json.optString("variant") != "summary" || !retainBoundItem(item)) return
343
+ currentItem = item
344
+ contentDescription = accessibilityText(item)
345
+ // The retained item makes the next full bind a no-op, so this path must
346
+ // leave text and visibility exactly as bindSectionHeader would.
347
+ showText(title, item.json.optString("title"), 1)
348
+ val value = item.json.optString("value")
349
+ if (value.isEmpty()) {
350
+ trailingViews[0].text = ""
351
+ trailingViews[0].visibility = GONE
352
+ } else {
353
+ showTrailing(
354
+ 0,
355
+ value,
356
+ true,
357
+ item.json.optString("valueActionKey"),
358
+ color(currentTheme, "secondaryText", "#0000009B"),
359
+ )
360
+ }
361
+ applyValueSegments(trailingViews[0], item.json.optJSONArray("valueSegments"))
362
+ applyTextStyle(item)
363
+ applySelectorTypography(item)
364
+ }
365
+
366
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
367
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec)
368
+ val item = currentItem ?: return
369
+ if (
370
+ item.hasExplicitHeight &&
371
+ item.json.optString("presentation") == "networkSelector" &&
372
+ checkboxControl.visibility == VISIBLE &&
373
+ trailingColumn.parent === this
374
+ ) {
375
+ val density = resources.displayMetrics.density
376
+ val values = trailingViews.filter { it.visibility == VISIBLE }
377
+ val trailing = values.sumOf { it.measuredWidth } + (20 + 12 * values.size) * density
378
+ val sourceLeft = (measuredWidth - 12 * density - trailing).roundToInt()
379
+ val measuredLeft = measuredWidth - paddingRight - trailingColumn.measuredWidth
380
+ mainColumn.measure(
381
+ MeasureSpec.makeMeasureSpec(
382
+ (mainColumn.measuredWidth + sourceLeft - measuredLeft).coerceAtLeast(0),
383
+ MeasureSpec.EXACTLY,
384
+ ),
385
+ MeasureSpec.makeMeasureSpec(mainColumn.measuredHeight, MeasureSpec.EXACTLY),
386
+ )
387
+ }
388
+ }
389
+
390
+ override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
391
+ super.onLayout(changed, left, top, right, bottom)
392
+ val item = currentItem ?: return
393
+ if (
394
+ item.hasExplicitHeight &&
395
+ item.json.optString("presentation") == "networkSelector" &&
396
+ item.json.optString("variant") == "summary" &&
397
+ item.json
398
+ .optJSONObject("style")
399
+ ?.optJSONObject("container")
400
+ ?.has("contentVerticalAlignment") != true
401
+ ) {
402
+ val margins = trailingColumn.layoutParams as MarginLayoutParams
403
+ val available = height - paddingTop - paddingBottom - margins.topMargin - margins.bottomMargin
404
+ trailingColumn.offsetTopAndBottom(
405
+ paddingTop + margins.topMargin + (available - trailingColumn.height + 1) / 2 -
406
+ trailingColumn.top
407
+ )
408
+ }
409
+ }
410
+
411
+ override fun recycleContent() {
412
+ checkboxControl.reset()
413
+ currentItem = null
414
+ titleSpinner.visibility = GONE
415
+ }
416
+
417
+ override fun disposeContent() {
418
+ recycleContent()
419
+ }
420
+
421
+ private fun bindSectionHeader(
422
+ item: NativeListItem,
423
+ theme: JSONObject?,
424
+ checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
425
+ ) {
426
+ val variant = item.json.optString("variant")
427
+ val isSummary = variant == "summary"
428
+ val isGallery = variant == "gallery"
429
+ val isTable = currentLayout == "table"
430
+ clipToPadding = true
431
+ // OneKey patch: title help emits its own frame instead of toggling the section.
432
+ item.json
433
+ .optString("titleActionKey")
434
+ .takeIf { it.isNotEmpty() }
435
+ ?.let { key ->
436
+ title.setOnClickListener { emitAction(item, key, null, title, "leadingAction") }
437
+ }
438
+ val isNetworkSelector = item.json.optString("presentation") == "networkSelector"
439
+ val isHistory = variant == "history"
440
+ val isExplicitNetworkHeader = isNetworkSelector && item.hasExplicitHeight
441
+ val hasDottedTitle =
442
+ isSummary ||
443
+ (isNetworkSelector &&
444
+ (!isExplicitNetworkHeader || item.json.optString("titleActionKey").isNotEmpty())) ||
445
+ (item.json.optString("value").isNotEmpty() && item.json.optJSONObject("checkbox") != null)
446
+ // Linear/sectioned snapshots reserve the ListItem mx=8 at RecyclerView
447
+ // level, so header-local insets below are source px minus that outer inset.
448
+ val headerHorizontalInset = 12
449
+ if (item.json.optBoolean("titleLoading")) {
450
+ titleSpinner.visibility = VISIBLE
451
+ addView(titleSpinner, LayoutParams(dp(20), dp(20)).apply { marginEnd = dp(8) })
452
+ } else {
453
+ titleSpinner.visibility = GONE
454
+ }
455
+ addView(mainColumn, weighted())
456
+ showText(title, item.json.optString("title"), 1)
457
+ if (hasDottedTitle) {
458
+ title.showsDottedUnderline = true
459
+ title.dottedUnderlineColor = color(theme, "secondaryText", "#0000009B")
460
+ title.setPadding(0, 0, 0, dp(3))
461
+ }
462
+ title.setTextColor(
463
+ color(
464
+ theme,
465
+ if (isSummary || isGallery) "primaryText" else "secondaryText",
466
+ if (isSummary || isGallery) "#000000DF" else "#0000009B",
467
+ )
468
+ )
469
+ if (isNetworkSelector) {
470
+ val verticalInset =
471
+ if (isExplicitNetworkHeader && item.json.optString("titleActionKey").isEmpty()) 8 else 12
472
+ setPadding(
473
+ dp(headerHorizontalInset),
474
+ dp(verticalInset),
475
+ dp(headerHorizontalInset),
476
+ dp(verticalInset),
477
+ )
478
+ title.textSize = sp(14f)
479
+ title.typeface = NativeListFonts.medium(context)
480
+ TextViewCompat.setLineHeight(title, dp(20))
481
+ } else if (isHistory) {
482
+ setPadding(0, 0, 0, 0)
483
+ title.text = item.json.optString("title").uppercase()
484
+ title.textSize = sp(12f)
485
+ title.typeface = NativeListFonts.semibold(context)
486
+ title.letterSpacing = 0.8f / sp(12f)
487
+ TextViewCompat.setLineHeight(title, dp(16))
488
+ } else if (!isTable && !isGallery && !isSummary) {
489
+ // SectionList.SectionHeader: h=36, px=20, headingSm 14/20 semibold.
490
+ setPadding(dp(headerHorizontalInset), dp(8), dp(headerHorizontalInset), dp(8))
491
+ TextViewCompat.setLineHeight(title, dp(20))
492
+ } else if (isTable) {
493
+ setPadding(dp(16), dp(12), dp(16), dp(2))
494
+ title.includeFontPadding = false
495
+ title.layoutParams = wrap()
496
+ titleLine.layoutParams = wrap()
497
+ item.json.optJSONObject("titleIcon")?.let { icon ->
498
+ headerTitleIcon.visibility = VISIBLE
499
+ headerTitleIcon.iconName = icon.optString("name")
500
+ headerTitleIcon.tintColor =
501
+ safeColor(icon.optString("tintColor"), color(theme, "iconSubdued", "#00000072"))
502
+ titleLine.addView(
503
+ headerTitleIcon,
504
+ LayoutParams(dp(12), dp(12)).apply { marginStart = dp(4) },
505
+ )
506
+ if (icon.optString("name") != "ChevronGrabberVerOutline") {
507
+ title.setTextColor(color(theme, "primaryText", "#000000DF"))
508
+ }
509
+ }
510
+ }
511
+ showText(subtitle, item.json.optString("subtitle"), 1)
512
+ if (isGallery) {
513
+ setPadding(dp(12), 0, dp(12), dp(8))
514
+ } else if (isSummary) {
515
+ addView(trailingColumn, wrap())
516
+ // NetworkListHeader: outer mt=16/pb=12, inner XStack px=20/py=8.
517
+ setPadding(dp(headerHorizontalInset), dp(24), dp(headerHorizontalInset), dp(20))
518
+ showTrailing(
519
+ 0,
520
+ item.json.optString("value"),
521
+ true,
522
+ item.json.optString("valueActionKey"),
523
+ color(theme, "secondaryText", "#0000009B"),
524
+ )
525
+ trailingViews[0].setTag(
526
+ com.facebook.react.R.id.react_test_id,
527
+ item.json.optString("valueActionTestID").takeIf { it.isNotEmpty() },
528
+ )
529
+ trailingViews[0].accessibilityDelegate = selectorAccessibilityDelegate
530
+ trailingViews[0].textSize = sp(16f)
531
+ trailingViews[0].typeface = NativeListFonts.medium(context)
532
+ TextViewCompat.setLineHeight(trailingViews[0], dp(24))
533
+ // OneKey patch: the migrated media button shares the original 24-point text box.
534
+ if (isExplicitNetworkHeader) trailingViews[0].setPadding(0, 0, 0, 0)
535
+ else trailingViews[0].setPadding(dp(14), dp(6), dp(14), dp(6))
536
+ trailingViews[0].layoutParams = wrap()
537
+ } else if (!isGallery && !isHistory) {
538
+ val value = item.json.optString("value")
539
+ val checkboxData = item.json.optJSONObject("checkbox")
540
+ if (isExplicitNetworkHeader && checkboxData != null) {
541
+ // OneKey patch: the asset section title reserves its original 8dp trailing margin.
542
+ (mainColumn.layoutParams as LayoutParams).marginEnd = dp(8)
543
+ }
544
+ if (checkboxData != null && value.isNotEmpty()) {
545
+ // Value and checkbox share the trailing edge as one compound accessory.
546
+ trailingColumn.orientation = HORIZONTAL
547
+ trailingColumn.gravity = Gravity.END or Gravity.CENTER_VERTICAL
548
+ trailingViews[0].layoutParams = wrap()
549
+ checkboxControl.layoutParams = LayoutParams(dp(20), dp(20)).apply { marginStart = dp(12) }
550
+ }
551
+ addView(trailingColumn, wrap())
552
+ showTrailing(0, value, true)
553
+ if (isTable) {
554
+ trailingColumn.orientation = HORIZONTAL
555
+ trailingColumn.gravity = Gravity.END or Gravity.CENTER_VERTICAL
556
+ trailingViews[0].includeFontPadding = false
557
+ trailingViews[0].textSize = sp(11f)
558
+ trailingViews[0].typeface = NativeListFonts.regular(context)
559
+ trailingViews[0].setTextColor(color(theme, "secondaryText", "#0000009B"))
560
+ item.json.optJSONObject("valueIcon")?.let { icon ->
561
+ headerValueIcon.visibility = VISIBLE
562
+ headerValueIcon.iconName = icon.optString("name")
563
+ headerValueIcon.tintColor =
564
+ safeColor(icon.optString("tintColor"), color(theme, "iconSubdued", "#00000072"))
565
+ trailingColumn.addView(
566
+ headerValueIcon,
567
+ LayoutParams(dp(12), dp(12)).apply { marginStart = dp(4) },
568
+ )
569
+ if (icon.optString("name") != "ChevronGrabberVerOutline") {
570
+ trailingViews[0].setTextColor(color(theme, "primaryText", "#000000DF"))
571
+ }
572
+ }
573
+ }
574
+ checkboxData?.let { bindCheckbox(item, it, checkboxState) }
575
+ // Legacy: selector checkbox borders may round into the row padding.
576
+ if (checkboxControl.requestsUnclippedHost) clipToPadding = false
577
+ }
578
+ applyValueSegments(trailingViews[0], item.json.optJSONArray("valueSegments"))
579
+ }
580
+
581
+ private fun showTrailing(
582
+ index: Int,
583
+ value: String,
584
+ primary: Boolean,
585
+ actionKey: String? = null,
586
+ textColor: Int? = null,
587
+ ) {
588
+ if (index !in trailingViews.indices || value.isEmpty()) return
589
+ val view = trailingViews[index]
590
+ view.maxLines = 1
591
+ view.text = value
592
+ view.textSize = sp(if (primary) 16f else 14f)
593
+ view.typeface =
594
+ if (primary) NativeListFonts.medium(context) else NativeListFonts.regular(context)
595
+ view.includeFontPadding = false
596
+ view.fontFeatureSettings = "tnum"
597
+ TextViewCompat.setLineHeight(view, dp(if (primary) 24 else 20))
598
+ textColor?.let(view::setTextColor)
599
+ view.visibility = VISIBLE
600
+ if (!actionKey.isNullOrEmpty()) {
601
+ view.setOnClickListener {
602
+ currentItem
603
+ ?.takeUnless { item -> item.json.optBoolean("disabled", false) }
604
+ ?.let { item -> emitAction(item, actionKey, null, view, "trailingAccessory", index) }
605
+ }
606
+ }
607
+ }
608
+
609
+ private fun applyValueSegments(
610
+ view: TextView,
611
+ segments: JSONArray?,
612
+ fontSize: Int = 16,
613
+ lineHeight: Int = 24,
614
+ medium: Boolean = true,
615
+ ) {
616
+ if (segments == null || segments.length() == 0) return
617
+ val value = SpannableStringBuilder()
618
+ for (index in 0 until segments.length()) {
619
+ val segment = segments.getJSONObject(index)
620
+ val start = value.length
621
+ value.append(segment.optString("text"))
622
+ if (segment.optString("style") == "subscript") {
623
+ val size = kotlin.math.ceil(fontSize * 0.6).toFloat()
624
+ val span =
625
+ if (sourceScale)
626
+ AbsoluteSizeSpan(
627
+ kotlin.math.ceil((size * resources.displayMetrics.density).toDouble()).toInt(),
628
+ false,
629
+ )
630
+ else AbsoluteSizeSpan(sp(size).roundToInt(), true)
631
+ value.setSpan(span, start, value.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
632
+ }
633
+ }
634
+ view.textSize = sp(fontSize.toFloat())
635
+ view.typeface =
636
+ if (medium) NativeListFonts.medium(context) else NativeListFonts.regular(context)
637
+ TextViewCompat.setLineHeight(view, dp(lineHeight))
638
+ view.text = value
639
+ }
640
+
641
+ private fun applyStyledText(view: TextView, style: JSONObject) {
642
+ if (style.has("fontSize")) {
643
+ view.setTextSize(
644
+ TypedValue.COMPLEX_UNIT_PX,
645
+ (style.optDouble("fontSize") * resources.displayMetrics.density).toFloat(),
646
+ )
647
+ val text = SpannableStringBuilder(view.text)
648
+ text.getSpans(0, text.length, AbsoluteSizeSpan::class.java).forEach(text::removeSpan)
649
+ view.text = text
650
+ }
651
+ style.optString("fontWeight").takeIf(String::isNotEmpty)?.let {
652
+ view.typeface =
653
+ when (it) {
654
+ "medium" -> NativeListFonts.medium(context)
655
+ "semibold" -> NativeListFonts.semibold(context)
656
+ "bold" -> NativeListFonts.bold(context)
657
+ else -> NativeListFonts.regular(context)
658
+ }
659
+ }
660
+ style.optString("color").takeIf(String::isNotEmpty)?.let {
661
+ val color = safeColor(it, view.currentTextColor)
662
+ view.setTextColor(color)
663
+ val text = SpannableStringBuilder(view.text)
664
+ text.getSpans(0, text.length, ForegroundColorSpan::class.java).forEach(text::removeSpan)
665
+ view.text = text
666
+ }
667
+ if (style.has("lineHeight")) {
668
+ val text = SpannableStringBuilder(view.text)
669
+ text.getSpans(0, text.length, NativeListLineHeightSpan::class.java).forEach(text::removeSpan)
670
+ text.setSpan(
671
+ NativeListLineHeightSpan(stylePx(style.optDouble("lineHeight"))),
672
+ 0,
673
+ text.length,
674
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
675
+ )
676
+ view.setLineSpacing(0f, 1f)
677
+ view.text = text
678
+ }
679
+ if (style.has("lines")) {
680
+ view.maxLines = style.optInt("lines").coerceIn(1, 3)
681
+ view.ellipsize = TextUtils.TruncateAt.END
682
+ }
683
+ if (style.has("truncate") || style.has("lines")) {
684
+ view.setHorizontallyScrolling(view.maxLines == 1)
685
+ view.ellipsize =
686
+ if (style.optString("truncate", "tail") == "clip") null else TextUtils.TruncateAt.END
687
+ if (view.maxLines == 1) {
688
+ val text = SpannableStringBuilder(view.text)
689
+ Regex("\\r\\n|[\\r\\n]").findAll(text).toList().asReversed().forEach { match ->
690
+ text.replace(match.range.first, match.range.last + 1, " ")
691
+ }
692
+ view.text = text
693
+ }
694
+ }
695
+ if (style.has("verticalAlignment")) {
696
+ view.gravity =
697
+ (view.gravity and Gravity.VERTICAL_GRAVITY_MASK.inv()) or
698
+ when (style.optString("verticalAlignment")) {
699
+ "top" -> Gravity.TOP
700
+ "bottom" -> Gravity.BOTTOM
701
+ else -> Gravity.CENTER_VERTICAL
702
+ }
703
+ }
704
+ if (style.has("offsetY"))
705
+ (view as? NativeListTextView)?.opticalOffsetY =
706
+ (style.optDouble("offsetY") * resources.displayMetrics.density).toFloat()
707
+ style.optString("alignment").takeIf(String::isNotEmpty)?.let {
708
+ view.gravity =
709
+ (view.gravity and Gravity.VERTICAL_GRAVITY_MASK) or
710
+ when (it) {
711
+ "center" -> Gravity.CENTER_HORIZONTAL
712
+ "end" -> Gravity.END
713
+ else -> Gravity.START
714
+ }
715
+ }
716
+ }
717
+
718
+ private fun applySelectorTypography(item: NativeListItem) {
719
+ if (
720
+ item.json.optString("presentation") !in
721
+ setOf("accountSelector", "networkSelector", "walletSidebar")
722
+ )
723
+ return
724
+ fun visit(view: View) {
725
+ if (view is TextView) {
726
+ view.fontFeatureSettings = "tnum"
727
+ if (sourceScale) {
728
+ paintDefaults.putIfAbsent(view, view.paintFlags)
729
+ view.paintFlags = view.paintFlags or Paint.SUBPIXEL_TEXT_FLAG or Paint.LINEAR_TEXT_FLAG
730
+ val (fontSize, line) =
731
+ selectorTextMetrics.getOrPut(view) { view.textSize to view.lineHeight }
732
+ view.setTextSize(
733
+ TypedValue.COMPLEX_UNIT_PX,
734
+ kotlin.math
735
+ .ceil(
736
+ (fontSize * resources.displayMetrics.density /
737
+ resources.displayMetrics.scaledDensity)
738
+ .toDouble()
739
+ )
740
+ .toFloat(),
741
+ )
742
+ view.letterSpacing = 0f
743
+ if (view.text.isNotEmpty()) {
744
+ val text = SpannableStringBuilder(view.text)
745
+ text
746
+ .getSpans(0, text.length, NativeListLineHeightSpan::class.java)
747
+ .forEach(text::removeSpan)
748
+ text.setSpan(
749
+ NativeListLineHeightSpan(line),
750
+ 0,
751
+ text.length,
752
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
753
+ )
754
+ view.setLineSpacing(0f, 1f)
755
+ view.text = text
756
+ }
757
+ }
758
+ }
759
+ if (view is ViewGroup) for (i in 0 until view.childCount) visit(view.getChildAt(i))
760
+ }
761
+ visit(this)
762
+ }
763
+ }