@onekeyfe/react-native-native-list 6.7.0-2 → 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/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1953 -117
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
- package/docs/ROW_TEMPLATES.md +70 -11
- package/docs/SPEC.md +1235 -20
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +235 -39
- package/ios/NativeListActivityDetailsView.swift +30 -11
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +155 -27
- package/ios/NativeListDesignAssets.swift +9 -0
- package/ios/NativeListIdentityRenderer.swift +239 -31
- package/ios/NativeListLeadingVisual.swift +119 -22
- package/ios/NativeListMarketRenderer.swift +113 -18
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListModels.swift +42 -2
- package/ios/NativeListRendererRegistry.swift +1 -0
- package/ios/NativeListResolvedText.swift +2 -1
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +88 -0
- package/ios/RNCNativeListView.swift +1052 -58
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
- package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2789 -3
- package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
- package/lib/module/NativeList.js +223 -36
- package/lib/module/NativeList.web.js +260 -33
- package/lib/module/index.js +1 -1
- package/lib/module/models.js +3 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +1386 -81
- package/lib/module/web/NativeListWebEngine.js +914 -80
- package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
- package/lib/module/web/templates/DataRowRenderer.js +40 -5
- package/lib/module/web/templates/IdentityRowRenderer.js +145 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- package/lib/module/web/templates/MessageRowRenderer.js +18 -2
- package/lib/module/web/templates/RowContainerStyle.js +1 -0
- package/lib/module/web/templates/RowRendererRegistry.js +8 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/lib/typescript/src/NativeList.d.ts +3 -3
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
- package/lib/typescript/src/NativeList.types.d.ts +29 -1
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +196 -17
- package/lib/typescript/src/validation.d.ts +20 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/package.json +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +418 -89
- package/src/NativeList.types.ts +34 -1
- package/src/NativeList.web.tsx +417 -66
- package/src/index.ts +2 -0
- package/src/models.ts +355 -143
- package/src/selection.ts +1 -0
- package/src/validation.ts +3315 -166
- package/src/web/NativeListWebEngine.ts +1473 -113
- package/src/web/templates/ActivityRowRenderer.ts +732 -8
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +217 -6
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +21 -6
- package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.margelo.nitro.nativelist
|
|
2
2
|
|
|
3
|
+
import android.graphics.PointF
|
|
3
4
|
import android.graphics.drawable.GradientDrawable
|
|
4
5
|
import android.text.Spannable
|
|
5
6
|
import android.text.SpannableStringBuilder
|
|
@@ -8,6 +9,7 @@ import android.text.style.AbsoluteSizeSpan
|
|
|
8
9
|
import android.text.style.ForegroundColorSpan
|
|
9
10
|
import android.util.TypedValue
|
|
10
11
|
import android.view.Gravity
|
|
12
|
+
import android.view.MotionEvent
|
|
11
13
|
import android.view.View
|
|
12
14
|
import android.view.ViewGroup
|
|
13
15
|
import android.widget.LinearLayout
|
|
@@ -28,17 +30,42 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
28
30
|
private val mainColumn = LinearLayout(context)
|
|
29
31
|
private val titleLine = PackedTitleLineLayout(context)
|
|
30
32
|
private val title = NativeListTextView(context)
|
|
33
|
+
private val titleIcon = OneKeyIconView(context)
|
|
34
|
+
private var titleImage: NativeListImageSlot? = null
|
|
31
35
|
private val subtitle = NativeListTextView(context)
|
|
32
36
|
private val tertiary = NativeListTextView(context)
|
|
33
37
|
private val badgeLine = NativeListTextView(context)
|
|
38
|
+
private val titleSuffixLabels = mutableListOf<NativeListTextView>()
|
|
39
|
+
private val titleSuffixMaxWidths = mutableListOf<Int>()
|
|
34
40
|
private val trailingColumn = NativeListAccessoryStack(context, fonts)
|
|
35
41
|
private val semanticBadgeLabels = mutableListOf<TextView>()
|
|
36
42
|
private val semanticSubtitleLabels = mutableListOf<TextView>()
|
|
37
43
|
private var walletBadgeLine: View? = null
|
|
38
44
|
private var currentItem: NativeListItem? = null
|
|
39
45
|
private var currentTheme: JSONObject? = null
|
|
46
|
+
private var longPressPoint: PointF? = null
|
|
47
|
+
private var longPressPointEpoch = -1L
|
|
40
48
|
private val paintDefaults = mutableMapOf<TextView, Int>()
|
|
41
49
|
|
|
50
|
+
override fun onRowTouch(event: MotionEvent) {
|
|
51
|
+
when (event.actionMasked) {
|
|
52
|
+
MotionEvent.ACTION_DOWN -> {
|
|
53
|
+
longPressPoint = if (currentItem?.isRowPressEnabled == true) PointF(event.x, event.y) else null
|
|
54
|
+
longPressPointEpoch = bindingEpoch
|
|
55
|
+
}
|
|
56
|
+
MotionEvent.ACTION_MOVE -> {
|
|
57
|
+
if (longPressPointEpoch == bindingEpoch && longPressPoint != null &&
|
|
58
|
+
event.x >= 0 && event.y >= 0 && event.x < width && event.y < height
|
|
59
|
+
) longPressPoint?.set(event.x, event.y)
|
|
60
|
+
else longPressPoint = null
|
|
61
|
+
}
|
|
62
|
+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
|
63
|
+
longPressPoint = null
|
|
64
|
+
longPressPointEpoch = -1L
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
42
69
|
override fun backgroundGroupPosition(
|
|
43
70
|
item: NativeListItem,
|
|
44
71
|
layout: String,
|
|
@@ -53,7 +80,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
53
80
|
"single"
|
|
54
81
|
else item.json.optString("groupPosition")
|
|
55
82
|
|
|
56
|
-
override val assetFields = listOf("leading")
|
|
83
|
+
override val assetFields = listOf("leading", "titleImage")
|
|
57
84
|
|
|
58
85
|
override fun usesSourceScale(item: NativeListItem, provided: Boolean) =
|
|
59
86
|
item.usesSelectorSourceScale || provided
|
|
@@ -83,6 +110,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
83
110
|
titleLine.orientation = HORIZONTAL
|
|
84
111
|
titleLine.gravity = Gravity.CENTER_VERTICAL
|
|
85
112
|
titleLine.addView(title, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
|
|
113
|
+
titleLine.addView(titleIcon, LayoutParams(dp(20), dp(20)).apply { marginStart = dp(4) })
|
|
86
114
|
titleLine.addView(badgeLine)
|
|
87
115
|
trailingColumn.onAction = { key, view, slot, target ->
|
|
88
116
|
emitAction(key, view, "trailingAccessory", slot, target, trailingColumn.anchorInset(view))
|
|
@@ -111,7 +139,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
111
139
|
|
|
112
140
|
private fun showText(view: TextView, text: String, lines: Int) {
|
|
113
141
|
view.text = text
|
|
114
|
-
view.maxLines = lines
|
|
142
|
+
view.maxLines = if (lines == 0) Int.MAX_VALUE else lines
|
|
115
143
|
view.visibility = if (text.isEmpty()) GONE else VISIBLE
|
|
116
144
|
}
|
|
117
145
|
|
|
@@ -135,10 +163,42 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
135
163
|
layout: String,
|
|
136
164
|
checkboxState: (NativeListItem, NativeSelectionTarget?, String) -> String,
|
|
137
165
|
) {
|
|
166
|
+
cancelLongPress()
|
|
167
|
+
longPressPoint = null
|
|
168
|
+
longPressPointEpoch = -1L
|
|
138
169
|
currentItem = item
|
|
170
|
+
val longPressActionKey = item.json.optString("longPressActionKey")
|
|
171
|
+
val boundEpoch = bindingEpoch
|
|
172
|
+
setOnLongClickListener(
|
|
173
|
+
if (longPressActionKey.isNotEmpty())
|
|
174
|
+
OnLongClickListener {
|
|
175
|
+
val point = longPressPoint
|
|
176
|
+
if (!isEnabled || !item.isRowPressEnabled || currentItem?.key != item.key ||
|
|
177
|
+
bindingEpoch != boundEpoch ||
|
|
178
|
+
(longPressPointEpoch == boundEpoch && point == null)) false
|
|
179
|
+
else {
|
|
180
|
+
val windowPoint = point?.takeIf { longPressPointEpoch == boundEpoch }?.let {
|
|
181
|
+
val location = IntArray(2)
|
|
182
|
+
getLocationInWindow(location)
|
|
183
|
+
PointF(location[0] + it.x, location[1] + it.y)
|
|
184
|
+
}
|
|
185
|
+
onAction?.invoke(item, longPressActionKey, null,
|
|
186
|
+
NativeListActionOrigin(this, this, bindingEpoch, "row",
|
|
187
|
+
windowPointPixels = windowPoint))
|
|
188
|
+
longPressPoint = null
|
|
189
|
+
longPressPointEpoch = -1L
|
|
190
|
+
true
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else null
|
|
194
|
+
)
|
|
195
|
+
isLongClickable = longPressActionKey.isNotEmpty()
|
|
139
196
|
currentTheme = theme
|
|
140
197
|
removeAllViews()
|
|
141
198
|
mainColumn.removeAllViews()
|
|
199
|
+
titleSuffixLabels.forEach(titleLine::removeView)
|
|
200
|
+
titleSuffixLabels.clear()
|
|
201
|
+
titleSuffixMaxWidths.clear()
|
|
142
202
|
semanticBadgeLabels.clear()
|
|
143
203
|
semanticSubtitleLabels.clear()
|
|
144
204
|
walletBadgeLine = null
|
|
@@ -157,8 +217,12 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
157
217
|
mainColumn.gravity = Gravity.CENTER_VERTICAL
|
|
158
218
|
titleLine.gravity = Gravity.CENTER_VERTICAL
|
|
159
219
|
titleLine.packsChildrenAtStart = false
|
|
220
|
+
titleLine.leadingTextMaxWidth = Int.MAX_VALUE
|
|
160
221
|
titleLine.layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
|
161
222
|
title.layoutParams = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f)
|
|
223
|
+
titleIcon.visibility = GONE
|
|
224
|
+
titleIcon.contentDescription = null
|
|
225
|
+
titleIcon.setOnClickListener(null)
|
|
162
226
|
for (view in listOf(title, subtitle, tertiary, badgeLine)) {
|
|
163
227
|
view.text = ""
|
|
164
228
|
view.visibility = GONE
|
|
@@ -199,6 +263,29 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
199
263
|
leadingActionIcon.useSourceScale = sourceScale
|
|
200
264
|
leadingActionIcon.setOnClickListener(null)
|
|
201
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
|
+
}
|
|
202
289
|
TextViewCompat.setLineHeight(
|
|
203
290
|
title,
|
|
204
291
|
dp(if (item.json.optString("presentation") == "walletSidebar") 16 else 24),
|
|
@@ -294,6 +381,19 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
294
381
|
private fun addLeading(visual: JSONObject?, sizeDp: Int, spacingDp: Int = 12) {
|
|
295
382
|
// Legacy: a missing visual still reserves an empty, transparent leading slot.
|
|
296
383
|
val descriptor = visual ?: JSONObject().put("backgroundColor", "#00000000")
|
|
384
|
+
val overlays = descriptor.optJSONArray("overlays")
|
|
385
|
+
if (overlays != null && (0 until minOf(2, overlays.length())).any { index ->
|
|
386
|
+
val overlay = overlays.optJSONObject(index) ?: return@any false
|
|
387
|
+
overlay.optInt("offsetX", overlay.optInt("offset", 2)) > 0 ||
|
|
388
|
+
overlay.optInt("offsetY", overlay.optInt("offset", 2)) > 0
|
|
389
|
+
}) {
|
|
390
|
+
// The badge extends beyond the avatar and the row's padded content box.
|
|
391
|
+
clipChildren = false
|
|
392
|
+
clipToPadding = false
|
|
393
|
+
}
|
|
394
|
+
leadingFrame.bitmapBorderWidth =
|
|
395
|
+
if (descriptor.optString("borderColor").isNotEmpty() &&
|
|
396
|
+
descriptor.optString("borderStyle") != "dashed") dp(1) else 0
|
|
297
397
|
if (visual == null) leadingFrame.recycle()
|
|
298
398
|
val item = currentItem!!
|
|
299
399
|
val style = item.json.optJSONObject("style")?.optJSONObject("image") ?: JSONObject()
|
|
@@ -310,6 +410,16 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
310
410
|
if (item.json.optString("presentation") == "accountSelector" && item.hasExplicitHeight) 8
|
|
311
411
|
else 10
|
|
312
412
|
leadingFrame.bind(descriptor, style, item.key, currentTheme, false, sourceScale)
|
|
413
|
+
// The leading badges (overlay, cornerIcon, token network image) hang past the
|
|
414
|
+
// leading frame, and Android clips a child to its own bounds while its parent
|
|
415
|
+
// clips children: with the row's default clipping the account selector's
|
|
416
|
+
// bottom-right network badge was cut flat on Android only (OK-65694); iOS and
|
|
417
|
+
// Web let it overflow. Stop clipping the row, as the Market and Message
|
|
418
|
+
// renderers do for their network badges.
|
|
419
|
+
if (leadingFrame.requestsUnclippedHost) {
|
|
420
|
+
clipChildren = false
|
|
421
|
+
clipToPadding = false
|
|
422
|
+
}
|
|
313
423
|
leadingFallback.typeface = fonts.bold(context)
|
|
314
424
|
leadingFallback.textSize = sp(13f)
|
|
315
425
|
leadingFallback.setLineSpacing(0f, 1f)
|
|
@@ -356,7 +466,61 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
356
466
|
}
|
|
357
467
|
|
|
358
468
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
|
469
|
+
val ratio = currentItem?.json?.optJSONObject("style")
|
|
470
|
+
?.optDouble("leadingContentMaxWidthRatio", Double.NaN) ?: Double.NaN
|
|
471
|
+
titleLine.leadingTextMaxWidth =
|
|
472
|
+
if (ratio.isFinite() && ratio > 0.0 && ratio <= 1.0 && leadingFrame.parent === this) {
|
|
473
|
+
val inner = (MeasureSpec.getSize(widthMeasureSpec) - paddingLeft - paddingRight)
|
|
474
|
+
.coerceAtLeast(0)
|
|
475
|
+
val leading = leadingFrame.layoutParams as LayoutParams
|
|
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
|
|
480
|
+
(inner * ratio).roundToInt()
|
|
481
|
+
.minus(leading.width + leading.marginEnd + icon)
|
|
482
|
+
.coerceAtLeast(0)
|
|
483
|
+
} else Int.MAX_VALUE
|
|
484
|
+
titleSuffixLabels.forEachIndexed { index, label ->
|
|
485
|
+
label.maxWidth = titleSuffixMaxWidths[index]
|
|
486
|
+
}
|
|
359
487
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
|
488
|
+
if (titleSuffixLabels.isNotEmpty()) {
|
|
489
|
+
val fixedWidth =
|
|
490
|
+
(1 until titleLine.childCount).sumOf { index ->
|
|
491
|
+
val view = titleLine.getChildAt(index)
|
|
492
|
+
if (view.visibility == GONE || titleSuffixLabels.any { it === view }) 0
|
|
493
|
+
else {
|
|
494
|
+
val margins = view.layoutParams as MarginLayoutParams
|
|
495
|
+
view.measuredWidth + margins.leftMargin + margins.rightMargin
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
val suffixMargins = titleSuffixLabels.sumOf {
|
|
499
|
+
val margins = it.layoutParams as MarginLayoutParams
|
|
500
|
+
margins.leftMargin + margins.rightMargin
|
|
501
|
+
}
|
|
502
|
+
val available =
|
|
503
|
+
(titleLine.measuredWidth - fixedWidth - suffixMargins - dp(80)).coerceAtLeast(0)
|
|
504
|
+
val desired = titleSuffixLabels.mapIndexed { index, label ->
|
|
505
|
+
label.paint.measureText(label.text.toString()).roundToInt()
|
|
506
|
+
.coerceAtMost(titleSuffixMaxWidths[index])
|
|
507
|
+
}
|
|
508
|
+
val total = desired.sum()
|
|
509
|
+
var remaining = available
|
|
510
|
+
var changed = false
|
|
511
|
+
titleSuffixLabels.forEachIndexed { index, label ->
|
|
512
|
+
val share =
|
|
513
|
+
if (total <= available) desired[index]
|
|
514
|
+
else if (index == titleSuffixLabels.lastIndex) remaining
|
|
515
|
+
else (desired[index].toLong() * available / total).toInt()
|
|
516
|
+
remaining -= share
|
|
517
|
+
if (label.maxWidth != share) {
|
|
518
|
+
label.maxWidth = share
|
|
519
|
+
changed = true
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
if (changed) super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
|
523
|
+
}
|
|
360
524
|
val item = currentItem ?: return
|
|
361
525
|
if (
|
|
362
526
|
item.hasExplicitHeight &&
|
|
@@ -414,7 +578,13 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
414
578
|
}
|
|
415
579
|
|
|
416
580
|
override fun recycleContent() {
|
|
581
|
+
cancelLongPress()
|
|
582
|
+
longPressPoint = null
|
|
583
|
+
longPressPointEpoch = -1L
|
|
417
584
|
leadingFrame.recycle()
|
|
585
|
+
titleImage?.recycle()
|
|
586
|
+
titleImage?.view?.visibility = GONE
|
|
587
|
+
titleImage?.view?.contentDescription = null
|
|
418
588
|
trailingColumn.reset()
|
|
419
589
|
currentItem = null
|
|
420
590
|
}
|
|
@@ -422,6 +592,7 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
422
592
|
override fun disposeContent() {
|
|
423
593
|
recycleContent()
|
|
424
594
|
leadingFrame.dispose()
|
|
595
|
+
titleImage?.dispose()
|
|
425
596
|
}
|
|
426
597
|
|
|
427
598
|
private fun bindIdentity(
|
|
@@ -582,6 +753,48 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
582
753
|
titleLine.packsChildrenAtStart = true
|
|
583
754
|
title.ellipsize = TextUtils.TruncateAt.END
|
|
584
755
|
showText(title, item.json.optString("title"), item.json.optInt("titleLines", 1))
|
|
756
|
+
item.json.optJSONArray("titleSuffixes")?.let { suffixes ->
|
|
757
|
+
for (index in 0 until suffixes.length()) {
|
|
758
|
+
val suffix = suffixes.optJSONObject(index) ?: continue
|
|
759
|
+
val label = NativeListTextView(context).apply {
|
|
760
|
+
text = suffix.optString("text")
|
|
761
|
+
typeface = fonts.regular(context)
|
|
762
|
+
textSize = sp(12f)
|
|
763
|
+
includeFontPadding = false
|
|
764
|
+
maxLines = 1
|
|
765
|
+
ellipsize = TextUtils.TruncateAt.END
|
|
766
|
+
setTextColor(
|
|
767
|
+
color(
|
|
768
|
+
theme,
|
|
769
|
+
if (suffix.optString("tone") == "disabled") "disabledText" else "secondaryText",
|
|
770
|
+
"#0000009B",
|
|
771
|
+
)
|
|
772
|
+
)
|
|
773
|
+
}
|
|
774
|
+
TextViewCompat.setLineHeight(label, dp(16))
|
|
775
|
+
val maxWidth =
|
|
776
|
+
if (suffix.has("maxWidth")) stylePx(suffix.optDouble("maxWidth")) else Int.MAX_VALUE
|
|
777
|
+
label.maxWidth = maxWidth
|
|
778
|
+
titleSuffixMaxWidths.add(maxWidth)
|
|
779
|
+
titleSuffixLabels.add(label)
|
|
780
|
+
titleLine.addView(
|
|
781
|
+
label,
|
|
782
|
+
titleLine.childCount - 1,
|
|
783
|
+
LayoutParams(LayoutParams.WRAP_CONTENT, dp(16)).apply { marginStart = dp(8) },
|
|
784
|
+
)
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
item.json.optJSONObject("titleIcon")?.let { icon ->
|
|
788
|
+
titleIcon.iconName = icon.optString("name")
|
|
789
|
+
titleIcon.glyphSizeDp = 20
|
|
790
|
+
titleIcon.useSourceScale = sourceScale
|
|
791
|
+
titleIcon.tintColor = safeColor(
|
|
792
|
+
icon.optString("tintColor").takeIf(String::isNotEmpty),
|
|
793
|
+
color(theme, "iconSubdued", "#00000072"),
|
|
794
|
+
)
|
|
795
|
+
titleIcon.contentDescription = icon.optString("accessibilityLabel").takeIf(String::isNotEmpty)
|
|
796
|
+
titleIcon.visibility = VISIBLE
|
|
797
|
+
}
|
|
585
798
|
if (item.json.optString("presentation") == "accountSelector") {
|
|
586
799
|
title.typeface = fonts.regular(context)
|
|
587
800
|
}
|
|
@@ -696,15 +909,16 @@ internal class NativeListIdentityRowView(context: ThemedReactContext, fonts: Nat
|
|
|
696
909
|
sourceScale,
|
|
697
910
|
checkboxState,
|
|
698
911
|
horizontal =
|
|
699
|
-
(
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
912
|
+
nativeListIdentityTrailingIsHorizontal(
|
|
913
|
+
(0 until accessories.length()).map { index ->
|
|
914
|
+
val accessory = accessories.getJSONObject(index)
|
|
915
|
+
NativeListTrailingDescriptor(
|
|
916
|
+
kind = accessory.optString("kind"),
|
|
917
|
+
name = accessory.optString("name"),
|
|
918
|
+
actionKey = accessory.optString("actionKey"),
|
|
919
|
+
)
|
|
920
|
+
}
|
|
921
|
+
),
|
|
708
922
|
)
|
|
709
923
|
trailingColumn.endInset?.let { setPadding(paddingLeft, paddingTop, it, paddingBottom) }
|
|
710
924
|
}
|