@onekeyfe/react-native-native-list 6.7.0-alpha.343 → 6.7.0-alpha.354
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 +7 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -3
- 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 +87 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +135 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +43 -14
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +17 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +22 -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 +585 -21
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
- package/docs/ROW_TEMPLATES.md +60 -9
- package/docs/SPEC.md +361 -8
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +10 -0
- package/ios/NativeListAccessoryStack.swift +220 -37
- package/ios/NativeListActivityDetailsView.swift +18 -8
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +105 -8
- package/ios/NativeListDesignAssets.swift +3 -0
- package/ios/NativeListIdentityRenderer.swift +119 -4
- package/ios/NativeListLeadingVisual.swift +49 -14
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListModels.swift +16 -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 +331 -29
- 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_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_refresh_ccw_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
- package/ios/tests/NativeListLifecycleTests.swift +890 -3
- package/lib/module/NativeList.js +64 -27
- package/lib/module/NativeList.web.js +84 -17
- package/lib/module/models.js +1 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +532 -18
- package/lib/module/web/NativeListWebEngine.js +391 -24
- package/lib/module/web/templates/ActivityRowRenderer.js +8 -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 +90 -4
- 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 +3 -0
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
- package/lib/typescript/src/NativeList.types.d.ts +8 -0
- package/lib/typescript/src/models.d.ts +101 -9
- package/lib/typescript/src/validation.d.ts +13 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -0
- 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/MessageRowRenderer.d.ts +9 -3
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/package.json +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +1 -0
- package/src/NativeList.tsx +155 -69
- package/src/NativeList.types.ts +9 -0
- package/src/NativeList.web.tsx +159 -49
- package/src/models.ts +113 -3
- package/src/selection.ts +1 -0
- package/src/validation.ts +1156 -18
- package/src/web/NativeListWebEngine.ts +594 -28
- package/src/web/templates/ActivityRowRenderer.ts +14 -6
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +150 -5
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +11 -1
- package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
package com.margelo.nitro.nativelist
|
|
2
2
|
|
|
3
3
|
import android.animation.TimeInterpolator
|
|
4
|
+
import android.animation.ValueAnimator
|
|
5
|
+
import android.animation.Animator
|
|
6
|
+
import android.animation.AnimatorListenerAdapter
|
|
4
7
|
import android.content.Context
|
|
5
8
|
import android.graphics.Canvas
|
|
6
9
|
import android.graphics.Color
|
|
@@ -11,6 +14,7 @@ import android.graphics.RectF
|
|
|
11
14
|
import android.graphics.drawable.ShapeDrawable
|
|
12
15
|
import android.graphics.drawable.shapes.PathShape
|
|
13
16
|
import android.os.Bundle
|
|
17
|
+
import android.os.Build
|
|
14
18
|
import android.os.Handler
|
|
15
19
|
import android.os.Looper
|
|
16
20
|
import android.os.SystemClock
|
|
@@ -32,6 +36,7 @@ import android.widget.TextView
|
|
|
32
36
|
import androidx.core.view.ViewCompat
|
|
33
37
|
import androidx.core.view.WindowInsetsCompat
|
|
34
38
|
import androidx.recyclerview.widget.ConcatAdapter
|
|
39
|
+
import androidx.recyclerview.widget.DefaultItemAnimator
|
|
35
40
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
36
41
|
import androidx.recyclerview.widget.ItemTouchHelper
|
|
37
42
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
@@ -203,24 +208,129 @@ class NativeListView(
|
|
|
203
208
|
var keyboardDismissMode = NativeListKeyboardDismissMode.NONE
|
|
204
209
|
var keyboardShouldPersistTaps = NativeListKeyboardShouldPersistTaps.NEVER
|
|
205
210
|
private val density = resources.displayMetrics.density
|
|
206
|
-
private val recyclerView = RecyclerView(context)
|
|
211
|
+
private val recyclerView = object : RecyclerView(context) {
|
|
212
|
+
override fun onMeasure(widthSpec: Int, heightSpec: Int) {
|
|
213
|
+
if (isLayoutSuppressed) {
|
|
214
|
+
setMeasuredDimension(measuredWidth, measuredHeight)
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
super.onMeasure(widthSpec, heightSpec)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
|
221
|
+
if (isLayoutSuppressed) return
|
|
222
|
+
super.onLayout(changed, left, top, right, bottom)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
207
225
|
private var configuredTopPaddingPx = 0
|
|
208
226
|
private var slotInsetPx = 0
|
|
227
|
+
private var slotRightInsetPx = 0
|
|
209
228
|
private var configuredBottomPaddingPx = 0
|
|
229
|
+
private data class SidecarLayout(val width: Int, val gap: Int, val maxContentWidth: Int)
|
|
230
|
+
private var sidecarLayout: SidecarLayout? = null
|
|
231
|
+
private var sidecarSpacerHeightPx = 0
|
|
232
|
+
private var sidecarSpacerScheduled = false
|
|
233
|
+
private var consumedStructuralTransitionId: String? = null
|
|
234
|
+
private var structuralAnimator: ValueAnimator? = null
|
|
235
|
+
private var structuralSpacerHeightPx = 0
|
|
236
|
+
private var structuralStartSpacerPx = 0
|
|
237
|
+
private var structuralFooterVisualStartTop: Int? = null
|
|
238
|
+
private var structuralFooterVisualEndTop: Int? = null
|
|
239
|
+
private var structuralFooterVisualProgress = 0f
|
|
240
|
+
private var structuralFooterCompensatedHeightPx: Int? = null
|
|
241
|
+
private var structuralScrollInterrupted = false
|
|
242
|
+
private var structuralFooterHoldTop: Int? = null
|
|
243
|
+
private var structuralTransitionEpoch = 0
|
|
244
|
+
private data class PendingStructuralTransition(
|
|
245
|
+
val transition: NativeListConfig.StructuralTransition,
|
|
246
|
+
val epoch: Int,
|
|
247
|
+
val anchorKey: String?,
|
|
248
|
+
val anchorTop: Int?,
|
|
249
|
+
val footerStartTop: Int?,
|
|
250
|
+
val heldHeightPx: Int,
|
|
251
|
+
val collapsing: Boolean,
|
|
252
|
+
val spacerInserted: Boolean = false,
|
|
253
|
+
val footerAnchorAppliedTop: Int? = null,
|
|
254
|
+
val rowAnchorAppliedTop: Int? = null,
|
|
255
|
+
)
|
|
256
|
+
private var pendingStructuralTransition: PendingStructuralTransition? = null
|
|
257
|
+
private var pendingStructuralStartScheduled = false
|
|
210
258
|
private val refreshLayout = SwipeRefreshLayout(context)
|
|
211
259
|
private val refreshIndicatorTravelPx = refreshLayout.progressViewEndOffset
|
|
212
260
|
private val defaultRefreshTriggerDistancePx = (64 * resources.displayMetrics.density).roundToInt()
|
|
213
261
|
private var refreshIndicatorOffsetPx = 0
|
|
214
262
|
private val contentContainer = FrameLayout(context)
|
|
263
|
+
private val sidecarHost = object : FrameLayout(context) {
|
|
264
|
+
private val touchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
|
265
|
+
private var down: MotionEvent? = null
|
|
266
|
+
private var routing = false
|
|
267
|
+
|
|
268
|
+
private fun route(event: MotionEvent) {
|
|
269
|
+
val copy = MotionEvent.obtain(event)
|
|
270
|
+
copy.offsetLocation(x - refreshLayout.x, y - refreshLayout.y)
|
|
271
|
+
refreshLayout.dispatchTouchEvent(copy)
|
|
272
|
+
copy.recycle()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
|
276
|
+
when (event.actionMasked) {
|
|
277
|
+
MotionEvent.ACTION_DOWN -> {
|
|
278
|
+
down?.recycle()
|
|
279
|
+
down = MotionEvent.obtain(event)
|
|
280
|
+
routing = false
|
|
281
|
+
}
|
|
282
|
+
MotionEvent.ACTION_MOVE -> {
|
|
283
|
+
if (routing) {
|
|
284
|
+
route(event)
|
|
285
|
+
return true
|
|
286
|
+
}
|
|
287
|
+
val start = down
|
|
288
|
+
if (start != null && abs(event.y - start.y) > touchSlop &&
|
|
289
|
+
abs(event.y - start.y) > abs(event.x - start.x)) {
|
|
290
|
+
val cancel = MotionEvent.obtain(event)
|
|
291
|
+
cancel.action = MotionEvent.ACTION_CANCEL
|
|
292
|
+
super.dispatchTouchEvent(cancel)
|
|
293
|
+
cancel.recycle()
|
|
294
|
+
route(start)
|
|
295
|
+
route(event)
|
|
296
|
+
routing = true
|
|
297
|
+
return true
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
|
|
301
|
+
if (routing) route(event)
|
|
302
|
+
down?.recycle()
|
|
303
|
+
down = null
|
|
304
|
+
if (routing) {
|
|
305
|
+
routing = false
|
|
306
|
+
return true
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else -> if (routing) {
|
|
310
|
+
route(event)
|
|
311
|
+
return true
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return super.dispatchTouchEvent(event)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
215
317
|
private val adapter = NativeListAdapter(reactContext, fonts)
|
|
216
318
|
private val containerSlots = mutableListOf<View>()
|
|
217
|
-
private val slotHeights = IntArray(
|
|
319
|
+
private val slotHeights = IntArray(4)
|
|
320
|
+
private var initialHeaderInsertionHandled = false
|
|
218
321
|
private var containerSlotRelayoutPending = false
|
|
219
322
|
private var containerSlotRelayoutScheduled = false
|
|
220
323
|
private val headerSlotAdapter = NativeListContainerSlotAdapter()
|
|
221
324
|
private val emptySlotAdapter = NativeListContainerSlotAdapter()
|
|
325
|
+
private val structuralSpacerView = View(context)
|
|
326
|
+
private val structuralSpacerAdapter = NativeListContainerSlotAdapter()
|
|
222
327
|
private val footerSlotAdapter = NativeListContainerSlotAdapter()
|
|
223
|
-
private val
|
|
328
|
+
private val sidecarSpacerView = View(context)
|
|
329
|
+
private val sidecarSpacerAdapter = NativeListContainerSlotAdapter()
|
|
330
|
+
private val scrollContentAdapter = ConcatAdapter(
|
|
331
|
+
headerSlotAdapter, adapter, emptySlotAdapter, structuralSpacerAdapter,
|
|
332
|
+
footerSlotAdapter, sidecarSpacerAdapter,
|
|
333
|
+
)
|
|
224
334
|
|
|
225
335
|
private val homeOffsetDiagnosticEnabled =
|
|
226
336
|
context.applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE != 0
|
|
@@ -238,7 +348,8 @@ class NativeListView(
|
|
|
238
348
|
headerSlotAdapter -> 0
|
|
239
349
|
adapter -> 1
|
|
240
350
|
emptySlotAdapter -> 2
|
|
241
|
-
|
|
351
|
+
structuralSpacerAdapter -> 3
|
|
352
|
+
footerSlotAdapter -> 4
|
|
242
353
|
else -> -1
|
|
243
354
|
}
|
|
244
355
|
val focused = recyclerView.findFocus()
|
|
@@ -248,7 +359,7 @@ class NativeListView(
|
|
|
248
359
|
"seq=${++homeOffsetDiagnosticSequence} wallMs=${System.currentTimeMillis()} monoMs=${SystemClock.uptimeMillis()} " +
|
|
249
360
|
"list=${System.identityHashCode(this)} view=${System.identityHashCode(recyclerView)} tag=$id " +
|
|
250
361
|
"generation=${config?.generation} configuredCount=${config?.items?.size} " +
|
|
251
|
-
"counts=${headerSlotAdapter.itemCount},${adapter.itemCount},${emptySlotAdapter.itemCount},${footerSlotAdapter.itemCount} " +
|
|
362
|
+
"counts=${headerSlotAdapter.itemCount},${adapter.itemCount},${emptySlotAdapter.itemCount},${structuralSpacerAdapter.itemCount},${footerSlotAdapter.itemCount} " +
|
|
252
363
|
"total=${scrollContentAdapter.itemCount} pendingCommand=${pendingScrollRequest?.javaClass?.simpleName ?: "none"} " +
|
|
253
364
|
"stateCount=${state?.itemCount} preLayout=${state?.isPreLayout} structureChanged=${state?.didStructureChange()} predictive=${state?.willRunPredictiveAnimations()} " +
|
|
254
365
|
"first=$first last=${layoutManager.findLastVisibleItemPosition()} " +
|
|
@@ -279,21 +390,143 @@ class NativeListView(
|
|
|
279
390
|
|
|
280
391
|
fun setContainerSlotHeightsJson(json: String) {
|
|
281
392
|
val values = runCatching { JSONArray(json) }.getOrNull() ?: return
|
|
282
|
-
if (values.length() !=
|
|
283
|
-
for (index in 0..
|
|
393
|
+
if (values.length() != 4) return
|
|
394
|
+
for (index in 0..3) {
|
|
284
395
|
val value = values.optDouble(index)
|
|
285
396
|
if (!value.isFinite() || value < 0) return
|
|
286
397
|
}
|
|
398
|
+
reconcileStructuralFooterHeight((values.getDouble(2) * density).roundToInt())
|
|
287
399
|
var changed = false
|
|
288
|
-
for (index in 0..
|
|
400
|
+
for (index in 0..3) {
|
|
289
401
|
val height = (values.getDouble(index) * density).roundToInt()
|
|
290
402
|
if (slotHeights[index] != height) changed = true
|
|
291
403
|
slotHeights[index] = height
|
|
292
404
|
}
|
|
293
405
|
updateContainerSlots()
|
|
406
|
+
updateSidecarGeometry()
|
|
407
|
+
scheduleSidecarSpacer()
|
|
294
408
|
if (changed) scheduleContainerSlotRelayout()
|
|
295
409
|
}
|
|
296
410
|
|
|
411
|
+
private fun reconcileStructuralFooterHeight(nextHeightPx: Int) {
|
|
412
|
+
val previousHeightPx = structuralFooterCompensatedHeightPx ?: slotHeights[2]
|
|
413
|
+
val footerDelta = previousHeightPx - nextHeightPx
|
|
414
|
+
if (footerDelta == 0) return
|
|
415
|
+
if (pendingStructuralTransition != null || structuralAnimator != null || structuralFooterHoldTop != null) {
|
|
416
|
+
structuralFooterCompensatedHeightPx = nextHeightPx
|
|
417
|
+
}
|
|
418
|
+
if (pendingStructuralTransition != null) {
|
|
419
|
+
pendingStructuralTransition = pendingStructuralTransition?.let {
|
|
420
|
+
val updated = it.copy(
|
|
421
|
+
footerStartTop = it.footerStartTop?.plus(footerDelta),
|
|
422
|
+
heldHeightPx = (it.heldHeightPx + footerDelta).coerceAtLeast(0),
|
|
423
|
+
)
|
|
424
|
+
if (updated.spacerInserted) setStructuralSpacerHeight(updated.heldHeightPx)
|
|
425
|
+
updated
|
|
426
|
+
}
|
|
427
|
+
structuralFooterHoldTop = structuralFooterHoldTop?.plus(footerDelta)
|
|
428
|
+
updateStructuralFooterHoldPosition()
|
|
429
|
+
} else if (structuralFooterHoldTop != null && structuralAnimator == null) {
|
|
430
|
+
setStructuralSpacerHeight(structuralSpacerHeightPx + footerDelta)
|
|
431
|
+
structuralFooterHoldTop = structuralFooterHoldTop?.plus(footerDelta)
|
|
432
|
+
updateStructuralFooterHoldPosition()
|
|
433
|
+
} else if (structuralAnimator != null) {
|
|
434
|
+
structuralStartSpacerPx = (structuralStartSpacerPx + footerDelta).coerceAtLeast(0)
|
|
435
|
+
structuralFooterVisualStartTop = structuralFooterVisualStartTop?.plus(footerDelta)
|
|
436
|
+
val fraction = (structuralAnimator?.animatedValue as? Float) ?: 0f
|
|
437
|
+
setStructuralSpacerHeight((structuralStartSpacerPx * (1f - fraction)).roundToInt())
|
|
438
|
+
updateStructuralFooterVisualPosition()
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
fun setSidecarLayoutJson(json: String) {
|
|
443
|
+
val next = if (json.isEmpty()) null else {
|
|
444
|
+
val value = runCatching { JSONObject(json) }.getOrNull() ?: return
|
|
445
|
+
val width = value.optDouble("width")
|
|
446
|
+
val gap = value.optDouble("gap")
|
|
447
|
+
val maxWidth = value.optDouble("maxContentWidth")
|
|
448
|
+
if (!width.isFinite() || width <= 0 || !gap.isFinite() || gap < 0 ||
|
|
449
|
+
!maxWidth.isFinite() || maxWidth <= width + gap) return
|
|
450
|
+
SidecarLayout((width * density).roundToInt(), (gap * density).roundToInt(),
|
|
451
|
+
(maxWidth * density).roundToInt())
|
|
452
|
+
}
|
|
453
|
+
if (next == sidecarLayout) return
|
|
454
|
+
sidecarLayout = next
|
|
455
|
+
config?.let(::updateLayout)
|
|
456
|
+
updateSidecarGeometry()
|
|
457
|
+
scheduleSidecarSpacer()
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
private fun sidecarBaseInsetPx(): Int {
|
|
461
|
+
val layout = sidecarLayout ?: return 0
|
|
462
|
+
val width = recyclerView.width
|
|
463
|
+
return max(0, (width - minOf(width, layout.maxContentWidth)) / 2)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
private fun updateSidecarGeometry() {
|
|
467
|
+
val layout = sidecarLayout
|
|
468
|
+
val root = containerSlots.getOrNull(3)
|
|
469
|
+
if (root !== sidecarHost.getChildAt(0)) {
|
|
470
|
+
sidecarHost.removeAllViews()
|
|
471
|
+
(root?.parent as? ViewGroup)?.removeView(root)
|
|
472
|
+
if (root != null) sidecarHost.addView(root)
|
|
473
|
+
}
|
|
474
|
+
val params = sidecarHost.layoutParams as? FrameLayout.LayoutParams
|
|
475
|
+
?: FrameLayout.LayoutParams(0, 0, Gravity.TOP or Gravity.RIGHT)
|
|
476
|
+
val nextWidth = layout?.width ?: 0
|
|
477
|
+
val nextHeight = if (layout != null) slotHeights[3] else 0
|
|
478
|
+
val isRtl = layoutDirection == LAYOUT_DIRECTION_RTL
|
|
479
|
+
val nextGravity = Gravity.TOP or (if (isRtl) Gravity.LEFT else Gravity.RIGHT)
|
|
480
|
+
val nextSideMargin = sidecarBaseInsetPx()
|
|
481
|
+
if (params.width != nextWidth || params.height != nextHeight ||
|
|
482
|
+
params.gravity != nextGravity ||
|
|
483
|
+
params.leftMargin != (if (isRtl) nextSideMargin else 0) ||
|
|
484
|
+
params.rightMargin != (if (isRtl) 0 else nextSideMargin)) {
|
|
485
|
+
params.width = nextWidth
|
|
486
|
+
params.height = nextHeight
|
|
487
|
+
params.gravity = nextGravity
|
|
488
|
+
params.leftMargin = if (isRtl) nextSideMargin else 0
|
|
489
|
+
params.rightMargin = if (isRtl) 0 else nextSideMargin
|
|
490
|
+
sidecarHost.layoutParams = params
|
|
491
|
+
}
|
|
492
|
+
sidecarHost.visibility = if (layout != null && root != null && slotHeights[3] > 0) VISIBLE else GONE
|
|
493
|
+
updateSidecarPosition()
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private fun updateSidecarPosition(resync: Boolean = false) {
|
|
497
|
+
if (sidecarLayout == null) return
|
|
498
|
+
if (resync) measuredScrollDistancePx()?.let { logicalScrollDistancePx = it }
|
|
499
|
+
sidecarHost.translationY = (recyclerView.paddingTop - logicalScrollDistancePx).toFloat()
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
private fun sidecarLeftExtentPx(): Int =
|
|
503
|
+
(nativeListScrollPrefixPx(
|
|
504
|
+
scrollContentAdapter.itemCount - sidecarSpacerAdapter.itemCount,
|
|
505
|
+
layoutManager.spanCount,
|
|
506
|
+
layoutManager.spanSizeLookup::getSpanSize,
|
|
507
|
+
::estimatedScrollExtentPx,
|
|
508
|
+
) + recyclerView.paddingTop + recyclerView.paddingBottom)
|
|
509
|
+
.coerceIn(0L, Int.MAX_VALUE.toLong()).toInt()
|
|
510
|
+
|
|
511
|
+
private fun scheduleSidecarSpacer() {
|
|
512
|
+
if (sidecarLayout == null && sidecarSpacerHeightPx == 0) return
|
|
513
|
+
if (disposed || sidecarSpacerScheduled) return
|
|
514
|
+
sidecarSpacerScheduled = true
|
|
515
|
+
recyclerView.post {
|
|
516
|
+
sidecarSpacerScheduled = false
|
|
517
|
+
if (disposed || recyclerView.width <= 0 || recyclerView.height <= 0) return@post
|
|
518
|
+
val desired = if (sidecarLayout != null) {
|
|
519
|
+
recyclerView.paddingTop + slotHeights[3] + recyclerView.paddingBottom
|
|
520
|
+
} else 0
|
|
521
|
+
val leftExtent = sidecarLeftExtentPx()
|
|
522
|
+
val next = (desired - leftExtent).coerceAtLeast(0)
|
|
523
|
+
if (abs(next - sidecarSpacerHeightPx) <= 1) return@post
|
|
524
|
+
sidecarSpacerHeightPx = next
|
|
525
|
+
sidecarSpacerAdapter.update(sidecarSpacerView, next, next > 0)
|
|
526
|
+
recyclerView.requestLayout()
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
297
530
|
private fun scheduleContainerSlotRelayout() {
|
|
298
531
|
if (disposed) return
|
|
299
532
|
containerSlotRelayoutPending = true
|
|
@@ -314,9 +547,27 @@ class NativeListView(
|
|
|
314
547
|
|
|
315
548
|
private fun updateContainerSlots() {
|
|
316
549
|
homeOffsetDiagnostic("slots-before")
|
|
550
|
+
val headerWasAbsent = headerSlotAdapter.itemCount == 0
|
|
551
|
+
val firstVisible = layoutManager.findFirstVisibleItemPosition()
|
|
552
|
+
val firstView = layoutManager.findViewByPosition(firstVisible)
|
|
553
|
+
val restoreInitialHeaderTop = !initialHeaderInsertionHandled && headerWasAbsent &&
|
|
554
|
+
layoutManager.orientation == RecyclerView.VERTICAL &&
|
|
555
|
+
adapter.itemCount > 0 && readingIntentEpoch == 0L && pendingScrollRequest == null &&
|
|
556
|
+
acceptedScrollRequest == null && !executingScrollCommand &&
|
|
557
|
+
recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE && firstVisible == 0 &&
|
|
558
|
+
firstView != null && abs(layoutManager.getDecoratedTop(firstView) - recyclerView.paddingTop) <= 1 &&
|
|
559
|
+
!recyclerView.canScrollVertically(-1)
|
|
317
560
|
headerSlotAdapter.update(containerSlots.getOrNull(0), slotHeights[0], true)
|
|
318
561
|
emptySlotAdapter.update(containerSlots.getOrNull(1), slotHeights[1], config?.items?.isEmpty() != false)
|
|
319
562
|
footerSlotAdapter.update(containerSlots.getOrNull(2), slotHeights[2], true)
|
|
563
|
+
updateSidecarGeometry()
|
|
564
|
+
if (headerWasAbsent && headerSlotAdapter.itemCount > 0) {
|
|
565
|
+
initialHeaderInsertionHandled = true
|
|
566
|
+
if (restoreInitialHeaderTop) {
|
|
567
|
+
// RecyclerView otherwise keeps the first body row at the top when this slot arrives late.
|
|
568
|
+
layoutManager.scrollToPositionWithOffset(0, 0)
|
|
569
|
+
}
|
|
570
|
+
}
|
|
320
571
|
homeOffsetDiagnostic("slots-after")
|
|
321
572
|
layoutManager.spanSizeLookup.invalidateSpanIndexCache()
|
|
322
573
|
recyclerView.requestLayout()
|
|
@@ -345,7 +596,13 @@ class NativeListView(
|
|
|
345
596
|
if (position < headerCount) return slotHeights[0]
|
|
346
597
|
val row = position - headerCount
|
|
347
598
|
if (row >= adapter.itemCount) {
|
|
348
|
-
|
|
599
|
+
val slot = row - adapter.itemCount
|
|
600
|
+
return when {
|
|
601
|
+
slot < emptySlotAdapter.itemCount -> slotHeights[1]
|
|
602
|
+
slot < emptySlotAdapter.itemCount + structuralSpacerAdapter.itemCount -> structuralSpacerHeightPx
|
|
603
|
+
slot < emptySlotAdapter.itemCount + structuralSpacerAdapter.itemCount + footerSlotAdapter.itemCount -> slotHeights[2]
|
|
604
|
+
else -> sidecarSpacerHeightPx
|
|
605
|
+
}
|
|
349
606
|
}
|
|
350
607
|
val item = adapter.itemAt(row)
|
|
351
608
|
item?.key?.let(measuredRowExtentsPx::get)?.let { return it }
|
|
@@ -354,6 +611,115 @@ class NativeListView(
|
|
|
354
611
|
return if (measuredRowExtentsPx.isEmpty()) 0 else (measuredRowExtentSumPx / measuredRowExtentsPx.size).toInt()
|
|
355
612
|
}
|
|
356
613
|
|
|
614
|
+
private fun estimatedItemExtentPx(item: NativeListItem): Int {
|
|
615
|
+
measuredRowExtentsPx[item.key]?.let { return it }
|
|
616
|
+
val explicit = item.styledHeight ?: item.json.optDouble("height").takeIf { it.isFinite() }
|
|
617
|
+
if (explicit != null) return (explicit * density).roundToInt()
|
|
618
|
+
return if (measuredRowExtentsPx.isEmpty()) dp(56)
|
|
619
|
+
else (measuredRowExtentSumPx / measuredRowExtentsPx.size).toInt()
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private fun setStructuralSpacerHeight(heightPx: Int) {
|
|
623
|
+
val next = heightPx.coerceAtLeast(0)
|
|
624
|
+
if (next == structuralSpacerHeightPx) return
|
|
625
|
+
structuralSpacerHeightPx = next
|
|
626
|
+
structuralSpacerAdapter.update(structuralSpacerView, next, true)
|
|
627
|
+
layoutManager.spanSizeLookup.invalidateSpanIndexCache()
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
private fun updateStructuralFooterHoldPosition() {
|
|
631
|
+
val targetTop = structuralFooterHoldTop ?: return
|
|
632
|
+
if (footerSlotAdapter.itemCount == 0) return
|
|
633
|
+
val footerPosition = scrollContentAdapter.itemCount - 1 - sidecarSpacerAdapter.itemCount
|
|
634
|
+
layoutManager.findViewByPosition(footerPosition)?.let { footer ->
|
|
635
|
+
footerSlotAdapter.setVisualTranslationY((targetTop - layoutManager.getDecoratedTop(footer)).toFloat())
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
private fun updateStructuralFooterVisualPosition() {
|
|
640
|
+
val startTop = structuralFooterVisualStartTop ?: return
|
|
641
|
+
val endTop = structuralFooterVisualEndTop ?: return
|
|
642
|
+
if (footerSlotAdapter.itemCount == 0) return
|
|
643
|
+
val footerPosition = scrollContentAdapter.itemCount - 1 - sidecarSpacerAdapter.itemCount
|
|
644
|
+
layoutManager.findViewByPosition(footerPosition)?.let { footer ->
|
|
645
|
+
val desiredTop = startTop + (endTop - startTop) * structuralFooterVisualProgress
|
|
646
|
+
footerSlotAdapter.setVisualTranslationY(desiredTop - layoutManager.getDecoratedTop(footer))
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
private fun cancelStructuralTransition() {
|
|
651
|
+
structuralTransitionEpoch += 1
|
|
652
|
+
pendingStructuralTransition = null
|
|
653
|
+
pendingStructuralStartScheduled = false
|
|
654
|
+
structuralAnimator?.cancel()
|
|
655
|
+
structuralAnimator = null
|
|
656
|
+
recyclerView.itemAnimator = null
|
|
657
|
+
setStructuralSpacerHeight(0)
|
|
658
|
+
footerSlotAdapter.setVisualTranslationY(0f)
|
|
659
|
+
structuralFooterHoldTop = null
|
|
660
|
+
structuralFooterVisualStartTop = null
|
|
661
|
+
structuralFooterVisualEndTop = null
|
|
662
|
+
structuralFooterVisualProgress = 0f
|
|
663
|
+
structuralFooterCompensatedHeightPx = null
|
|
664
|
+
structuralStartSpacerPx = 0
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
private fun startPendingStructuralTransition() {
|
|
668
|
+
val pending = pendingStructuralTransition ?: return
|
|
669
|
+
if (pending.epoch != structuralTransitionEpoch || disposed || pendingStructuralStartScheduled) return
|
|
670
|
+
val expected = config?.items?.map { it.key } ?: return
|
|
671
|
+
if (adapter.currentList.map { it.key } != expected) return
|
|
672
|
+
pendingStructuralStartScheduled = true
|
|
673
|
+
recyclerView.postOnAnimation {
|
|
674
|
+
if (pending.epoch != structuralTransitionEpoch) return@postOnAnimation
|
|
675
|
+
pendingStructuralStartScheduled = false
|
|
676
|
+
val latest = pendingStructuralTransition
|
|
677
|
+
if (latest?.epoch == pending.epoch && !disposed) {
|
|
678
|
+
if (recyclerView.isComputingLayout) {
|
|
679
|
+
startPendingStructuralTransition()
|
|
680
|
+
return@postOnAnimation
|
|
681
|
+
}
|
|
682
|
+
alignPendingStructuralAnchor(latest)
|
|
683
|
+
if (latest.anchorTop != null || (latest.collapsing && latest.footerStartTop != null)) {
|
|
684
|
+
relayoutRecyclerViewImmediately()
|
|
685
|
+
}
|
|
686
|
+
pendingStructuralTransition = null
|
|
687
|
+
startStructuralTransition(
|
|
688
|
+
latest.transition, latest.epoch, latest.anchorKey, latest.anchorTop,
|
|
689
|
+
latest.footerStartTop,
|
|
690
|
+
)
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
private fun alignPendingStructuralFooter(pending: PendingStructuralTransition): Boolean {
|
|
696
|
+
val top = pending.footerStartTop ?: return false
|
|
697
|
+
if (!pending.collapsing || !pending.spacerInserted || footerSlotAdapter.itemCount == 0 || structuralScrollInterrupted) return false
|
|
698
|
+
if (pending.footerAnchorAppliedTop == top) return false
|
|
699
|
+
val footerPosition = scrollContentAdapter.itemCount - 1 - sidecarSpacerAdapter.itemCount
|
|
700
|
+
layoutManager.scrollToPositionWithOffset(footerPosition, top - recyclerView.paddingTop)
|
|
701
|
+
pendingStructuralTransition = pending.copy(footerAnchorAppliedTop = top)
|
|
702
|
+
return true
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
private fun alignPendingStructuralRow(pending: PendingStructuralTransition): Boolean {
|
|
706
|
+
val key = pending.anchorKey ?: return false
|
|
707
|
+
val top = pending.anchorTop ?: return false
|
|
708
|
+
if (structuralScrollInterrupted || pending.rowAnchorAppliedTop == top) return false
|
|
709
|
+
val desiredItems = config?.items ?: return false
|
|
710
|
+
val rowIndex = desiredItems.indexOfFirst { it.key == key }
|
|
711
|
+
if (rowIndex < 0 || adapter.itemCount != desiredItems.size ||
|
|
712
|
+
adapter.currentList.getOrNull(rowIndex)?.key != key) return false
|
|
713
|
+
layoutManager.scrollToPositionWithOffset(scrollPositionForRow(rowIndex), top - recyclerView.paddingTop)
|
|
714
|
+
pendingStructuralTransition = pending.copy(rowAnchorAppliedTop = top)
|
|
715
|
+
return true
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
private fun alignPendingStructuralAnchor(pending: PendingStructuralTransition) {
|
|
719
|
+
if (pending.anchorTop != null) alignPendingStructuralRow(pending)
|
|
720
|
+
else alignPendingStructuralFooter(pending)
|
|
721
|
+
}
|
|
722
|
+
|
|
357
723
|
private fun measuredScrollDistancePx(): Int? {
|
|
358
724
|
if (layoutManager.orientation != RecyclerView.VERTICAL) return null
|
|
359
725
|
val first = layoutManager.findFirstVisibleItemPosition()
|
|
@@ -527,6 +893,14 @@ class NativeListView(
|
|
|
527
893
|
override fun onDetachedFromWindow() { down?.recycle(); down = null; super.onDetachedFromWindow() }
|
|
528
894
|
}
|
|
529
895
|
private val stickyPreDraw = android.view.ViewTreeObserver.OnPreDrawListener {
|
|
896
|
+
if (pendingStructuralTransition != null || structuralAnimator != null) {
|
|
897
|
+
val measuredHeightPx = footerSlotAdapter.contentView()?.measuredHeight ?: 0
|
|
898
|
+
if (measuredHeightPx > 0) {
|
|
899
|
+
// React layout can change the footer's contents before its onLayout height reaches JS.
|
|
900
|
+
val roundedDip = ceil(measuredHeightPx / density.toDouble())
|
|
901
|
+
reconcileStructuralFooterHeight((roundedDip * density).roundToInt())
|
|
902
|
+
}
|
|
903
|
+
}
|
|
530
904
|
updateStickyHeader()
|
|
531
905
|
finishScrollCommandIfSettled()
|
|
532
906
|
true
|
|
@@ -595,7 +969,7 @@ class NativeListView(
|
|
|
595
969
|
recyclerView.addItemDecoration(reorderPlaceholderDecoration)
|
|
596
970
|
// OneKey patch: full-width selector header backgrounds do not change row content insets.
|
|
597
971
|
recyclerView.addItemDecoration(SelectorBackgroundDecoration(adapter))
|
|
598
|
-
recyclerView.addItemDecoration(ContainerSlotInsetDecoration { slotInsetPx })
|
|
972
|
+
recyclerView.addItemDecoration(ContainerSlotInsetDecoration { slotInsetPx to slotRightInsetPx })
|
|
599
973
|
if (homeOffsetDiagnosticEnabled) layoutManager.onDiagnosticLayout = ::homeOffsetDiagnostic
|
|
600
974
|
layoutManager.onBeforeDataLayout = {
|
|
601
975
|
if (pendingBodyStartEpoch == readingIntentEpoch && adapter.itemCount > 0 && pendingScrollRequest == null) {
|
|
@@ -603,10 +977,14 @@ class NativeListView(
|
|
|
603
977
|
pendingBodyStartEpoch = null
|
|
604
978
|
homeOffsetDiagnostic("first-fill-body-start")
|
|
605
979
|
}
|
|
980
|
+
pendingStructuralTransition?.let(::alignPendingStructuralAnchor)
|
|
606
981
|
}
|
|
607
982
|
layoutManager.onChildLaidOut = ::recordLaidOutRowExtent
|
|
608
983
|
layoutManager.onLayoutPassCompleted = {
|
|
984
|
+
if (structuralFooterHoldTop != null) updateStructuralFooterHoldPosition()
|
|
985
|
+
else if (structuralAnimator != null) updateStructuralFooterVisualPosition()
|
|
609
986
|
emitScrollPositionThresholdIfNeeded(resync = true)
|
|
987
|
+
updateSidecarPosition(resync = true)
|
|
610
988
|
if (containerSlotRelayoutPending) scheduleContainerSlotRelayout()
|
|
611
989
|
if (commandLayoutRequest === acceptedScrollRequest) commandLayoutRequest = null
|
|
612
990
|
finishScrollCommandIfSettled()
|
|
@@ -618,7 +996,7 @@ class NativeListView(
|
|
|
618
996
|
val rowPosition = rowPositionForScroll(position)
|
|
619
997
|
if (rowPosition !in 0 until adapter.itemCount) return layoutManager.spanCount
|
|
620
998
|
val type = adapter.itemAt(rowPosition)?.type
|
|
621
|
-
return if (type == "sectionHeader" || type == "system" || type == "action") {
|
|
999
|
+
return if (type == "sectionHeader" || type == "system" || type == "action" || type == "buttonGroup") {
|
|
622
1000
|
layoutManager.spanCount
|
|
623
1001
|
} else {
|
|
624
1002
|
1
|
|
@@ -636,6 +1014,8 @@ class NativeListView(
|
|
|
636
1014
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
637
1015
|
),
|
|
638
1016
|
)
|
|
1017
|
+
contentContainer.addView(sidecarHost,
|
|
1018
|
+
FrameLayout.LayoutParams(0, 0, Gravity.TOP or Gravity.RIGHT))
|
|
639
1019
|
stickyHeaderHost.visibility = GONE
|
|
640
1020
|
stickyHeaderHost.addView(stickyHeaderView, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
|
641
1021
|
contentContainer.addView(stickyHeaderHost, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP))
|
|
@@ -700,6 +1080,8 @@ class NativeListView(
|
|
|
700
1080
|
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
701
1081
|
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
|
702
1082
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
|
1083
|
+
if (structuralAnimator != null || pendingStructuralTransition != null)
|
|
1084
|
+
structuralScrollInterrupted = true
|
|
703
1085
|
cancelExecutingScrollCommand()
|
|
704
1086
|
readingIntentEpoch++
|
|
705
1087
|
pendingBodyStartEpoch = null
|
|
@@ -724,6 +1106,20 @@ class NativeListView(
|
|
|
724
1106
|
|
|
725
1107
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
726
1108
|
logicalScrollDistancePx = (logicalScrollDistancePx + dy).coerceAtLeast(0)
|
|
1109
|
+
if (structuralScrollInterrupted && dy != 0) {
|
|
1110
|
+
if (pendingStructuralTransition != null) {
|
|
1111
|
+
pendingStructuralTransition = pendingStructuralTransition?.let {
|
|
1112
|
+
it.copy(footerStartTop = it.footerStartTop?.minus(dy))
|
|
1113
|
+
}
|
|
1114
|
+
structuralFooterHoldTop = structuralFooterHoldTop?.minus(dy)
|
|
1115
|
+
updateStructuralFooterHoldPosition()
|
|
1116
|
+
} else if (structuralAnimator != null) {
|
|
1117
|
+
structuralFooterVisualStartTop = structuralFooterVisualStartTop?.minus(dy)
|
|
1118
|
+
structuralFooterVisualEndTop = structuralFooterVisualEndTop?.minus(dy)
|
|
1119
|
+
updateStructuralFooterVisualPosition()
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
updateSidecarPosition()
|
|
727
1123
|
emitScrollPositionThresholdIfNeeded(resync = dx == 0 && dy == 0)
|
|
728
1124
|
if (dx != 0 || dy != 0) invalidateActionAnchor("scroll")
|
|
729
1125
|
syncSectionIndexToVisibleRows()
|
|
@@ -781,6 +1177,8 @@ class NativeListView(
|
|
|
781
1177
|
}
|
|
782
1178
|
val nextWidth = right - left
|
|
783
1179
|
val nextHeight = bottom - top
|
|
1180
|
+
val widthChanged = lastLayoutWidth != nextWidth
|
|
1181
|
+
val directionChanged = layoutDirection != lastLayoutDirection
|
|
784
1182
|
if (
|
|
785
1183
|
lastLayoutWidth >= 0 &&
|
|
786
1184
|
(nextWidth != lastLayoutWidth || nextHeight != lastLayoutHeight || layoutDirection != lastLayoutDirection)
|
|
@@ -790,6 +1188,9 @@ class NativeListView(
|
|
|
790
1188
|
lastLayoutWidth = nextWidth
|
|
791
1189
|
lastLayoutHeight = nextHeight
|
|
792
1190
|
lastLayoutDirection = layoutDirection
|
|
1191
|
+
if ((widthChanged || directionChanged) && sidecarLayout != null) config?.let(::updateLayout)
|
|
1192
|
+
updateSidecarGeometry()
|
|
1193
|
+
scheduleSidecarSpacer()
|
|
793
1194
|
updateSectionIndexAttachment()
|
|
794
1195
|
performPendingScrollIfNeeded()
|
|
795
1196
|
}
|
|
@@ -844,6 +1245,42 @@ class NativeListView(
|
|
|
844
1245
|
homeOffsetDiagnostic("snapshot-before-nextCount=${next.items.size}")
|
|
845
1246
|
invalidateActionAnchor("snapshot")
|
|
846
1247
|
val previous = config
|
|
1248
|
+
val transition = next.structuralTransition
|
|
1249
|
+
val isNewTransition = transition != null && transition.id != consumedStructuralTransitionId
|
|
1250
|
+
if (transition != null) consumedStructuralTransitionId = transition.id
|
|
1251
|
+
val oldKeys = previous?.items?.map { it.key } ?: emptyList()
|
|
1252
|
+
val nextKeys = next.items.map { it.key }
|
|
1253
|
+
val animateStructure = previous != null && isNewTransition && oldKeys != nextKeys &&
|
|
1254
|
+
next.orientation == "vertical" && (next.layout == "linear" || next.layout == "table") &&
|
|
1255
|
+
(transition?.durationMs ?: 0) > 0 &&
|
|
1256
|
+
(if (Build.VERSION.SDK_INT >= 26) ValueAnimator.areAnimatorsEnabled() else
|
|
1257
|
+
android.provider.Settings.Global.getFloat(context.contentResolver, "animator_duration_scale", 1f) > 0f)
|
|
1258
|
+
val nextKeySet = nextKeys.toHashSet()
|
|
1259
|
+
val visibleAnchor = if (animateStructure) {
|
|
1260
|
+
val first = layoutManager.findFirstVisibleItemPosition()
|
|
1261
|
+
val last = layoutManager.findLastVisibleItemPosition()
|
|
1262
|
+
(first..last).firstNotNullOfOrNull { position ->
|
|
1263
|
+
val rowIndex = rowPositionForScroll(position)
|
|
1264
|
+
oldKeys.getOrNull(rowIndex)?.takeIf(nextKeySet::contains)?.let { key ->
|
|
1265
|
+
layoutManager.findViewByPosition(position)?.let { key to layoutManager.getDecoratedTop(it) }
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
} else null
|
|
1269
|
+
val anchorKey = visibleAnchor?.first ?: transition?.anchorKey?.takeIf(nextKeySet::contains)
|
|
1270
|
+
val anchorTop = visibleAnchor?.second
|
|
1271
|
+
val footerStartTop = if (animateStructure && footerSlotAdapter.itemCount > 0) {
|
|
1272
|
+
layoutManager.findViewByPosition(scrollContentAdapter.itemCount - 1 - sidecarSpacerAdapter.itemCount)?.let {
|
|
1273
|
+
layoutManager.getDecoratedTop(it) + it.translationY.roundToInt()
|
|
1274
|
+
}
|
|
1275
|
+
} else null
|
|
1276
|
+
val oldKeySet = oldKeys.toHashSet()
|
|
1277
|
+
val removedExtent = if (animateStructure) previous?.items?.sumOf { item ->
|
|
1278
|
+
if (nextKeySet.contains(item.key)) 0 else estimatedItemExtentPx(item)
|
|
1279
|
+
} ?: 0 else 0
|
|
1280
|
+
val addedExtent = if (animateStructure) next.items.sumOf { item ->
|
|
1281
|
+
if (oldKeySet.contains(item.key)) 0 else estimatedItemExtentPx(item)
|
|
1282
|
+
} else 0
|
|
1283
|
+
if (!animateStructure && oldKeys != nextKeys) cancelStructuralTransition()
|
|
847
1284
|
if (previous?.items?.isEmpty() == true && next.items.isNotEmpty() && adapter.itemCount == 0 &&
|
|
848
1285
|
pendingScrollRequest == null && recyclerView.scrollState != RecyclerView.SCROLL_STATE_DRAGGING &&
|
|
849
1286
|
!recyclerView.canScrollVertically(-1) && layoutManager.findFirstVisibleItemPosition() == 0) {
|
|
@@ -883,6 +1320,8 @@ class NativeListView(
|
|
|
883
1320
|
// OneKey patch: DiffUtil has dispatched its payloads; release the old serialized rows.
|
|
884
1321
|
next.items.forEach { it.selectionUpdateFromContent = null }
|
|
885
1322
|
recyclerView.post {
|
|
1323
|
+
scheduleSidecarSpacer()
|
|
1324
|
+
startPendingStructuralTransition()
|
|
886
1325
|
bindVisibleSelection(changedSummaryKeys)
|
|
887
1326
|
bindFooterSelection()
|
|
888
1327
|
performPendingScrollIfNeeded()
|
|
@@ -919,12 +1358,40 @@ class NativeListView(
|
|
|
919
1358
|
adapter.selectedKeys = next.selectedKeys
|
|
920
1359
|
configureSectionIndex(next)
|
|
921
1360
|
updateLayout(next)
|
|
1361
|
+
if (animateStructure && transition != null) {
|
|
1362
|
+
structuralTransitionEpoch += 1
|
|
1363
|
+
pendingStructuralStartScheduled = false
|
|
1364
|
+
structuralAnimator?.cancel()
|
|
1365
|
+
structuralAnimator = null
|
|
1366
|
+
structuralScrollInterrupted = false
|
|
1367
|
+
structuralFooterHoldTop = footerStartTop
|
|
1368
|
+
structuralFooterCompensatedHeightPx = slotHeights[2]
|
|
1369
|
+
val held = (structuralSpacerHeightPx + removedExtent - addedExtent).coerceAtLeast(0)
|
|
1370
|
+
pendingStructuralTransition = PendingStructuralTransition(
|
|
1371
|
+
transition, structuralTransitionEpoch, anchorKey, anchorTop, footerStartTop, held,
|
|
1372
|
+
removedExtent > addedExtent,
|
|
1373
|
+
)
|
|
1374
|
+
recyclerView.itemAnimator = DefaultItemAnimator().apply {
|
|
1375
|
+
addDuration = transition.durationMs
|
|
1376
|
+
removeDuration = transition.durationMs
|
|
1377
|
+
moveDuration = 0
|
|
1378
|
+
changeDuration = 0
|
|
1379
|
+
supportsChangeAnimations = false
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
922
1382
|
adapter.submitList(next.items) {
|
|
1383
|
+
pendingStructuralTransition?.takeIf { it.epoch == structuralTransitionEpoch }?.let {
|
|
1384
|
+
setStructuralSpacerHeight(it.heldHeightPx)
|
|
1385
|
+
pendingStructuralTransition = it.copy(spacerInserted = true)
|
|
1386
|
+
pendingStructuralTransition?.let(::alignPendingStructuralAnchor)
|
|
1387
|
+
}
|
|
923
1388
|
homeOffsetDiagnostic("snapshot-submit-commit-marketAnchor=${marketStartOffset != null}")
|
|
924
1389
|
if (marketStartOffset != null) {
|
|
925
1390
|
layoutManager.scrollToPositionWithOffset(scrollPositionForRow(0), marketStartOffset)
|
|
926
1391
|
}
|
|
927
1392
|
relayoutContents(preserveMarketPaginationAnchor)
|
|
1393
|
+
scheduleSidecarSpacer()
|
|
1394
|
+
startPendingStructuralTransition()
|
|
928
1395
|
performPendingScrollIfNeeded()
|
|
929
1396
|
syncSectionIndexToVisibleRows()
|
|
930
1397
|
scheduleVisibleEvent()
|
|
@@ -937,6 +1404,85 @@ class NativeListView(
|
|
|
937
1404
|
updateReordering(next)
|
|
938
1405
|
}
|
|
939
1406
|
|
|
1407
|
+
private fun startStructuralTransition(
|
|
1408
|
+
transition: NativeListConfig.StructuralTransition,
|
|
1409
|
+
epoch: Int,
|
|
1410
|
+
anchorKey: String?,
|
|
1411
|
+
anchorTop: Int?,
|
|
1412
|
+
footerStartTop: Int?,
|
|
1413
|
+
) {
|
|
1414
|
+
structuralFooterHoldTop = null
|
|
1415
|
+
val startSpacer = structuralSpacerHeightPx
|
|
1416
|
+
structuralStartSpacerPx = startSpacer
|
|
1417
|
+
structuralFooterVisualStartTop = footerStartTop
|
|
1418
|
+
structuralFooterVisualProgress = 0f
|
|
1419
|
+
val startOffset = measuredScrollDistancePx()?.also { logicalScrollDistancePx = it }
|
|
1420
|
+
?: logicalScrollDistancePx
|
|
1421
|
+
val anchorIndex = anchorKey?.let { key -> adapter.currentList.indexOfFirst { it.key == key } }
|
|
1422
|
+
val currentAnchorTop = anchorIndex?.takeIf { it >= 0 }?.let { index ->
|
|
1423
|
+
layoutManager.findViewByPosition(scrollPositionForRow(index))?.let(layoutManager::getDecoratedTop)
|
|
1424
|
+
}
|
|
1425
|
+
val anchorDelta = if (anchorTop != null && currentAnchorTop != null) currentAnchorTop - anchorTop else 0
|
|
1426
|
+
val leftFinal = (sidecarLeftExtentPx() - startSpacer).coerceAtLeast(0)
|
|
1427
|
+
val sidecarBottom = if (sidecarLayout != null)
|
|
1428
|
+
recyclerView.paddingTop + slotHeights[3] + recyclerView.paddingBottom else 0
|
|
1429
|
+
val finalMax = (max(leftFinal, sidecarBottom) - recyclerView.height).coerceAtLeast(0)
|
|
1430
|
+
var targetOffset = (startOffset + anchorDelta).coerceIn(0, finalMax)
|
|
1431
|
+
if (anchorTop == null && anchorIndex != null && anchorIndex >= 0) {
|
|
1432
|
+
val fallbackTop = nativeListScrollPrefixPx(
|
|
1433
|
+
scrollPositionForRow(anchorIndex),
|
|
1434
|
+
layoutManager.spanCount,
|
|
1435
|
+
layoutManager.spanSizeLookup::getSpanSize,
|
|
1436
|
+
::estimatedScrollExtentPx,
|
|
1437
|
+
).coerceIn(0L, Int.MAX_VALUE.toLong()).toInt()
|
|
1438
|
+
targetOffset = minOf(targetOffset, fallbackTop)
|
|
1439
|
+
}
|
|
1440
|
+
structuralFooterVisualEndTop = if (footerStartTop != null && footerSlotAdapter.itemCount > 0) {
|
|
1441
|
+
val footerPosition = scrollContentAdapter.itemCount - 1 - sidecarSpacerAdapter.itemCount
|
|
1442
|
+
val finalPrefix = nativeListScrollPrefixPx(
|
|
1443
|
+
footerPosition,
|
|
1444
|
+
layoutManager.spanCount,
|
|
1445
|
+
layoutManager.spanSizeLookup::getSpanSize,
|
|
1446
|
+
::estimatedScrollExtentPx,
|
|
1447
|
+
) - startSpacer
|
|
1448
|
+
(finalPrefix + recyclerView.paddingTop - targetOffset)
|
|
1449
|
+
.coerceIn(Int.MIN_VALUE.toLong(), Int.MAX_VALUE.toLong()).toInt()
|
|
1450
|
+
} else null
|
|
1451
|
+
structuralAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
|
|
1452
|
+
duration = transition.durationMs
|
|
1453
|
+
interpolator = android.view.animation.AccelerateDecelerateInterpolator()
|
|
1454
|
+
addUpdateListener { animation ->
|
|
1455
|
+
if (epoch != structuralTransitionEpoch || disposed) return@addUpdateListener
|
|
1456
|
+
val fraction = animation.animatedValue as Float
|
|
1457
|
+
structuralFooterVisualProgress = fraction
|
|
1458
|
+
setStructuralSpacerHeight((structuralStartSpacerPx * (1f - fraction)).roundToInt())
|
|
1459
|
+
measuredScrollDistancePx()?.let { logicalScrollDistancePx = it }
|
|
1460
|
+
val finalLeftExtent = (sidecarLeftExtentPx() - structuralSpacerHeightPx).coerceAtLeast(0)
|
|
1461
|
+
val finalMaximum = (max(finalLeftExtent, sidecarBottom) - recyclerView.height).coerceAtLeast(0)
|
|
1462
|
+
val desired = (startOffset + (minOf(targetOffset, finalMaximum) - startOffset) * fraction).roundToInt()
|
|
1463
|
+
if (!structuralScrollInterrupted && recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE)
|
|
1464
|
+
recyclerView.scrollBy(0, desired - logicalScrollDistancePx)
|
|
1465
|
+
updateStructuralFooterVisualPosition()
|
|
1466
|
+
}
|
|
1467
|
+
addListener(object : AnimatorListenerAdapter() {
|
|
1468
|
+
override fun onAnimationEnd(animation: Animator) {
|
|
1469
|
+
if (epoch != structuralTransitionEpoch) return
|
|
1470
|
+
structuralAnimator = null
|
|
1471
|
+
recyclerView.itemAnimator = null
|
|
1472
|
+
setStructuralSpacerHeight(0)
|
|
1473
|
+
scheduleSidecarSpacer()
|
|
1474
|
+
footerSlotAdapter.setVisualTranslationY(0f)
|
|
1475
|
+
structuralFooterVisualStartTop = null
|
|
1476
|
+
structuralFooterVisualEndTop = null
|
|
1477
|
+
structuralFooterVisualProgress = 0f
|
|
1478
|
+
structuralFooterCompensatedHeightPx = null
|
|
1479
|
+
structuralStartSpacerPx = 0
|
|
1480
|
+
}
|
|
1481
|
+
})
|
|
1482
|
+
start()
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
|
|
940
1486
|
private fun captureVisibleMarketAnchor(): VisibleMarketAnchor? {
|
|
941
1487
|
val position = rowPositionForScroll(layoutManager.findFirstVisibleItemPosition()).coerceAtLeast(0)
|
|
942
1488
|
if (position == RecyclerView.NO_POSITION) return null
|
|
@@ -1353,6 +1899,7 @@ class NativeListView(
|
|
|
1353
1899
|
}
|
|
1354
1900
|
is ScrollRequest.End -> {
|
|
1355
1901
|
val finalSlotHeight = when {
|
|
1902
|
+
sidecarSpacerAdapter.itemCount > 0 -> sidecarSpacerHeightPx
|
|
1356
1903
|
footerSlotAdapter.itemCount > 0 -> slotHeights[2]
|
|
1357
1904
|
emptySlotAdapter.itemCount > 0 -> slotHeights[1]
|
|
1358
1905
|
adapter.itemCount == 0 && headerSlotAdapter.itemCount > 0 -> slotHeights[0]
|
|
@@ -1658,6 +2205,8 @@ class NativeListView(
|
|
|
1658
2205
|
private fun disposeResources() {
|
|
1659
2206
|
if (resourcesDisposed) return
|
|
1660
2207
|
resourcesDisposed = true
|
|
2208
|
+
cancelStructuralTransition()
|
|
2209
|
+
recyclerView.itemAnimator = null
|
|
1661
2210
|
stopSectionIndexAttachmentTracking()
|
|
1662
2211
|
scheduleSectionIndexAttachmentToList()
|
|
1663
2212
|
stopReorderRelayoutLoop()
|
|
@@ -1722,12 +2271,26 @@ class NativeListView(
|
|
|
1722
2271
|
val coordinatorBottomPadding = (recyclerView.paddingBottom - configuredBottomPaddingPx).coerceAtLeast(0)
|
|
1723
2272
|
// Slot roots are laid out by React at the unscaled JS inset, without the index gutter.
|
|
1724
2273
|
slotInsetPx = (horizontalPadding * density).roundToInt()
|
|
2274
|
+
val sidecar = sidecarLayout
|
|
2275
|
+
val contentWidth = recyclerView.width
|
|
2276
|
+
if (sidecar != null && contentWidth > 0) {
|
|
2277
|
+
slotInsetPx = (contentWidth - minOf(contentWidth, sidecar.maxContentWidth)) / 2
|
|
2278
|
+
}
|
|
2279
|
+
val sidecarSpace = (sidecar?.width ?: 0) + (sidecar?.gap ?: 0)
|
|
2280
|
+
val baseSlotInset = slotInsetPx
|
|
2281
|
+
if (sidecar != null && layoutDirection == LAYOUT_DIRECTION_RTL) {
|
|
2282
|
+
slotInsetPx += sidecarSpace
|
|
2283
|
+
slotRightInsetPx = baseSlotInset
|
|
2284
|
+
} else {
|
|
2285
|
+
slotRightInsetPx = baseSlotInset + sidecarSpace
|
|
2286
|
+
}
|
|
1725
2287
|
configuredTopPaddingPx = dp(topPadding)
|
|
1726
2288
|
configuredBottomPaddingPx = dp(bottomPadding)
|
|
1727
2289
|
recyclerView.setPaddingRelative(
|
|
1728
|
-
dp(horizontalPadding),
|
|
2290
|
+
if (sidecar == null) dp(horizontalPadding) else baseSlotInset + dp(horizontalPadding),
|
|
1729
2291
|
configuredTopPaddingPx + coordinatorTopPadding,
|
|
1730
|
-
dp(horizontalPadding + indexGutter)
|
|
2292
|
+
if (sidecar == null) dp(horizontalPadding + indexGutter)
|
|
2293
|
+
else baseSlotInset + sidecarSpace + dp(horizontalPadding + indexGutter),
|
|
1731
2294
|
configuredBottomPaddingPx + coordinatorBottomPadding,
|
|
1732
2295
|
)
|
|
1733
2296
|
recyclerView.clipToPadding = false
|
|
@@ -2111,15 +2674,16 @@ class NativeListView(
|
|
|
2111
2674
|
actionAnchor = record
|
|
2112
2675
|
// OneKey patch: selector menus anchor to the glyph slot, not its expanded press target.
|
|
2113
2676
|
val anchorInset = origin.anchorInsetPixels
|
|
2677
|
+
val helpBounds = (origin.sourceView as? NativeListTextView)?.helpAnchorBounds
|
|
2114
2678
|
return JSONObject()
|
|
2115
2679
|
.put("token", token)
|
|
2116
2680
|
.put(
|
|
2117
2681
|
"windowRect",
|
|
2118
2682
|
JSONObject()
|
|
2119
|
-
.put("x", (location[0] + anchorInset) / density)
|
|
2120
|
-
.put("y", (location[1] + anchorInset) / density)
|
|
2121
|
-
.put("width", (origin.sourceView.width - anchorInset * 2) / density)
|
|
2122
|
-
.put("height", (origin.sourceView.height - anchorInset * 2) / density),
|
|
2683
|
+
.put("x", (location[0] + (helpBounds?.left ?: anchorInset.toFloat())) / density)
|
|
2684
|
+
.put("y", (location[1] + (helpBounds?.top ?: anchorInset.toFloat())) / density)
|
|
2685
|
+
.put("width", (helpBounds?.width() ?: (origin.sourceView.width - anchorInset * 2).toFloat()) / density)
|
|
2686
|
+
.put("height", (helpBounds?.height() ?: (origin.sourceView.height - anchorInset * 2).toFloat()) / density),
|
|
2123
2687
|
)
|
|
2124
2688
|
.put("source", origin.source)
|
|
2125
2689
|
.put("generation", generation)
|
|
@@ -3348,7 +3912,7 @@ private class ItemSpacingDecoration(
|
|
|
3348
3912
|
* from each edge. Row padding may be scaled or widened by the section-index gutter, so slot
|
|
3349
3913
|
* holders offset themselves (possibly negatively) back to the JavaScript inset.
|
|
3350
3914
|
*/
|
|
3351
|
-
private class ContainerSlotInsetDecoration(private val
|
|
3915
|
+
private class ContainerSlotInsetDecoration(private val insetsPx: () -> Pair<Int, Int>) : RecyclerView.ItemDecoration() {
|
|
3352
3916
|
override fun getItemOffsets(
|
|
3353
3917
|
outRect: android.graphics.Rect,
|
|
3354
3918
|
view: View,
|
|
@@ -3356,9 +3920,9 @@ private class ContainerSlotInsetDecoration(private val insetPx: () -> Int) : Rec
|
|
|
3356
3920
|
state: RecyclerView.State,
|
|
3357
3921
|
) {
|
|
3358
3922
|
if (parent.getChildViewHolder(view) !is NativeListContainerSlotAdapter.Holder) return
|
|
3359
|
-
val
|
|
3360
|
-
outRect.left =
|
|
3361
|
-
outRect.right =
|
|
3923
|
+
val (leftInset, rightInset) = insetsPx()
|
|
3924
|
+
outRect.left = leftInset - parent.paddingLeft
|
|
3925
|
+
outRect.right = rightInset - parent.paddingRight
|
|
3362
3926
|
}
|
|
3363
3927
|
}
|
|
3364
3928
|
|