@onekeyfe/react-native-native-list 6.7.0-17 → 6.7.0-19

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.
@@ -69,13 +69,10 @@ private class NativeListGridLayoutManager(
69
69
  var onChildLaidOut: ((View, Int) -> Unit)? = null
70
70
  var onLayoutPassCompleted: (() -> Unit)? = null
71
71
  var onBeforeDataLayout: (() -> Unit)? = null
72
- var onDiagnosticLayout: ((String, RecyclerView.State) -> Unit)? = null
73
72
 
74
73
  override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) {
75
- onDiagnosticLayout?.invoke("layout-children-before", state)
76
74
  if (!state.isPreLayout) onBeforeDataLayout?.invoke()
77
75
  super.onLayoutChildren(recycler, state)
78
- onDiagnosticLayout?.invoke("layout-children-after", state)
79
76
  }
80
77
 
81
78
  // Scroll fills and layout passes both place children here, including rows that a
@@ -87,7 +84,6 @@ private class NativeListGridLayoutManager(
87
84
 
88
85
  override fun onLayoutCompleted(state: RecyclerView.State) {
89
86
  super.onLayoutCompleted(state)
90
- onDiagnosticLayout?.invoke("layout-completed", state)
91
87
  onLayoutPassCompleted?.invoke()
92
88
  }
93
89
 
@@ -445,47 +441,6 @@ class NativeListView(
445
441
  footerSlotAdapter, sidecarSpacerAdapter,
446
442
  )
447
443
 
448
- private val homeOffsetDiagnosticEnabled =
449
- context.applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE != 0
450
- private var homeOffsetDiagnosticSequence = 0L
451
-
452
- private fun homeOffsetDiagnostic(phase: String, state: RecyclerView.State? = null) {
453
- if (!homeOffsetDiagnosticEnabled) return
454
- try {
455
- val first = layoutManager.findFirstVisibleItemPosition()
456
- val firstView = layoutManager.findViewByPosition(first)
457
- val holder = firstView?.let { recyclerView.getChildViewHolder(it) }
458
- val lastView = layoutManager.findViewByPosition(layoutManager.findLastVisibleItemPosition())
459
- val lastHolder = lastView?.let { recyclerView.getChildViewHolder(it) }
460
- fun adapterOrdinal(value: RecyclerView.Adapter<*>?): Int = when (value) {
461
- headerSlotAdapter -> 0
462
- adapter -> 1
463
- emptySlotAdapter -> 2
464
- structuralSpacerAdapter -> 3
465
- footerSlotAdapter -> 4
466
- else -> -1
467
- }
468
- val focused = recyclerView.findFocus()
469
- val focusChild = focused?.let { recyclerView.findContainingItemView(it) }
470
- val focusHolder = focusChild?.let { recyclerView.getChildViewHolder(it) }
471
- OneKeyLog.debug("NativeList", "[HOME-OFFSET-DIAG] listPhase=$phase " +
472
- "seq=${++homeOffsetDiagnosticSequence} wallMs=${System.currentTimeMillis()} monoMs=${SystemClock.uptimeMillis()} " +
473
- "list=${System.identityHashCode(this)} view=${System.identityHashCode(recyclerView)} tag=$id " +
474
- "generation=${config?.generation} configuredCount=${config?.items?.size} " +
475
- "counts=${headerSlotAdapter.itemCount},${adapter.itemCount},${emptySlotAdapter.itemCount},${structuralSpacerAdapter.itemCount},${footerSlotAdapter.itemCount} " +
476
- "total=${scrollContentAdapter.itemCount} pendingCommand=${pendingScrollRequest?.javaClass?.simpleName ?: "none"} " +
477
- "stateCount=${state?.itemCount} preLayout=${state?.isPreLayout} structureChanged=${state?.didStructureChange()} predictive=${state?.willRunPredictiveAnimations()} " +
478
- "first=$first last=${layoutManager.findLastVisibleItemPosition()} " +
479
- "adapterOrdinal=${adapterOrdinal(holder?.bindingAdapter)} layout=${holder?.layoutPosition} absolute=${holder?.absoluteAdapterPosition} binding=${holder?.bindingAdapterPosition} lastAdapterOrdinal=${adapterOrdinal(lastHolder?.bindingAdapter)} lastLayout=${lastHolder?.layoutPosition} lastAbsolute=${lastHolder?.absoluteAdapterPosition} lastBinding=${lastHolder?.bindingAdapterPosition} " +
480
- "anchorTop=${firstView?.let(layoutManager::getDecoratedTop)} paddingTop=${recyclerView.paddingTop} " +
481
- "childHeight=${firstView?.height} height=${recyclerView.height} range=${recyclerView.computeVerticalScrollRange()} extent=${recyclerView.computeVerticalScrollExtent()} " +
482
- "canUp=${recyclerView.canScrollVertically(-1)} canDown=${recyclerView.canScrollVertically(1)} " +
483
- "focusClass=${focused?.javaClass?.simpleName ?: "none"} focusId=${focused?.id} focusAdapterOrdinal=${adapterOrdinal(focusHolder?.bindingAdapter)} focusLayout=${focusHolder?.layoutPosition} focusPosition=${focusHolder?.absoluteAdapterPosition} focusBinding=${focusHolder?.bindingAdapterPosition}")
484
- } catch (_: Exception) {
485
- // Diagnostic reads must not affect layout or command delivery.
486
- }
487
- }
488
-
489
444
  fun mountContainerSlot(view: View, index: Int) {
490
445
  containerSlots.add(index.coerceIn(0, containerSlots.size), view)
491
446
  updateContainerSlots()
@@ -797,7 +752,6 @@ class NativeListView(
797
752
  }
798
753
 
799
754
  private fun updateContainerSlots() {
800
- homeOffsetDiagnostic("slots-before")
801
755
  val headerWasAbsent = headerSlotAdapter.itemCount == 0
802
756
  val firstVisible = layoutManager.findFirstVisibleItemPosition()
803
757
  val firstView = layoutManager.findViewByPosition(firstVisible)
@@ -820,7 +774,6 @@ class NativeListView(
820
774
  layoutManager.scrollToPositionWithOffset(0, 0)
821
775
  }
822
776
  }
823
- homeOffsetDiagnostic("slots-after")
824
777
  layoutManager.spanSizeLookup.invalidateSpanIndexCache()
825
778
  recyclerView.requestLayout()
826
779
  }
@@ -1609,6 +1562,7 @@ class NativeListView(
1609
1562
  structuralScrollInterrupted = false
1610
1563
  structuralFooterCompensatedHeightPx = null
1611
1564
  recyclerView.itemAnimator = null
1565
+ acceptRowIndex(next, previous)
1612
1566
  config = next
1613
1567
  pruneMeasuredRowExtents(next.items)
1614
1568
  updateContainerSlots()
@@ -1705,7 +1659,11 @@ class NativeListView(
1705
1659
  }
1706
1660
  }
1707
1661
 
1708
- private fun updatePrefixTailSnapshot(previous: NativeListConfig, next: NativeListConfig): Boolean {
1662
+ private fun updatePrefixTailSnapshot(
1663
+ previous: NativeListConfig,
1664
+ next: NativeListConfig,
1665
+ acceptIndex: Boolean = false,
1666
+ ): Boolean {
1709
1667
  val tail = structuralTail ?: return false
1710
1668
  if (structuralTailPreparing || structuralTailFinalizing ||
1711
1669
  structuralTailRowsInAdapterPx > 0 ||
@@ -1728,6 +1686,7 @@ class NativeListView(
1728
1686
  explicitTailRowSpacingPx(after, next.itemSpacing))
1729
1687
  return false
1730
1688
  }
1689
+ if (acceptIndex) acceptRowIndex(next, previous)
1731
1690
  config = next
1732
1691
  adapter.selectedKeys = next.selectedKeys
1733
1692
  adapter.submitList(next.items.take(tail.prefixCount)) {
@@ -2097,7 +2056,6 @@ class NativeListView(
2097
2056
  private var dispatchingScrollRequest: ScrollRequest? = null
2098
2057
  private var commandLayoutRequest: ScrollRequest? = null
2099
2058
  private var commandAlignmentRequest: ScrollRequest? = null
2100
- private var commandFinishDiagnosticReason: String? = null
2101
2059
  private var readingIntentEpoch = 0L
2102
2060
  private var pendingBodyStartEpoch: Long? = null
2103
2061
  private val actionAnchorInstanceId = UUID.randomUUID().toString()
@@ -2109,6 +2067,17 @@ class NativeListView(
2109
2067
  private var lastMarketPaginationAnchorLogAtMs = 0L
2110
2068
  private var disposed = false
2111
2069
  private var resourcesDisposed = false
2070
+ private var acceptedKeyIndex: Map<String, Int>? = null
2071
+
2072
+ private fun acceptRowIndex(next: NativeListConfig, previous: NativeListConfig?) {
2073
+ if (previous != null && acceptedKeyIndex != null &&
2074
+ previous.generation == next.generation && previous.items.size == next.items.size &&
2075
+ previous.items.indices.all { index ->
2076
+ previous.items[index].key == next.items[index].key &&
2077
+ previous.items[index].type == next.items[index].type
2078
+ }) return
2079
+ acceptedKeyIndex = next.items.withIndex().associate { it.value.key to it.index }
2080
+ }
2112
2081
 
2113
2082
  init {
2114
2083
  orientation = VERTICAL
@@ -2121,12 +2090,10 @@ class NativeListView(
2121
2090
  // OneKey patch: full-width selector header backgrounds do not change row content insets.
2122
2091
  recyclerView.addItemDecoration(SelectorBackgroundDecoration(adapter))
2123
2092
  recyclerView.addItemDecoration(ContainerSlotInsetDecoration { slotInsetPx to slotRightInsetPx })
2124
- if (homeOffsetDiagnosticEnabled) layoutManager.onDiagnosticLayout = ::homeOffsetDiagnostic
2125
2093
  layoutManager.onBeforeDataLayout = {
2126
2094
  if (pendingBodyStartEpoch == readingIntentEpoch && adapter.itemCount > 0 && pendingScrollRequest == null) {
2127
2095
  layoutManager.scrollToPositionWithOffset(0, 0)
2128
2096
  pendingBodyStartEpoch = null
2129
- homeOffsetDiagnostic("first-fill-body-start")
2130
2097
  }
2131
2098
  pendingStructuralTransition?.let(::alignPendingStructuralAnchor)
2132
2099
  }
@@ -2420,7 +2387,6 @@ class NativeListView(
2420
2387
  } catch (_: Exception) {
2421
2388
  return
2422
2389
  }
2423
- homeOffsetDiagnostic("snapshot-before-nextCount=${next.items.size}")
2424
2390
  invalidateActionAnchor("snapshot")
2425
2391
  val previous = config
2426
2392
  val transition = next.structuralTransition
@@ -2469,7 +2435,9 @@ class NativeListView(
2469
2435
  if (structuralTail != null) {
2470
2436
  if (!disclosureGeometryInvalid && !animateStructure && oldKeys == nextKeys &&
2471
2437
  (Build.VERSION.SDK_INT < 26 || ValueAnimator.areAnimatorsEnabled()) &&
2472
- previous != null && updatePrefixTailSnapshot(previous, next)) return
2438
+ previous != null && updatePrefixTailSnapshot(previous, next, acceptIndex = true)) {
2439
+ return
2440
+ }
2473
2441
  heldTailEpoch = holdStructuralTailUntilListCommit()
2474
2442
  // Keep the accepted presentation until the full adapter list has committed.
2475
2443
  animateStructure = false
@@ -2522,6 +2490,7 @@ class NativeListView(
2522
2490
  previous.items[index].content != next.items[index].content
2523
2491
  }
2524
2492
  }.toSet()
2493
+ acceptRowIndex(next, previous)
2525
2494
  config = next
2526
2495
  if (heldTailEpoch == null) {
2527
2496
  disclosureFraction = if (next.disclosure?.expanded == true) 1f else 0f
@@ -2540,7 +2509,6 @@ class NativeListView(
2540
2509
  if (previous.listStyle?.toString() != next.listStyle?.toString()) bindFooter(next)
2541
2510
  adapter.submitList(next.items) {
2542
2511
  val committed: () -> Unit = {
2543
- homeOffsetDiagnostic("snapshot-stable-submit-commit")
2544
2512
  // OneKey patch: DiffUtil has dispatched its payloads; release the old serialized rows.
2545
2513
  next.items.forEach { it.selectionUpdateFromContent = null }
2546
2514
  recyclerView.post {
@@ -2580,6 +2548,7 @@ class NativeListView(
2580
2548
  layoutManager.getDecoratedTop(it) - recyclerView.paddingTop
2581
2549
  }
2582
2550
  } else null
2551
+ acceptRowIndex(next, previous)
2583
2552
  config = next
2584
2553
  if (heldTailEpoch == null) {
2585
2554
  disclosureFraction = if (next.disclosure?.expanded == true) 1f else 0f
@@ -2626,7 +2595,6 @@ class NativeListView(
2626
2595
  pendingStructuralTransition = it.copy(spacerInserted = true)
2627
2596
  pendingStructuralTransition?.let(::alignPendingStructuralAnchor)
2628
2597
  }
2629
- homeOffsetDiagnostic("snapshot-submit-commit-marketAnchor=${marketStartOffset != null}")
2630
2598
  if (marketStartOffset != null) {
2631
2599
  layoutManager.scrollToPositionWithOffset(scrollPositionForRow(0), marketStartOffset)
2632
2600
  }
@@ -2914,20 +2882,22 @@ class NativeListView(
2914
2882
 
2915
2883
  fun applyPatches(patchesJson: String) {
2916
2884
  val current = config ?: return
2885
+ val indexByKey = acceptedKeyIndex ?: return
2917
2886
  val patches = try {
2918
2887
  JSONArray(patchesJson)
2919
2888
  } catch (_: Exception) {
2920
2889
  return
2921
2890
  }
2922
- val indexByKey = current.items.withIndex().associate { it.value.key to it.index }
2923
2891
  val pending = ArrayList<Pair<Int, JSONObject>>(patches.length())
2924
2892
  val seen = HashSet<String>()
2925
2893
  for (index in 0 until patches.length()) {
2926
2894
  val patch = patches.optJSONObject(index) ?: return
2927
2895
  val key = patch.optString("key")
2928
2896
  val itemIndex = indexByKey[key] ?: return
2897
+ val item = current.items.getOrNull(itemIndex) ?: return
2898
+ if (item.key != key) return
2929
2899
  if (!seen.add(key)) return
2930
- if (patch.optString("type") != current.items[itemIndex].type) return
2900
+ if (patch.optString("type") != item.type) return
2931
2901
  val changes = patch.optJSONObject("changes") ?: return
2932
2902
  pending.add(itemIndex to changes)
2933
2903
  }
@@ -3035,7 +3005,6 @@ class NativeListView(
3035
3005
  commandLayoutRequest = null
3036
3006
  commandAlignmentRequest = null
3037
3007
  acceptedScrollRequest = request
3038
- commandFinishDiagnosticReason = null
3039
3008
  readingIntentEpoch++
3040
3009
  pendingBodyStartEpoch = null
3041
3010
  val explicitTop = when (request) {
@@ -3077,15 +3046,6 @@ class NativeListView(
3077
3046
 
3078
3047
  private fun finishScrollCommandIfSettled() {
3079
3048
  val request = acceptedScrollRequest ?: return
3080
- if (homeOffsetDiagnosticEnabled && executingScrollCommand) {
3081
- val reason = "pendingOwn=${pendingScrollRequest === request}-dispatchOwn=${dispatchingScrollRequest === request}" +
3082
- "-layoutOwn=${commandLayoutRequest === request}-alignOwn=${commandAlignmentRequest === request}" +
3083
- "-computing=${recyclerView.isComputingLayout}-scrollState=${recyclerView.scrollState}-smooth=${layoutManager.isSmoothScrolling}"
3084
- if (commandFinishDiagnosticReason != reason) {
3085
- commandFinishDiagnosticReason = reason
3086
- homeOffsetDiagnostic("command-finish-gates-$reason")
3087
- }
3088
- }
3089
3049
  if (
3090
3050
  !executingScrollCommand || pendingScrollRequest === request ||
3091
3051
  dispatchingScrollRequest === request || commandLayoutRequest === request ||
@@ -3101,7 +3061,6 @@ class NativeListView(
3101
3061
  private fun requestScroll(request: ScrollRequest) {
3102
3062
  acceptScrollRequest(request)
3103
3063
  if (config != null && acceptedScrollRequest !== request) return
3104
- homeOffsetDiagnostic("command-request-kind=${request.javaClass.simpleName}")
3105
3064
  if (performScroll(request)) {
3106
3065
  pendingScrollRequest = null
3107
3066
  finishScrollCommandIfSettled()
@@ -3117,7 +3076,6 @@ class NativeListView(
3117
3076
  if (pendingScrollRequest === request) pendingScrollRequest = null
3118
3077
  return
3119
3078
  }
3120
- homeOffsetDiagnostic("command-pending-kind=${request.javaClass.simpleName}")
3121
3079
  if (performScroll(request)) {
3122
3080
  pendingScrollRequest = null
3123
3081
  finishScrollCommandIfSettled()
@@ -3125,7 +3083,6 @@ class NativeListView(
3125
3083
  }
3126
3084
 
3127
3085
  private fun performScroll(request: ScrollRequest): Boolean {
3128
- homeOffsetDiagnostic("command-perform-kind=${request.javaClass.simpleName}")
3129
3086
  val current = config ?: return false
3130
3087
  if (adapter.itemCount != current.items.size) return false
3131
3088
  if (recyclerView.width <= 0 || recyclerView.height <= 0) return false
@@ -3306,13 +3263,11 @@ class NativeListView(
3306
3263
  val startView = manager.findViewByPosition(0)
3307
3264
  val paddingStart = if (manager.orientation == RecyclerView.VERTICAL) manager.paddingTop else manager.paddingLeft
3308
3265
  val relativeStart = startView?.let { decoratedStart(manager, it) - paddingStart }
3309
- homeOffsetDiagnostic("command-top-dispatch-first=${manager.findFirstVisibleItemPosition()}-relativeStart=$relativeStart-smooth=${manager.isSmoothScrolling}")
3310
3266
  if (
3311
3267
  startView != null && manager.findFirstVisibleItemPosition() == 0 && relativeStart == 0 &&
3312
3268
  recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE &&
3313
3269
  !recyclerView.isComputingLayout && !manager.isSmoothScrolling
3314
3270
  ) {
3315
- homeOffsetDiagnostic("command-top-noop")
3316
3271
  return
3317
3272
  }
3318
3273
  recyclerView.smoothScrollToPosition(0)
@@ -3465,6 +3420,7 @@ class NativeListView(
3465
3420
  fun dispose() {
3466
3421
  if (disposed) return
3467
3422
  disposed = true
3423
+ acceptedKeyIndex = null
3468
3424
  if (structuralTail != null) discardStructuralTail()
3469
3425
  val cancelTag = R.id.onekey_native_scroll_coordinator_command_cancel_listener
3470
3426
  if (recyclerView.getTag(cancelTag) === coordinatorCommandCancelListener) recyclerView.setTag(cancelTag, null)
@@ -3487,7 +3443,6 @@ class NativeListView(
3487
3443
  visibleEventScheduled = false
3488
3444
  layoutManager.onChildLaidOut = null
3489
3445
  layoutManager.onLayoutPassCompleted = null
3490
- layoutManager.onDiagnosticLayout = null
3491
3446
  layoutManager.onBeforeDataLayout = null
3492
3447
  pendingBodyStartEpoch = null
3493
3448
  executingScrollCommand = false
@@ -4501,6 +4456,7 @@ class NativeListView(
4501
4456
  if (from != RecyclerView.NO_POSITION && to != RecyclerView.NO_POSITION && from != to && reordered != null) {
4502
4457
  val moved = reordered.getOrNull(to)
4503
4458
  if (moved != null) {
4459
+ acceptedKeyIndex = reordered.withIndex().associate { it.value.key to it.index }
4504
4460
  config = config?.copy(items = reordered)
4505
4461
  val payload = JSONObject()
4506
4462
  .put("key", moved.key)
package/docs/SPEC.md CHANGED
@@ -418,6 +418,16 @@ section index titles retain their separate development-only
418
418
  no-surrounding-whitespace assertion.
419
419
  The 256-code-unit key limit is a development assertion, not a production limit.
420
420
 
421
+ Each iOS and Android host retains an index from accepted logical row keys to
422
+ row positions. An accepted complete snapshot reuses that index only when its
423
+ generation and ordered `(key, type)` sequence match the prior accepted
424
+ snapshot; otherwise it replaces the index. Reorder commits rebuild it and
425
+ disposal clears it. Patch batches reuse the index and never include retiring
426
+ presentation rows in it. They validate the whole batch against the current
427
+ accepted row models before changing config or presentation; invalid batches
428
+ leave both unchanged. iOS updates only changed accepted entries in its
429
+ presentation lookup after a valid patch, preserving any retiring rows.
430
+
421
431
  ### Validation environments and rejected input
422
432
 
423
433
  Development builds (`__DEV__ === true`) run the complete snapshot and patch
@@ -444,6 +454,24 @@ validators or Web behavior.
444
454
  An `undefined` value in an eligible field stays on the changed-row path only
445
455
  when that field was already `undefined`; clearing a present value uses the
446
456
  complete-snapshot path.
457
+
458
+ `planNativeListPatches(previous, next)` is an explicit, pure public helper for
459
+ callers that own two valid, immutable snapshots. It returns a readonly empty
460
+ batch for equal snapshots, value-only `identity` or `dataRow` row patches when
461
+ only eligible values change, and `undefined` when the caller must deliver a
462
+ complete snapshot. It never dispatches, accepts or validates an update, and
463
+ does not deep-copy, freeze or cache caller input. Returned patches may refer
464
+ to `next`'s immutable values; the caller retains baseline and commit ownership.
465
+ The component does not automatically invoke this planner for prop snapshots. Any
466
+ change outside `rows`, including generation, selection, layout, list style, empty state or
467
+ footer, requires a complete snapshot. Row keys, order and types must match.
468
+ `identity` may patch `subtitle`, `subtitleSegments` and `trailing`; `dataRow`
469
+ may patch non-asset columns and `trailing` while preserving the first asset
470
+ column. Changes to other row fields or to the presence of optional patch
471
+ fields require a complete snapshot. Comparison is by JSON value, ignores
472
+ object property order and properties whose value is `undefined`, and keeps
473
+ array order significant.
474
+
447
475
  Rejection emits a diagnostic without including row keys, text or image URLs.
448
476
  Explicit calls to the exported validation functions still throw on rejected
449
477
  input, so development tooling can inspect the full contract failure. Rejection
@@ -1040,7 +1068,7 @@ data adapter; adapter binding indices stay local while layout-manager positions
1040
1068
  are explicitly translated. Slots span all grid columns, do not select/reorder,
1041
1069
  and do not emit row actions, visible-row indices, or image-prefetch work.
1042
1070
 
1043
- ### Native disclosure slots and settlement (source implemented; limited runtime verification)
1071
+ ### Disclosure slots and settlement (source implemented; limited runtime verification)
1044
1072
 
1045
1073
  Native callers may opt in with `snapshot.disclosure: { expanded: boolean,
1046
1074
  expandedTrailingInset?: number }`, `listExpandedContent`, and
@@ -1048,9 +1076,18 @@ expandedTrailingInset?: number }`, `listExpandedContent`, and
1048
1076
  row count, the expanded slot's measured height, and the one-shot structural
1049
1077
  transition command. `expandedTrailingInset` defaults to zero and must be a
1050
1078
  finite, non-negative number of logical pixels. Without `disclosure`, the
1051
- existing four-slot and structural-transition behavior is unchanged. Web,
1052
- Desktop, and extension retain their existing structural presentation; these
1053
- native slots do not change the Web scroll-owner contract.
1079
+ existing four-slot and structural-transition behavior is unchanged. On Web,
1080
+ `C` and `T` occupy the existing single React footer band after the list rows,
1081
+ followed by the expanded trailing inset and the caller's footer `F`. `C` is
1082
+ mounted on first expansion and may remain mounted for that scope after collapse.
1083
+ Without an accepted `disclosure`, supplied `C` and `T` are hidden and inert.
1084
+ At the collapsed endpoint `C` has zero layout height and is hidden from pointer,
1085
+ keyboard, and accessibility interaction; `T` remains mounted and interactive
1086
+ through rapid reversals. Web does not use the native settlement callback to
1087
+ release `C`. The Web engine continues to measure that one footer band and to
1088
+ own its existing structural-tail animation and external scroll-host correction;
1089
+ its per-frame presentation need not match the native clip geometry. Desktop
1090
+ and extension retain their existing structural presentation.
1054
1091
 
1055
1092
  The native slot order is 0 header, 1 empty, 2 existing footer `F`, 3 sidecar,
1056
1093
  4 expanded content `C`, and 5 stable structure toggle `T`; the optional iOS
@@ -1097,8 +1134,14 @@ structural transition. An initial collapsed snapshot may omit or mount an
1097
1134
  empty `C` root; later collapse keeps its mounted instance through settlement.
1098
1135
 
1099
1136
  For each newly consumed `structuralTransition.id` with `disclosure`, native
1100
- emits `onStructuralTransitionSettled` once for the latest non-superseded id,
1101
- with JSON `{ transitionId: string, status: 'completed' | 'interrupted',
1137
+ emits `onStructuralTransitionSettled` once for the latest non-superseded id
1138
+ when a listener is registered. Without a listener, native still settles the
1139
+ command and releases its pending transition state, but does not serialize or
1140
+ cross the callback boundary. Adding or replacing a listener does not replay a
1141
+ settled id; removing it stops delivery for subsequent settlements. The caller
1142
+ may keep `C` mounted after settlement; native still controls its visibility,
1143
+ interaction, and accessibility. The callback carries JSON
1144
+ `{ transitionId: string, status: 'completed' | 'interrupted',
1102
1145
  settledExpanded: boolean }`. `settledExpanded` describes the accepted target
1103
1146
  after native geometry and scroll ownership have reached that state, never a
1104
1147
  guess from measured `C` height. Natural animation completion, reduced motion,
@@ -1112,8 +1155,9 @@ The caller guards the callback by its latest id and current list/account/network
1112
1155
  owner; a matching numeric id from a prior owner must not unmount current `C`.
1113
1156
  An already settled id
1114
1157
  does not re-emit on a same-id patch. Disposal drops the callback with its
1115
- owner. An unsupported or immediately settled new id must still acknowledge;
1116
- otherwise a caller could retain `C` indefinitely after collapse.
1158
+ owner. An unsupported or immediately settled new id must still acknowledge
1159
+ when a listener is registered; otherwise a caller could retain `C`
1160
+ indefinitely after collapse.
1117
1161
 
1118
1162
  On Android, mounting/unmounting a slot or changing its actual rounded native
1119
1163
  height MUST request one coalesced RecyclerView measurement/layout repair. The
@@ -119,7 +119,14 @@ final class HybridNativeList: HybridNativeListSpec {
119
119
  var onSelectionDelta: ((_ payloadJson: String) -> Void)?
120
120
  var onReorder: ((_ payloadJson: String) -> Void)?
121
121
  var onEndReached: ((_ payloadJson: String) -> Void)?
122
- var onStructuralTransitionSettled: ((_ payloadJson: String) -> Void)?
122
+ var onStructuralTransitionSettled: ((_ payloadJson: String) -> Void)? {
123
+ didSet {
124
+ runOnMain { [weak self] in
125
+ guard let self else { return }
126
+ self.hostView?.onStructuralTransitionSettled = self.onStructuralTransitionSettled
127
+ }
128
+ }
129
+ }
123
130
  var onVisibleRangeChanged: ((_ payloadJson: String) -> Void)? {
124
131
  didSet {
125
132
  runOnMain { [weak self] in
@@ -136,9 +143,6 @@ final class HybridNativeList: HybridNativeListSpec {
136
143
  hostView?.onSelectionDelta = { [weak self] in self?.onSelectionDelta?($0) }
137
144
  hostView?.onReorder = { [weak self] in self?.onReorder?($0) }
138
145
  hostView?.onEndReached = { [weak self] in self?.onEndReached?($0) }
139
- hostView?.onStructuralTransitionSettled = { [weak self] in
140
- self?.onStructuralTransitionSettled?($0)
141
- }
142
146
  }
143
147
 
144
148
  func applySnapshot(snapshotJson: String) throws {
@@ -654,7 +654,16 @@ final class NativeListView: UIView {
654
654
  private var sectionIndexHostHeightConstraint: NSLayoutConstraint?
655
655
  private var footerHeightConstraint: NSLayoutConstraint!
656
656
  private var dataSource: UICollectionViewDiffableDataSource<Int, String>!
657
+ private final class AcceptedRowIndex {
658
+ let byKey: [String: Int]
659
+
660
+ init(items: [NativeListItem]) {
661
+ byKey = Dictionary(uniqueKeysWithValues: items.enumerated().map { ($1.key, $0) })
662
+ }
663
+ }
664
+
657
665
  private var config: NativeListConfig?
666
+ private var acceptedRowIndex: AcceptedRowIndex?
658
667
  private var itemsByKey: [String: NativeListItem] = [:]
659
668
  private var endReachedGeneration: Int?
660
669
  private var lastVisibleRange: (first: Int, last: Int, firstKey: String?, lastKey: String?)?
@@ -996,6 +1005,18 @@ final class NativeListView: UIView {
996
1005
  }
997
1006
  }
998
1007
 
1008
+ private func acceptRowIndex(for next: NativeListConfig, replacing previous: NativeListConfig?) {
1009
+ if let previous, acceptedRowIndex != nil,
1010
+ previous.generation == next.generation,
1011
+ previous.items.count == next.items.count,
1012
+ zip(previous.items, next.items).allSatisfy({ old, new in
1013
+ old.key == new.key && old.type == new.type
1014
+ }) {
1015
+ return
1016
+ }
1017
+ acceptedRowIndex = AcceptedRowIndex(items: next.items)
1018
+ }
1019
+
999
1020
  func applySnapshotJson(_ json: String) {
1000
1021
  guard let next = try? NativeListConfig.parse(json: json) else { return }
1001
1022
  let transition = next.structuralTransition
@@ -1140,6 +1161,7 @@ final class NativeListView: UIView {
1140
1161
  if let current = config, !newDisclosureCommand,
1141
1162
  structuralRemovedItems.isEmpty, structuralTail == nil,
1142
1163
  isControlledSelectionSnapshotUpdate(from: current, to: next) {
1164
+ acceptRowIndex(for: next, replacing: current)
1143
1165
  config = next
1144
1166
  itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
1145
1167
  // OneKey patch: A controlled selection echo is fully handled by the
@@ -1178,6 +1200,7 @@ final class NativeListView: UIView {
1178
1200
  }
1179
1201
  } ?? false
1180
1202
  if config?.generation != next.generation { endReachedGeneration = nil }
1203
+ acceptRowIndex(for: next, replacing: config)
1181
1204
  config = next
1182
1205
  if structuralTail == nil {
1183
1206
  disclosureCVisibleHeight = next.disclosure?.expanded == true ? containerSlotHeights[4] : 0
@@ -1367,7 +1390,8 @@ final class NativeListView: UIView {
1367
1390
  consumedStructuralTransitionID == pending.id,
1368
1391
  config?.disclosure?.expanded == pending.expanded else { return }
1369
1392
  pendingDisclosureSettlement = nil
1370
- emit(onStructuralTransitionSettled, [
1393
+ guard let callback = onStructuralTransitionSettled else { return }
1394
+ emit(callback, [
1371
1395
  "transitionId": pending.id,
1372
1396
  "status": status,
1373
1397
  "settledExpanded": pending.expanded,
@@ -1479,14 +1503,16 @@ final class NativeListView: UIView {
1479
1503
 
1480
1504
  func applyPatchesJson(_ json: String) {
1481
1505
  guard var current = config,
1506
+ let indexByKey = acceptedRowIndex?.byKey,
1482
1507
  let bytes = json.data(using: .utf8),
1483
1508
  let patches = try? JSONSerialization.jsonObject(with: bytes) as? [[String: Any]] else { return }
1484
- let indexByKey = Dictionary(uniqueKeysWithValues: current.items.enumerated().map { ($1.key, $0) })
1485
1509
  var seen = Set<String>()
1486
1510
  var pending: [(Int, [String: Any])] = []
1487
1511
  for patch in patches {
1488
1512
  let key = patch.string("key")
1489
1513
  guard let index = indexByKey[key],
1514
+ current.items.indices.contains(index),
1515
+ current.items[index].key == key,
1490
1516
  seen.insert(key).inserted,
1491
1517
  patch.string("type") == current.items[index].type,
1492
1518
  let changes = patch.dictionary("changes") else { return }
@@ -1535,12 +1561,9 @@ final class NativeListView: UIView {
1535
1561
  cancelInteractiveReorderForStructuralUpdate()
1536
1562
  }
1537
1563
  config = current
1538
- itemsByKey = Dictionary(uniqueKeysWithValues: current.items.map { ($0.key, $0) })
1539
- itemsByKey.merge(structuralRemovedItems) { current, _ in current }
1540
- if let tail = structuralTail, !tail.retiringKeys.isEmpty {
1541
- itemsByKey.merge(Dictionary(uniqueKeysWithValues: tail.items.map { ($0.key, $0) })) {
1542
- current, _ in current
1543
- }
1564
+ for (index, _) in pending {
1565
+ let item = current.items[index]
1566
+ itemsByKey[item.key] = item
1544
1567
  }
1545
1568
  if let tail = structuralTail {
1546
1569
  for key in changedKeys.union(marketQuoteKeys) {
@@ -2150,6 +2173,7 @@ final class NativeListView: UIView {
2150
2173
  let toIndex = keys.firstIndex(of: source.key),
2151
2174
  items.count == keys.count else { return }
2152
2175
  current.items = items
2176
+ acceptedRowIndex = AcceptedRowIndex(items: items)
2153
2177
  config = current
2154
2178
  guard source.index != toIndex else { return }
2155
2179
  var payload: [String: Any] = [
@@ -2841,6 +2865,7 @@ final class NativeListView: UIView {
2841
2865
  let selectionChanged = current.selectionMode != next.selectionMode ||
2842
2866
  current.selectedKeys != next.selectedKeys
2843
2867
  if current.generation != next.generation { endReachedGeneration = nil }
2868
+ acceptRowIndex(for: next, replacing: current)
2844
2869
  config = next
2845
2870
  itemsByKey = Dictionary(uniqueKeysWithValues: next.items.map { ($0.key, $0) })
2846
2871
  let changedKeys = next.items.compactMap { item -> String? in
@@ -3041,6 +3066,7 @@ final class NativeListView: UIView {
3041
3066
  dataSource = nil
3042
3067
 
3043
3068
  config = nil
3069
+ acceptedRowIndex = nil
3044
3070
  pagerStickyHeights.removeAllObjects()
3045
3071
  for slot in reactContainerSlots { slot.host.layer.mask = nil }
3046
3072
  stopStructuralAnimation()
@@ -3457,6 +3483,7 @@ extension NativeListView: UICollectionViewDragDelegate, UICollectionViewDropDele
3457
3483
  guard sourceItem.isReorderable, targetItem.isReorderable, sourceItem.sectionKey == targetItem.sectionKey else { return }
3458
3484
  current.items.remove(at: source.item)
3459
3485
  current.items.insert(sourceItem, at: destination.item)
3486
+ acceptedRowIndex = AcceptedRowIndex(items: current.items)
3460
3487
  config = current
3461
3488
  itemsByKey = Dictionary(uniqueKeysWithValues: current.items.map { ($0.key, $0) })
3462
3489
  var snapshot = NSDiffableDataSourceSnapshot<Int, String>()