@onekeyfe/react-native-native-list 6.7.0-20 → 6.7.0-21
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.
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +29 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -10
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +15 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +33 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +13 -10
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +33 -8
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +11 -5
- package/docs/ROW_TEMPLATES.md +10 -2
- package/docs/SPEC.md +270 -42
- package/ios/NativeListActivityDetailsView.swift +13 -4
- package/ios/NativeListIdentityRenderer.swift +50 -3
- package/ios/NativeListMarketRenderer.swift +113 -18
- package/ios/RNCNativeListView.swift +21 -3
- package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
- package/ios/tests/NativeListLifecycleTests.swift +73 -4
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/lib/module/NativeList.js +25 -6
- package/lib/module/NativeList.web.js +9 -12
- package/lib/module/models.js +2 -0
- package/lib/module/validation.js +695 -114
- package/lib/module/web/NativeListWebEngine.js +3 -9
- package/lib/module/web/templates/IdentityRowRenderer.js +58 -4
- package/lib/typescript/src/models.d.ts +27 -14
- package/lib/typescript/src/validation.d.ts +7 -2
- package/package.json +3 -3
- package/src/NativeList.tsx +30 -10
- package/src/NativeList.web.tsx +10 -14
- package/src/models.ts +158 -153
- package/src/validation.ts +1757 -167
- package/src/web/NativeListWebEngine.ts +6 -10
- package/src/web/templates/IdentityRowRenderer.ts +70 -4
|
@@ -16,7 +16,11 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
|
|
|
16
16
|
var onAction: ((String, View, String, Int) -> Unit)? = null
|
|
17
17
|
private var sourceScale = false
|
|
18
18
|
private val main = LinearLayout(context).apply { orientation = HORIZONTAL; gravity = Gravity.CENTER_VERTICAL }
|
|
19
|
+
private val identityColumn = LinearLayout(context).apply { orientation = HORIZONTAL; gravity = Gravity.CENTER_VERTICAL }
|
|
19
20
|
private val visual = NativeListLeadingVisual(reactContext, fonts)
|
|
21
|
+
/** Whether the bound leading visual lays a badge past its frame; see [setClipping]. */
|
|
22
|
+
var leadingOverhangs = false
|
|
23
|
+
private set
|
|
20
24
|
private val identity = LinearLayout(context).apply { orientation = VERTICAL }
|
|
21
25
|
private val titleLine = LinearLayout(context).apply { orientation = HORIZONTAL; gravity = Gravity.CENTER_VERTICAL }
|
|
22
26
|
private val title = NativeListTextView(context)
|
|
@@ -40,13 +44,26 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
|
|
|
40
44
|
identity.addView(status)
|
|
41
45
|
feeLine.addView(feePrimary); feeLine.addView(feeSecondary)
|
|
42
46
|
fee.addView(feeLabel); fee.addView(feeLine)
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
identityColumn.addView(visual)
|
|
48
|
+
identityColumn.addView(identity, LayoutParams(0, -2, 1f))
|
|
49
|
+
main.addView(identityColumn, LayoutParams(0, -2, 1f))
|
|
45
50
|
main.addView(amounts)
|
|
46
51
|
main.addView(fee)
|
|
47
52
|
addView(main, LayoutParams(-1, -2))
|
|
48
53
|
addView(actions, LayoutParams(-1, -2))
|
|
49
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Android clips a child to its own bounds while its parent clips children, so
|
|
57
|
+
* every view between the leading visual and the row host stops clipping when
|
|
58
|
+
* the visual's network badge overhangs its box (SPEC "Leading badge overhang",
|
|
59
|
+
* OK-66275); the host row applies the same policy to itself.
|
|
60
|
+
*/
|
|
61
|
+
private fun setClipping(clips: Boolean) {
|
|
62
|
+
for (group in listOf(identityColumn, main, this)) {
|
|
63
|
+
group.clipChildren = clips
|
|
64
|
+
group.clipToPadding = clips
|
|
65
|
+
}
|
|
66
|
+
}
|
|
50
67
|
private fun dp(value: Int) = if (sourceScale) (value * resources.displayMetrics.density).roundToInt() else NativeListScale.dp(resources, value)
|
|
51
68
|
private fun px(value: Double) = (value * resources.displayMetrics.density).roundToInt()
|
|
52
69
|
private fun color(tone: String, theme: JSONObject?): Int {
|
|
@@ -77,6 +94,8 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
|
|
|
77
94
|
visual.visibility = if (hideLeading) GONE else VISIBLE
|
|
78
95
|
if (hideLeading) visual.recycle()
|
|
79
96
|
else visual.bind(data.optJSONObject("leading") ?: JSONObject(), image, item.key, theme, false, sourceScale, data.optJSONObject("secondaryLeading"))
|
|
97
|
+
leadingOverhangs = !hideLeading && visual.requestsUnclippedHost
|
|
98
|
+
setClipping(nativeListActivityHostClips(leadingOverhangs))
|
|
80
99
|
amounts.layoutParams = if (table) LayoutParams(0, -2, 1f).apply { marginStart = gap } else LayoutParams(-2, -2).apply { marginStart = gap }
|
|
81
100
|
text(title, data.optString("title"), style.optJSONObject("title"), 16f, color("primary", theme), 24, "medium")
|
|
82
101
|
text(description, data.optString("description"), style.optJSONObject("description"), 14f, color("secondary", theme), 20, lines = 2)
|
|
@@ -110,7 +129,9 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
|
|
|
110
129
|
val feeData = data.optJSONObject("fee")
|
|
111
130
|
fee.visibility = if (feeData == null) GONE else VISIBLE
|
|
112
131
|
fee.alpha = if (feeData?.optBoolean("hidden") == true) 0f else 1f
|
|
113
|
-
fee.layoutParams = LayoutParams(-2, -2).apply { marginStart = gap }
|
|
132
|
+
fee.layoutParams = (if (table) LayoutParams(0, -2, 0.6f) else LayoutParams(-2, -2)).apply { marginStart = gap }
|
|
133
|
+
feeLabel.layoutParams.width = if (table) LayoutParams.WRAP_CONTENT else LayoutParams.MATCH_PARENT
|
|
134
|
+
feeLine.layoutParams.width = if (table) LayoutParams.WRAP_CONTENT else LayoutParams.MATCH_PARENT
|
|
114
135
|
text(feeLabel, feeData?.optString("label") ?: "", style.optJSONObject("secondaryAmount"), 12f, color("secondary", theme), 16)
|
|
115
136
|
text(feePrimary, feeData?.optString("primary") ?: "", style.optJSONObject("secondaryAmount"), 14f, color("primary", theme), 20)
|
|
116
137
|
text(feeSecondary, feeData?.optString("secondary") ?: "", style.optJSONObject("secondaryAmount"), 12f, color("secondary", theme), 16)
|
|
@@ -149,7 +170,11 @@ internal class NativeListActivityDetailsView(private val reactContext: ThemedRea
|
|
|
149
170
|
}
|
|
150
171
|
label.text = styled
|
|
151
172
|
}
|
|
152
|
-
fun recycle() {
|
|
173
|
+
fun recycle() {
|
|
174
|
+
visual.recycle(); visual.visibility = VISIBLE; amountViews.forEach { it.recycle() }; description.setOnClickListener(null); actions.removeAllViews()
|
|
175
|
+
leadingOverhangs = false
|
|
176
|
+
setClipping(true)
|
|
177
|
+
}
|
|
153
178
|
fun dispose() { recycle(); visual.dispose(); amountViews.forEach { it.dispose() } }
|
|
154
179
|
|
|
155
180
|
private inner class AmountView : LinearLayout(context) {
|
|
@@ -83,10 +83,11 @@ internal class NativeListActivityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
83
83
|
setPadding(hp, vp, hp, vp)
|
|
84
84
|
visual.recycle()
|
|
85
85
|
details.bind(item, theme, sourceScale)
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
//
|
|
89
|
-
|
|
86
|
+
// The rich row's leading visual lives on the details view, where its
|
|
87
|
+
// network badge overhangs the box (OK-66275): this host must stop clipping
|
|
88
|
+
// as well, and a view reused from a badge row clips again when the bound
|
|
89
|
+
// row has no badge.
|
|
90
|
+
setHostClipping(nativeListActivityHostClips(details.leadingOverhangs))
|
|
90
91
|
return
|
|
91
92
|
}
|
|
92
93
|
details.recycle()
|
|
@@ -174,12 +175,7 @@ internal class NativeListActivityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
174
175
|
// Stop clipping the content row and this row's padding exactly when the
|
|
175
176
|
// bound visual reports such a badge (SPEC "Leading badge overhang"), as the
|
|
176
177
|
// Identity renderer does.
|
|
177
|
-
setHostClipping(
|
|
178
|
-
nativeListActivityHostClips(
|
|
179
|
-
rich = false,
|
|
180
|
-
leadingOverhangs = !hideLeading && visual.requestsUnclippedHost,
|
|
181
|
-
)
|
|
182
|
-
)
|
|
178
|
+
setHostClipping(nativeListActivityHostClips(!hideLeading && visual.requestsUnclippedHost))
|
|
183
179
|
bind(
|
|
184
180
|
title,
|
|
185
181
|
data.optString("title"),
|
|
@@ -240,9 +240,10 @@ internal class NativeListAdapter(
|
|
|
240
240
|
|
|
241
241
|
private fun isMarketQuoteUpdate(oldItem: NativeListItem, newItem: NativeListItem): Boolean {
|
|
242
242
|
if (oldItem.type != "market" || newItem.type != "market") return false
|
|
243
|
+
if (!hasSameMarketMetricStructure(oldItem, newItem)) return false
|
|
243
244
|
fun stableContent(item: NativeListItem): String {
|
|
244
245
|
val value = JSONObject(item.json.toString())
|
|
245
|
-
listOf("revision", "price", "priceSegments", "change", "accessibilityLabel")
|
|
246
|
+
listOf("revision", "price", "priceSegments", "change", "accessibilityLabel", "metrics")
|
|
246
247
|
.forEach(value::remove)
|
|
247
248
|
return value.toString()
|
|
248
249
|
}
|
|
@@ -256,3 +257,18 @@ internal const val SELECTION_PAYLOAD = "selection"
|
|
|
256
257
|
// OneKey patch: internal payload, never exposed through the serialized row contract.
|
|
257
258
|
internal const val SELECTION_ECHO_PAYLOAD = "selectionEcho"
|
|
258
259
|
internal const val MARKET_QUOTE_PAYLOAD = "marketQuote"
|
|
260
|
+
|
|
261
|
+
internal fun hasSameMarketMetricStructure(before: NativeListItem, after: NativeListItem): Boolean {
|
|
262
|
+
val old = before.json.optJSONArray("metrics")
|
|
263
|
+
val next = after.json.optJSONArray("metrics")
|
|
264
|
+
val oldCount = old?.length() ?: 0
|
|
265
|
+
if (oldCount != (next?.length() ?: 0)) return false
|
|
266
|
+
for (index in 0 until oldCount) {
|
|
267
|
+
val previous = old?.optJSONObject(index) ?: return false
|
|
268
|
+
val current = next?.optJSONObject(index) ?: return false
|
|
269
|
+
if (previous.optString("key") != current.optString("key") ||
|
|
270
|
+
previous.optInt("weight", 1) != current.optInt("weight", 1) ||
|
|
271
|
+
previous.optString("alignment", "end") != current.optString("alignment", "end")) return false
|
|
272
|
+
}
|
|
273
|
+
return true
|
|
274
|
+
}
|
|
@@ -292,12 +292,14 @@ private class NativeListTableColumnView(context: android.content.Context, privat
|
|
|
292
292
|
|
|
293
293
|
fun reset() {
|
|
294
294
|
primaryLine.gravity = Gravity.CENTER_VERTICAL
|
|
295
|
+
secondaryLine.gravity = Gravity.CENTER_VERTICAL
|
|
295
296
|
for (icon in listOf(titleIcon, secondaryTitleIcon)) {
|
|
296
297
|
icon.visibility = GONE
|
|
297
298
|
icon.iconName = ""
|
|
298
299
|
icon.contentDescription = null
|
|
299
300
|
icon.setOnClickListener(null)
|
|
300
301
|
}
|
|
302
|
+
(primaryLine.layoutParams as LayoutParams).gravity = -1
|
|
301
303
|
primaryLine.layoutParams.width = LayoutParams.WRAP_CONTENT
|
|
302
304
|
primaryLine.layoutParams.height = LayoutParams.WRAP_CONTENT
|
|
303
305
|
secondaryLine.layoutParams.height = LayoutParams.WRAP_CONTENT
|
|
@@ -357,6 +359,17 @@ private class NativeListTableColumnView(context: android.content.Context, privat
|
|
|
357
359
|
"end" -> Gravity.END
|
|
358
360
|
else -> Gravity.START
|
|
359
361
|
}
|
|
362
|
+
fun horizontalGravity(alignment: String) = when (alignment) {
|
|
363
|
+
"center" -> Gravity.CENTER_HORIZONTAL
|
|
364
|
+
"end" -> Gravity.END
|
|
365
|
+
else -> Gravity.START
|
|
366
|
+
}
|
|
367
|
+
val primaryAlignment = style.optJSONObject("columns")?.optString("alignment")
|
|
368
|
+
?.takeIf(String::isNotEmpty) ?: column.optString("alignment", "start")
|
|
369
|
+
(primaryLine.layoutParams as LayoutParams).gravity = horizontalGravity(primaryAlignment)
|
|
370
|
+
val secondaryAlignment = style.optJSONObject("columnSecondary")?.optString("alignment")
|
|
371
|
+
?.takeIf(String::isNotEmpty) ?: column.optString("alignment", "start")
|
|
372
|
+
secondaryLine.gravity = Gravity.CENTER_VERTICAL or horizontalGravity(secondaryAlignment)
|
|
360
373
|
fun bindText(
|
|
361
374
|
view: NativeListTextView,
|
|
362
375
|
value: String,
|
|
@@ -433,6 +446,8 @@ private class NativeListTableColumnView(context: android.content.Context, privat
|
|
|
433
446
|
secondaryLine.visibility = VISIBLE
|
|
434
447
|
}
|
|
435
448
|
if (!fixedTableGeometry) applyStyle(style)
|
|
449
|
+
(secondary.layoutParams as LayoutParams).marginStart =
|
|
450
|
+
if (secondaryLeading.visibility == VISIBLE) dp(4) else 0
|
|
436
451
|
if (fixedTableGeometry) {
|
|
437
452
|
// Legacy table lines: fixed 20dp primary and 16dp secondary/badge boxes.
|
|
438
453
|
primaryLine.layoutParams.height = dp(20)
|
|
@@ -31,6 +31,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
31
31
|
private val titleLine = PackedTitleLineLayout(context)
|
|
32
32
|
private val title = NativeListTextView(context)
|
|
33
33
|
private val titleIcon = OneKeyIconView(context)
|
|
34
|
+
private var titleImage: NativeListImageSlot? = null
|
|
34
35
|
private val subtitle = NativeListTextView(context)
|
|
35
36
|
private val tertiary = NativeListTextView(context)
|
|
36
37
|
private val badgeLine = NativeListTextView(context)
|
|
@@ -79,7 +80,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
79
80
|
"single"
|
|
80
81
|
else item.json.optString("groupPosition")
|
|
81
82
|
|
|
82
|
-
override val assetFields = listOf("leading")
|
|
83
|
+
override val assetFields = listOf("leading", "titleImage")
|
|
83
84
|
|
|
84
85
|
override fun usesSourceScale(item: NativeListItem, provided: Boolean) =
|
|
85
86
|
item.usesSelectorSourceScale || provided
|
|
@@ -262,6 +263,29 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
262
263
|
leadingActionIcon.useSourceScale = sourceScale
|
|
263
264
|
leadingActionIcon.setOnClickListener(null)
|
|
264
265
|
bindIdentity(item, theme, item.json.optBoolean("selected"), checkboxState)
|
|
266
|
+
val titleImageDescriptor = item.json.optJSONObject("titleImage")
|
|
267
|
+
val titleImageSource = titleImageDescriptor?.optJSONObject("image")
|
|
268
|
+
if (titleImageSource != null && titleImageSource.optString("uri").isNotEmpty()) {
|
|
269
|
+
if (item.json.optString("presentation") == "walletSidebar") {
|
|
270
|
+
titleLine.packsChildrenAtStart = true
|
|
271
|
+
title.layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
|
|
272
|
+
}
|
|
273
|
+
val slot = titleImage ?: NativeListImageSlot(reactContext).also { titleImage = it }
|
|
274
|
+
// Reinsert after icons so newly added suffixes cannot precede the image.
|
|
275
|
+
titleLine.removeView(slot.view)
|
|
276
|
+
titleLine.addView(slot.view, titleLine.indexOfChild(titleIcon) + 1)
|
|
277
|
+
val size = stylePx(titleImageSource.optDouble("width"))
|
|
278
|
+
slot.view.layoutParams = LayoutParams(size, size).apply { marginStart = dp(4) }
|
|
279
|
+
slot.view.visibility = VISIBLE
|
|
280
|
+
slot.view.contentDescription = titleImageDescriptor.optString("accessibilityLabel").takeIf(String::isNotEmpty)
|
|
281
|
+
slot.view.importantForAccessibility = if (slot.view.contentDescription == null)
|
|
282
|
+
View.IMPORTANT_FOR_ACCESSIBILITY_NO else View.IMPORTANT_FOR_ACCESSIBILITY_YES
|
|
283
|
+
slot.bind(titleImageSource, "${item.key}:titleImage", placeholder = "#00000000", round = true)
|
|
284
|
+
} else {
|
|
285
|
+
titleImage?.recycle()
|
|
286
|
+
titleImage?.view?.visibility = GONE
|
|
287
|
+
titleImage?.view?.contentDescription = null
|
|
288
|
+
}
|
|
265
289
|
TextViewCompat.setLineHeight(
|
|
266
290
|
title,
|
|
267
291
|
dp(if (item.json.optString("presentation") == "walletSidebar") 16 else 24),
|
|
@@ -449,7 +473,10 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
449
473
|
val inner = (MeasureSpec.getSize(widthMeasureSpec) - paddingLeft - paddingRight)
|
|
450
474
|
.coerceAtLeast(0)
|
|
451
475
|
val leading = leadingFrame.layoutParams as LayoutParams
|
|
452
|
-
val
|
|
476
|
+
val imageWidth = titleImage?.view?.takeIf { it.visibility == VISIBLE }?.let {
|
|
477
|
+
it.layoutParams.width + dp(4)
|
|
478
|
+
} ?: 0
|
|
479
|
+
val icon = (if (titleIcon.visibility == VISIBLE) dp(24) else 0) + imageWidth
|
|
453
480
|
(inner * ratio).roundToInt()
|
|
454
481
|
.minus(leading.width + leading.marginEnd + icon)
|
|
455
482
|
.coerceAtLeast(0)
|
|
@@ -555,6 +582,9 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
555
582
|
longPressPoint = null
|
|
556
583
|
longPressPointEpoch = -1L
|
|
557
584
|
leadingFrame.recycle()
|
|
585
|
+
titleImage?.recycle()
|
|
586
|
+
titleImage?.view?.visibility = GONE
|
|
587
|
+
titleImage?.view?.contentDescription = null
|
|
558
588
|
trailingColumn.reset()
|
|
559
589
|
currentItem = null
|
|
560
590
|
}
|
|
@@ -562,6 +592,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
562
592
|
override fun disposeContent() {
|
|
563
593
|
recycleContent()
|
|
564
594
|
leadingFrame.dispose()
|
|
595
|
+
titleImage?.dispose()
|
|
565
596
|
}
|
|
566
597
|
|
|
567
598
|
private fun bindIdentity(
|
|
@@ -38,6 +38,9 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
38
38
|
private val marketSubtitleLine = PackedTitleLineLayout(context)
|
|
39
39
|
private val trailingColumn = LinearLayout(context)
|
|
40
40
|
private val trailingViews = List(2) { NativeListTextView(context) }
|
|
41
|
+
private val metricColumns = List(3) { LinearLayout(context) }
|
|
42
|
+
private val metricPrimaryViews = List(3) { NativeListTextView(context) }
|
|
43
|
+
private val metricSecondaryViews = List(3) { NativeListTextView(context) }
|
|
41
44
|
private val marketBadgeViews = List(3) { LinearLayout(context) }
|
|
42
45
|
private val marketBadgeLabels = List(3) { TextView(context) }
|
|
43
46
|
private val badgeSlots = List(3) { NativeListImageSlot(context) }
|
|
@@ -88,6 +91,12 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
88
91
|
mainColumn.addView(subtitle)
|
|
89
92
|
mainColumn.addView(tertiary)
|
|
90
93
|
trailingViews.forEach(trailingColumn::addView)
|
|
94
|
+
metricColumns.forEachIndexed { index, column ->
|
|
95
|
+
column.orientation = VERTICAL
|
|
96
|
+
column.gravity = Gravity.CENTER_VERTICAL
|
|
97
|
+
column.addView(metricPrimaryViews[index])
|
|
98
|
+
column.addView(metricSecondaryViews[index])
|
|
99
|
+
}
|
|
91
100
|
leadingActionIcon.useSourceScale = true
|
|
92
101
|
marketBadgeViews.forEachIndexed { index, badge ->
|
|
93
102
|
badge.orientation = HORIZONTAL
|
|
@@ -129,6 +138,50 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
129
138
|
|
|
130
139
|
private fun weighted() = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
|
|
131
140
|
|
|
141
|
+
private fun metricColor(theme: JSONObject?, tone: String): Int =
|
|
142
|
+
when (tone) {
|
|
143
|
+
"positive" -> color(theme, "positive", "#218358")
|
|
144
|
+
"negative" -> color(theme, "negative", "#CE2C31")
|
|
145
|
+
"secondary" -> color(theme, "secondaryText", "#646464")
|
|
146
|
+
else -> color(theme, "primaryText", "#202020")
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private fun bindMetrics(metrics: JSONArray, theme: JSONObject?, gap: Int) {
|
|
150
|
+
updateMetricLabels(metrics, theme)
|
|
151
|
+
for (index in 0 until metrics.length()) {
|
|
152
|
+
val metric = metrics.getJSONObject(index)
|
|
153
|
+
addView(
|
|
154
|
+
metricColumns[index],
|
|
155
|
+
LayoutParams(0, LayoutParams.WRAP_CONTENT, metric.optInt("weight", 1).toFloat()).apply {
|
|
156
|
+
marginStart = dp(gap)
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private fun updateMetricLabels(metrics: JSONArray, theme: JSONObject?) {
|
|
163
|
+
for (index in 0 until metrics.length()) {
|
|
164
|
+
val metric = metrics.getJSONObject(index)
|
|
165
|
+
val alignment = metric.optString("alignment", "end")
|
|
166
|
+
val primary = metricPrimaryViews[index]
|
|
167
|
+
val secondary = metricSecondaryViews[index]
|
|
168
|
+
applyMarketTextStyle(
|
|
169
|
+
primary, null, 14f, 20, "medium",
|
|
170
|
+
metricColor(theme, metric.optString("tone")), alignment,
|
|
171
|
+
)
|
|
172
|
+
primary.text = marketText(metric.optString("text"), metric.optJSONArray("textSegments"), 14f)
|
|
173
|
+
primary.visibility = VISIBLE
|
|
174
|
+
applyMarketTextStyle(
|
|
175
|
+
secondary, null, 12f, 16, "regular",
|
|
176
|
+
metricColor(theme, metric.optString("secondaryTone", "secondary")), alignment,
|
|
177
|
+
)
|
|
178
|
+
secondary.text = marketText(
|
|
179
|
+
metric.optString("secondaryText"), metric.optJSONArray("secondaryTextSegments"), 12f,
|
|
180
|
+
)
|
|
181
|
+
secondary.visibility = if (secondary.text.isEmpty()) GONE else VISIBLE
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
132
185
|
private fun showText(view: TextView, text: String, lines: Int) {
|
|
133
186
|
view.text = text
|
|
134
187
|
view.maxLines = lines
|
|
@@ -146,18 +199,27 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
146
199
|
emitAction(key, view, source, slot, target)
|
|
147
200
|
}
|
|
148
201
|
|
|
149
|
-
override fun accessibilityText(item: NativeListItem)
|
|
150
|
-
item.json.
|
|
151
|
-
"accessibilityLabel"
|
|
202
|
+
override fun accessibilityText(item: NativeListItem): String {
|
|
203
|
+
if (item.json.has("accessibilityLabel") && !item.json.isNull("accessibilityLabel")) {
|
|
204
|
+
return item.json.optString("accessibilityLabel")
|
|
205
|
+
}
|
|
206
|
+
val metrics = item.json.optJSONArray("metrics")?.takeIf { it.length() in 2..3 }
|
|
207
|
+
val values = if (metrics != null) {
|
|
208
|
+
(0 until metrics.length()).flatMap { index ->
|
|
209
|
+
listOf(metricPrimaryViews[index], metricSecondaryViews[index])
|
|
210
|
+
.filter { it.visibility == VISIBLE }
|
|
211
|
+
.map { it.text.toString() }
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
152
214
|
listOf(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
215
|
+
item.json.optString("price"),
|
|
216
|
+
item.json.optJSONObject("change")?.optString("text") ?: "",
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
return (listOf(item.json.optString("title"), item.json.optString("subtitle")) + values)
|
|
220
|
+
.filter(String::isNotEmpty)
|
|
221
|
+
.joinToString(", ")
|
|
222
|
+
}
|
|
161
223
|
|
|
162
224
|
override fun bindContent(
|
|
163
225
|
item: NativeListItem,
|
|
@@ -183,7 +245,8 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
183
245
|
if (item.json.optJSONArray("badges")?.optJSONObject(index)?.optJSONObject("icon") == null)
|
|
184
246
|
badgeSlots[index].recycle()
|
|
185
247
|
}
|
|
186
|
-
for (view in listOf(title, subtitle, tertiary) + trailingViews
|
|
248
|
+
for (view in listOf(title, subtitle, tertiary) + trailingViews +
|
|
249
|
+
metricPrimaryViews + metricSecondaryViews) {
|
|
187
250
|
view.text = ""
|
|
188
251
|
view.visibility = GONE
|
|
189
252
|
view.maxLines = 1
|
|
@@ -217,7 +280,13 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
217
280
|
}
|
|
218
281
|
|
|
219
282
|
override fun bindMarketQuote(item: NativeListItem, theme: JSONObject?) {
|
|
220
|
-
if (retainBoundItem(item))
|
|
283
|
+
if (retainBoundItem(item)) {
|
|
284
|
+
item.json.optJSONArray("metrics")?.takeIf { it.length() in 2..3 }?.let {
|
|
285
|
+
updateMetricLabels(it, theme)
|
|
286
|
+
}
|
|
287
|
+
bindQuote(item, theme)
|
|
288
|
+
contentDescription = accessibilityText(item)
|
|
289
|
+
}
|
|
221
290
|
}
|
|
222
291
|
|
|
223
292
|
private fun cancelMarketHold() {
|
|
@@ -304,6 +373,7 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
304
373
|
longPressFired = false
|
|
305
374
|
leadingFrame.recycle()
|
|
306
375
|
badgeSlots.forEach { it.recycle() }
|
|
376
|
+
(metricPrimaryViews + metricSecondaryViews).forEach { it.text = "" }
|
|
307
377
|
imageSignature = ""
|
|
308
378
|
}
|
|
309
379
|
|
|
@@ -561,10 +631,12 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
561
631
|
)
|
|
562
632
|
// OneKey patch: retain the source gap without changing other templates.
|
|
563
633
|
// addView(mainColumn, weighted())
|
|
634
|
+
val metrics = item.json.optJSONArray("metrics")?.takeIf { it.length() in 2..3 }
|
|
564
635
|
addView(
|
|
565
636
|
mainColumn,
|
|
566
637
|
weighted().apply {
|
|
567
|
-
|
|
638
|
+
if (metrics != null) weight = 2f
|
|
639
|
+
else marginEnd = dp(style?.optDouble("contentTrailingGap", 0.0)?.roundToInt() ?: 0)
|
|
568
640
|
},
|
|
569
641
|
)
|
|
570
642
|
titleLine.packsChildrenAtStart = true
|
|
@@ -748,7 +820,11 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
748
820
|
}
|
|
749
821
|
trailingColumn.orientation = HORIZONTAL
|
|
750
822
|
trailingColumn.gravity = Gravity.END or Gravity.CENTER_VERTICAL
|
|
751
|
-
|
|
823
|
+
if (metrics != null) {
|
|
824
|
+
bindMetrics(metrics, theme, style?.optDouble("trailingGap", 8.0)?.roundToInt() ?: 8)
|
|
825
|
+
} else {
|
|
826
|
+
addView(trailingColumn, wrap())
|
|
827
|
+
}
|
|
752
828
|
bindQuote(item, theme)
|
|
753
829
|
val nextImageSignature =
|
|
754
830
|
nativeListCanonical(
|
|
@@ -861,18 +937,6 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
861
937
|
)
|
|
862
938
|
}
|
|
863
939
|
}
|
|
864
|
-
contentDescription =
|
|
865
|
-
item.json.optString(
|
|
866
|
-
"accessibilityLabel",
|
|
867
|
-
listOf(
|
|
868
|
-
item.json.optString("title"),
|
|
869
|
-
item.json.optString("subtitle"),
|
|
870
|
-
item.json.optString("price"),
|
|
871
|
-
changeData.optString("text"),
|
|
872
|
-
)
|
|
873
|
-
.filter(String::isNotEmpty)
|
|
874
|
-
.joinToString(", "),
|
|
875
|
-
)
|
|
876
940
|
}
|
|
877
941
|
|
|
878
942
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
@@ -912,7 +976,7 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
912
976
|
?.has("contentVerticalAlignment") == true
|
|
913
977
|
if (item.type == "market" && item.json.optJSONObject("style") != null) {
|
|
914
978
|
// OneKey patch: preserve Yoga's half-pixel centering for Market columns and badges.
|
|
915
|
-
for (column in listOf(leadingFrame, mainColumn, trailingColumn)) {
|
|
979
|
+
for (column in listOf(leadingFrame, mainColumn, trailingColumn) + metricColumns) {
|
|
916
980
|
if (!hasContainerAlignment && column.parent === this && column.visibility != GONE) {
|
|
917
981
|
column.offsetTopAndBottom((height - column.height + 1) / 2 - column.top)
|
|
918
982
|
}
|
|
@@ -50,16 +50,17 @@ internal fun nativeListLeadingVisualOverhangsFrame(
|
|
|
50
50
|
): Boolean = kind == "token" && sourceCount > 1 || hasCornerIcon || overlayCount > 0
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Whether an Activity row host
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
53
|
+
* Whether an Activity row host (and, for a rich `amounts` row, the details view
|
|
54
|
+
* with its nested columns) clips its children and padding for this bind. One
|
|
55
|
+
* row view serves both the legacy row and the rich row and is reused across
|
|
56
|
+
* binds, so clipping is derived from the bound item alone and applied on every
|
|
57
|
+
* bind: a row whose bound leading visual lays a badge past its frame
|
|
58
|
+
* ([nativeListLeadingVisualOverhangsFrame]) opts out, whether that visual sits
|
|
59
|
+
* on the host (legacy row, OK-66071) or on the details view (rich row,
|
|
60
|
+
* OK-66275); a row without such a badge clips again even when the view it
|
|
61
|
+
* reuses last showed one.
|
|
60
62
|
*/
|
|
61
|
-
internal fun nativeListActivityHostClips(
|
|
62
|
-
rich || !leadingOverhangs
|
|
63
|
+
internal fun nativeListActivityHostClips(leadingOverhangs: Boolean): Boolean = !leadingOverhangs
|
|
63
64
|
|
|
64
65
|
internal data class NativeListSlotFrame(val x: Int, val y: Int, val width: Int, val height: Int)
|
|
65
66
|
|
|
@@ -378,7 +379,9 @@ internal fun mergeRow(original: JSONObject, changes: JSONObject): JSONObject {
|
|
|
378
379
|
val keys = changes.keys()
|
|
379
380
|
while (keys.hasNext()) {
|
|
380
381
|
val key = keys.next()
|
|
381
|
-
if (key != "key" && key != "type")
|
|
382
|
+
if (key != "key" && key != "type") {
|
|
383
|
+
if (changes.isNull(key)) result.remove(key) else result.put(key, changes.get(key))
|
|
384
|
+
}
|
|
382
385
|
}
|
|
383
386
|
return result
|
|
384
387
|
}
|
|
@@ -46,6 +46,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
|
46
46
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
47
47
|
import com.facebook.react.uimanager.PointerEvents
|
|
48
48
|
import com.facebook.react.uimanager.ReactPointerEventsView
|
|
49
|
+
import com.facebook.react.uimanager.events.NativeGestureUtil
|
|
49
50
|
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
50
51
|
import org.json.JSONArray
|
|
51
52
|
import org.json.JSONObject
|
|
@@ -221,6 +222,14 @@ class NativeListView(
|
|
|
221
222
|
if (isLayoutSuppressed) return
|
|
222
223
|
super.onLayout(changed, left, top, right, bottom)
|
|
223
224
|
}
|
|
225
|
+
|
|
226
|
+
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
|
227
|
+
val handled = super.dispatchTouchEvent(event)
|
|
228
|
+
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
|
229
|
+
finishPagerNativeGesture(event)
|
|
230
|
+
}
|
|
231
|
+
return handled
|
|
232
|
+
}
|
|
224
233
|
}
|
|
225
234
|
private var configuredTopPaddingPx = 0
|
|
226
235
|
private var slotInsetPx = 0
|
|
@@ -1843,6 +1852,7 @@ class NativeListView(
|
|
|
1843
1852
|
// OneKey patch: vertical lists retain vertical drags and leave horizontal drags to a parent pager.
|
|
1844
1853
|
private val pagerGestureTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
|
1845
1854
|
private var pagerGestureIsVertical = false
|
|
1855
|
+
private var pagerNativeGestureStarted = false
|
|
1846
1856
|
private val pagerGestureTouchListener = object : RecyclerView.SimpleOnItemTouchListener() {
|
|
1847
1857
|
private var downX = 0f
|
|
1848
1858
|
private var downY = 0f
|
|
@@ -1856,30 +1866,43 @@ class NativeListView(
|
|
|
1856
1866
|
downY = event.y
|
|
1857
1867
|
directionResolved = false
|
|
1858
1868
|
pagerGestureIsVertical = false
|
|
1869
|
+
pagerNativeGestureStarted = false
|
|
1859
1870
|
}
|
|
1860
|
-
MotionEvent.ACTION_MOVE ->
|
|
1871
|
+
MotionEvent.ACTION_MOVE -> {
|
|
1861
1872
|
val deltaX = abs(event.x - downX)
|
|
1862
1873
|
val deltaY = abs(event.y - downY)
|
|
1863
|
-
if (max(deltaX, deltaY) > pagerGestureTouchSlop) {
|
|
1874
|
+
if (!directionResolved && max(deltaX, deltaY) > pagerGestureTouchSlop) {
|
|
1864
1875
|
directionResolved = true
|
|
1865
1876
|
pagerGestureIsVertical = deltaY >= deltaX
|
|
1866
1877
|
recyclerView.parent?.requestDisallowInterceptTouchEvent(pagerGestureIsVertical)
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1878
|
+
} else if (!pagerGestureIsVertical && deltaY > pagerGestureTouchSlop && deltaY >= deltaX) {
|
|
1879
|
+
pagerGestureIsVertical = true
|
|
1880
|
+
recyclerView.parent?.requestDisallowInterceptTouchEvent(true)
|
|
1881
|
+
}
|
|
1882
|
+
if (pagerGestureIsVertical && !pagerNativeGestureStarted) {
|
|
1883
|
+
NativeGestureUtil.notifyNativeGestureStarted(this@NativeListView, event)
|
|
1884
|
+
pagerNativeGestureStarted = true
|
|
1885
|
+
if (keyboardDismissMode == NativeListKeyboardDismissMode.ON_DRAG) {
|
|
1871
1886
|
dismissKeyboard()
|
|
1872
1887
|
}
|
|
1873
1888
|
}
|
|
1874
1889
|
}
|
|
1875
1890
|
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
|
1876
|
-
|
|
1877
|
-
pagerGestureIsVertical = false
|
|
1891
|
+
finishPagerNativeGesture(event)
|
|
1878
1892
|
}
|
|
1879
1893
|
}
|
|
1880
1894
|
return false
|
|
1881
1895
|
}
|
|
1882
1896
|
}
|
|
1897
|
+
|
|
1898
|
+
private fun finishPagerNativeGesture(event: MotionEvent) {
|
|
1899
|
+
if (pagerNativeGestureStarted) {
|
|
1900
|
+
NativeGestureUtil.notifyNativeGestureEnded(this, event)
|
|
1901
|
+
pagerNativeGestureStarted = false
|
|
1902
|
+
}
|
|
1903
|
+
recyclerView.parent?.requestDisallowInterceptTouchEvent(false)
|
|
1904
|
+
pagerGestureIsVertical = false
|
|
1905
|
+
}
|
|
1883
1906
|
// Intercept only a completed tap so RecyclerView keeps drag and reorder ownership.
|
|
1884
1907
|
private val keyboardTapTouchListener = object : RecyclerView.SimpleOnItemTouchListener() {
|
|
1885
1908
|
private var downX = 0f
|
|
@@ -2920,6 +2943,7 @@ class NativeListView(
|
|
|
2920
2943
|
previous.type == "market" &&
|
|
2921
2944
|
changes.keys().asSequence().all(MARKET_QUOTE_FIELDS::contains)
|
|
2922
2945
|
val merged = NativeListItem.parse(mergeRow(previous.json, changes))
|
|
2946
|
+
marketQuoteOnly = marketQuoteOnly && hasSameMarketMetricStructure(previous, merged)
|
|
2923
2947
|
nextItems[index] = merged
|
|
2924
2948
|
if (changes.has("selected")) {
|
|
2925
2949
|
if (changes.optBoolean("selected")) selected.add(merged.key) else selected.remove(merged.key)
|
|
@@ -4815,6 +4839,7 @@ class NativeListView(
|
|
|
4815
4839
|
"priceSegments",
|
|
4816
4840
|
"change",
|
|
4817
4841
|
"accessibilityLabel",
|
|
4842
|
+
"metrics",
|
|
4818
4843
|
)
|
|
4819
4844
|
private const val SECTION_INDEX_CONTENT_INSET_DP = 16
|
|
4820
4845
|
private const val SECTION_INDEX_RAIL_WIDTH_DP = 32
|
package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt
CHANGED
|
@@ -5,10 +5,12 @@ import org.junit.Test
|
|
|
5
5
|
|
|
6
6
|
class NativeListActivityHostClipPolicyTest {
|
|
7
7
|
// One Activity row view serves legacy and rich rows and is reused across
|
|
8
|
-
// binds. A
|
|
9
|
-
// clipping off
|
|
10
|
-
//
|
|
11
|
-
// a
|
|
8
|
+
// binds. A row with an overhanging network badge switches the host's
|
|
9
|
+
// clipping off, whether the badge sits on the host's visual (legacy row,
|
|
10
|
+
// OK-66071) or on the details view's visual (rich row, OK-66275); the next
|
|
11
|
+
// bind must derive clipping afresh, so a row without a badge reusing that
|
|
12
|
+
// view clips again instead of drawing over a neighbouring row (PR #185
|
|
13
|
+
// review).
|
|
12
14
|
@Test
|
|
13
15
|
fun rebindSequenceDerivesClippingFromEachBoundItem() {
|
|
14
16
|
data class Bind(val name: String, val rich: Boolean, val leadingOverhangs: Boolean, val clips: Boolean)
|
|
@@ -17,13 +19,17 @@ class NativeListActivityHostClipPolicyTest {
|
|
|
17
19
|
Bind("legacy row, plain token", rich = false, leadingOverhangs = false, clips = true),
|
|
18
20
|
Bind("legacy row, network badge", rich = false, leadingOverhangs = true, clips = false),
|
|
19
21
|
Bind("rich row reusing the badge row's view", rich = true, leadingOverhangs = false, clips = true),
|
|
22
|
+
// The app's history rows carry `amounts`, so their badge lives on the
|
|
23
|
+
// details view's leading visual: a rich row with such a badge must stop
|
|
24
|
+
// clipping too (OK-66275).
|
|
25
|
+
Bind("rich row, network badge in details", rich = true, leadingOverhangs = true, clips = false),
|
|
20
26
|
Bind("legacy row, badge again", rich = false, leadingOverhangs = true, clips = false),
|
|
21
27
|
Bind("legacy row, hidden leading", rich = false, leadingOverhangs = false, clips = true),
|
|
22
28
|
)
|
|
23
29
|
|
|
24
30
|
assertEquals(
|
|
25
31
|
binds.map(Bind::clips),
|
|
26
|
-
binds.map { nativeListActivityHostClips(
|
|
32
|
+
binds.map { nativeListActivityHostClips(leadingOverhangs = it.leadingOverhangs) },
|
|
27
33
|
)
|
|
28
34
|
}
|
|
29
35
|
}
|
package/docs/ROW_TEMPLATES.md
CHANGED
|
@@ -59,6 +59,10 @@ separately from source implementation in STYLE_SPEC §9.
|
|
|
59
59
|
a 4-point gap. It has no click action; an optional Web `hoverActionKey`
|
|
60
60
|
emits an icon-anchored tooltip request on hover or touch. A trailing `button` is the fixed small
|
|
61
61
|
secondary text action and uses the normal accessory event slot.
|
|
62
|
+
- **Title image:** optional `titleImage` renders a circular image after the title
|
|
63
|
+
icons and before suffixes/badges. Its `ImageSource` dimensions must be square,
|
|
64
|
+
1...40 logical units. Optional Web `hoverActionKey` uses the existing anchored
|
|
65
|
+
help event; native keeps the image decorative for touch. See SPEC.md.
|
|
62
66
|
- **Second Web help icon:** `secondaryTitleIcon` uses the same descriptor after
|
|
63
67
|
`titleIcon`; each glyph has its own hover/touch anchor. Native ignores it.
|
|
64
68
|
- **Decorative refresh:** a trailing `RefreshCcwOutline` without `actionKey`
|
|
@@ -178,8 +182,12 @@ separately from source implementation in STYLE_SPEC §9.
|
|
|
178
182
|
with at most 32 unique keyed entries. Each entry supports a leading visual,
|
|
179
183
|
tone, primary/secondary text and subscript segments. The title supports at
|
|
180
184
|
most four keyed badges. `descriptionActionKey` emits a description action.
|
|
181
|
-
`presentation: 'table'` allocates
|
|
182
|
-
optional fee
|
|
185
|
+
`presentation: 'table'` allocates identity (including the leading visual and
|
|
186
|
+
its gap), amounts and optional fee in a stable `1:1:0.6` ratio after column
|
|
187
|
+
gaps. Without fee, identity and amounts have equal widths. Amount content
|
|
188
|
+
stays start-aligned; native fee content stays end-aligned, while Web retains its
|
|
189
|
+
existing start alignment. Fee text length and leading visibility do not move
|
|
190
|
+
the amount column. `stacked` keeps right-aligned amounts beside identity.
|
|
183
191
|
`fee.hidden` reserves its column while hiding its content. The Web rich
|
|
184
192
|
Activity renderer uses these fields and the same `hideLeading` visibility.
|
|
185
193
|
|