@onekeyfe/react-native-native-list 6.8.0-3 → 6.8.0-31
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/build.gradle +3 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +18 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +12 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +166 -36
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +3 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +8 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +6 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +21 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +24 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListRowUpdates.kt +34 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +11 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentLayout.kt +71 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTitleSegmentsView.kt +126 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +84 -9
- package/android/src/main/res/values/native_scroll_coordinator_ids.xml +1 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentitySubtitleBindingTest.kt +177 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +2 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListTitleSegmentLayoutTest.kt +130 -0
- package/docs/ROW_TEMPLATES.md +8 -1
- package/docs/SPEC.md +312 -5
- package/docs/STYLE_SPEC.md +7 -1
- package/ios/NativeListAccessoryStack.swift +22 -0
- package/ios/NativeListActivityDetailsView.swift +45 -1
- package/ios/NativeListDataRowRenderer.swift +12 -5
- package/ios/NativeListIdentityRenderer.swift +145 -66
- package/ios/NativeListLeadingVisual.swift +8 -0
- package/ios/NativeListMarketRenderer.swift +6 -2
- package/ios/NativeListModels.swift +7 -0
- package/ios/NativeListResolvedText.swift +9 -7
- package/ios/NativeListSectionHeaderRenderer.swift +9 -43
- package/ios/NativeListTextStyles.swift +72 -12
- package/ios/NativeListTitleSegmentLayout.swift +72 -0
- package/ios/NativeListTitleSegmentsLabel.swift +92 -0
- package/ios/RNCNativeListView.swift +203 -45
- package/ios/tests/NativeListActivityPresentationTests.swift +137 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +155 -0
- package/ios/tests/NativeListLifecycleTests.swift +298 -24
- package/ios/tests/NativeListMediaVisibilityTests.swift +2 -1
- package/lib/module/models.js +2 -0
- package/lib/module/validation.js +96 -13
- package/lib/module/web/NativeListWebEngine.js +427 -100
- package/lib/module/web/templates/ActivityRowRenderer.js +1 -1
- package/lib/module/web/templates/IdentityRowRenderer.js +134 -3
- package/lib/module/web/templates/MarketRowRenderer.js +2 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +1 -0
- package/lib/module/web/templates/RowElements.js +2 -2
- package/lib/module/web/templates/RowText.js +2 -0
- package/lib/typescript/src/models.d.ts +35 -1
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +17 -2
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +6 -2
- package/lib/typescript/src/web/templates/RowVisual.d.ts +1 -1
- package/package.json +1 -1
- package/src/models.ts +38 -0
- package/src/validation.ts +196 -6
- package/src/web/NativeListWebEngine.ts +671 -112
- package/src/web/templates/ActivityRowRenderer.ts +1 -1
- package/src/web/templates/IdentityRowRenderer.ts +208 -3
- package/src/web/templates/MarketRowRenderer.ts +2 -0
- package/src/web/templates/MediaTileRowRenderer.ts +1 -0
- package/src/web/templates/RowElements.ts +3 -2
- package/src/web/templates/RowText.ts +6 -0
- package/src/web/templates/RowVisual.ts +2 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.margelo.nitro.nativelist
|
|
2
|
+
|
|
3
|
+
import org.json.JSONObject
|
|
4
|
+
|
|
5
|
+
/** Compare account-selector content that the subtitle and selection binders cannot refresh. */
|
|
6
|
+
internal fun canUpdateIdentitySubtitle(previous: NativeListItem, next: NativeListItem): Boolean {
|
|
7
|
+
if (previous.key != next.key || previous.type != "identity" || next.type != "identity") return false
|
|
8
|
+
|
|
9
|
+
fun structure(item: NativeListItem): String? {
|
|
10
|
+
val data = JSONObject(item.content)
|
|
11
|
+
if (data.optString("presentation") != "accountSelector") return null
|
|
12
|
+
val segments = data.optJSONArray("subtitleSegments") ?: return null
|
|
13
|
+
if (segments.length() == 0) return null
|
|
14
|
+
for (index in 0 until segments.length()) {
|
|
15
|
+
val segment = segments.optJSONObject(index) ?: return null
|
|
16
|
+
segment.remove("text")
|
|
17
|
+
segment.remove("textSegments")
|
|
18
|
+
segment.remove("tone")
|
|
19
|
+
}
|
|
20
|
+
data.remove("accessibilityLabel")
|
|
21
|
+
// Selection chrome and the existing checkbox are refreshed on every bind.
|
|
22
|
+
data.remove("selected")
|
|
23
|
+
data.optJSONArray("trailing")?.let { accessories ->
|
|
24
|
+
for (index in 0 until accessories.length()) {
|
|
25
|
+
val accessory = accessories.optJSONObject(index) ?: continue
|
|
26
|
+
if (accessory.optString("kind") == "checkbox") accessory.remove("state")
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return nativeListCanonical(data)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
val previousStructure = structure(previous) ?: return false
|
|
33
|
+
return previousStructure == structure(next)
|
|
34
|
+
}
|
|
@@ -773,6 +773,7 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
|
|
|
773
773
|
if (style.has("offsetY"))
|
|
774
774
|
(view as? NativeListTextView)?.opticalOffsetY =
|
|
775
775
|
(style.optDouble("offsetY") * resources.displayMetrics.density).toFloat()
|
|
776
|
+
applyNativeListTextSpacing(view, style, defaultLetterSpacing = view.letterSpacing)
|
|
776
777
|
style.optString("alignment").takeIf(String::isNotEmpty)?.let {
|
|
777
778
|
view.gravity =
|
|
778
779
|
(view.gravity and Gravity.VERTICAL_GRAVITY_MASK) or
|
|
@@ -790,15 +791,21 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
|
|
|
790
791
|
setOf("accountSelector", "networkSelector", "walletSidebar")
|
|
791
792
|
)
|
|
792
793
|
return
|
|
794
|
+
val rowStyle = item.json.optJSONObject("style")
|
|
793
795
|
fun visit(view: View) {
|
|
794
796
|
if (view is TextView) {
|
|
795
|
-
|
|
797
|
+
val explicit = when (view) {
|
|
798
|
+
title -> rowStyle?.optJSONObject("title")
|
|
799
|
+
subtitle -> rowStyle?.optJSONObject("subtitle")
|
|
800
|
+
trailingViews[0] -> rowStyle?.optJSONObject("value")
|
|
801
|
+
else -> null
|
|
802
|
+
}
|
|
796
803
|
if (sourceScale) {
|
|
797
804
|
paintDefaults.putIfAbsent(view, view.paintFlags)
|
|
798
805
|
view.paintFlags = view.paintFlags or Paint.SUBPIXEL_TEXT_FLAG or Paint.LINEAR_TEXT_FLAG
|
|
799
806
|
val (fontSize, line) =
|
|
800
807
|
selectorTextMetrics.getOrPut(view) { view.textSize to view.lineHeight }
|
|
801
|
-
view.setTextSize(
|
|
808
|
+
if (explicit?.has("fontSize") != true) view.setTextSize(
|
|
802
809
|
TypedValue.COMPLEX_UNIT_PX,
|
|
803
810
|
kotlin.math
|
|
804
811
|
.ceil(
|
|
@@ -808,8 +815,7 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
|
|
|
808
815
|
)
|
|
809
816
|
.toFloat(),
|
|
810
817
|
)
|
|
811
|
-
view.
|
|
812
|
-
if (view.text.isNotEmpty()) {
|
|
818
|
+
if (explicit?.has("lineHeight") != true && view.text.isNotEmpty()) {
|
|
813
819
|
val text = SpannableStringBuilder(view.text)
|
|
814
820
|
text
|
|
815
821
|
.getSpans(0, text.length, NativeListLineHeightSpan::class.java)
|
|
@@ -824,6 +830,7 @@ internal class NativeListSectionHeaderRowView(context: ThemedReactContext, fonts
|
|
|
824
830
|
view.text = text
|
|
825
831
|
}
|
|
826
832
|
}
|
|
833
|
+
applyNativeListTextSpacing(view, explicit, defaultLetterSpacing = view.letterSpacing)
|
|
827
834
|
}
|
|
828
835
|
if (view is ViewGroup) for (i in 0 until view.childCount) visit(view.getChildAt(i))
|
|
829
836
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
package com.margelo.nitro.nativelist
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Widths for identity title runs (docs/SPEC.md, "Identity title segments and
|
|
5
|
+
* leading title icon"). A run's base width is its natural width under its cap;
|
|
6
|
+
* the one shrinking run takes what the others leave; runs that do not shrink
|
|
7
|
+
* and still overflow are cut from the end of the line.
|
|
8
|
+
*/
|
|
9
|
+
internal fun nativeListTitleSegmentWidths(
|
|
10
|
+
natural: List<Float>,
|
|
11
|
+
shrink: List<Boolean>,
|
|
12
|
+
maxWidthRatio: List<Float?>,
|
|
13
|
+
available: Float,
|
|
14
|
+
): List<Float> {
|
|
15
|
+
val line = available.coerceAtLeast(0f)
|
|
16
|
+
val widths =
|
|
17
|
+
natural.indices
|
|
18
|
+
.map { index ->
|
|
19
|
+
val width = natural[index].coerceAtLeast(0f)
|
|
20
|
+
val ratio = maxWidthRatio.getOrNull(index)
|
|
21
|
+
if (ratio == null) width else minOf(width, ratio * line)
|
|
22
|
+
}
|
|
23
|
+
.toMutableList()
|
|
24
|
+
val shrinking = shrink.indexOf(true)
|
|
25
|
+
if (shrinking in widths.indices) {
|
|
26
|
+
val others = widths.indices.filter { it != shrinking }.sumOf { widths[it].toDouble() }.toFloat()
|
|
27
|
+
widths[shrinking] = minOf(widths[shrinking], line - others).coerceAtLeast(0f)
|
|
28
|
+
}
|
|
29
|
+
var overflow = widths.sum() - line
|
|
30
|
+
var index = widths.lastIndex
|
|
31
|
+
while (overflow > 0f && index >= 0) {
|
|
32
|
+
val cut = minOf(widths[index], overflow)
|
|
33
|
+
widths[index] -= cut
|
|
34
|
+
overflow -= cut
|
|
35
|
+
index -= 1
|
|
36
|
+
}
|
|
37
|
+
return widths
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Wallet sidebar rows keep the plain title: no runs and no leading glyph (docs/SPEC.md). */
|
|
41
|
+
internal fun nativeListAllowsTitleDecorations(presentation: String): Boolean =
|
|
42
|
+
presentation != "walletSidebar"
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Whether the runs replace `title`: not where `title` itself is highlighted
|
|
46
|
+
* (`titleMatch` indexes it), and never on a wallet sidebar row.
|
|
47
|
+
*/
|
|
48
|
+
internal fun nativeListShowsTitleRuns(presentation: String, runCount: Int, matchCount: Int): Boolean =
|
|
49
|
+
runCount > 0 && matchCount == 0 && nativeListAllowsTitleDecorations(presentation)
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The run that has to end with an ellipsis because the line was cut exactly
|
|
53
|
+
* after it: a run that does not shrink lost its whole width, and this one is
|
|
54
|
+
* drawn in full, so nothing else would show that the title goes on. Null when
|
|
55
|
+
* the line is not cut, when it is cut inside a run, which then truncates by
|
|
56
|
+
* itself, and when only the shrinking run gave up its width, which it may.
|
|
57
|
+
*/
|
|
58
|
+
internal fun nativeListTitleSegmentOverflowIndex(
|
|
59
|
+
natural: List<Float>,
|
|
60
|
+
shrink: List<Boolean>,
|
|
61
|
+
widths: List<Float>,
|
|
62
|
+
): Int? {
|
|
63
|
+
val last = widths.indexOfLast { it > 0f }
|
|
64
|
+
if (last !in natural.indices) return null
|
|
65
|
+
val cutsAFixedRun =
|
|
66
|
+
natural.indices.any { it > last && natural[it] > 0f && shrink.getOrNull(it) != true }
|
|
67
|
+
return if (cutsAFixedRun && widths[last] >= natural[last]) last else null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A run is one line: a hard break folds into one space, as in a one-line title. */
|
|
71
|
+
internal fun nativeListTitleRunText(text: String): String = text.replace(Regex("\\r\\n|[\\r\\n]"), " ")
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
package com.margelo.nitro.nativelist
|
|
2
|
+
|
|
3
|
+
import android.graphics.Typeface
|
|
4
|
+
import android.text.SpannableStringBuilder
|
|
5
|
+
import android.text.Spanned
|
|
6
|
+
import android.text.TextPaint
|
|
7
|
+
import android.text.TextUtils
|
|
8
|
+
import android.text.style.ForegroundColorSpan
|
|
9
|
+
import android.text.style.MetricAffectingSpan
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Identity title runs on one line. The text is rebuilt for each measured width
|
|
13
|
+
* from the widths `nativeListTitleSegmentWidths` allocates, so a run gives up
|
|
14
|
+
* width without the others; accessibility reads the row's `title` instead.
|
|
15
|
+
*/
|
|
16
|
+
internal class NativeListTitleSegmentsView(context: android.content.Context) :
|
|
17
|
+
NativeListTextView(context) {
|
|
18
|
+
class Run(
|
|
19
|
+
val text: String,
|
|
20
|
+
// Null keeps the view's typeface, which follows the title's.
|
|
21
|
+
val typeface: Typeface?,
|
|
22
|
+
val color: Int,
|
|
23
|
+
val shrink: Boolean,
|
|
24
|
+
val maxWidthRatio: Float?,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
private var runs: List<Run> = emptyList()
|
|
28
|
+
private var builtForWidth = -1
|
|
29
|
+
|
|
30
|
+
// `style.title.lineHeight` in pixels. The plain title carries it as a span
|
|
31
|
+
// on its text, so the rebuilt text here needs the same span to match.
|
|
32
|
+
var explicitLineHeight: Int? = null
|
|
33
|
+
set(value) {
|
|
34
|
+
if (field == value) return
|
|
35
|
+
field = value
|
|
36
|
+
builtForWidth = -1
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fun setRuns(runs: List<Run>, spokenText: String) {
|
|
40
|
+
this.runs = runs
|
|
41
|
+
builtForWidth = -1
|
|
42
|
+
contentDescription = spokenText.takeIf(String::isNotEmpty)
|
|
43
|
+
text = runs.joinToString("") { it.text }
|
|
44
|
+
requestLayout()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun clearRuns() {
|
|
48
|
+
runs = emptyList()
|
|
49
|
+
builtForWidth = -1
|
|
50
|
+
explicitLineHeight = null
|
|
51
|
+
contentDescription = null
|
|
52
|
+
text = ""
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
56
|
+
if (runs.isEmpty()) {
|
|
57
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
var outer =
|
|
61
|
+
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) Int.MAX_VALUE
|
|
62
|
+
else MeasureSpec.getSize(widthMeasureSpec)
|
|
63
|
+
if (maxWidth in 0 until outer) outer = maxWidth
|
|
64
|
+
val available =
|
|
65
|
+
if (outer == Int.MAX_VALUE) outer
|
|
66
|
+
else (outer - compoundPaddingLeft - compoundPaddingRight).coerceAtLeast(0)
|
|
67
|
+
if (available != builtForWidth) {
|
|
68
|
+
builtForWidth = available
|
|
69
|
+
// The same width rebuilds the same text, so the relayout this asks for
|
|
70
|
+
// measures once more and stops.
|
|
71
|
+
setText(build(available), BufferType.SPANNABLE)
|
|
72
|
+
}
|
|
73
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
|
74
|
+
// The runs fill what the title line leaves, so a ratio is a share of it.
|
|
75
|
+
if (outer != Int.MAX_VALUE) setMeasuredDimension(outer, measuredHeight)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun build(available: Int): CharSequence {
|
|
79
|
+
val paints = runs.map { run -> TextPaint(paint).apply { run.typeface?.let { typeface = it } } }
|
|
80
|
+
val natural = runs.mapIndexed { index, run -> paints[index].measureText(run.text) }
|
|
81
|
+
val widths =
|
|
82
|
+
nativeListTitleSegmentWidths(
|
|
83
|
+
natural,
|
|
84
|
+
runs.map { it.shrink },
|
|
85
|
+
runs.map { it.maxWidthRatio },
|
|
86
|
+
if (available == Int.MAX_VALUE) Float.MAX_VALUE else available.toFloat(),
|
|
87
|
+
)
|
|
88
|
+
val overflowing = nativeListTitleSegmentOverflowIndex(natural, runs.map { it.shrink }, widths)
|
|
89
|
+
val built = SpannableStringBuilder()
|
|
90
|
+
runs.forEachIndexed { index, run ->
|
|
91
|
+
val width = widths[index]
|
|
92
|
+
if (width <= 0f) return@forEachIndexed
|
|
93
|
+
val shown =
|
|
94
|
+
// Text after this run is hidden: one character more than fits makes
|
|
95
|
+
// the truncation show it. A run too narrow for the ellipsis itself
|
|
96
|
+
// would come back empty, so it is drawn whole instead.
|
|
97
|
+
if (index == overflowing)
|
|
98
|
+
TextUtils.ellipsize(run.text + "\u2026", paints[index], width, TextUtils.TruncateAt.END)
|
|
99
|
+
.takeIf { it.isNotEmpty() } ?: run.text
|
|
100
|
+
else if (width >= natural[index]) run.text
|
|
101
|
+
else TextUtils.ellipsize(run.text, paints[index], width, TextUtils.TruncateAt.END)
|
|
102
|
+
if (shown.isEmpty()) return@forEachIndexed
|
|
103
|
+
val start = built.length
|
|
104
|
+
built.append(shown)
|
|
105
|
+
built.setSpan(ForegroundColorSpan(run.color), start, built.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
106
|
+
run.typeface?.let {
|
|
107
|
+
built.setSpan(TypefaceRunSpan(it), start, built.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
explicitLineHeight?.let {
|
|
111
|
+
if (built.isNotEmpty())
|
|
112
|
+
built.setSpan(NativeListLineHeightSpan(it), 0, built.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
113
|
+
}
|
|
114
|
+
return built
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private class TypefaceRunSpan(private val typeface: Typeface) : MetricAffectingSpan() {
|
|
119
|
+
override fun updateMeasureState(paint: TextPaint) {
|
|
120
|
+
paint.typeface = typeface
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
override fun updateDrawState(paint: TextPaint) {
|
|
124
|
+
paint.typeface = typeface
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -7,6 +7,7 @@ import android.animation.AnimatorListenerAdapter
|
|
|
7
7
|
import android.content.Context
|
|
8
8
|
import android.graphics.Canvas
|
|
9
9
|
import android.graphics.Color
|
|
10
|
+
import android.graphics.Matrix
|
|
10
11
|
import android.graphics.Paint
|
|
11
12
|
import android.graphics.Path
|
|
12
13
|
import android.graphics.Rect
|
|
@@ -2791,6 +2792,7 @@ class NativeListView(
|
|
|
2791
2792
|
previous.selectionMode != next.selectionMode ||
|
|
2792
2793
|
previous.rowPressToggles != next.rowPressToggles ||
|
|
2793
2794
|
previous.reorderable != next.reorderable ||
|
|
2795
|
+
previous.reorderFromHandleOnly != next.reorderFromHandleOnly ||
|
|
2794
2796
|
previous.pullToRefresh != next.pullToRefresh ||
|
|
2795
2797
|
previous.refreshTriggerDistance != next.refreshTriggerDistance ||
|
|
2796
2798
|
previous.refreshing != next.refreshing ||
|
|
@@ -4537,18 +4539,35 @@ class NativeListView(
|
|
|
4537
4539
|
reorderTouchHandler = handler
|
|
4538
4540
|
val movementLimit = dp(REORDER_ALLOWABLE_MOVEMENT_DP).toFloat()
|
|
4539
4541
|
reorderTouchListener = object : RecyclerView.SimpleOnItemTouchListener() {
|
|
4540
|
-
private var candidate:
|
|
4542
|
+
private var candidate: NativeListViewHolder? = null
|
|
4543
|
+
private var candidateItem: NativeListItem? = null
|
|
4544
|
+
private var candidateHandle: View? = null
|
|
4545
|
+
private var candidateBindingEpoch = 0L
|
|
4546
|
+
private var rawDownX = 0f
|
|
4547
|
+
private var rawDownY = 0f
|
|
4541
4548
|
private var downX = 0f
|
|
4542
4549
|
private var downY = 0f
|
|
4543
4550
|
private var dragStarted = false
|
|
4544
4551
|
private val startDrag = Runnable {
|
|
4545
4552
|
val holder = candidate ?: return@Runnable
|
|
4546
|
-
val
|
|
4547
|
-
|
|
4548
|
-
if (!item.isReorderable) return@Runnable
|
|
4549
|
-
if (item.type != "walletGroup" && recyclerView.isLayoutRequested) {
|
|
4553
|
+
val original = candidateItem ?: return@Runnable
|
|
4554
|
+
if (original.type != "walletGroup" && recyclerView.isLayoutRequested) {
|
|
4550
4555
|
relayoutRecyclerViewImmediately()
|
|
4551
4556
|
}
|
|
4557
|
+
val item = adapter.itemAt(holder.bindingAdapterPosition) ?: return@Runnable
|
|
4558
|
+
val acceptedIndex = acceptedKeyIndex?.get(original.key) ?: return@Runnable
|
|
4559
|
+
val current = config ?: return@Runnable
|
|
4560
|
+
val accepted = current.items.getOrNull(acceptedIndex) ?: return@Runnable
|
|
4561
|
+
if (item.key != original.key || accepted.key != original.key || !accepted.isReorderable)
|
|
4562
|
+
return@Runnable
|
|
4563
|
+
val handle = candidateHandle
|
|
4564
|
+
if (handle != null) {
|
|
4565
|
+
val controlled = current.selectionMode == "single" || current.selectionMode == "multiple"
|
|
4566
|
+
if (holder.rowView.bindingEpoch != candidateBindingEpoch ||
|
|
4567
|
+
(accepted.content != original.content && !isStableSelectionUpdate(original, accepted, controlled)) ||
|
|
4568
|
+
findReorderHandle(holder.itemView, rawDownX, rawDownY) !== handle
|
|
4569
|
+
) return@Runnable
|
|
4570
|
+
}
|
|
4552
4571
|
dragStarted = true
|
|
4553
4572
|
beginDrag(holder)
|
|
4554
4573
|
}
|
|
@@ -4562,6 +4581,8 @@ class NativeListView(
|
|
|
4562
4581
|
private fun cancelPending() {
|
|
4563
4582
|
handler.removeCallbacks(startDrag)
|
|
4564
4583
|
candidate = null
|
|
4584
|
+
candidateItem = null
|
|
4585
|
+
candidateHandle = null
|
|
4565
4586
|
}
|
|
4566
4587
|
|
|
4567
4588
|
override fun onInterceptTouchEvent(recyclerView: RecyclerView, event: MotionEvent): Boolean {
|
|
@@ -4572,11 +4593,14 @@ class NativeListView(
|
|
|
4572
4593
|
dragStarted = false
|
|
4573
4594
|
downX = event.x
|
|
4574
4595
|
downY = event.y
|
|
4596
|
+
rawDownX = event.rawX
|
|
4597
|
+
rawDownY = event.rawY
|
|
4575
4598
|
val child = recyclerView.findChildViewUnder(event.x, event.y)
|
|
4576
4599
|
candidate = child
|
|
4577
4600
|
?.let(recyclerView::getChildViewHolder)
|
|
4578
4601
|
// Container-slot holders report binding position 0 in their own adapter.
|
|
4579
|
-
?.
|
|
4602
|
+
?.let { it as? NativeListViewHolder }
|
|
4603
|
+
?.takeIf { holder -> holder.bindingAdapter === adapter }
|
|
4580
4604
|
?.takeIf { holder ->
|
|
4581
4605
|
adapter.itemAt(holder.bindingAdapterPosition)?.let { item ->
|
|
4582
4606
|
// OneKey patch: any wallet group member can initiate the group drag.
|
|
@@ -4586,10 +4610,14 @@ class NativeListView(
|
|
|
4586
4610
|
// item.type != "walletGroup" ||
|
|
4587
4611
|
// event.rawY in holderLocation[1].toFloat()..(holderLocation[1] + dp(68)).toFloat()
|
|
4588
4612
|
// )
|
|
4613
|
+
candidateItem = item
|
|
4614
|
+
if (config?.reorderFromHandleOnly == true) {
|
|
4615
|
+
candidateHandle = findReorderHandle(holder.itemView, rawDownX, rawDownY)
|
|
4616
|
+
if (candidateHandle == null) return@let false
|
|
4617
|
+
candidateBindingEpoch = holder.rowView.bindingEpoch
|
|
4618
|
+
}
|
|
4589
4619
|
item.isReorderable &&
|
|
4590
|
-
(
|
|
4591
|
-
event.y - holder.itemView.top,
|
|
4592
|
-
) != false
|
|
4620
|
+
holder.rowView.canStartWalletGroupReorder(event.y - holder.itemView.top)
|
|
4593
4621
|
} == true
|
|
4594
4622
|
}
|
|
4595
4623
|
if (candidate != null) handler.postDelayed(startDrag, REORDER_LONG_PRESS_MS)
|
|
@@ -4607,6 +4635,53 @@ class NativeListView(
|
|
|
4607
4635
|
}.also(recyclerView::addOnItemTouchListener)
|
|
4608
4636
|
}
|
|
4609
4637
|
|
|
4638
|
+
/** Find the visible trailing handle whose button frame contains the initial press. */
|
|
4639
|
+
private fun findReorderHandle(root: View, rawX: Float, rawY: Float): View? {
|
|
4640
|
+
if (root.visibility != View.VISIBLE) return null
|
|
4641
|
+
if (root.getTag(R.id.onekey_native_list_reorder_handle) == true) {
|
|
4642
|
+
return root.takeIf { reorderHandleContainsScreenPoint(it, rawX, rawY) }
|
|
4643
|
+
}
|
|
4644
|
+
if (root is ViewGroup) {
|
|
4645
|
+
for (index in 0 until root.childCount) {
|
|
4646
|
+
findReorderHandle(root.getChildAt(index), rawX, rawY)?.let { return it }
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
4649
|
+
return null
|
|
4650
|
+
}
|
|
4651
|
+
|
|
4652
|
+
private fun reorderHandleContainsScreenPoint(handle: View, rawX: Float, rawY: Float): Boolean {
|
|
4653
|
+
val localToScreen = Matrix()
|
|
4654
|
+
var view = handle
|
|
4655
|
+
while (true) {
|
|
4656
|
+
val parent = view.parent as? View ?: break
|
|
4657
|
+
localToScreen.postConcat(view.matrix)
|
|
4658
|
+
localToScreen.postTranslate(
|
|
4659
|
+
(view.left - parent.scrollX).toFloat(),
|
|
4660
|
+
(view.top - parent.scrollY).toFloat(),
|
|
4661
|
+
)
|
|
4662
|
+
view = parent
|
|
4663
|
+
}
|
|
4664
|
+
|
|
4665
|
+
// The top-level View's screen origin already includes its transform and
|
|
4666
|
+
// the window offset. Subtract its mapped origin to apply the matrix once.
|
|
4667
|
+
val screenOrigin = IntArray(2)
|
|
4668
|
+
view.getLocationOnScreen(screenOrigin)
|
|
4669
|
+
val mappedOrigin = floatArrayOf(0f, 0f)
|
|
4670
|
+
view.matrix.mapPoints(mappedOrigin)
|
|
4671
|
+
localToScreen.postConcat(view.matrix)
|
|
4672
|
+
localToScreen.postTranslate(
|
|
4673
|
+
screenOrigin[0] - mappedOrigin[0],
|
|
4674
|
+
screenOrigin[1] - mappedOrigin[1],
|
|
4675
|
+
)
|
|
4676
|
+
|
|
4677
|
+
val screenToLocal = Matrix()
|
|
4678
|
+
if (!localToScreen.invert(screenToLocal)) return false
|
|
4679
|
+
val point = floatArrayOf(rawX, rawY)
|
|
4680
|
+
screenToLocal.mapPoints(point)
|
|
4681
|
+
return point[0] >= 0f && point[0] < handle.width &&
|
|
4682
|
+
point[1] >= 0f && point[1] < handle.height
|
|
4683
|
+
}
|
|
4684
|
+
|
|
4610
4685
|
private fun prepareDisplacedReorderAnimation(view: View, helper: ItemTouchHelper) {
|
|
4611
4686
|
val previousX = view.x
|
|
4612
4687
|
val previousY = view.y
|
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
<item name="onekey_native_scroll_coordinator_refresh_inset" type="id" />
|
|
5
5
|
<item name="onekey_native_scroll_coordinator_command_listener" type="id" />
|
|
6
6
|
<item name="onekey_native_scroll_coordinator_command_cancel_listener" type="id" />
|
|
7
|
+
<item name="onekey_native_list_reorder_handle" type="id" />
|
|
7
8
|
</resources>
|
package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentitySubtitleBindingTest.kt
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
package com.margelo.nitro.nativelist
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.view.View
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import android.widget.FrameLayout
|
|
7
|
+
import android.widget.TextView
|
|
8
|
+
import com.facebook.react.bridge.BridgeReactContext
|
|
9
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
10
|
+
import org.json.JSONArray
|
|
11
|
+
import org.json.JSONObject
|
|
12
|
+
import org.junit.After
|
|
13
|
+
import org.junit.Assert.assertEquals
|
|
14
|
+
import org.junit.Assert.assertFalse
|
|
15
|
+
import org.junit.Assert.assertNull
|
|
16
|
+
import org.junit.Assert.assertSame
|
|
17
|
+
import org.junit.Assert.assertTrue
|
|
18
|
+
import org.junit.Before
|
|
19
|
+
import org.junit.Test
|
|
20
|
+
import org.junit.runner.RunWith
|
|
21
|
+
import org.robolectric.Robolectric
|
|
22
|
+
import org.robolectric.RobolectricTestRunner
|
|
23
|
+
import org.robolectric.annotation.Config
|
|
24
|
+
|
|
25
|
+
@RunWith(RobolectricTestRunner::class)
|
|
26
|
+
@Config(sdk = [34])
|
|
27
|
+
class NativeListIdentitySubtitleBindingTest {
|
|
28
|
+
private val controller = Robolectric.buildActivity(Activity::class.java)
|
|
29
|
+
private lateinit var row: NativeListIdentityRowView
|
|
30
|
+
private val checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String =
|
|
31
|
+
{ _, _, fallback -> fallback }
|
|
32
|
+
|
|
33
|
+
@Before
|
|
34
|
+
fun setUp() {
|
|
35
|
+
val activity = controller.setup().visible().get()
|
|
36
|
+
val context = ThemedReactContext(BridgeReactContext(activity.application), activity, "test", 1)
|
|
37
|
+
row = NativeListIdentityRowView(context, NativeListFonts())
|
|
38
|
+
activity.setContentView(FrameLayout(activity).apply { addView(row) })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@After
|
|
42
|
+
fun tearDown() {
|
|
43
|
+
row.dispose()
|
|
44
|
+
controller.pause().stop().destroy()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Test
|
|
48
|
+
fun longerPlainBalanceRemeasuresTheExistingLabelWithoutDetachingAvatar() {
|
|
49
|
+
bind(account("--"))
|
|
50
|
+
measureRow()
|
|
51
|
+
val balance = requireNotNull(label("--"))
|
|
52
|
+
val originalWidth = balance.measuredWidth
|
|
53
|
+
assertTrue(originalWidth > 0)
|
|
54
|
+
assertFalse(balance.isLayoutRequested)
|
|
55
|
+
val originalEpoch = row.bindingEpoch
|
|
56
|
+
val avatarDetachments = watchAvatarDetachments()
|
|
57
|
+
|
|
58
|
+
val updated = account("12345678.90")
|
|
59
|
+
bind(updated)
|
|
60
|
+
assertTrue(balance.isLayoutRequested)
|
|
61
|
+
measureRow()
|
|
62
|
+
|
|
63
|
+
assertSame(balance, label("12345678.90"))
|
|
64
|
+
assertTrue(balance.measuredWidth > originalWidth)
|
|
65
|
+
assertSame(updated, row.tag)
|
|
66
|
+
assertEquals("Account, 12345678.90", row.contentDescription)
|
|
67
|
+
assertEquals(originalEpoch, row.bindingEpoch)
|
|
68
|
+
assertEquals(0, avatarDetachments())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Test
|
|
72
|
+
fun selectionEchoThenBalanceKeepsTheSubtitleAndAvatarAttached() {
|
|
73
|
+
bind(account("--", checkbox = "unchecked"))
|
|
74
|
+
val balance = requireNotNull(label("--"))
|
|
75
|
+
val originalEpoch = row.bindingEpoch
|
|
76
|
+
val avatarDetachments = watchAvatarDetachments()
|
|
77
|
+
val checkbox = descendants(row).filterIsInstance<OneKeyCheckboxView>().single()
|
|
78
|
+
|
|
79
|
+
row.bindSelection(
|
|
80
|
+
account("--", selected = true, checkbox = "checked"), null, "linear", 0, true, checkboxState,
|
|
81
|
+
)
|
|
82
|
+
assertEquals("CheckboxCheckedCustom", checkbox.iconName)
|
|
83
|
+
bind(account("12.34", selected = true, checkbox = "checked"))
|
|
84
|
+
|
|
85
|
+
assertSame(balance, label("12.34"))
|
|
86
|
+
assertEquals("CheckboxCheckedCustom", checkbox.iconName)
|
|
87
|
+
assertEquals(originalEpoch, row.bindingEpoch)
|
|
88
|
+
assertEquals(0, avatarDetachments())
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Test
|
|
92
|
+
fun subtitleUpdateUsesRenderedContentAfterSelectionHasAdvancedTheModel() {
|
|
93
|
+
bind(account("--", showAction = true))
|
|
94
|
+
val originalEpoch = row.bindingEpoch
|
|
95
|
+
val previousAction = requireNotNull(label("Manage"))
|
|
96
|
+
|
|
97
|
+
row.bindSelection(account("--", selected = true), null, "linear", 0, true, checkboxState)
|
|
98
|
+
assertSame(previousAction, label("Manage"))
|
|
99
|
+
bind(account("12.34", selected = true))
|
|
100
|
+
|
|
101
|
+
assertNull(label("Manage"))
|
|
102
|
+
assertEquals("12.34", label("12.34")?.text.toString())
|
|
103
|
+
assertTrue(row.bindingEpoch > originalEpoch)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Test
|
|
107
|
+
fun formattedBalanceUpdateReusesTheLabelAndClearsOldSpansOnPlainText() {
|
|
108
|
+
bind(account("--"))
|
|
109
|
+
val balance = requireNotNull(label("--"))
|
|
110
|
+
val originalEpoch = row.bindingEpoch
|
|
111
|
+
bind(account("0.0004", formatted = true))
|
|
112
|
+
assertSame(balance, label("0.04"))
|
|
113
|
+
bind(account("1.23"))
|
|
114
|
+
assertSame(balance, label("1.23"))
|
|
115
|
+
assertEquals(originalEpoch, row.bindingEpoch)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private fun bind(item: NativeListItem) {
|
|
119
|
+
row.bind(
|
|
120
|
+
item, null, "linear", "vertical", 0, item.json.optBoolean("selected"), checkboxState,
|
|
121
|
+
useSourceScale = false,
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private fun measureRow() {
|
|
126
|
+
row.measure(
|
|
127
|
+
View.MeasureSpec.makeMeasureSpec(640, View.MeasureSpec.EXACTLY),
|
|
128
|
+
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
|
|
129
|
+
)
|
|
130
|
+
row.layout(0, 0, row.measuredWidth, row.measuredHeight)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fun account(
|
|
134
|
+
balance: String,
|
|
135
|
+
showAction: Boolean = false,
|
|
136
|
+
formatted: Boolean = false,
|
|
137
|
+
selected: Boolean = false,
|
|
138
|
+
checkbox: String? = null,
|
|
139
|
+
): NativeListItem {
|
|
140
|
+
val json = JSONObject("""
|
|
141
|
+
{"key":"account","type":"identity","presentation":"accountSelector","title":"Account",
|
|
142
|
+
"leading":{"kind":"account","fallbackText":"AC"},
|
|
143
|
+
"subtitleSegments":[{"text":"$balance"},{"text":"0x1234","separatorBefore":true}]}
|
|
144
|
+
""").put("accessibilityLabel", "Account, $balance").put("selected", selected)
|
|
145
|
+
if (showAction) {
|
|
146
|
+
json.put("trailing", JSONArray("""[{"kind":"button","label":"Manage","actionKey":"manage"}]"""))
|
|
147
|
+
}
|
|
148
|
+
if (checkbox != null) {
|
|
149
|
+
json.put("trailing", JSONArray().put(JSONObject().put("kind", "checkbox").put("state", checkbox)))
|
|
150
|
+
}
|
|
151
|
+
if (formatted) {
|
|
152
|
+
json.getJSONArray("subtitleSegments").getJSONObject(0)
|
|
153
|
+
.put("textSegments", JSONArray("""[{"text":"0.0"},{"text":"4","style":"subscript"}]"""))
|
|
154
|
+
}
|
|
155
|
+
return NativeListItem.parse(json)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private fun label(text: String): TextView? =
|
|
159
|
+
descendants(row).filterIsInstance<TextView>().singleOrNull { it.text.toString() == text && it.visibility == View.VISIBLE }
|
|
160
|
+
|
|
161
|
+
private fun watchAvatarDetachments(): () -> Int {
|
|
162
|
+
val avatar = descendants(row).single { it is NativeListLeadingVisual }
|
|
163
|
+
var detachments = 0
|
|
164
|
+
avatar.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
|
165
|
+
override fun onViewAttachedToWindow(view: View) = Unit
|
|
166
|
+
override fun onViewDetachedFromWindow(view: View) { detachments++ }
|
|
167
|
+
})
|
|
168
|
+
return { detachments }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private fun descendants(view: View): Sequence<View> = sequence {
|
|
172
|
+
yield(view)
|
|
173
|
+
if (view is ViewGroup) {
|
|
174
|
+
for (index in 0 until view.childCount) yieldAll(descendants(view.getChildAt(index)))
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt
CHANGED
|
@@ -24,6 +24,8 @@ class NativeListIdentityTrailingAxisTest {
|
|
|
24
24
|
listOf(d("icon", "RefreshCcwOutline"), d("chevron")) to true,
|
|
25
25
|
listOf(d("icon", "RefreshCcwOutline", "refresh"), d("chevron")) to false,
|
|
26
26
|
listOf(d("icon", "PencilOutline", "edit"), d("icon", "DragOutline")) to true,
|
|
27
|
+
listOf(d("icon", "PencilOutline", "edit"), d("drag")) to true,
|
|
28
|
+
listOf(d("icon", "InfoCircleOutline", "edit"), d("drag")) to false,
|
|
27
29
|
listOf(d("value"), d("checkbox")) to true,
|
|
28
30
|
listOf(d("valuePair"), d("icon", "DotVerSolid", "menu"), d("chevron")) to false,
|
|
29
31
|
)
|