@onekeyfe/react-native-native-list 6.8.0-alpha.514 → 6.8.0-alpha.540
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/NativeListIdentityRenderer.kt +70 -33
- 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/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/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/docs/SPEC.md +159 -2
- package/docs/STYLE_SPEC.md +7 -1
- package/ios/NativeListAccessoryStack.swift +22 -0
- package/ios/NativeListDataRowRenderer.swift +12 -5
- package/ios/NativeListIdentityRenderer.swift +36 -58
- 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/RNCNativeListView.swift +203 -45
- package/ios/tests/NativeListLifecycleTests.swift +298 -24
- package/lib/module/validation.js +21 -10
- package/lib/module/web/NativeListWebEngine.js +213 -23
- package/lib/module/web/templates/ActivityRowRenderer.js +1 -1
- package/lib/module/web/templates/IdentityRowRenderer.js +12 -1
- 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 +15 -1
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +8 -1
- 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 +15 -0
- package/src/validation.ts +67 -4
- package/src/web/NativeListWebEngine.ts +382 -27
- package/src/web/templates/ActivityRowRenderer.ts +1 -1
- package/src/web/templates/IdentityRowRenderer.ts +23 -1
- 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
package/android/build.gradle
CHANGED
|
@@ -75,6 +75,8 @@ android {
|
|
|
75
75
|
disable "GradleCompatible"
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
testOptions { unitTests.includeAndroidResources = true }
|
|
79
|
+
|
|
78
80
|
compileOptions {
|
|
79
81
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
80
82
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
@@ -110,4 +112,5 @@ dependencies {
|
|
|
110
112
|
implementation project(":onekeyfe_react-native-native-logger")
|
|
111
113
|
implementation project(":onekeyfe_react-native-image")
|
|
112
114
|
testImplementation "junit:junit:4.13.2"
|
|
115
|
+
testImplementation "org.robolectric:robolectric:4.17"
|
|
113
116
|
}
|
|
@@ -255,10 +255,12 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
|
|
|
255
255
|
v.ellipsize = null
|
|
256
256
|
v.setLineSpacing(0f, 1f)
|
|
257
257
|
v.letterSpacing = 0f
|
|
258
|
+
v.fontFeatureSettings = null
|
|
258
259
|
}
|
|
259
260
|
trailingIcons.forEach {
|
|
260
261
|
it.visibility = GONE
|
|
261
262
|
it.setOnClickListener(null)
|
|
263
|
+
it.setTag(R.id.onekey_native_list_reorder_handle, null)
|
|
262
264
|
it.background = null
|
|
263
265
|
it.useSourceScale = selectorUsesSourceScale
|
|
264
266
|
it.glyphSizeDp = null
|
|
@@ -441,13 +443,20 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
|
|
|
441
443
|
theme,
|
|
442
444
|
)
|
|
443
445
|
"menu" -> showTrailingMenu(textIndex++, accessory.optString("actionKey"))
|
|
444
|
-
"drag" ->
|
|
446
|
+
"drag" -> {
|
|
447
|
+
val handleIndex = textIndex++
|
|
445
448
|
showTrailingIcon(
|
|
446
|
-
|
|
449
|
+
handleIndex,
|
|
447
450
|
item,
|
|
448
|
-
|
|
451
|
+
// ListItem draws the handle as a medium tertiary IconButton.
|
|
452
|
+
JSONObject(accessory.toString()).apply {
|
|
453
|
+
put("name", "DragOutline")
|
|
454
|
+
put("buttonStyle", "tertiary")
|
|
455
|
+
},
|
|
449
456
|
theme,
|
|
450
457
|
)
|
|
458
|
+
trailingIcons.getOrNull(handleIndex)?.setTag(R.id.onekey_native_list_reorder_handle, true)
|
|
459
|
+
}
|
|
451
460
|
"icon" -> showTrailingIcon(textIndex++, item, accessory, theme)
|
|
452
461
|
"spinner" -> spinner.visibility = VISIBLE
|
|
453
462
|
"progress" ->
|
|
@@ -719,9 +728,13 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
|
|
|
719
728
|
icon.contentDescription = data.optString("accessibilityLabel").takeIf { it.isNotEmpty() }
|
|
720
729
|
if (data.optString("buttonStyle") == "tertiary") {
|
|
721
730
|
icon.glyphSizeDp = 24
|
|
731
|
+
// A rename + drag pair sits in ListItem's <XStack gap="$6">: 24dp between
|
|
732
|
+
// the buttons' 24dp layout slots, after the second frame's m=-7.
|
|
733
|
+
val pairGap =
|
|
734
|
+
orientation == HORIZONTAL && index > 0 && data.optString("name") == "DragOutline"
|
|
722
735
|
icon.layoutParams = LayoutParams(dp(38), dp(38)).apply {
|
|
723
736
|
gravity = Gravity.CENTER_VERTICAL
|
|
724
|
-
marginStart = -dp(7)
|
|
737
|
+
marginStart = if (pairGap) dp(24) - dp(7) else -dp(7)
|
|
725
738
|
marginEnd = -dp(7)
|
|
726
739
|
}
|
|
727
740
|
icon.background = StateListDrawable().apply {
|
|
@@ -895,6 +908,7 @@ internal class NativeListAccessoryStack(context: android.content.Context, val fo
|
|
|
895
908
|
if (style.has("offsetY"))
|
|
896
909
|
(view as? NativeListTextView)?.opticalOffsetY =
|
|
897
910
|
(style.optDouble("offsetY") * resources.displayMetrics.density).toFloat()
|
|
911
|
+
applyNativeListTextSpacing(view, style, view.fontFeatureSettings)
|
|
898
912
|
style.optString("alignment").takeIf(String::isNotEmpty)?.let {
|
|
899
913
|
view.gravity =
|
|
900
914
|
(view.gravity and Gravity.VERTICAL_GRAVITY_MASK) or
|
|
@@ -157,6 +157,26 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
157
157
|
private fun JSONArray?.hasAccessory(kind: String) =
|
|
158
158
|
this != null && (0 until length()).any { optJSONObject(it)?.optString("kind") == kind }
|
|
159
159
|
|
|
160
|
+
override fun bindContentUpdate(
|
|
161
|
+
previous: NativeListItem,
|
|
162
|
+
item: NativeListItem,
|
|
163
|
+
theme: JSONObject?,
|
|
164
|
+
): Boolean {
|
|
165
|
+
val segments = item.json.optJSONArray("subtitleSegments") ?: return false
|
|
166
|
+
if (semanticSubtitleLabels.isEmpty() || semanticSubtitleLabels.size != segments.length() ||
|
|
167
|
+
!canUpdateIdentitySubtitle(previous, item)
|
|
168
|
+
) return false
|
|
169
|
+
|
|
170
|
+
val style = item.json.optJSONObject("style")?.optJSONObject("subtitle")
|
|
171
|
+
semanticSubtitleLabels.forEachIndexed { index, label ->
|
|
172
|
+
bindIdentitySubtitleLabel(label, segments.getJSONObject(index), theme)
|
|
173
|
+
style?.let { applyStyledText(label, it) }
|
|
174
|
+
applySelectorTextTypography(label, style)
|
|
175
|
+
label.requestLayout()
|
|
176
|
+
}
|
|
177
|
+
return true
|
|
178
|
+
}
|
|
179
|
+
|
|
160
180
|
override fun bindContent(
|
|
161
181
|
item: NativeListItem,
|
|
162
182
|
theme: JSONObject?,
|
|
@@ -172,8 +192,9 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
172
192
|
setOnLongClickListener(
|
|
173
193
|
if (longPressActionKey.isNotEmpty())
|
|
174
194
|
OnLongClickListener {
|
|
195
|
+
val actionItem = currentItem ?: return@OnLongClickListener false
|
|
175
196
|
val point = longPressPoint
|
|
176
|
-
if (!isEnabled || !
|
|
197
|
+
if (!isEnabled || !actionItem.isRowPressEnabled || actionItem.key != item.key ||
|
|
177
198
|
bindingEpoch != boundEpoch ||
|
|
178
199
|
(longPressPointEpoch == boundEpoch && point == null)) false
|
|
179
200
|
else {
|
|
@@ -182,7 +203,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
182
203
|
getLocationInWindow(location)
|
|
183
204
|
PointF(location[0] + it.x, location[1] + it.y)
|
|
184
205
|
}
|
|
185
|
-
onAction?.invoke(
|
|
206
|
+
onAction?.invoke(actionItem, longPressActionKey, null,
|
|
186
207
|
NativeListActionOrigin(this, this, bindingEpoch, "row",
|
|
187
208
|
windowPointPixels = windowPoint))
|
|
188
209
|
longPressPoint = null
|
|
@@ -365,19 +386,21 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
365
386
|
)
|
|
366
387
|
return
|
|
367
388
|
fun visit(view: View) {
|
|
368
|
-
if (view is TextView)
|
|
369
|
-
view.fontFeatureSettings = "tnum"
|
|
370
|
-
if (sourceScale) {
|
|
371
|
-
paintDefaults.putIfAbsent(view, view.paintFlags)
|
|
372
|
-
// Explicit style fontSize/lineHeight are kept as the caller set them.
|
|
373
|
-
applyNativeListSourceTypography(view, explicitStyle(view))
|
|
374
|
-
}
|
|
375
|
-
}
|
|
389
|
+
if (view is TextView) applySelectorTextTypography(view, explicitStyle(view))
|
|
376
390
|
if (view is ViewGroup) for (i in 0 until view.childCount) visit(view.getChildAt(i))
|
|
377
391
|
}
|
|
378
392
|
visit(this)
|
|
379
393
|
}
|
|
380
394
|
|
|
395
|
+
private fun applySelectorTextTypography(view: TextView, style: JSONObject?) {
|
|
396
|
+
if (sourceScale) {
|
|
397
|
+
paintDefaults.putIfAbsent(view, view.paintFlags)
|
|
398
|
+
applyNativeListSourceTypography(view, style)
|
|
399
|
+
} else {
|
|
400
|
+
applyNativeListTextSpacing(view, style)
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
381
404
|
private fun addLeading(visual: JSONObject?, sizeDp: Int, spacingDp: Int = 12) {
|
|
382
405
|
// Legacy: a missing visual still reserves an empty, transparent leading slot.
|
|
383
406
|
val descriptor = visual ?: JSONObject().put("backgroundColor", "#00000000")
|
|
@@ -393,7 +416,13 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
393
416
|
}
|
|
394
417
|
leadingFrame.bitmapBorderWidth =
|
|
395
418
|
if (descriptor.optString("borderColor").isNotEmpty() &&
|
|
396
|
-
descriptor.optString("borderStyle") != "dashed")
|
|
419
|
+
descriptor.optString("borderStyle") != "dashed") {
|
|
420
|
+
// Optional borderWidth (logical units); a hairline still draws one physical pixel.
|
|
421
|
+
descriptor.optDouble("borderWidth", Double.NaN)
|
|
422
|
+
.takeIf { it.isFinite() && it > 0 && it <= 4 }
|
|
423
|
+
?.let { (it * resources.displayMetrics.density).roundToInt().coerceAtLeast(1) }
|
|
424
|
+
?: dp(1)
|
|
425
|
+
} else 0
|
|
397
426
|
if (visual == null) leadingFrame.recycle()
|
|
398
427
|
val item = currentItem!!
|
|
399
428
|
val style = item.json.optJSONObject("style")?.optJSONObject("image") ?: JSONObject()
|
|
@@ -722,11 +751,11 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
722
751
|
leadingActionIcon.setOnClickListener {
|
|
723
752
|
emitAction(item, action.optString("actionKey"), null, leadingActionIcon, "leadingAction")
|
|
724
753
|
}
|
|
725
|
-
// ListItem.IconButton is
|
|
726
|
-
//
|
|
727
|
-
//
|
|
728
|
-
setPadding(dp(
|
|
729
|
-
addView(leadingActionIcon, LayoutParams(dp(36), dp(36)).apply { marginEnd = dp(
|
|
754
|
+
// ListItem.IconButton is 38dp (6dp padding plus a 1dp border) with m=-7,
|
|
755
|
+
// so its glyph sits on a 24dp slot at the 12dp padding. This 36dp frame
|
|
756
|
+
// centers the same glyph with a 6dp inset and a 6dp following gap.
|
|
757
|
+
setPadding(dp(6), paddingTop, paddingRight, paddingBottom)
|
|
758
|
+
addView(leadingActionIcon, LayoutParams(dp(36), dp(36)).apply { marginEnd = dp(6) })
|
|
730
759
|
}
|
|
731
760
|
addLeading(
|
|
732
761
|
leading,
|
|
@@ -827,27 +856,11 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
827
856
|
}
|
|
828
857
|
val label =
|
|
829
858
|
NativeListTextView(context).apply {
|
|
830
|
-
text = segment.optString("text")
|
|
831
|
-
typeface = fonts.regular(context)
|
|
832
|
-
textSize = sp(14f)
|
|
833
859
|
includeFontPadding = false
|
|
834
860
|
maxLines = 1
|
|
835
861
|
ellipsize = TextUtils.TruncateAt.END
|
|
836
|
-
val toneKey =
|
|
837
|
-
when (segment.optString("tone")) {
|
|
838
|
-
"primary" -> "primaryText"
|
|
839
|
-
"disabled" -> "disabledText"
|
|
840
|
-
"caution" -> "caution"
|
|
841
|
-
"positive" -> "positive"
|
|
842
|
-
"negative" -> "negative"
|
|
843
|
-
else -> "secondaryText"
|
|
844
|
-
}
|
|
845
|
-
setTextColor(
|
|
846
|
-
color(theme, toneKey, if (toneKey == "caution") "#AB6400" else "#0000009B")
|
|
847
|
-
)
|
|
848
862
|
}
|
|
849
|
-
|
|
850
|
-
applyValueSegments(label, segment.optJSONArray("textSegments"), 14, 20, false)
|
|
863
|
+
bindIdentitySubtitleLabel(label, segment, theme)
|
|
851
864
|
semanticSubtitleLabels.add(label)
|
|
852
865
|
line.addView(label, LayoutParams(LayoutParams.WRAP_CONTENT, dp(20)))
|
|
853
866
|
}
|
|
@@ -921,6 +934,29 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
921
934
|
),
|
|
922
935
|
)
|
|
923
936
|
trailingColumn.endInset?.let { setPadding(paddingLeft, paddingTop, it, paddingBottom) }
|
|
937
|
+
// ListItem keeps 12dp between the text and a tertiary button's 24dp slot; the
|
|
938
|
+
// button's m=-7 would otherwise pull its slot over the text column.
|
|
939
|
+
val first = accessories.optJSONObject(0)
|
|
940
|
+
if (first?.optString("kind") == "drag" || first?.optString("buttonStyle") == "tertiary") {
|
|
941
|
+
(mainColumn.layoutParams as LayoutParams).marginEnd = dp(12)
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
private fun bindIdentitySubtitleLabel(label: TextView, segment: JSONObject, theme: JSONObject?) {
|
|
946
|
+
label.text = segment.optString("text")
|
|
947
|
+
label.typeface = fonts.regular(context)
|
|
948
|
+
label.textSize = sp(14f)
|
|
949
|
+
TextViewCompat.setLineHeight(label, dp(20))
|
|
950
|
+
val toneKey = when (segment.optString("tone")) {
|
|
951
|
+
"primary" -> "primaryText"
|
|
952
|
+
"disabled" -> "disabledText"
|
|
953
|
+
"caution" -> "caution"
|
|
954
|
+
"positive" -> "positive"
|
|
955
|
+
"negative" -> "negative"
|
|
956
|
+
else -> "secondaryText"
|
|
957
|
+
}
|
|
958
|
+
label.setTextColor(color(theme, toneKey, if (toneKey == "caution") "#AB6400" else "#0000009B"))
|
|
959
|
+
applyValueSegments(label, segment.optJSONArray("textSegments"), 14, 20, false)
|
|
924
960
|
}
|
|
925
961
|
|
|
926
962
|
private fun applyValueSegments(
|
|
@@ -1021,6 +1057,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
1021
1057
|
if (style.has("offsetY"))
|
|
1022
1058
|
(view as? NativeListTextView)?.opticalOffsetY =
|
|
1023
1059
|
(style.optDouble("offsetY") * resources.displayMetrics.density).toFloat()
|
|
1060
|
+
applyNativeListTextSpacing(view, style)
|
|
1024
1061
|
style.optString("alignment").takeIf(String::isNotEmpty)?.let {
|
|
1025
1062
|
view.gravity =
|
|
1026
1063
|
(view.gravity and Gravity.VERTICAL_GRAVITY_MASK) or
|
|
@@ -401,10 +401,10 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
401
401
|
defaultAlignment: String,
|
|
402
402
|
) {
|
|
403
403
|
view.includeFontPadding = false
|
|
404
|
-
view.fontFeatureSettings = "tnum"
|
|
405
404
|
view.textSize =
|
|
406
405
|
sp(style?.optDouble("fontSize", defaultSize.toDouble())?.toFloat() ?: defaultSize)
|
|
407
406
|
view.typeface = marketTypeface(style?.optString("fontWeight").orEmpty(), defaultWeight)
|
|
407
|
+
applyNativeListTextSpacing(view, style)
|
|
408
408
|
view.setTextColor(safeColor(style?.optString("color"), defaultColor))
|
|
409
409
|
val alignment = style?.optString("alignment", defaultAlignment) ?: defaultAlignment
|
|
410
410
|
view.gravity =
|
|
@@ -437,6 +437,7 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
437
437
|
kotlin.math.ceil(sourceSize.toDouble()).toFloat(),
|
|
438
438
|
)
|
|
439
439
|
}
|
|
440
|
+
applyNativeListTextSpacing(view, style)
|
|
440
441
|
// Legacy parity: keep marketText's subscript AbsoluteSizeSpan (ceil(0.6 x fontSize)).
|
|
441
442
|
val text = SpannableStringBuilder(view.text)
|
|
442
443
|
text.getSpans(0, text.length, NativeListLineHeightSpan::class.java).forEach(text::removeSpan)
|
|
@@ -703,8 +704,8 @@ internal class NativeListMarketRowView(context: ThemedReactContext, fonts: Nativ
|
|
|
703
704
|
}
|
|
704
705
|
badgeLabel.text = text
|
|
705
706
|
// OneKey patch: match SizableText's tabular numerals only for explicit Market metrics.
|
|
706
|
-
badgeLabel.fontFeatureSettings = if (badgeStyle != null) "tnum" else null
|
|
707
707
|
badgeLabel.textSize = sp(badgeStyle?.optDouble("fontSize", 11.0)?.toFloat() ?: 11f)
|
|
708
|
+
applyNativeListTextSpacing(badgeLabel, badgeStyle, if (badgeStyle != null) "tnum" else null)
|
|
708
709
|
badgeLabel.typeface =
|
|
709
710
|
marketTypeface(badgeStyle?.optString("fontWeight").orEmpty(), "medium")
|
|
710
711
|
if (badgeStyle?.has("lineHeight") == true) {
|
|
@@ -197,7 +197,8 @@ internal fun nativeListIdentityTrailingIsHorizontal(
|
|
|
197
197
|
first.actionKey.isEmpty()) ||
|
|
198
198
|
(kinds == listOf("icon", "icon") &&
|
|
199
199
|
first.name == "PencilOutline" &&
|
|
200
|
-
second.name == "DragOutline")
|
|
200
|
+
second.name == "DragOutline") ||
|
|
201
|
+
(kinds == listOf("icon", "drag") && first.name == "PencilOutline")
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
internal fun resolveNativeListSelectorBackgroundColor(
|
|
@@ -330,6 +331,8 @@ internal data class NativeListConfig(
|
|
|
330
331
|
val rowPressToggles: Boolean,
|
|
331
332
|
val selectedKeys: LinkedHashSet<String>,
|
|
332
333
|
val reorderable: Boolean,
|
|
334
|
+
/** `handle` starts a reorder only from a long press on a trailing `drag` accessory. */
|
|
335
|
+
val reorderFromHandleOnly: Boolean = false,
|
|
333
336
|
val pullToRefresh: Boolean,
|
|
334
337
|
val refreshTriggerDistance: Double? = null,
|
|
335
338
|
val refreshing: Boolean,
|
|
@@ -377,6 +380,9 @@ internal data class NativeListConfig(
|
|
|
377
380
|
val layout = root.getJSONObject("layout")
|
|
378
381
|
val selection = root.optJSONObject("selection")
|
|
379
382
|
val capabilities = root.optJSONObject("capabilities")
|
|
383
|
+
val reorderActivation = capabilities?.opt("reorderActivation")
|
|
384
|
+
require(reorderActivation == null || reorderActivation == "row" ||
|
|
385
|
+
reorderActivation == "handle") { "Invalid reorderActivation" }
|
|
380
386
|
val sectionIndex = capabilities?.optJSONObject("sectionIndex")
|
|
381
387
|
val rowArray = root.getJSONArray("rows")
|
|
382
388
|
val items = ArrayList<NativeListItem>(rowArray.length())
|
|
@@ -410,6 +416,7 @@ internal data class NativeListConfig(
|
|
|
410
416
|
rowPressToggles = selection?.optBoolean("rowPressToggles", false) ?: false,
|
|
411
417
|
selectedKeys = selectedKeys,
|
|
412
418
|
reorderable = capabilities?.optBoolean("reorderable", false) ?: false,
|
|
419
|
+
reorderFromHandleOnly = reorderActivation == "handle",
|
|
413
420
|
pullToRefresh = capabilities?.optBoolean("pullToRefresh", false) ?: false,
|
|
414
421
|
refreshTriggerDistance = capabilities?.optDouble("refreshTriggerDistance")?.takeIf { it.isFinite() && it > 0 },
|
|
415
422
|
refreshing = capabilities?.optBoolean("refreshing", false) ?: false,
|
|
@@ -28,6 +28,12 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
|
|
|
28
28
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
+
protected open fun bindContentUpdate(
|
|
32
|
+
previous: NativeListItem,
|
|
33
|
+
item: NativeListItem,
|
|
34
|
+
theme: JSONObject?,
|
|
35
|
+
): Boolean = false
|
|
36
|
+
|
|
31
37
|
protected open fun bindSelectionContent(
|
|
32
38
|
item: NativeListItem,
|
|
33
39
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
|
|
@@ -50,7 +56,8 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
|
|
|
50
56
|
}
|
|
51
57
|
|
|
52
58
|
protected fun retainBoundItem(item: NativeListItem): Boolean {
|
|
53
|
-
if (
|
|
59
|
+
if (renderedItem?.key != item.key) return false
|
|
60
|
+
renderedItem = item
|
|
54
61
|
current = item
|
|
55
62
|
tag = item
|
|
56
63
|
return true
|
|
@@ -106,6 +113,8 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
|
|
|
106
113
|
protected open val pressedColorName = "rowPressedBackground"
|
|
107
114
|
protected open val pressedColorFallback = "#00000017"
|
|
108
115
|
private var current: NativeListItem? = null
|
|
116
|
+
// Selection can advance current before RecyclerView binds the new content.
|
|
117
|
+
private var renderedItem: NativeListItem? = null
|
|
109
118
|
protected val boundItem: NativeListItem?
|
|
110
119
|
get() = current
|
|
111
120
|
private var theme: JSONObject? = null
|
|
@@ -189,7 +198,8 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
|
|
|
189
198
|
val iconUpdate = NativeListIconUpdate(this)
|
|
190
199
|
try {
|
|
191
200
|
|
|
192
|
-
val
|
|
201
|
+
val previous = renderedItem
|
|
202
|
+
val update = update(previous, item)
|
|
193
203
|
val signature =
|
|
194
204
|
nativeListCanonical(
|
|
195
205
|
JSONObject()
|
|
@@ -201,8 +211,13 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
|
|
|
201
211
|
.put("listStyle", listStyle)
|
|
202
212
|
)
|
|
203
213
|
sourceScale = usesSourceScale(item, useSourceScale)
|
|
204
|
-
|
|
205
|
-
|
|
214
|
+
val signatureChanged = signature != inputSignature
|
|
215
|
+
val updatedContentInPlace = update == NativeListRendererUpdate.CONTENT &&
|
|
216
|
+
!signatureChanged && previous != null && bindContentUpdate(previous, item, theme)
|
|
217
|
+
if (!updatedContentInPlace &&
|
|
218
|
+
(update != NativeListRendererUpdate.UNCHANGED || signatureChanged)
|
|
219
|
+
) {
|
|
220
|
+
if (previous != null) onBindingInvalidated?.invoke(this, bindingEpoch)
|
|
206
221
|
bindingEpoch++
|
|
207
222
|
if (update == NativeListRendererUpdate.REPLACE) {
|
|
208
223
|
recycleContent()
|
|
@@ -211,6 +226,7 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
|
|
|
211
226
|
bindContent(item, theme, layout, checkboxState)
|
|
212
227
|
inputSignature = signature
|
|
213
228
|
}
|
|
229
|
+
renderedItem = item
|
|
214
230
|
current = item
|
|
215
231
|
tag = item
|
|
216
232
|
this.theme = theme
|
|
@@ -409,6 +425,7 @@ internal abstract class NativeListRendererRowView(protected val reactContext: Th
|
|
|
409
425
|
if (current != null) onBindingInvalidated?.invoke(this, bindingEpoch)
|
|
410
426
|
bindingEpoch++
|
|
411
427
|
current = null
|
|
428
|
+
renderedItem = null
|
|
412
429
|
tag = null
|
|
413
430
|
inputSignature = ""
|
|
414
431
|
touchPressed = false
|
|
@@ -42,6 +42,7 @@ internal data class NativeListResolvedText(
|
|
|
42
42
|
val clip: Boolean,
|
|
43
43
|
val gravity: Int,
|
|
44
44
|
val offset: Float,
|
|
45
|
+
private val style: JSONObject?,
|
|
45
46
|
) {
|
|
46
47
|
/** Offset into [text] for a UTF-16 offset into the [source] it was resolved from. */
|
|
47
48
|
fun displayOffset(sourceOffset: Long, source: String): Int =
|
|
@@ -49,11 +50,10 @@ internal data class NativeListResolvedText(
|
|
|
49
50
|
|
|
50
51
|
fun bind(view: NativeListTextView) {
|
|
51
52
|
view.includeFontPadding = false
|
|
52
|
-
view.fontFeatureSettings = "tnum"
|
|
53
53
|
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
|
|
54
54
|
view.typeface = typeface
|
|
55
55
|
view.setTextColor(color)
|
|
56
|
-
view
|
|
56
|
+
applyNativeListTextSpacing(view, style)
|
|
57
57
|
view.gravity = gravity
|
|
58
58
|
view.opticalOffsetY = offset
|
|
59
59
|
view.maxLines = if (lines == 0) Int.MAX_VALUE else lines
|
|
@@ -137,11 +137,32 @@ internal data class NativeListResolvedText(
|
|
|
137
137
|
style?.optString("truncate") == "clip",
|
|
138
138
|
horizontal or vertical,
|
|
139
139
|
((style?.optDouble("offsetY", 0.0) ?: 0.0) * density).toFloat(),
|
|
140
|
+
style,
|
|
140
141
|
)
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
|
|
146
|
+
/** Apply tracking after the final font size, then rebuild font features for this binding. */
|
|
147
|
+
internal fun applyNativeListTextSpacing(
|
|
148
|
+
view: TextView,
|
|
149
|
+
style: JSONObject?,
|
|
150
|
+
defaultFeatures: String? = "tnum",
|
|
151
|
+
defaultLetterSpacing: Float = 0f,
|
|
152
|
+
) {
|
|
153
|
+
val tracking = style?.optDouble("letterSpacing")?.takeIf { it.isFinite() }
|
|
154
|
+
val digitFeatures = when {
|
|
155
|
+
style?.has("tabularNumbers") != true -> defaultFeatures
|
|
156
|
+
style.optBoolean("tabularNumbers") -> "tnum"
|
|
157
|
+
else -> "'tnum' 0, 'pnum' 1"
|
|
158
|
+
}
|
|
159
|
+
view.fontFeatureSettings = if (tracking == null) digitFeatures else
|
|
160
|
+
listOfNotNull(digitFeatures, "'kern' 0").joinToString(", ")
|
|
161
|
+
view.letterSpacing = if (tracking != null && view.textSize > 0f)
|
|
162
|
+
(tracking * view.resources.displayMetrics.density / view.textSize).toFloat()
|
|
163
|
+
else defaultLetterSpacing
|
|
164
|
+
}
|
|
165
|
+
|
|
145
166
|
/**
|
|
146
167
|
* Legacy selector source-scale typography (accountSelector / networkSelector /
|
|
147
168
|
* walletSidebar with source scaling): whole-pixel unscaled font size, unhinted
|
|
@@ -158,7 +179,7 @@ internal fun applyNativeListSourceTypography(view: TextView, style: JSONObject?)
|
|
|
158
179
|
TypedValue.COMPLEX_UNIT_PX,
|
|
159
180
|
kotlin.math.ceil((view.textSize * metrics.density / metrics.scaledDensity).toDouble()).toFloat(),
|
|
160
181
|
)
|
|
161
|
-
view
|
|
182
|
+
applyNativeListTextSpacing(view, style)
|
|
162
183
|
if (style?.has("lineHeight") != true && view.text.isNotEmpty()) {
|
|
163
184
|
val text = SpannableStringBuilder(view.text)
|
|
164
185
|
text.getSpans(0, text.length, NativeListLineHeightSpan::class.java).forEach(text::removeSpan)
|
|
@@ -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
|
}
|