@onekeyfe/react-native-native-list 3.0.158 → 3.0.160
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/README.md +21 -5
- package/android/build.gradle +7 -0
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +20 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +711 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListActionRenderer.kt +169 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +179 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +264 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +20 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +53 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +487 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListEndAlignment.kt +5 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +820 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListImageSlot.kt +147 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +453 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +997 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaPreviewSlot.kt +268 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMediaTileRenderer.kt +243 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +232 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListMetricCardRenderer.kt +551 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +27 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +475 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRailRenderer.kt +143 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +42 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +415 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +163 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRowHost.kt +70 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListScrollPositionTracker.kt +59 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +763 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListSystemRenderer.kt +464 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +432 -124
- package/android/src/main/java/com/onekey/nativelist/NativeListWalletGroupRenderer.kt +407 -0
- package/android/src/main/res/values/native_scroll_coordinator_ids.xml +5 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListEndAlignmentTest.kt +34 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListScrollPositionTrackerTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListSelectorBackgroundColorTest.kt +34 -0
- package/docs/DESIGN.md +520 -9
- package/docs/MIGRATION_BASELINE.md +117 -0
- package/docs/ROW_TEMPLATES.md +404 -0
- package/docs/SPEC.md +621 -0
- package/docs/STYLE_SPEC.md +988 -0
- package/docs/images/list-capabilities.svg +39 -0
- package/docs/images/row-action.svg +17 -0
- package/docs/images/row-activity.svg +24 -0
- package/docs/images/row-data.svg +24 -0
- package/docs/images/row-identity.svg +25 -0
- package/docs/images/row-market.svg +23 -0
- package/docs/images/row-media-tile.svg +26 -0
- package/docs/images/row-message.svg +20 -0
- package/docs/images/row-metric-card.svg +33 -0
- package/docs/images/row-rail.svg +18 -0
- package/docs/images/row-section-header.svg +19 -0
- package/docs/images/row-style-regions.svg +30 -0
- package/docs/images/row-system.svg +30 -0
- package/docs/images/row-wallet-group.svg +26 -0
- package/ios/HybridNativeList.swift +30 -0
- package/ios/NativeListAccessoryStack.swift +680 -0
- package/ios/NativeListActionRenderer.swift +108 -0
- package/ios/NativeListActivityDetailsView.swift +291 -0
- package/ios/NativeListActivityRenderer.swift +201 -0
- package/ios/NativeListDataRowRenderer.swift +444 -0
- package/ios/NativeListIdentityRenderer.swift +685 -0
- package/ios/NativeListImageSlot.swift +140 -0
- package/ios/NativeListLeadingVisual.swift +372 -0
- package/ios/NativeListMarketRenderer.swift +698 -0
- package/ios/NativeListMediaPreviewSlot.swift +259 -0
- package/ios/NativeListMediaTileRenderer.swift +190 -0
- package/ios/NativeListMessageRenderer.swift +168 -0
- package/ios/NativeListMetricCardRenderer.swift +420 -0
- package/ios/NativeListModels.swift +36 -1
- package/ios/NativeListRailRenderer.swift +152 -0
- package/ios/NativeListRendererCell.swift +311 -0
- package/ios/NativeListRendererRegistry.swift +50 -0
- package/ios/NativeListResolvedText.swift +130 -0
- package/ios/NativeListRowHost.swift +63 -0
- package/ios/NativeListScrollPositionTracker.swift +30 -0
- package/ios/NativeListSectionHeaderRenderer.swift +734 -0
- package/ios/NativeListSystemRenderer.swift +568 -0
- package/ios/NativeListTextLabel.swift +42 -0
- package/ios/NativeListTextStyles.swift +236 -0
- package/ios/NativeListWalletGroupRenderer.swift +255 -0
- package/ios/RNCNativeListView.swift +282 -184
- package/ios/tests/NativeListActivityPresentationTests.swift +97 -0
- package/ios/tests/NativeListLifecycleTests.swift +241 -0
- package/ios/tests/NativeListMediaVisibilityTests.swift +109 -0
- package/ios/tests/NativeListScrollPositionTrackerTests.swift +25 -0
- package/lib/module/NativeList.js +56 -3
- package/lib/module/NativeList.web.js +5 -0
- package/lib/module/models.js +54 -0
- package/lib/module/validation.js +386 -28
- package/lib/module/web/NativeListWebEngine.js +148 -936
- package/lib/module/web/templates/ActionRowRenderer.js +97 -0
- package/lib/module/web/templates/ActivityRowRenderer.js +95 -0
- package/lib/module/web/templates/DataRowRenderer.js +145 -0
- package/lib/module/web/templates/IdentityRowRenderer.js +289 -0
- package/lib/module/web/templates/MarketRowRenderer.js +310 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +132 -0
- package/lib/module/web/templates/MessageRowRenderer.js +165 -0
- package/lib/module/web/templates/MetricCardRowRenderer.js +172 -0
- package/lib/module/web/templates/RailRowRenderer.js +98 -0
- package/lib/module/web/templates/RowContainerStyle.js +100 -0
- package/lib/module/web/templates/RowElements.js +93 -0
- package/lib/module/web/templates/RowRendererRegistry.js +70 -0
- package/lib/module/web/templates/RowText.js +121 -0
- package/lib/module/web/templates/RowVisual.js +43 -0
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +146 -0
- package/lib/module/web/templates/SystemRowRenderer.js +161 -0
- package/lib/module/web/templates/WalletGroupRowRenderer.js +96 -0
- package/lib/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
- package/lib/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
- package/lib/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
- package/lib/typescript/src/NativeList.nitro.d.ts +3 -0
- package/lib/typescript/src/NativeList.types.d.ts +14 -1
- package/lib/typescript/src/models.d.ts +199 -18
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +18 -16
- package/lib/typescript/src/web/templates/ActionRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/DataRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +16 -0
- package/lib/typescript/src/web/templates/MarketRowRenderer.d.ts +30 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +44 -0
- package/lib/typescript/src/web/templates/MetricCardRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/RailRowRenderer.d.ts +28 -0
- package/lib/typescript/src/web/templates/RowContainerStyle.d.ts +9 -0
- package/lib/typescript/src/web/templates/RowElements.d.ts +38 -0
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +83 -0
- package/lib/typescript/src/web/templates/RowText.d.ts +9 -0
- package/lib/typescript/src/web/templates/RowVisual.d.ts +20 -0
- package/lib/typescript/src/web/templates/SectionHeaderRowRenderer.d.ts +15 -0
- package/lib/typescript/src/web/templates/SystemRowRenderer.d.ts +16 -0
- package/lib/typescript/src/web/templates/WalletGroupRowRenderer.d.ts +20 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +39 -3
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +6 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +15 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/Func_void_bool.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +26 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/views/HybridNativeListManager.kt +24 -9
- package/nitrogen/generated/android/nativelistOnLoad.cpp +2 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Bridge.hpp +37 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +23 -2
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +32 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +3 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +54 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +6 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +8 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +6 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +11 -2
- package/nitrogen/generated/shared/json/NativeListConfig.json +3 -0
- package/package.json +7 -6
- package/react-native-native-list.podspec +6 -0
- package/scripts/enable-container-slots.mjs +58 -0
- package/scripts/enable-container-slots.test.mjs +58 -0
- package/src/NativeList.nitro.ts +3 -0
- package/src/NativeList.tsx +84 -2
- package/src/NativeList.types.ts +14 -1
- package/src/NativeList.web.tsx +5 -0
- package/src/models.ts +320 -20
- package/src/validation.ts +641 -49
- package/src/web/NativeListWebEngine.ts +361 -1932
- package/src/web/templates/ActionRowRenderer.ts +123 -0
- package/src/web/templates/ActivityRowRenderer.ts +159 -0
- package/src/web/templates/DataRowRenderer.ts +212 -0
- package/src/web/templates/IdentityRowRenderer.ts +527 -0
- package/src/web/templates/MarketRowRenderer.ts +467 -0
- package/src/web/templates/MediaTileRowRenderer.ts +182 -0
- package/src/web/templates/MessageRowRenderer.ts +306 -0
- package/src/web/templates/MetricCardRowRenderer.ts +337 -0
- package/src/web/templates/RailRowRenderer.ts +136 -0
- package/src/web/templates/RowContainerStyle.ts +131 -0
- package/src/web/templates/RowElements.ts +160 -0
- package/src/web/templates/RowRendererRegistry.ts +111 -0
- package/src/web/templates/RowText.ts +181 -0
- package/src/web/templates/RowVisual.ts +115 -0
- package/src/web/templates/SectionHeaderRowRenderer.ts +243 -0
- package/src/web/templates/SystemRowRenderer.ts +282 -0
- package/src/web/templates/WalletGroupRowRenderer.ts +131 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRowView.kt +0 -4538
- package/ios/NativeListCell.swift +0 -4300
|
@@ -31,6 +31,7 @@ import android.widget.SeekBar
|
|
|
31
31
|
import android.widget.TextView
|
|
32
32
|
import androidx.core.view.ViewCompat
|
|
33
33
|
import androidx.core.view.WindowInsetsCompat
|
|
34
|
+
import androidx.recyclerview.widget.ConcatAdapter
|
|
34
35
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
35
36
|
import androidx.recyclerview.widget.ItemTouchHelper
|
|
36
37
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
@@ -57,6 +58,21 @@ private class NativeListGridLayoutManager(
|
|
|
57
58
|
context: Context,
|
|
58
59
|
spanCount: Int,
|
|
59
60
|
) : GridLayoutManager(context, spanCount) {
|
|
61
|
+
var onChildLaidOut: ((View, Int) -> Unit)? = null
|
|
62
|
+
var onLayoutPassCompleted: (() -> Unit)? = null
|
|
63
|
+
|
|
64
|
+
// Scroll fills and layout passes both place children here, including rows that a
|
|
65
|
+
// positional jump lays out and immediately leaves offscreen.
|
|
66
|
+
override fun layoutDecoratedWithMargins(child: View, left: Int, top: Int, right: Int, bottom: Int) {
|
|
67
|
+
super.layoutDecoratedWithMargins(child, left, top, right, bottom)
|
|
68
|
+
onChildLaidOut?.invoke(child, if (orientation == RecyclerView.VERTICAL) bottom - top else right - left)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override fun onLayoutCompleted(state: RecyclerView.State) {
|
|
72
|
+
super.onLayoutCompleted(state)
|
|
73
|
+
onLayoutPassCompleted?.invoke()
|
|
74
|
+
}
|
|
75
|
+
|
|
60
76
|
override fun removeAndRecycleViewAt(index: Int, recycler: RecyclerView.Recycler) {
|
|
61
77
|
val child = getChildAt(index) ?: return
|
|
62
78
|
removeViewAt(index)
|
|
@@ -111,6 +127,43 @@ class NativeListView(
|
|
|
111
127
|
data class End(val animated: Boolean) : ScrollRequest()
|
|
112
128
|
}
|
|
113
129
|
|
|
130
|
+
private val coordinatorOffsetListener = Runnable { emitScrollPositionThresholdIfNeeded() }
|
|
131
|
+
private var logicalScrollDistancePx = 0
|
|
132
|
+
private val scrollPositionTracker = NativeListScrollPositionTracker()
|
|
133
|
+
private val measuredRowExtentsPx = HashMap<String, Int>()
|
|
134
|
+
private var measuredRowExtentSumPx = 0L
|
|
135
|
+
var onScrollPositionThresholdChange: ((Boolean) -> Unit)? = null
|
|
136
|
+
set(value) {
|
|
137
|
+
field = value
|
|
138
|
+
scrollPositionTracker.resetDelivery()
|
|
139
|
+
emitScrollPositionThresholdIfNeeded(resync = true)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
fun setScrollPositionThresholdsJson(json: String) {
|
|
143
|
+
val config = runCatching { JSONObject(json) }.getOrNull()
|
|
144
|
+
scrollPositionTracker.configure(config?.optDouble("start"), config?.optDouble("end"))
|
|
145
|
+
emitScrollPositionThresholdIfNeeded(resync = true)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Continuous scrolling accumulates the exact consumed dy. Layout passes and positional
|
|
150
|
+
* jumps (scrollToIndex/End, anchor restores, inserts above) report no dy, so they re-derive
|
|
151
|
+
* the distance from the laid-out first item plus the extents of every item before it.
|
|
152
|
+
*/
|
|
153
|
+
private fun emitScrollPositionThresholdIfNeeded(resync: Boolean = false) {
|
|
154
|
+
if (disposed) return
|
|
155
|
+
val callback = onScrollPositionThresholdChange ?: return
|
|
156
|
+
if (!scrollPositionTracker.isConfigured) return
|
|
157
|
+
if (resync || layoutManager.findFirstVisibleItemPosition() == 0) {
|
|
158
|
+
measuredScrollDistancePx()?.let { logicalScrollDistancePx = it }
|
|
159
|
+
}
|
|
160
|
+
val contributions = recyclerView.getTag(R.id.onekey_native_scroll_coordinator_consumed_offsets) as? Map<*, *>
|
|
161
|
+
val parentDistance = contributions?.values?.sumOf { (it as? Int)?.coerceAtLeast(0)?.toLong() ?: 0L } ?: 0L
|
|
162
|
+
val distance = logicalScrollDistancePx.toLong() + parentDistance
|
|
163
|
+
val next = scrollPositionTracker.update(distance.toDouble() / density) ?: return
|
|
164
|
+
callback(next)
|
|
165
|
+
}
|
|
166
|
+
|
|
114
167
|
var onRowAction: ((String) -> Unit)? = null
|
|
115
168
|
var onActionAnchorInvalidated: ((String) -> Unit)? = null
|
|
116
169
|
var onSelectionDelta: ((String) -> Unit)? = null
|
|
@@ -122,12 +175,103 @@ class NativeListView(
|
|
|
122
175
|
private val density = resources.displayMetrics.density
|
|
123
176
|
private val recyclerView = RecyclerView(context)
|
|
124
177
|
private var configuredTopPaddingPx = 0
|
|
178
|
+
private var slotInsetPx = 0
|
|
125
179
|
private var configuredBottomPaddingPx = 0
|
|
126
180
|
private val refreshLayout = SwipeRefreshLayout(context)
|
|
127
181
|
private val refreshIndicatorTravelPx = refreshLayout.progressViewEndOffset
|
|
182
|
+
private val defaultRefreshTriggerDistancePx = (64 * resources.displayMetrics.density).roundToInt()
|
|
128
183
|
private var refreshIndicatorOffsetPx = 0
|
|
129
184
|
private val contentContainer = FrameLayout(context)
|
|
130
185
|
private val adapter = NativeListAdapter(reactContext)
|
|
186
|
+
private val containerSlots = mutableListOf<View>()
|
|
187
|
+
private val slotHeights = IntArray(3)
|
|
188
|
+
private val headerSlotAdapter = NativeListContainerSlotAdapter()
|
|
189
|
+
private val emptySlotAdapter = NativeListContainerSlotAdapter()
|
|
190
|
+
private val footerSlotAdapter = NativeListContainerSlotAdapter()
|
|
191
|
+
private val scrollContentAdapter = ConcatAdapter(headerSlotAdapter, adapter, emptySlotAdapter, footerSlotAdapter)
|
|
192
|
+
|
|
193
|
+
fun mountContainerSlot(view: View, index: Int) {
|
|
194
|
+
containerSlots.add(index.coerceIn(0, containerSlots.size), view)
|
|
195
|
+
updateContainerSlots()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
fun containerSlotCount(): Int = containerSlots.size
|
|
199
|
+
fun containerSlotAt(index: Int): View = containerSlots[index]
|
|
200
|
+
fun unmountContainerSlot(index: Int) {
|
|
201
|
+
val view = containerSlots.removeAt(index)
|
|
202
|
+
(view.parent as? ViewGroup)?.removeView(view)
|
|
203
|
+
updateContainerSlots()
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fun setContainerSlotHeightsJson(json: String) {
|
|
207
|
+
val values = runCatching { JSONArray(json) }.getOrNull() ?: return
|
|
208
|
+
if (values.length() != 3) return
|
|
209
|
+
for (index in 0..2) {
|
|
210
|
+
val value = values.optDouble(index)
|
|
211
|
+
if (!value.isFinite() || value < 0) return
|
|
212
|
+
}
|
|
213
|
+
for (index in 0..2) slotHeights[index] = (values.getDouble(index) * density).roundToInt()
|
|
214
|
+
updateContainerSlots()
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private fun updateContainerSlots() {
|
|
218
|
+
headerSlotAdapter.update(containerSlots.getOrNull(0), slotHeights[0], true)
|
|
219
|
+
emptySlotAdapter.update(containerSlots.getOrNull(1), slotHeights[1], config?.items?.isEmpty() != false)
|
|
220
|
+
footerSlotAdapter.update(containerSlots.getOrNull(2), slotHeights[2], true)
|
|
221
|
+
layoutManager.spanSizeLookup.invalidateSpanIndexCache()
|
|
222
|
+
recyclerView.requestLayout()
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private fun scrollPositionForRow(index: Int): Int = index + headerSlotAdapter.itemCount
|
|
226
|
+
|
|
227
|
+
private fun recordLaidOutRowExtent(child: View, extentPx: Int) {
|
|
228
|
+
val holder = recyclerView.getChildViewHolder(child) as? NativeListViewHolder ?: return
|
|
229
|
+
if (holder.bindingAdapter !== adapter) return
|
|
230
|
+
val key = adapter.itemAt(holder.bindingAdapterPosition)?.key ?: return
|
|
231
|
+
val previous = measuredRowExtentsPx.put(key, extentPx)
|
|
232
|
+
measuredRowExtentSumPx += extentPx - (previous ?: 0)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private fun pruneMeasuredRowExtents(items: List<NativeListItem>) {
|
|
236
|
+
if (measuredRowExtentsPx.isEmpty()) return
|
|
237
|
+
val keys = items.mapTo(HashSet(items.size)) { it.key }
|
|
238
|
+
measuredRowExtentsPx.keys.retainAll(keys)
|
|
239
|
+
measuredRowExtentSumPx = measuredRowExtentsPx.values.sumOf { it.toLong() }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Rows skipped by a jump have never been laid out; explicit heights beat the average. */
|
|
243
|
+
private fun estimatedScrollExtentPx(position: Int): Int {
|
|
244
|
+
val headerCount = headerSlotAdapter.itemCount
|
|
245
|
+
if (position < headerCount) return slotHeights[0]
|
|
246
|
+
val row = position - headerCount
|
|
247
|
+
if (row >= adapter.itemCount) {
|
|
248
|
+
return if (row - adapter.itemCount < emptySlotAdapter.itemCount) slotHeights[1] else slotHeights[2]
|
|
249
|
+
}
|
|
250
|
+
val item = adapter.itemAt(row)
|
|
251
|
+
item?.key?.let(measuredRowExtentsPx::get)?.let { return it }
|
|
252
|
+
val explicit = item?.styledHeight ?: item?.json?.optDouble("height")?.takeIf { it.isFinite() }
|
|
253
|
+
if (explicit != null) return (explicit * density).roundToInt()
|
|
254
|
+
return if (measuredRowExtentsPx.isEmpty()) 0 else (measuredRowExtentSumPx / measuredRowExtentsPx.size).toInt()
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private fun measuredScrollDistancePx(): Int? {
|
|
258
|
+
if (layoutManager.orientation != RecyclerView.VERTICAL) return null
|
|
259
|
+
val first = layoutManager.findFirstVisibleItemPosition()
|
|
260
|
+
if (first == RecyclerView.NO_POSITION) return null
|
|
261
|
+
val view = layoutManager.findViewByPosition(first) ?: return null
|
|
262
|
+
val prefix = nativeListScrollPrefixPx(
|
|
263
|
+
first,
|
|
264
|
+
layoutManager.spanCount,
|
|
265
|
+
layoutManager.spanSizeLookup::getSpanSize,
|
|
266
|
+
::estimatedScrollExtentPx,
|
|
267
|
+
)
|
|
268
|
+
val topMargin = (view.layoutParams as? ViewGroup.MarginLayoutParams)?.topMargin ?: 0
|
|
269
|
+
val top = layoutManager.getDecoratedTop(view) - topMargin
|
|
270
|
+
return (prefix + recyclerView.paddingTop - top).coerceIn(0L, Int.MAX_VALUE.toLong()).toInt()
|
|
271
|
+
}
|
|
272
|
+
private fun rowPositionForScroll(index: Int): Int =
|
|
273
|
+
if (index == RecyclerView.NO_POSITION) RecyclerView.NO_POSITION else index - headerSlotAdapter.itemCount
|
|
274
|
+
|
|
131
275
|
private val layoutManager = NativeListGridLayoutManager(context, 1)
|
|
132
276
|
// OneKey patch: vertical lists retain vertical drags and leave horizontal drags to a parent pager.
|
|
133
277
|
private val pagerGestureTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
|
@@ -226,12 +370,69 @@ class NativeListView(
|
|
|
226
370
|
mass = REORDER_SPRING_MASS,
|
|
227
371
|
durationSeconds = REORDER_SPRING_DURATION_MS / 1_000.0,
|
|
228
372
|
)
|
|
229
|
-
private
|
|
373
|
+
private var footerView: NativeListRowHost = NativeListRendererRegistry.create(reactContext, NativeListRendererKey.ACTION.ordinal)
|
|
374
|
+
private var footerRendererKey = NativeListRendererKey.ACTION
|
|
230
375
|
private val sectionIndexView = NativeListSectionIndexView(context)
|
|
231
376
|
private val sectionIndexPreview = TextView(context)
|
|
232
377
|
private var config: NativeListConfig? = null
|
|
233
378
|
private var usesSelectorSourceScale = false
|
|
234
|
-
private
|
|
379
|
+
private val stickyHeaderView = NativeListRendererRegistry.create(reactContext, NativeListRendererKey.SECTION_HEADER.ordinal)
|
|
380
|
+
private var stickyHeaderSignature: String? = null
|
|
381
|
+
private var stickyHeaderConfig: NativeListConfig? = null
|
|
382
|
+
private val stickyHeaderHost = object : FrameLayout(reactContext) {
|
|
383
|
+
private var down: MotionEvent? = null
|
|
384
|
+
private var forwarding = false
|
|
385
|
+
|
|
386
|
+
private fun forward(event: MotionEvent) {
|
|
387
|
+
val copy = MotionEvent.obtain(event)
|
|
388
|
+
copy.offsetLocation(x - refreshLayout.x - recyclerView.x, y - refreshLayout.y - recyclerView.y)
|
|
389
|
+
recyclerView.dispatchTouchEvent(copy)
|
|
390
|
+
copy.recycle()
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
|
394
|
+
when (event.actionMasked) {
|
|
395
|
+
MotionEvent.ACTION_DOWN -> { down?.recycle(); down = MotionEvent.obtain(event); forwarding = false }
|
|
396
|
+
MotionEvent.ACTION_MOVE -> {
|
|
397
|
+
val initial = down
|
|
398
|
+
if (initial != null && kotlin.math.abs(event.y - initial.y) > pagerGestureTouchSlop) {
|
|
399
|
+
startForwarding(initial, event)
|
|
400
|
+
return true
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { down?.recycle(); down = null }
|
|
404
|
+
}
|
|
405
|
+
return false
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// The intercepting MOVE is not redelivered to onTouchEvent, so forward it
|
|
409
|
+
// together with the initial DOWN to keep the list's drag continuous.
|
|
410
|
+
private fun startForwarding(initial: MotionEvent, event: MotionEvent) {
|
|
411
|
+
forward(initial)
|
|
412
|
+
forward(event)
|
|
413
|
+
forwarding = true
|
|
414
|
+
parent?.requestDisallowInterceptTouchEvent(true)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
override fun onTouchEvent(event: MotionEvent): Boolean {
|
|
418
|
+
if (!forwarding) return super.onTouchEvent(event)
|
|
419
|
+
forward(event)
|
|
420
|
+
if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
|
421
|
+
forwarding = false
|
|
422
|
+
down?.recycle(); down = null
|
|
423
|
+
}
|
|
424
|
+
return true
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
override fun onDetachedFromWindow() { down?.recycle(); down = null; super.onDetachedFromWindow() }
|
|
428
|
+
}
|
|
429
|
+
private val stickyPreDraw = android.view.ViewTreeObserver.OnPreDrawListener {
|
|
430
|
+
updateStickyHeader()
|
|
431
|
+
true
|
|
432
|
+
}
|
|
433
|
+
// Registered only while attached, on the captured window observer, so detach
|
|
434
|
+
// removes the same instance the listener was merged into.
|
|
435
|
+
private var stickyObservedTree: ViewTreeObserver? = null
|
|
235
436
|
private var spacingDecoration: ItemSpacingDecoration? = null
|
|
236
437
|
private var itemTouchHelper: ItemTouchHelper? = null
|
|
237
438
|
private var reorderTouchListener: RecyclerView.OnItemTouchListener? = null
|
|
@@ -276,7 +477,7 @@ class NativeListView(
|
|
|
276
477
|
|
|
277
478
|
init {
|
|
278
479
|
orientation = VERTICAL
|
|
279
|
-
recyclerView.adapter =
|
|
480
|
+
recyclerView.adapter = scrollContentAdapter
|
|
280
481
|
recyclerView.layoutManager = layoutManager
|
|
281
482
|
recyclerView.itemAnimator = null
|
|
282
483
|
recyclerView.addOnItemTouchListener(keyboardTapTouchListener)
|
|
@@ -284,11 +485,16 @@ class NativeListView(
|
|
|
284
485
|
recyclerView.addItemDecoration(reorderPlaceholderDecoration)
|
|
285
486
|
// OneKey patch: full-width selector header backgrounds do not change row content insets.
|
|
286
487
|
recyclerView.addItemDecoration(SelectorBackgroundDecoration(adapter))
|
|
488
|
+
recyclerView.addItemDecoration(ContainerSlotInsetDecoration { slotInsetPx })
|
|
489
|
+
layoutManager.onChildLaidOut = ::recordLaidOutRowExtent
|
|
490
|
+
layoutManager.onLayoutPassCompleted = { emitScrollPositionThresholdIfNeeded(resync = true) }
|
|
287
491
|
recyclerView.setHasFixedSize(false)
|
|
288
492
|
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
|
289
493
|
override fun getSpanSize(position: Int): Int {
|
|
290
494
|
if (config?.layout != "grid") return 1
|
|
291
|
-
val
|
|
495
|
+
val rowPosition = rowPositionForScroll(position)
|
|
496
|
+
if (rowPosition !in 0 until adapter.itemCount) return layoutManager.spanCount
|
|
497
|
+
val type = adapter.itemAt(rowPosition)?.type
|
|
292
498
|
return if (type == "sectionHeader" || type == "system" || type == "action") {
|
|
293
499
|
layoutManager.spanCount
|
|
294
500
|
} else {
|
|
@@ -307,6 +513,9 @@ class NativeListView(
|
|
|
307
513
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
308
514
|
),
|
|
309
515
|
)
|
|
516
|
+
stickyHeaderHost.visibility = GONE
|
|
517
|
+
stickyHeaderHost.addView(stickyHeaderView, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
|
518
|
+
contentContainer.addView(stickyHeaderHost, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP))
|
|
310
519
|
contentContainer.addView(
|
|
311
520
|
sectionIndexView,
|
|
312
521
|
FrameLayout.LayoutParams(
|
|
@@ -342,6 +551,9 @@ class NativeListView(
|
|
|
342
551
|
adapter.onAction = ::handleAction
|
|
343
552
|
adapter.onBindingInvalidated = ::handleBindingInvalidated
|
|
344
553
|
adapter.checkboxState = ::resolveCheckboxState
|
|
554
|
+
stickyHeaderView.onRowPress = ::handleRowPress
|
|
555
|
+
stickyHeaderView.onAction = ::handleAction
|
|
556
|
+
stickyHeaderView.onBindingInvalidated = ::handleBindingInvalidated
|
|
345
557
|
footerView.onRowPress = ::handleRowPress
|
|
346
558
|
footerView.onAction = ::handleAction
|
|
347
559
|
footerView.onBindingInvalidated = ::handleBindingInvalidated
|
|
@@ -380,6 +592,8 @@ class NativeListView(
|
|
|
380
592
|
}
|
|
381
593
|
|
|
382
594
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
595
|
+
logicalScrollDistancePx = (logicalScrollDistancePx + dy).coerceAtLeast(0)
|
|
596
|
+
emitScrollPositionThresholdIfNeeded(resync = dx == 0 && dy == 0)
|
|
383
597
|
if (dx != 0 || dy != 0) invalidateActionAnchor("scroll")
|
|
384
598
|
syncSectionIndexToVisibleRows()
|
|
385
599
|
scheduleVisibleEvent()
|
|
@@ -406,7 +620,7 @@ class NativeListView(
|
|
|
406
620
|
|
|
407
621
|
private fun keyboardTapIsHandled(recyclerView: RecyclerView, event: MotionEvent): Boolean {
|
|
408
622
|
val child = recyclerView.findChildViewUnder(event.x, event.y) ?: return false
|
|
409
|
-
val position = recyclerView.getChildAdapterPosition(child)
|
|
623
|
+
val position = rowPositionForScroll(recyclerView.getChildAdapterPosition(child))
|
|
410
624
|
val item = adapter.itemAt(position) ?: return false
|
|
411
625
|
val clickable = clickableDescendantAt(child, event.rawX.toInt(), event.rawY.toInt())
|
|
412
626
|
val accessoryHandlesTap = clickable != null && clickable !== child
|
|
@@ -449,6 +663,8 @@ class NativeListView(
|
|
|
449
663
|
}
|
|
450
664
|
|
|
451
665
|
private fun updateRefreshIndicatorOffset(offset: Int) {
|
|
666
|
+
// Let an ancestor render above its shared header without guessing caller offsets.
|
|
667
|
+
refreshLayout.setTag(R.id.onekey_native_scroll_coordinator_refresh_inset, offset)
|
|
452
668
|
if (refreshIndicatorOffsetPx == offset) return
|
|
453
669
|
refreshIndicatorOffsetPx = offset
|
|
454
670
|
val refreshing = refreshLayout.isRefreshing
|
|
@@ -459,6 +675,9 @@ class NativeListView(
|
|
|
459
675
|
|
|
460
676
|
override fun onAttachedToWindow() {
|
|
461
677
|
super.onAttachedToWindow()
|
|
678
|
+
recyclerView.setTag(R.id.onekey_native_scroll_coordinator_offset_listener, coordinatorOffsetListener)
|
|
679
|
+
emitScrollPositionThresholdIfNeeded()
|
|
680
|
+
startStickyHeaderTracking()
|
|
462
681
|
updateSectionIndexAttachment()
|
|
463
682
|
val first = config?.items?.firstOrNull()
|
|
464
683
|
if (recyclerView.isLayoutRequested && (first?.type == "market" || first?.json?.optString("presentation") == "market")) {
|
|
@@ -467,6 +686,10 @@ class NativeListView(
|
|
|
467
686
|
}
|
|
468
687
|
|
|
469
688
|
override fun onDetachedFromWindow() {
|
|
689
|
+
if (recyclerView.getTag(R.id.onekey_native_scroll_coordinator_offset_listener) === coordinatorOffsetListener) {
|
|
690
|
+
recyclerView.setTag(R.id.onekey_native_scroll_coordinator_offset_listener, null)
|
|
691
|
+
}
|
|
692
|
+
stopStickyHeaderTracking()
|
|
470
693
|
stopSectionIndexAttachmentTracking()
|
|
471
694
|
scheduleSectionIndexAttachmentToList()
|
|
472
695
|
updateRefreshIndicatorOffset(0)
|
|
@@ -497,12 +720,17 @@ class NativeListView(
|
|
|
497
720
|
}
|
|
498
721
|
}.toSet()
|
|
499
722
|
config = next
|
|
723
|
+
updateContainerSlots()
|
|
500
724
|
usesSelectorSourceScale = next.items.any { it.usesSelectorSourceScale }
|
|
501
725
|
adapter.usesSelectorSourceScale = usesSelectorSourceScale
|
|
502
726
|
adapter.theme = next.theme
|
|
727
|
+
adapter.listStyle = next.listStyle
|
|
503
728
|
adapter.layout = next.layout
|
|
504
729
|
adapter.orientation = next.orientation
|
|
505
730
|
adapter.selectedKeys = next.selectedKeys
|
|
731
|
+
// Rows rebind through the adapter's listStyle invalidation; the fixed footer is bound
|
|
732
|
+
// outside the adapter, so a listStyle-only snapshot must rebind it here.
|
|
733
|
+
if (previous.listStyle?.toString() != next.listStyle?.toString()) bindFooter(next)
|
|
506
734
|
adapter.submitList(next.items) {
|
|
507
735
|
// OneKey patch: DiffUtil has dispatched its payloads; release the old serialized rows.
|
|
508
736
|
next.items.forEach { it.selectionUpdateFromContent = null }
|
|
@@ -523,18 +751,21 @@ class NativeListView(
|
|
|
523
751
|
previous?.items?.firstOrNull()?.type == "market" &&
|
|
524
752
|
next.items.firstOrNull()?.type == "market" &&
|
|
525
753
|
previous.items.firstOrNull()?.key != next.items.firstOrNull()?.key &&
|
|
526
|
-
layoutManager.findFirstVisibleItemPosition() == 0
|
|
754
|
+
rowPositionForScroll(layoutManager.findFirstVisibleItemPosition()) == 0
|
|
527
755
|
) {
|
|
528
|
-
layoutManager.findViewByPosition(0)?.let {
|
|
756
|
+
layoutManager.findViewByPosition(scrollPositionForRow(0))?.let {
|
|
529
757
|
layoutManager.getDecoratedTop(it) - recyclerView.paddingTop
|
|
530
758
|
}
|
|
531
759
|
} else null
|
|
532
760
|
config = next
|
|
761
|
+
pruneMeasuredRowExtents(next.items)
|
|
762
|
+
updateContainerSlots()
|
|
533
763
|
usesSelectorSourceScale = next.items.any { it.usesSelectorSourceScale }
|
|
534
764
|
adapter.usesSelectorSourceScale = usesSelectorSourceScale
|
|
535
765
|
if (previous?.generation != next.generation) endReachedGeneration = null
|
|
536
766
|
pendingReorder = null
|
|
537
767
|
adapter.theme = next.theme
|
|
768
|
+
adapter.listStyle = next.listStyle
|
|
538
769
|
adapter.layout = next.layout
|
|
539
770
|
adapter.orientation = next.orientation
|
|
540
771
|
adapter.selectedKeys = next.selectedKeys
|
|
@@ -542,7 +773,7 @@ class NativeListView(
|
|
|
542
773
|
updateLayout(next)
|
|
543
774
|
adapter.submitList(next.items) {
|
|
544
775
|
if (marketStartOffset != null) {
|
|
545
|
-
layoutManager.scrollToPositionWithOffset(0, marketStartOffset)
|
|
776
|
+
layoutManager.scrollToPositionWithOffset(scrollPositionForRow(0), marketStartOffset)
|
|
546
777
|
}
|
|
547
778
|
relayoutContents(preserveMarketPaginationAnchor)
|
|
548
779
|
performPendingScrollIfNeeded()
|
|
@@ -551,16 +782,17 @@ class NativeListView(
|
|
|
551
782
|
if (next.items.isNotEmpty()) checkEndReached()
|
|
552
783
|
}
|
|
553
784
|
refreshLayout.isEnabled = next.pullToRefresh
|
|
785
|
+
refreshLayout.setDistanceToTriggerSync(next.refreshTriggerDistance?.let { (it * density).roundToInt() } ?: defaultRefreshTriggerDistancePx)
|
|
554
786
|
refreshLayout.isRefreshing = next.refreshing
|
|
555
787
|
bindFooter(next)
|
|
556
788
|
updateReordering(next)
|
|
557
789
|
}
|
|
558
790
|
|
|
559
791
|
private fun captureVisibleMarketAnchor(): VisibleMarketAnchor? {
|
|
560
|
-
val position = layoutManager.findFirstVisibleItemPosition()
|
|
792
|
+
val position = rowPositionForScroll(layoutManager.findFirstVisibleItemPosition()).coerceAtLeast(0)
|
|
561
793
|
if (position == RecyclerView.NO_POSITION) return null
|
|
562
794
|
val item = adapter.itemAt(position) ?: return null
|
|
563
|
-
val view = layoutManager.findViewByPosition(position) ?: return null
|
|
795
|
+
val view = layoutManager.findViewByPosition(scrollPositionForRow(position)) ?: return null
|
|
564
796
|
return VisibleMarketAnchor(
|
|
565
797
|
key = item.key,
|
|
566
798
|
offset = layoutManager.getDecoratedTop(view) - recyclerView.paddingTop,
|
|
@@ -616,6 +848,7 @@ class NativeListView(
|
|
|
616
848
|
previous.rowPressToggles != next.rowPressToggles ||
|
|
617
849
|
previous.reorderable != next.reorderable ||
|
|
618
850
|
previous.pullToRefresh != next.pullToRefresh ||
|
|
851
|
+
previous.refreshTriggerDistance != next.refreshTriggerDistance ||
|
|
619
852
|
previous.refreshing != next.refreshing ||
|
|
620
853
|
previous.loadMore != next.loadMore ||
|
|
621
854
|
previous.endReachedThreshold != next.endReachedThreshold ||
|
|
@@ -767,6 +1000,7 @@ class NativeListView(
|
|
|
767
1000
|
if (!marketQuoteOnly) invalidateActionAnchor("snapshot")
|
|
768
1001
|
val next = current.copy(items = nextItems, selectedKeys = selected)
|
|
769
1002
|
config = next
|
|
1003
|
+
updateContainerSlots()
|
|
770
1004
|
usesSelectorSourceScale = next.items.any { it.usesSelectorSourceScale }
|
|
771
1005
|
adapter.usesSelectorSourceScale = usesSelectorSourceScale
|
|
772
1006
|
adapter.selectedKeys = selected
|
|
@@ -870,7 +1104,32 @@ class NativeListView(
|
|
|
870
1104
|
true
|
|
871
1105
|
}
|
|
872
1106
|
is ScrollRequest.End -> {
|
|
873
|
-
|
|
1107
|
+
val finalSlotHeight = when {
|
|
1108
|
+
footerSlotAdapter.itemCount > 0 -> slotHeights[2]
|
|
1109
|
+
emptySlotAdapter.itemCount > 0 -> slotHeights[1]
|
|
1110
|
+
adapter.itemCount == 0 && headerSlotAdapter.itemCount > 0 -> slotHeights[0]
|
|
1111
|
+
else -> null
|
|
1112
|
+
}
|
|
1113
|
+
if (finalSlotHeight != null) {
|
|
1114
|
+
val target = scrollContentAdapter.itemCount - 1
|
|
1115
|
+
if (request.animated) {
|
|
1116
|
+
val manager = layoutManager
|
|
1117
|
+
val scroller = object : LinearSmoothScroller(context) {
|
|
1118
|
+
override fun calculateDyToMakeVisible(view: View, snapPreference: Int): Int =
|
|
1119
|
+
nativeListEndAlignmentOffset(
|
|
1120
|
+
manager.height - manager.paddingBottom,
|
|
1121
|
+
manager.getDecoratedBottom(view),
|
|
1122
|
+
)
|
|
1123
|
+
}
|
|
1124
|
+
scroller.targetPosition = target
|
|
1125
|
+
layoutManager.startSmoothScroll(scroller)
|
|
1126
|
+
} else {
|
|
1127
|
+
layoutManager.scrollToPositionWithOffset(
|
|
1128
|
+
target,
|
|
1129
|
+
nativeListEndAlignmentOffset(viewportLength(layoutManager), finalSlotHeight),
|
|
1130
|
+
)
|
|
1131
|
+
}
|
|
1132
|
+
} else if (current.items.isNotEmpty()) {
|
|
874
1133
|
performIndexScroll(
|
|
875
1134
|
current.items.lastIndex,
|
|
876
1135
|
request.animated,
|
|
@@ -892,7 +1151,7 @@ class NativeListView(
|
|
|
892
1151
|
viewOffset: Double,
|
|
893
1152
|
) {
|
|
894
1153
|
val manager = recyclerView.layoutManager as? LinearLayoutManager ?: return
|
|
895
|
-
val visibleView = manager.findViewByPosition(index)
|
|
1154
|
+
val visibleView = manager.findViewByPosition(scrollPositionForRow(index))
|
|
896
1155
|
val viewPosition = if (alignment == "nearest") {
|
|
897
1156
|
val viewportStart = if (manager.orientation == RecyclerView.VERTICAL) {
|
|
898
1157
|
manager.paddingTop
|
|
@@ -913,7 +1172,7 @@ class NativeListView(
|
|
|
913
1172
|
else -> return
|
|
914
1173
|
}
|
|
915
1174
|
} else {
|
|
916
|
-
val firstVisible = manager.findFirstVisibleItemPosition()
|
|
1175
|
+
val firstVisible = rowPositionForScroll(manager.findFirstVisibleItemPosition())
|
|
917
1176
|
if (firstVisible != RecyclerView.NO_POSITION && index < firstVisible) 0.0 else 1.0
|
|
918
1177
|
}
|
|
919
1178
|
} else {
|
|
@@ -940,13 +1199,13 @@ class NativeListView(
|
|
|
940
1199
|
return smoothAlignmentDelta(manager, view, viewPosition, offsetPx)
|
|
941
1200
|
}
|
|
942
1201
|
}
|
|
943
|
-
smoothScroller.targetPosition = index
|
|
1202
|
+
smoothScroller.targetPosition = scrollPositionForRow(index)
|
|
944
1203
|
manager.startSmoothScroll(smoothScroller)
|
|
945
1204
|
return
|
|
946
1205
|
}
|
|
947
1206
|
|
|
948
1207
|
val provisionalOffset = (viewPosition * viewportLength(manager)).roundToInt() + offsetPx
|
|
949
|
-
manager.scrollToPositionWithOffset(index, provisionalOffset)
|
|
1208
|
+
manager.scrollToPositionWithOffset(scrollPositionForRow(index), provisionalOffset)
|
|
950
1209
|
relayoutRecyclerView()
|
|
951
1210
|
alignAfterLayout(index, viewPosition, offsetPx)
|
|
952
1211
|
}
|
|
@@ -954,6 +1213,9 @@ class NativeListView(
|
|
|
954
1213
|
private fun performOffsetScroll(offset: Double, animated: Boolean) {
|
|
955
1214
|
val manager = recyclerView.layoutManager as? LinearLayoutManager ?: return
|
|
956
1215
|
val target = (offset * density).roundToInt().coerceAtLeast(0)
|
|
1216
|
+
if (!animated) {
|
|
1217
|
+
logicalScrollDistancePx = target
|
|
1218
|
+
}
|
|
957
1219
|
if (!animated) {
|
|
958
1220
|
recyclerView.stopScroll()
|
|
959
1221
|
manager.scrollToPositionWithOffset(0, -target)
|
|
@@ -985,7 +1247,7 @@ class NativeListView(
|
|
|
985
1247
|
) {
|
|
986
1248
|
recyclerView.post {
|
|
987
1249
|
val manager = recyclerView.layoutManager as? LinearLayoutManager ?: return@post
|
|
988
|
-
val view = manager.findViewByPosition(index)
|
|
1250
|
+
val view = manager.findViewByPosition(scrollPositionForRow(index))
|
|
989
1251
|
if (view == null) {
|
|
990
1252
|
if (attemptsRemaining > 0) {
|
|
991
1253
|
alignAfterLayout(index, viewPosition, viewOffset, attemptsRemaining - 1)
|
|
@@ -1096,6 +1358,7 @@ class NativeListView(
|
|
|
1096
1358
|
fun dispose() {
|
|
1097
1359
|
if (disposed) return
|
|
1098
1360
|
disposed = true
|
|
1361
|
+
onScrollPositionThresholdChange = null
|
|
1099
1362
|
if (!isAttachedToWindow) disposeResources()
|
|
1100
1363
|
}
|
|
1101
1364
|
|
|
@@ -1109,6 +1372,10 @@ class NativeListView(
|
|
|
1109
1372
|
actionAnchor = null
|
|
1110
1373
|
pendingScrollRequest = null
|
|
1111
1374
|
visibleEventScheduled = false
|
|
1375
|
+
layoutManager.onChildLaidOut = null
|
|
1376
|
+
layoutManager.onLayoutPassCompleted = null
|
|
1377
|
+
measuredRowExtentsPx.clear()
|
|
1378
|
+
measuredRowExtentSumPx = 0L
|
|
1112
1379
|
reorderTouchHandler?.removeCallbacksAndMessages(null)
|
|
1113
1380
|
reorderTouchHandler = null
|
|
1114
1381
|
reorderTouchListener?.let(recyclerView::removeOnItemTouchListener)
|
|
@@ -1119,6 +1386,9 @@ class NativeListView(
|
|
|
1119
1386
|
itemTouchHelper = null
|
|
1120
1387
|
footerView.recycle()
|
|
1121
1388
|
footerView.dispose()
|
|
1389
|
+
stopStickyHeaderTracking()
|
|
1390
|
+
stickyHeaderView.dispose()
|
|
1391
|
+
stickyHeaderHost.visibility = GONE
|
|
1122
1392
|
recyclerView.swapAdapter(null, false)
|
|
1123
1393
|
adapter.dispose()
|
|
1124
1394
|
}
|
|
@@ -1138,6 +1408,8 @@ class NativeListView(
|
|
|
1138
1408
|
// Content/theme snapshots must replace only the padding owned by NativeList.
|
|
1139
1409
|
val coordinatorTopPadding = (recyclerView.paddingTop - configuredTopPaddingPx).coerceAtLeast(0)
|
|
1140
1410
|
val coordinatorBottomPadding = (recyclerView.paddingBottom - configuredBottomPaddingPx).coerceAtLeast(0)
|
|
1411
|
+
// Slot roots are laid out by React at the unscaled JS inset, without the index gutter.
|
|
1412
|
+
slotInsetPx = (horizontalPadding * density).roundToInt()
|
|
1141
1413
|
configuredTopPaddingPx = dp(topPadding)
|
|
1142
1414
|
configuredBottomPaddingPx = dp(bottomPadding)
|
|
1143
1415
|
recyclerView.setPaddingRelative(
|
|
@@ -1151,10 +1423,63 @@ class NativeListView(
|
|
|
1151
1423
|
|
|
1152
1424
|
spacingDecoration?.let(recyclerView::removeItemDecoration)
|
|
1153
1425
|
spacingDecoration = ItemSpacingDecoration(dp(next.itemSpacing), next.itemSpacing, density).also(recyclerView::addItemDecoration)
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1426
|
+
stickyHeaderSignature = null
|
|
1427
|
+
if (!next.stickyHeaders || orientation != RecyclerView.VERTICAL) stickyHeaderHost.visibility = GONE
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
private fun updateStickyHeader() {
|
|
1431
|
+
val current = config
|
|
1432
|
+
if (current == null || !current.stickyHeaders || layoutManager.orientation != RecyclerView.VERTICAL || recyclerView.width <= 0) {
|
|
1433
|
+
stickyHeaderHost.visibility = GONE
|
|
1434
|
+
return
|
|
1435
|
+
}
|
|
1436
|
+
val first = rowPositionForScroll(layoutManager.findFirstVisibleItemPosition())
|
|
1437
|
+
var position = first
|
|
1438
|
+
while (position >= 0 && adapter.itemAt(position)?.let(::isStickySectionHeader) != true) position--
|
|
1439
|
+
val item = adapter.itemAt(position)
|
|
1440
|
+
if (item == null || first == RecyclerView.NO_POSITION || (layoutManager.findViewByPosition(scrollPositionForRow(position))?.top ?: -1) > 0) {
|
|
1441
|
+
stickyHeaderHost.visibility = GONE
|
|
1442
|
+
return
|
|
1443
|
+
}
|
|
1444
|
+
val width = recyclerView.width - recyclerView.paddingLeft - recyclerView.paddingRight
|
|
1445
|
+
if (width <= 0) {
|
|
1446
|
+
stickyHeaderHost.visibility = GONE
|
|
1447
|
+
return
|
|
1448
|
+
}
|
|
1449
|
+
val signature = "${item.content}:$width:${recyclerView.layoutDirection}:$usesSelectorSourceScale"
|
|
1450
|
+
if (stickyHeaderConfig !== current || stickyHeaderSignature != signature) {
|
|
1451
|
+
stickyHeaderConfig = current
|
|
1452
|
+
stickyHeaderSignature = signature
|
|
1453
|
+
stickyHeaderView.listStyle = current.listStyle
|
|
1454
|
+
stickyHeaderView.bind(item, current.theme, current.layout, current.orientation, position,
|
|
1455
|
+
item.json.optBoolean("selected", false) || current.selectedKeys.contains(item.key), ::resolveCheckboxState,
|
|
1456
|
+
useSourceScale = usesSelectorSourceScale)
|
|
1457
|
+
stickyHeaderView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED))
|
|
1458
|
+
stickyHeaderHost.layoutParams = (stickyHeaderHost.layoutParams as FrameLayout.LayoutParams).apply {
|
|
1459
|
+
this.width = width
|
|
1460
|
+
height = stickyHeaderView.measuredHeight
|
|
1461
|
+
leftMargin = recyclerView.paddingLeft
|
|
1462
|
+
rightMargin = recyclerView.paddingRight
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
val height = stickyHeaderView.measuredHeight
|
|
1466
|
+
var nextTop = Int.MAX_VALUE
|
|
1467
|
+
for (index in 0 until recyclerView.childCount) {
|
|
1468
|
+
val child = recyclerView.getChildAt(index)
|
|
1469
|
+
val childPosition = rowPositionForScroll(recyclerView.getChildAdapterPosition(child))
|
|
1470
|
+
if (childPosition > position && adapter.itemAt(childPosition)?.let(::isStickySectionHeader) == true) nextTop = minOf(nextTop, child.top)
|
|
1471
|
+
}
|
|
1472
|
+
stickyHeaderHost.translationY = minOf(0, nextTop - height).toFloat()
|
|
1473
|
+
stickyHeaderHost.visibility = VISIBLE
|
|
1474
|
+
// React Native can retain the measured parent while this overlay becomes
|
|
1475
|
+
// visible in pre-draw. Lay out the container-owned header immediately.
|
|
1476
|
+
if (stickyHeaderHost.isLayoutRequested || stickyHeaderHost.width != width || stickyHeaderHost.height != height) {
|
|
1477
|
+
stickyHeaderHost.measure(
|
|
1478
|
+
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
1479
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY),
|
|
1480
|
+
)
|
|
1481
|
+
stickyHeaderHost.layout(recyclerView.paddingLeft, 0, recyclerView.paddingLeft + width, height)
|
|
1482
|
+
}
|
|
1158
1483
|
}
|
|
1159
1484
|
|
|
1160
1485
|
private fun configureSectionIndex(next: NativeListConfig) {
|
|
@@ -1264,6 +1589,20 @@ class NativeListView(
|
|
|
1264
1589
|
}
|
|
1265
1590
|
}
|
|
1266
1591
|
|
|
1592
|
+
private fun startStickyHeaderTracking() {
|
|
1593
|
+
if (resourcesDisposed) return
|
|
1594
|
+
val observer = viewTreeObserver
|
|
1595
|
+
if (stickyObservedTree === observer) return
|
|
1596
|
+
stopStickyHeaderTracking()
|
|
1597
|
+
observer.addOnPreDrawListener(stickyPreDraw)
|
|
1598
|
+
stickyObservedTree = observer
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
private fun stopStickyHeaderTracking() {
|
|
1602
|
+
stickyObservedTree?.takeIf(ViewTreeObserver::isAlive)?.removeOnPreDrawListener(stickyPreDraw)
|
|
1603
|
+
stickyObservedTree = null
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1267
1606
|
private fun startSectionIndexAttachmentTracking() {
|
|
1268
1607
|
val observer = viewTreeObserver
|
|
1269
1608
|
if (sectionIndexObservedTree === observer) return
|
|
@@ -1361,7 +1700,7 @@ class NativeListView(
|
|
|
1361
1700
|
|
|
1362
1701
|
private fun syncSectionIndexToVisibleRows() {
|
|
1363
1702
|
if (sectionIndexScrubbing || sectionIndexProgrammaticScroll || sectionIndexEntries.isEmpty()) return
|
|
1364
|
-
val firstVisible = layoutManager.findFirstVisibleItemPosition()
|
|
1703
|
+
val firstVisible = rowPositionForScroll(layoutManager.findFirstVisibleItemPosition())
|
|
1365
1704
|
if (firstVisible == RecyclerView.NO_POSITION) return
|
|
1366
1705
|
sectionIndexView.setActiveIndex(
|
|
1367
1706
|
sectionIndexEntries.indexOfLast { it.position <= firstVisible }.takeIf { it >= 0 },
|
|
@@ -1380,7 +1719,21 @@ class NativeListView(
|
|
|
1380
1719
|
footerView.visibility = GONE
|
|
1381
1720
|
footerView.recycle()
|
|
1382
1721
|
} else {
|
|
1722
|
+
if (footer.rendererKey != footerRendererKey) {
|
|
1723
|
+
val previous = footerView
|
|
1724
|
+
val position = indexOfChild(previous)
|
|
1725
|
+
previous.recycle()
|
|
1726
|
+
previous.dispose()
|
|
1727
|
+
footerView = NativeListRendererRegistry.create(reactContext, footer.rendererKey.ordinal)
|
|
1728
|
+
footerView.onRowPress = ::handleRowPress
|
|
1729
|
+
footerView.onAction = ::handleAction
|
|
1730
|
+
footerView.onBindingInvalidated = ::handleBindingInvalidated
|
|
1731
|
+
removeView(previous)
|
|
1732
|
+
addView(footerView, position, previous.layoutParams)
|
|
1733
|
+
footerRendererKey = footer.rendererKey
|
|
1734
|
+
}
|
|
1383
1735
|
footerView.visibility = VISIBLE
|
|
1736
|
+
footerView.listStyle = next.listStyle
|
|
1384
1737
|
footerView.bind(
|
|
1385
1738
|
footer,
|
|
1386
1739
|
next.theme,
|
|
@@ -1490,7 +1843,7 @@ class NativeListView(
|
|
|
1490
1843
|
return false
|
|
1491
1844
|
}
|
|
1492
1845
|
|
|
1493
|
-
private fun handleBindingInvalidated(row:
|
|
1846
|
+
private fun handleBindingInvalidated(row: NativeListRowHost, epoch: Long) {
|
|
1494
1847
|
val anchor = actionAnchor ?: return
|
|
1495
1848
|
if (anchor.ownerRowView.get() === row && anchor.bindingEpoch == epoch) {
|
|
1496
1849
|
invalidateActionAnchor("rebind")
|
|
@@ -1712,6 +2065,7 @@ class NativeListView(
|
|
|
1712
2065
|
}
|
|
1713
2066
|
|
|
1714
2067
|
override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
|
|
2068
|
+
if (viewHolder !is NativeListViewHolder) return makeMovementFlags(0, 0)
|
|
1715
2069
|
val item = adapter.itemAt(viewHolder.bindingAdapterPosition)
|
|
1716
2070
|
if (item == null || !item.isReorderable) return makeMovementFlags(0, 0)
|
|
1717
2071
|
val dragFlags = if (next.orientation == "horizontal") ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT else ItemTouchHelper.UP or ItemTouchHelper.DOWN
|
|
@@ -1723,6 +2077,7 @@ class NativeListView(
|
|
|
1723
2077
|
source: RecyclerView.ViewHolder,
|
|
1724
2078
|
target: RecyclerView.ViewHolder,
|
|
1725
2079
|
): Boolean {
|
|
2080
|
+
if (source !is NativeListViewHolder || target !is NativeListViewHolder) return false
|
|
1726
2081
|
val from = source.bindingAdapterPosition
|
|
1727
2082
|
val to = target.bindingAdapterPosition
|
|
1728
2083
|
val base = pendingReorder ?: adapter.currentList
|
|
@@ -1934,7 +2289,7 @@ class NativeListView(
|
|
|
1934
2289
|
?.takeIf { it != RecyclerView.NO_POSITION }
|
|
1935
2290
|
?: destinationPosition
|
|
1936
2291
|
val destinationRow = recyclerView
|
|
1937
|
-
.findViewHolderForAdapterPosition(resolvedPosition)
|
|
2292
|
+
.findViewHolderForAdapterPosition(scrollPositionForRow(resolvedPosition))
|
|
1938
2293
|
?.let { it as? NativeListViewHolder }
|
|
1939
2294
|
?.rowView
|
|
1940
2295
|
val groupRow = destinationRow?.takeIf {
|
|
@@ -2021,6 +2376,8 @@ class NativeListView(
|
|
|
2021
2376
|
val child = recyclerView.findChildViewUnder(event.x, event.y)
|
|
2022
2377
|
candidate = child
|
|
2023
2378
|
?.let(recyclerView::getChildViewHolder)
|
|
2379
|
+
// Container-slot holders report binding position 0 in their own adapter.
|
|
2380
|
+
?.takeIf { holder -> holder is NativeListViewHolder && holder.bindingAdapter === adapter }
|
|
2024
2381
|
?.takeIf { holder ->
|
|
2025
2382
|
adapter.itemAt(holder.bindingAdapterPosition)?.let { item ->
|
|
2026
2383
|
// OneKey patch: any wallet group member can initiate the group drag.
|
|
@@ -2097,8 +2454,20 @@ class NativeListView(
|
|
|
2097
2454
|
Choreographer.getInstance().postFrameCallback {
|
|
2098
2455
|
visibleEventScheduled = false
|
|
2099
2456
|
val manager = recyclerView.layoutManager as? LinearLayoutManager ?: return@postFrameCallback
|
|
2100
|
-
val
|
|
2101
|
-
|
|
2457
|
+
val visibleRows = (0 until recyclerView.childCount).mapNotNull { index ->
|
|
2458
|
+
val child = recyclerView.getChildAt(index)
|
|
2459
|
+
val holder = recyclerView.getChildViewHolder(child) as? NativeListViewHolder ?: return@mapNotNull null
|
|
2460
|
+
val visible = if (manager.orientation == RecyclerView.VERTICAL) {
|
|
2461
|
+
manager.getDecoratedBottom(child) > recyclerView.paddingTop &&
|
|
2462
|
+
manager.getDecoratedTop(child) < recyclerView.height - recyclerView.paddingBottom
|
|
2463
|
+
} else {
|
|
2464
|
+
manager.getDecoratedRight(child) > recyclerView.paddingLeft &&
|
|
2465
|
+
manager.getDecoratedLeft(child) < recyclerView.width - recyclerView.paddingRight
|
|
2466
|
+
}
|
|
2467
|
+
holder.bindingAdapterPosition.takeIf { visible && it != RecyclerView.NO_POSITION }
|
|
2468
|
+
}
|
|
2469
|
+
val first = visibleRows.minOrNull() ?: RecyclerView.NO_POSITION
|
|
2470
|
+
val last = visibleRows.maxOrNull() ?: RecyclerView.NO_POSITION
|
|
2102
2471
|
val firstKey = adapter.itemAt(first)?.key
|
|
2103
2472
|
val lastKey = adapter.itemAt(last)?.key
|
|
2104
2473
|
val signature = "$first:$last:${firstKey.orEmpty()}:${lastKey.orEmpty()}"
|
|
@@ -2117,7 +2486,7 @@ class NativeListView(
|
|
|
2117
2486
|
val current = config ?: return
|
|
2118
2487
|
if (!current.loadMore || current.generation == endReachedGeneration || adapter.itemCount == 0) return
|
|
2119
2488
|
val manager = recyclerView.layoutManager as? LinearLayoutManager ?: return
|
|
2120
|
-
val lastVisible = manager.findLastVisibleItemPosition()
|
|
2489
|
+
val lastVisible = rowPositionForScroll(manager.findLastVisibleItemPosition())
|
|
2121
2490
|
val thresholdItems = max(1, ceil(adapter.itemCount * current.endReachedThreshold).toInt())
|
|
2122
2491
|
if (lastVisible >= adapter.itemCount - thresholdItems) {
|
|
2123
2492
|
endReachedGeneration = current.generation
|
|
@@ -2157,7 +2526,7 @@ class NativeListView(
|
|
|
2157
2526
|
adapter.currentList.indexOfFirst { it.key == currentAnchor.key }
|
|
2158
2527
|
} ?: RecyclerView.NO_POSITION
|
|
2159
2528
|
if (anchor != null && anchorIndex >= 0) {
|
|
2160
|
-
layoutManager.scrollToPositionWithOffset(anchorIndex, anchor.offset)
|
|
2529
|
+
layoutManager.scrollToPositionWithOffset(scrollPositionForRow(anchorIndex), anchor.offset)
|
|
2161
2530
|
}
|
|
2162
2531
|
forceLayout()
|
|
2163
2532
|
measure(
|
|
@@ -2319,7 +2688,11 @@ private class ReorderPlaceholderDecoration(
|
|
|
2319
2688
|
val isWalletSidebar =
|
|
2320
2689
|
item.type == "identity" && item.json.optString("presentation") == "walletSidebar"
|
|
2321
2690
|
if (!isWalletSidebar && item.type != "walletGroup") return
|
|
2322
|
-
val view = parent.
|
|
2691
|
+
val view = (0 until parent.childCount).asSequence().map(parent::getChildAt)
|
|
2692
|
+
.firstOrNull { child ->
|
|
2693
|
+
val holder = parent.getChildViewHolder(child)
|
|
2694
|
+
holder is NativeListViewHolder && holder.bindingAdapterPosition == position
|
|
2695
|
+
} ?: return
|
|
2323
2696
|
bounds.set(
|
|
2324
2697
|
(view.left + insetPx).toFloat(),
|
|
2325
2698
|
view.top.toFloat(),
|
|
@@ -2590,112 +2963,40 @@ private class ItemSpacingDecoration(
|
|
|
2590
2963
|
parent: RecyclerView,
|
|
2591
2964
|
state: RecyclerView.State,
|
|
2592
2965
|
) {
|
|
2593
|
-
if (spacing <= 0) return
|
|
2966
|
+
if (spacing <= 0 || parent.getChildViewHolder(view) !is NativeListViewHolder) return
|
|
2594
2967
|
val horizontal = (parent.layoutManager as? LinearLayoutManager)?.orientation == RecyclerView.HORIZONTAL
|
|
2595
2968
|
val item = view.tag as? NativeListItem
|
|
2596
|
-
val sourceWallet = item?.type == "identity" && item.json.optString("presentation") == "walletSidebar" && item.
|
|
2969
|
+
val sourceWallet = item?.type == "identity" && item.json.optString("presentation") == "walletSidebar" && item.hasExplicitHeight
|
|
2597
2970
|
// OneKey patch: V1 measures the wallet and its bottom padding as one sortable row.
|
|
2598
2971
|
val itemSpacing = if (!horizontal && sourceWallet) {
|
|
2599
|
-
val sourceHeight = item!!.json.
|
|
2972
|
+
val sourceHeight = item!!.styledHeight ?: item.json.optDouble("height")
|
|
2600
2973
|
((sourceHeight + sourceSpacing) * density).roundToInt() - (sourceHeight * density).roundToInt()
|
|
2601
2974
|
} else spacing
|
|
2602
2975
|
if (horizontal) outRect.right = itemSpacing else outRect.bottom = itemSpacing
|
|
2603
2976
|
}
|
|
2604
2977
|
}
|
|
2605
2978
|
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
) : RecyclerView.ItemDecoration() {
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
val manager = parent.layoutManager as? LinearLayoutManager ?: return
|
|
2623
|
-
val first = manager.findFirstVisibleItemPosition()
|
|
2624
|
-
if (first == RecyclerView.NO_POSITION) return
|
|
2625
|
-
var header: NativeListItem? = null
|
|
2626
|
-
for (index in first downTo 0) {
|
|
2627
|
-
val candidate = adapter.itemAt(index)
|
|
2628
|
-
if (candidate?.type == "sectionHeader") {
|
|
2629
|
-
if (candidate.json.optString("variant") == "summary" || !candidate.json.optBoolean("sticky", true)) continue
|
|
2630
|
-
header = candidate.takeIf(::isSimpleStickySectionHeader)
|
|
2631
|
-
break
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2634
|
-
val item = header ?: return
|
|
2635
|
-
// OneKey patch: a pinned selector heading must use the same text rasterization as its row.
|
|
2636
|
-
textPaint.flags = if (item.usesSelectorSourceScale) Paint.ANTI_ALIAS_FLAG or Paint.SUBPIXEL_TEXT_FLAG or Paint.LINEAR_TEXT_FLAG else Paint.ANTI_ALIAS_FLAG
|
|
2637
|
-
val isHistory = item.json.optString("variant") == "history" ||
|
|
2638
|
-
item.sectionKey?.startsWith("history-") == true
|
|
2639
|
-
val sourceHeight = item.json.optInt("height", 36) * density
|
|
2640
|
-
val height = if (item.usesSelectorSourceScale) {
|
|
2641
|
-
if (item.json.optString("heightRounding") == "nearest") sourceHeight.roundToInt() else sourceHeight.toInt()
|
|
2642
|
-
} else NativeListScale.dp(context.resources, if (isHistory) 16 else 36)
|
|
2643
|
-
val textSize = if (item.usesSelectorSourceScale) 14f else NativeListScale.font(context.resources, if (isHistory) 12f else 14f)
|
|
2644
|
-
textPaint.textSize = if (item.usesSelectorSourceScale) kotlin.math.ceil((textSize * density).toDouble()).toFloat() else textSize * density
|
|
2645
|
-
val horizontalInset = if (item.usesSelectorSourceScale) ((20 * density).toInt() - parent.paddingLeft).toFloat() else NativeListScale.dp(context.resources, if (isHistory) 8 else 20).toFloat()
|
|
2646
|
-
val left = parent.paddingLeft.toFloat()
|
|
2647
|
-
val right = (parent.width - parent.paddingRight).toFloat()
|
|
2648
|
-
canvas.drawRect(left, 0f, right, height.toFloat(), backgroundPaint)
|
|
2649
|
-
val baseline = if (item.usesSelectorSourceScale) {
|
|
2650
|
-
val metrics = textPaint.fontMetricsInt
|
|
2651
|
-
val lineHeight = kotlin.math.ceil(20 * density.toDouble()).toInt()
|
|
2652
|
-
val leading = lineHeight - (metrics.descent - metrics.ascent)
|
|
2653
|
-
(height - lineHeight) / 2 - metrics.ascent + kotlin.math.ceil(leading / 2.0).toFloat()
|
|
2654
|
-
} else height / 2f - (textPaint.descent() + textPaint.ascent()) / 2f
|
|
2655
|
-
val value = item.json.optString("title").let { if (isHistory) it.uppercase() else it }
|
|
2656
|
-
val isRightToLeft = parent.layoutDirection == View.LAYOUT_DIRECTION_RTL
|
|
2657
|
-
val textWidth = if (isHistory) {
|
|
2658
|
-
spacedTextWidth(value, NativeListScale.dp(context.resources, 1).toFloat())
|
|
2659
|
-
} else {
|
|
2660
|
-
textPaint.measureText(value)
|
|
2661
|
-
}
|
|
2662
|
-
val x = if (isRightToLeft) right - horizontalInset - textWidth else left + horizontalInset
|
|
2663
|
-
if (isHistory) {
|
|
2664
|
-
drawSpacedText(canvas, value, x, baseline, NativeListScale.dp(context.resources, 1).toFloat())
|
|
2665
|
-
} else {
|
|
2666
|
-
canvas.drawText(value, x, baseline, textPaint)
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
private fun drawSpacedText(canvas: Canvas, value: String, x: Float, baseline: Float, spacing: Float) {
|
|
2671
|
-
var cursor = x
|
|
2672
|
-
value.forEachIndexed { index, character ->
|
|
2673
|
-
val glyph = character.toString()
|
|
2674
|
-
canvas.drawText(glyph, cursor, baseline, textPaint)
|
|
2675
|
-
cursor += textPaint.measureText(glyph)
|
|
2676
|
-
if (index < value.lastIndex) cursor += spacing * 0.8f
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
|
|
2680
|
-
private fun spacedTextWidth(value: String, spacing: Float): Float =
|
|
2681
|
-
value.sumOf { textPaint.measureText(it.toString()).toDouble() }.toFloat() +
|
|
2682
|
-
max(0, value.length - 1) * spacing * 0.8f
|
|
2683
|
-
|
|
2684
|
-
companion object {
|
|
2685
|
-
private fun parseColor(value: String?, fallback: String): Int = try {
|
|
2686
|
-
parseNativeListColor(if (value.isNullOrEmpty()) fallback else value)
|
|
2687
|
-
} catch (_: IllegalArgumentException) {
|
|
2688
|
-
parseNativeListColor(fallback)
|
|
2689
|
-
}
|
|
2979
|
+
/**
|
|
2980
|
+
* React lays out slot content at `contentPaddingHorizontal ?? contentPadding` logical units
|
|
2981
|
+
* from each edge. Row padding may be scaled or widened by the section-index gutter, so slot
|
|
2982
|
+
* holders offset themselves (possibly negatively) back to the JavaScript inset.
|
|
2983
|
+
*/
|
|
2984
|
+
private class ContainerSlotInsetDecoration(private val insetPx: () -> Int) : RecyclerView.ItemDecoration() {
|
|
2985
|
+
override fun getItemOffsets(
|
|
2986
|
+
outRect: android.graphics.Rect,
|
|
2987
|
+
view: View,
|
|
2988
|
+
parent: RecyclerView,
|
|
2989
|
+
state: RecyclerView.State,
|
|
2990
|
+
) {
|
|
2991
|
+
if (parent.getChildViewHolder(view) !is NativeListContainerSlotAdapter.Holder) return
|
|
2992
|
+
val inset = insetPx()
|
|
2993
|
+
outRect.left = inset - parent.paddingLeft
|
|
2994
|
+
outRect.right = inset - parent.paddingRight
|
|
2690
2995
|
}
|
|
2691
2996
|
}
|
|
2692
2997
|
|
|
2693
|
-
internal fun
|
|
2694
|
-
item.type == "sectionHeader" &&
|
|
2695
|
-
item.json.optBoolean("sticky", true) &&
|
|
2696
|
-
item.json.optString("variant") != "summary" &&
|
|
2697
|
-
item.json.optString("value").isEmpty() &&
|
|
2698
|
-
item.json.optJSONObject("checkbox") == null
|
|
2998
|
+
internal fun isStickySectionHeader(item: NativeListItem): Boolean =
|
|
2999
|
+
item.type == "sectionHeader" && item.json.optBoolean("sticky", true) && item.json.optString("variant") != "summary"
|
|
2699
3000
|
|
|
2700
3001
|
// OneKey patch: paint only explicitly requested backgrounds into list side padding.
|
|
2701
3002
|
private class SelectorBackgroundDecoration(private val adapter: NativeListAdapter) : RecyclerView.ItemDecoration() {
|
|
@@ -2703,11 +3004,18 @@ private class SelectorBackgroundDecoration(private val adapter: NativeListAdapte
|
|
|
2703
3004
|
override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
|
2704
3005
|
for (index in 0 until parent.childCount) {
|
|
2705
3006
|
val child = parent.getChildAt(index)
|
|
2706
|
-
val item = adapter.itemAt(parent.
|
|
3007
|
+
val item = adapter.itemAt(parent.getChildViewHolder(child).takeIf { it is NativeListViewHolder }?.bindingAdapterPosition ?: RecyclerView.NO_POSITION) ?: continue
|
|
2707
3008
|
if (!item.json.optBoolean("backgroundFullWidth", false)) continue
|
|
2708
|
-
val color =
|
|
2709
|
-
|
|
3009
|
+
val color = resolveNativeListSelectorBackgroundColor(
|
|
3010
|
+
rowType = item.type,
|
|
3011
|
+
styleBackgroundColor = item.json.optJSONObject("style")
|
|
3012
|
+
?.optJSONObject("container")
|
|
3013
|
+
?.optString("backgroundColor"),
|
|
3014
|
+
rowBackgroundColor = item.json.optString("backgroundColor"),
|
|
3015
|
+
) ?: continue
|
|
2710
3016
|
paint.color = try { parseNativeListColor(color) } catch (_: IllegalArgumentException) { Color.TRANSPARENT }
|
|
3017
|
+
val opacity = item.json.optJSONObject("style")?.optJSONObject("container")?.optDouble("opacity", item.json.optDouble("opacity", 1.0)) ?: item.json.optDouble("opacity", 1.0)
|
|
3018
|
+
paint.alpha = (Color.alpha(paint.color) * opacity * (if (item.json.optBoolean("disabled", false)) 0.5 else 1.0)).toInt()
|
|
2711
3019
|
val top = child.y
|
|
2712
3020
|
canvas.drawRect(0f, top, parent.width.toFloat(), top + child.height, paint)
|
|
2713
3021
|
if (item.type == "system" && item.json.optString("variant") == "warning") {
|