@onekeyfe/react-native-native-list 6.7.0-alpha.359 → 6.7.0-alpha.363
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 +0 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +7 -240
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +4 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +3 -6
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +0 -12
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +7 -87
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +1 -135
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +14 -43
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +0 -25
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +2 -17
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +0 -22
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +0 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +2 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +0 -69
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +1 -55
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +29 -587
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +0 -1
- package/docs/ROW_TEMPLATES.md +9 -60
- package/docs/SPEC.md +15 -317
- package/docs/STYLE_SPEC.md +0 -6
- package/ios/HybridNativeList.swift +0 -10
- package/ios/NativeListAccessoryStack.swift +37 -220
- package/ios/NativeListActivityDetailsView.swift +8 -18
- package/ios/NativeListActivityRenderer.swift +2 -8
- package/ios/NativeListDataRowRenderer.swift +16 -128
- package/ios/NativeListDesignAssets.swift +0 -3
- package/ios/NativeListIdentityRenderer.swift +5 -123
- package/ios/NativeListLeadingVisual.swift +14 -49
- package/ios/NativeListMessageRenderer.swift +1 -34
- package/ios/NativeListModels.swift +2 -16
- package/ios/NativeListRendererRegistry.swift +0 -1
- package/ios/NativeListResolvedText.swift +1 -2
- package/ios/NativeListRowHost.swift +0 -14
- package/ios/NativeListSectionHeaderRenderer.swift +0 -88
- package/ios/RNCNativeListView.swift +29 -335
- package/ios/tests/NativeListActivityPresentationTests.swift +0 -56
- package/ios/tests/NativeListLifecycleTests.swift +3 -1283
- package/lib/module/NativeList.js +21 -39
- package/lib/module/NativeList.web.js +4 -51
- package/lib/module/models.js +0 -1
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +8 -320
- package/lib/module/web/NativeListWebEngine.js +18 -373
- package/lib/module/web/templates/ActivityRowRenderer.js +7 -8
- package/lib/module/web/templates/DataRowRenderer.js +5 -40
- package/lib/module/web/templates/IdentityRowRenderer.js +4 -90
- package/lib/module/web/templates/MessageRowRenderer.js +2 -18
- package/lib/module/web/templates/RowContainerStyle.js +0 -1
- package/lib/module/web/templates/RowRendererRegistry.js +0 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +2 -36
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/lib/typescript/src/NativeList.nitro.d.ts +0 -1
- package/lib/typescript/src/NativeList.types.d.ts +0 -8
- package/lib/typescript/src/models.d.ts +9 -101
- package/lib/typescript/src/validation.d.ts +0 -10
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +0 -26
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +3 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +0 -9
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +0 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +0 -6
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +0 -7
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +0 -6
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +0 -11
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +0 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +0 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +0 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +0 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +0 -1
- package/src/NativeList.nitro.ts +0 -1
- package/src/NativeList.tsx +24 -72
- package/src/NativeList.types.ts +0 -9
- package/src/NativeList.web.tsx +8 -72
- package/src/models.ts +3 -113
- package/src/selection.ts +0 -1
- package/src/validation.ts +6 -721
- package/src/web/NativeListWebEngine.ts +19 -568
- package/src/web/templates/ActivityRowRenderer.ts +6 -14
- package/src/web/templates/DataRowRenderer.ts +20 -93
- package/src/web/templates/IdentityRowRenderer.ts +5 -150
- package/src/web/templates/MessageRowRenderer.ts +7 -23
- package/src/web/templates/RowContainerStyle.ts +0 -2
- package/src/web/templates/RowRendererRegistry.ts +1 -11
- package/src/web/templates/SectionHeaderRowRenderer.ts +4 -47
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +0 -102
- package/ios/NativeListButtonGroupRenderer.swift +0 -89
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +0 -4
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +0 -3
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +0 -15
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +0 -3
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +0 -47
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +0 -14
- package/src/web/templates/ButtonGroupRowRenderer.ts +0 -58
|
@@ -1,9 +1,6 @@
|
|
|
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
|
|
7
4
|
import android.content.Context
|
|
8
5
|
import android.graphics.Canvas
|
|
9
6
|
import android.graphics.Color
|
|
@@ -14,7 +11,6 @@ import android.graphics.RectF
|
|
|
14
11
|
import android.graphics.drawable.ShapeDrawable
|
|
15
12
|
import android.graphics.drawable.shapes.PathShape
|
|
16
13
|
import android.os.Bundle
|
|
17
|
-
import android.os.Build
|
|
18
14
|
import android.os.Handler
|
|
19
15
|
import android.os.Looper
|
|
20
16
|
import android.os.SystemClock
|
|
@@ -36,7 +32,6 @@ import android.widget.TextView
|
|
|
36
32
|
import androidx.core.view.ViewCompat
|
|
37
33
|
import androidx.core.view.WindowInsetsCompat
|
|
38
34
|
import androidx.recyclerview.widget.ConcatAdapter
|
|
39
|
-
import androidx.recyclerview.widget.DefaultItemAnimator
|
|
40
35
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
41
36
|
import androidx.recyclerview.widget.ItemTouchHelper
|
|
42
37
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
@@ -208,129 +203,24 @@ class NativeListView(
|
|
|
208
203
|
var keyboardDismissMode = NativeListKeyboardDismissMode.NONE
|
|
209
204
|
var keyboardShouldPersistTaps = NativeListKeyboardShouldPersistTaps.NEVER
|
|
210
205
|
private val density = resources.displayMetrics.density
|
|
211
|
-
private val recyclerView =
|
|
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
|
-
}
|
|
206
|
+
private val recyclerView = RecyclerView(context)
|
|
225
207
|
private var configuredTopPaddingPx = 0
|
|
226
208
|
private var slotInsetPx = 0
|
|
227
|
-
private var slotRightInsetPx = 0
|
|
228
209
|
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
|
|
258
210
|
private val refreshLayout = SwipeRefreshLayout(context)
|
|
259
211
|
private val refreshIndicatorTravelPx = refreshLayout.progressViewEndOffset
|
|
260
212
|
private val defaultRefreshTriggerDistancePx = (64 * resources.displayMetrics.density).roundToInt()
|
|
261
213
|
private var refreshIndicatorOffsetPx = 0
|
|
262
214
|
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
|
-
}
|
|
317
215
|
private val adapter = NativeListAdapter(reactContext, fonts)
|
|
318
216
|
private val containerSlots = mutableListOf<View>()
|
|
319
|
-
private val slotHeights = IntArray(
|
|
320
|
-
private var initialHeaderInsertionHandled = false
|
|
217
|
+
private val slotHeights = IntArray(3)
|
|
321
218
|
private var containerSlotRelayoutPending = false
|
|
322
219
|
private var containerSlotRelayoutScheduled = false
|
|
323
220
|
private val headerSlotAdapter = NativeListContainerSlotAdapter()
|
|
324
221
|
private val emptySlotAdapter = NativeListContainerSlotAdapter()
|
|
325
|
-
private val structuralSpacerView = View(context)
|
|
326
|
-
private val structuralSpacerAdapter = NativeListContainerSlotAdapter()
|
|
327
222
|
private val footerSlotAdapter = NativeListContainerSlotAdapter()
|
|
328
|
-
private val
|
|
329
|
-
private val sidecarSpacerAdapter = NativeListContainerSlotAdapter()
|
|
330
|
-
private val scrollContentAdapter = ConcatAdapter(
|
|
331
|
-
headerSlotAdapter, adapter, emptySlotAdapter, structuralSpacerAdapter,
|
|
332
|
-
footerSlotAdapter, sidecarSpacerAdapter,
|
|
333
|
-
)
|
|
223
|
+
private val scrollContentAdapter = ConcatAdapter(headerSlotAdapter, adapter, emptySlotAdapter, footerSlotAdapter)
|
|
334
224
|
|
|
335
225
|
private val homeOffsetDiagnosticEnabled =
|
|
336
226
|
context.applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE != 0
|
|
@@ -348,8 +238,7 @@ class NativeListView(
|
|
|
348
238
|
headerSlotAdapter -> 0
|
|
349
239
|
adapter -> 1
|
|
350
240
|
emptySlotAdapter -> 2
|
|
351
|
-
|
|
352
|
-
footerSlotAdapter -> 4
|
|
241
|
+
footerSlotAdapter -> 3
|
|
353
242
|
else -> -1
|
|
354
243
|
}
|
|
355
244
|
val focused = recyclerView.findFocus()
|
|
@@ -359,7 +248,7 @@ class NativeListView(
|
|
|
359
248
|
"seq=${++homeOffsetDiagnosticSequence} wallMs=${System.currentTimeMillis()} monoMs=${SystemClock.uptimeMillis()} " +
|
|
360
249
|
"list=${System.identityHashCode(this)} view=${System.identityHashCode(recyclerView)} tag=$id " +
|
|
361
250
|
"generation=${config?.generation} configuredCount=${config?.items?.size} " +
|
|
362
|
-
"counts=${headerSlotAdapter.itemCount},${adapter.itemCount},${emptySlotAdapter.itemCount},${
|
|
251
|
+
"counts=${headerSlotAdapter.itemCount},${adapter.itemCount},${emptySlotAdapter.itemCount},${footerSlotAdapter.itemCount} " +
|
|
363
252
|
"total=${scrollContentAdapter.itemCount} pendingCommand=${pendingScrollRequest?.javaClass?.simpleName ?: "none"} " +
|
|
364
253
|
"stateCount=${state?.itemCount} preLayout=${state?.isPreLayout} structureChanged=${state?.didStructureChange()} predictive=${state?.willRunPredictiveAnimations()} " +
|
|
365
254
|
"first=$first last=${layoutManager.findLastVisibleItemPosition()} " +
|
|
@@ -390,143 +279,21 @@ class NativeListView(
|
|
|
390
279
|
|
|
391
280
|
fun setContainerSlotHeightsJson(json: String) {
|
|
392
281
|
val values = runCatching { JSONArray(json) }.getOrNull() ?: return
|
|
393
|
-
if (values.length() !=
|
|
394
|
-
for (index in 0..
|
|
282
|
+
if (values.length() != 3) return
|
|
283
|
+
for (index in 0..2) {
|
|
395
284
|
val value = values.optDouble(index)
|
|
396
285
|
if (!value.isFinite() || value < 0) return
|
|
397
286
|
}
|
|
398
|
-
reconcileStructuralFooterHeight((values.getDouble(2) * density).roundToInt())
|
|
399
287
|
var changed = false
|
|
400
|
-
for (index in 0..
|
|
288
|
+
for (index in 0..2) {
|
|
401
289
|
val height = (values.getDouble(index) * density).roundToInt()
|
|
402
290
|
if (slotHeights[index] != height) changed = true
|
|
403
291
|
slotHeights[index] = height
|
|
404
292
|
}
|
|
405
293
|
updateContainerSlots()
|
|
406
|
-
updateSidecarGeometry()
|
|
407
|
-
scheduleSidecarSpacer()
|
|
408
294
|
if (changed) scheduleContainerSlotRelayout()
|
|
409
295
|
}
|
|
410
296
|
|
|
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
|
-
|
|
530
297
|
private fun scheduleContainerSlotRelayout() {
|
|
531
298
|
if (disposed) return
|
|
532
299
|
containerSlotRelayoutPending = true
|
|
@@ -547,27 +314,9 @@ class NativeListView(
|
|
|
547
314
|
|
|
548
315
|
private fun updateContainerSlots() {
|
|
549
316
|
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)
|
|
560
317
|
headerSlotAdapter.update(containerSlots.getOrNull(0), slotHeights[0], true)
|
|
561
318
|
emptySlotAdapter.update(containerSlots.getOrNull(1), slotHeights[1], config?.items?.isEmpty() != false)
|
|
562
319
|
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
|
-
}
|
|
571
320
|
homeOffsetDiagnostic("slots-after")
|
|
572
321
|
layoutManager.spanSizeLookup.invalidateSpanIndexCache()
|
|
573
322
|
recyclerView.requestLayout()
|
|
@@ -596,13 +345,7 @@ class NativeListView(
|
|
|
596
345
|
if (position < headerCount) return slotHeights[0]
|
|
597
346
|
val row = position - headerCount
|
|
598
347
|
if (row >= adapter.itemCount) {
|
|
599
|
-
|
|
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
|
-
}
|
|
348
|
+
return if (row - adapter.itemCount < emptySlotAdapter.itemCount) slotHeights[1] else slotHeights[2]
|
|
606
349
|
}
|
|
607
350
|
val item = adapter.itemAt(row)
|
|
608
351
|
item?.key?.let(measuredRowExtentsPx::get)?.let { return it }
|
|
@@ -611,115 +354,6 @@ class NativeListView(
|
|
|
611
354
|
return if (measuredRowExtentsPx.isEmpty()) 0 else (measuredRowExtentSumPx / measuredRowExtentsPx.size).toInt()
|
|
612
355
|
}
|
|
613
356
|
|
|
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
|
-
|
|
723
357
|
private fun measuredScrollDistancePx(): Int? {
|
|
724
358
|
if (layoutManager.orientation != RecyclerView.VERTICAL) return null
|
|
725
359
|
val first = layoutManager.findFirstVisibleItemPosition()
|
|
@@ -893,14 +527,6 @@ class NativeListView(
|
|
|
893
527
|
override fun onDetachedFromWindow() { down?.recycle(); down = null; super.onDetachedFromWindow() }
|
|
894
528
|
}
|
|
895
529
|
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
|
-
}
|
|
904
530
|
updateStickyHeader()
|
|
905
531
|
finishScrollCommandIfSettled()
|
|
906
532
|
true
|
|
@@ -969,7 +595,7 @@ class NativeListView(
|
|
|
969
595
|
recyclerView.addItemDecoration(reorderPlaceholderDecoration)
|
|
970
596
|
// OneKey patch: full-width selector header backgrounds do not change row content insets.
|
|
971
597
|
recyclerView.addItemDecoration(SelectorBackgroundDecoration(adapter))
|
|
972
|
-
recyclerView.addItemDecoration(ContainerSlotInsetDecoration { slotInsetPx
|
|
598
|
+
recyclerView.addItemDecoration(ContainerSlotInsetDecoration { slotInsetPx })
|
|
973
599
|
if (homeOffsetDiagnosticEnabled) layoutManager.onDiagnosticLayout = ::homeOffsetDiagnostic
|
|
974
600
|
layoutManager.onBeforeDataLayout = {
|
|
975
601
|
if (pendingBodyStartEpoch == readingIntentEpoch && adapter.itemCount > 0 && pendingScrollRequest == null) {
|
|
@@ -977,14 +603,10 @@ class NativeListView(
|
|
|
977
603
|
pendingBodyStartEpoch = null
|
|
978
604
|
homeOffsetDiagnostic("first-fill-body-start")
|
|
979
605
|
}
|
|
980
|
-
pendingStructuralTransition?.let(::alignPendingStructuralAnchor)
|
|
981
606
|
}
|
|
982
607
|
layoutManager.onChildLaidOut = ::recordLaidOutRowExtent
|
|
983
608
|
layoutManager.onLayoutPassCompleted = {
|
|
984
|
-
if (structuralFooterHoldTop != null) updateStructuralFooterHoldPosition()
|
|
985
|
-
else if (structuralAnimator != null) updateStructuralFooterVisualPosition()
|
|
986
609
|
emitScrollPositionThresholdIfNeeded(resync = true)
|
|
987
|
-
updateSidecarPosition(resync = true)
|
|
988
610
|
if (containerSlotRelayoutPending) scheduleContainerSlotRelayout()
|
|
989
611
|
if (commandLayoutRequest === acceptedScrollRequest) commandLayoutRequest = null
|
|
990
612
|
finishScrollCommandIfSettled()
|
|
@@ -996,7 +618,7 @@ class NativeListView(
|
|
|
996
618
|
val rowPosition = rowPositionForScroll(position)
|
|
997
619
|
if (rowPosition !in 0 until adapter.itemCount) return layoutManager.spanCount
|
|
998
620
|
val type = adapter.itemAt(rowPosition)?.type
|
|
999
|
-
return if (type == "sectionHeader" || type == "system" || type == "action"
|
|
621
|
+
return if (type == "sectionHeader" || type == "system" || type == "action") {
|
|
1000
622
|
layoutManager.spanCount
|
|
1001
623
|
} else {
|
|
1002
624
|
1
|
|
@@ -1014,8 +636,6 @@ class NativeListView(
|
|
|
1014
636
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
1015
637
|
),
|
|
1016
638
|
)
|
|
1017
|
-
contentContainer.addView(sidecarHost,
|
|
1018
|
-
FrameLayout.LayoutParams(0, 0, Gravity.TOP or Gravity.RIGHT))
|
|
1019
639
|
stickyHeaderHost.visibility = GONE
|
|
1020
640
|
stickyHeaderHost.addView(stickyHeaderView, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT))
|
|
1021
641
|
contentContainer.addView(stickyHeaderHost, FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP))
|
|
@@ -1080,8 +700,6 @@ class NativeListView(
|
|
|
1080
700
|
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
|
1081
701
|
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
|
|
1082
702
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
|
1083
|
-
if (structuralAnimator != null || pendingStructuralTransition != null)
|
|
1084
|
-
structuralScrollInterrupted = true
|
|
1085
703
|
cancelExecutingScrollCommand()
|
|
1086
704
|
readingIntentEpoch++
|
|
1087
705
|
pendingBodyStartEpoch = null
|
|
@@ -1106,20 +724,6 @@ class NativeListView(
|
|
|
1106
724
|
|
|
1107
725
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
|
1108
726
|
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()
|
|
1123
727
|
emitScrollPositionThresholdIfNeeded(resync = dx == 0 && dy == 0)
|
|
1124
728
|
if (dx != 0 || dy != 0) invalidateActionAnchor("scroll")
|
|
1125
729
|
syncSectionIndexToVisibleRows()
|
|
@@ -1177,8 +781,6 @@ class NativeListView(
|
|
|
1177
781
|
}
|
|
1178
782
|
val nextWidth = right - left
|
|
1179
783
|
val nextHeight = bottom - top
|
|
1180
|
-
val widthChanged = lastLayoutWidth != nextWidth
|
|
1181
|
-
val directionChanged = layoutDirection != lastLayoutDirection
|
|
1182
784
|
if (
|
|
1183
785
|
lastLayoutWidth >= 0 &&
|
|
1184
786
|
(nextWidth != lastLayoutWidth || nextHeight != lastLayoutHeight || layoutDirection != lastLayoutDirection)
|
|
@@ -1188,9 +790,6 @@ class NativeListView(
|
|
|
1188
790
|
lastLayoutWidth = nextWidth
|
|
1189
791
|
lastLayoutHeight = nextHeight
|
|
1190
792
|
lastLayoutDirection = layoutDirection
|
|
1191
|
-
if ((widthChanged || directionChanged) && sidecarLayout != null) config?.let(::updateLayout)
|
|
1192
|
-
updateSidecarGeometry()
|
|
1193
|
-
scheduleSidecarSpacer()
|
|
1194
793
|
updateSectionIndexAttachment()
|
|
1195
794
|
performPendingScrollIfNeeded()
|
|
1196
795
|
}
|
|
@@ -1245,42 +844,6 @@ class NativeListView(
|
|
|
1245
844
|
homeOffsetDiagnostic("snapshot-before-nextCount=${next.items.size}")
|
|
1246
845
|
invalidateActionAnchor("snapshot")
|
|
1247
846
|
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()
|
|
1284
847
|
if (previous?.items?.isEmpty() == true && next.items.isNotEmpty() && adapter.itemCount == 0 &&
|
|
1285
848
|
pendingScrollRequest == null && recyclerView.scrollState != RecyclerView.SCROLL_STATE_DRAGGING &&
|
|
1286
849
|
!recyclerView.canScrollVertically(-1) && layoutManager.findFirstVisibleItemPosition() == 0) {
|
|
@@ -1320,8 +883,6 @@ class NativeListView(
|
|
|
1320
883
|
// OneKey patch: DiffUtil has dispatched its payloads; release the old serialized rows.
|
|
1321
884
|
next.items.forEach { it.selectionUpdateFromContent = null }
|
|
1322
885
|
recyclerView.post {
|
|
1323
|
-
scheduleSidecarSpacer()
|
|
1324
|
-
startPendingStructuralTransition()
|
|
1325
886
|
bindVisibleSelection(changedSummaryKeys)
|
|
1326
887
|
bindFooterSelection()
|
|
1327
888
|
performPendingScrollIfNeeded()
|
|
@@ -1358,40 +919,12 @@ class NativeListView(
|
|
|
1358
919
|
adapter.selectedKeys = next.selectedKeys
|
|
1359
920
|
configureSectionIndex(next)
|
|
1360
921
|
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
|
-
}
|
|
1382
922
|
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
|
-
}
|
|
1388
923
|
homeOffsetDiagnostic("snapshot-submit-commit-marketAnchor=${marketStartOffset != null}")
|
|
1389
924
|
if (marketStartOffset != null) {
|
|
1390
925
|
layoutManager.scrollToPositionWithOffset(scrollPositionForRow(0), marketStartOffset)
|
|
1391
926
|
}
|
|
1392
927
|
relayoutContents(preserveMarketPaginationAnchor)
|
|
1393
|
-
scheduleSidecarSpacer()
|
|
1394
|
-
startPendingStructuralTransition()
|
|
1395
928
|
performPendingScrollIfNeeded()
|
|
1396
929
|
syncSectionIndexToVisibleRows()
|
|
1397
930
|
scheduleVisibleEvent()
|
|
@@ -1404,85 +937,6 @@ class NativeListView(
|
|
|
1404
937
|
updateReordering(next)
|
|
1405
938
|
}
|
|
1406
939
|
|
|
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
|
-
|
|
1486
940
|
private fun captureVisibleMarketAnchor(): VisibleMarketAnchor? {
|
|
1487
941
|
val position = rowPositionForScroll(layoutManager.findFirstVisibleItemPosition()).coerceAtLeast(0)
|
|
1488
942
|
if (position == RecyclerView.NO_POSITION) return null
|
|
@@ -1899,7 +1353,6 @@ class NativeListView(
|
|
|
1899
1353
|
}
|
|
1900
1354
|
is ScrollRequest.End -> {
|
|
1901
1355
|
val finalSlotHeight = when {
|
|
1902
|
-
sidecarSpacerAdapter.itemCount > 0 -> sidecarSpacerHeightPx
|
|
1903
1356
|
footerSlotAdapter.itemCount > 0 -> slotHeights[2]
|
|
1904
1357
|
emptySlotAdapter.itemCount > 0 -> slotHeights[1]
|
|
1905
1358
|
adapter.itemCount == 0 && headerSlotAdapter.itemCount > 0 -> slotHeights[0]
|
|
@@ -2205,8 +1658,6 @@ class NativeListView(
|
|
|
2205
1658
|
private fun disposeResources() {
|
|
2206
1659
|
if (resourcesDisposed) return
|
|
2207
1660
|
resourcesDisposed = true
|
|
2208
|
-
cancelStructuralTransition()
|
|
2209
|
-
recyclerView.itemAnimator = null
|
|
2210
1661
|
stopSectionIndexAttachmentTracking()
|
|
2211
1662
|
scheduleSectionIndexAttachmentToList()
|
|
2212
1663
|
stopReorderRelayoutLoop()
|
|
@@ -2271,26 +1722,12 @@ class NativeListView(
|
|
|
2271
1722
|
val coordinatorBottomPadding = (recyclerView.paddingBottom - configuredBottomPaddingPx).coerceAtLeast(0)
|
|
2272
1723
|
// Slot roots are laid out by React at the unscaled JS inset, without the index gutter.
|
|
2273
1724
|
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
|
-
}
|
|
2287
1725
|
configuredTopPaddingPx = dp(topPadding)
|
|
2288
1726
|
configuredBottomPaddingPx = dp(bottomPadding)
|
|
2289
1727
|
recyclerView.setPaddingRelative(
|
|
2290
|
-
|
|
1728
|
+
dp(horizontalPadding),
|
|
2291
1729
|
configuredTopPaddingPx + coordinatorTopPadding,
|
|
2292
|
-
|
|
2293
|
-
else baseSlotInset + sidecarSpace + dp(horizontalPadding + indexGutter),
|
|
1730
|
+
dp(horizontalPadding + indexGutter),
|
|
2294
1731
|
configuredBottomPaddingPx + coordinatorBottomPadding,
|
|
2295
1732
|
)
|
|
2296
1733
|
recyclerView.clipToPadding = false
|
|
@@ -2502,7 +1939,10 @@ class NativeListView(
|
|
|
2502
1939
|
|
|
2503
1940
|
private fun attachSectionIndexToList() {
|
|
2504
1941
|
if (sectionIndexView.parent === contentContainer) return
|
|
2505
|
-
(sectionIndexView.parent as? ViewGroup)?.
|
|
1942
|
+
(sectionIndexView.parent as? ViewGroup)?.let { previous ->
|
|
1943
|
+
previous.removeView(sectionIndexView)
|
|
1944
|
+
previous.endViewTransition(sectionIndexView)
|
|
1945
|
+
}
|
|
2506
1946
|
sectionIndexView.translationX = 0f
|
|
2507
1947
|
contentContainer.addView(
|
|
2508
1948
|
sectionIndexView,
|
|
@@ -2538,7 +1978,10 @@ class NativeListView(
|
|
|
2538
1978
|
topMargin = (windowHost.height - railHeight) / 2
|
|
2539
1979
|
}
|
|
2540
1980
|
if (sectionIndexView.parent !== windowHost) {
|
|
2541
|
-
(sectionIndexView.parent as? ViewGroup)?.
|
|
1981
|
+
(sectionIndexView.parent as? ViewGroup)?.let { previous ->
|
|
1982
|
+
previous.removeView(sectionIndexView)
|
|
1983
|
+
previous.endViewTransition(sectionIndexView)
|
|
1984
|
+
}
|
|
2542
1985
|
windowHost.addView(sectionIndexView, layoutParams)
|
|
2543
1986
|
sectionIndexView.bringToFront()
|
|
2544
1987
|
} else if (!sectionIndexView.hasSameWindowLayout(layoutParams)) {
|
|
@@ -2674,16 +2117,15 @@ class NativeListView(
|
|
|
2674
2117
|
actionAnchor = record
|
|
2675
2118
|
// OneKey patch: selector menus anchor to the glyph slot, not its expanded press target.
|
|
2676
2119
|
val anchorInset = origin.anchorInsetPixels
|
|
2677
|
-
val helpBounds = (origin.sourceView as? NativeListTextView)?.helpAnchorBounds
|
|
2678
2120
|
return JSONObject()
|
|
2679
2121
|
.put("token", token)
|
|
2680
2122
|
.put(
|
|
2681
2123
|
"windowRect",
|
|
2682
2124
|
JSONObject()
|
|
2683
|
-
.put("x", (location[0] +
|
|
2684
|
-
.put("y", (location[1] +
|
|
2685
|
-
.put("width", (
|
|
2686
|
-
.put("height", (
|
|
2125
|
+
.put("x", (location[0] + anchorInset) / density)
|
|
2126
|
+
.put("y", (location[1] + anchorInset) / density)
|
|
2127
|
+
.put("width", (origin.sourceView.width - anchorInset * 2) / density)
|
|
2128
|
+
.put("height", (origin.sourceView.height - anchorInset * 2) / density),
|
|
2687
2129
|
)
|
|
2688
2130
|
.put("source", origin.source)
|
|
2689
2131
|
.put("generation", generation)
|
|
@@ -3912,7 +3354,7 @@ private class ItemSpacingDecoration(
|
|
|
3912
3354
|
* from each edge. Row padding may be scaled or widened by the section-index gutter, so slot
|
|
3913
3355
|
* holders offset themselves (possibly negatively) back to the JavaScript inset.
|
|
3914
3356
|
*/
|
|
3915
|
-
private class ContainerSlotInsetDecoration(private val
|
|
3357
|
+
private class ContainerSlotInsetDecoration(private val insetPx: () -> Int) : RecyclerView.ItemDecoration() {
|
|
3916
3358
|
override fun getItemOffsets(
|
|
3917
3359
|
outRect: android.graphics.Rect,
|
|
3918
3360
|
view: View,
|
|
@@ -3920,9 +3362,9 @@ private class ContainerSlotInsetDecoration(private val insetsPx: () -> Pair<Int,
|
|
|
3920
3362
|
state: RecyclerView.State,
|
|
3921
3363
|
) {
|
|
3922
3364
|
if (parent.getChildViewHolder(view) !is NativeListContainerSlotAdapter.Holder) return
|
|
3923
|
-
val
|
|
3924
|
-
outRect.left =
|
|
3925
|
-
outRect.right =
|
|
3365
|
+
val inset = insetPx()
|
|
3366
|
+
outRect.left = inset - parent.paddingLeft
|
|
3367
|
+
outRect.right = inset - parent.paddingRight
|
|
3926
3368
|
}
|
|
3927
3369
|
}
|
|
3928
3370
|
|