@onekeyfe/react-native-native-list 6.7.0-18 → 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
  }
@@ -2103,7 +2056,6 @@ class NativeListView(
2103
2056
  private var dispatchingScrollRequest: ScrollRequest? = null
2104
2057
  private var commandLayoutRequest: ScrollRequest? = null
2105
2058
  private var commandAlignmentRequest: ScrollRequest? = null
2106
- private var commandFinishDiagnosticReason: String? = null
2107
2059
  private var readingIntentEpoch = 0L
2108
2060
  private var pendingBodyStartEpoch: Long? = null
2109
2061
  private val actionAnchorInstanceId = UUID.randomUUID().toString()
@@ -2138,12 +2090,10 @@ class NativeListView(
2138
2090
  // OneKey patch: full-width selector header backgrounds do not change row content insets.
2139
2091
  recyclerView.addItemDecoration(SelectorBackgroundDecoration(adapter))
2140
2092
  recyclerView.addItemDecoration(ContainerSlotInsetDecoration { slotInsetPx to slotRightInsetPx })
2141
- if (homeOffsetDiagnosticEnabled) layoutManager.onDiagnosticLayout = ::homeOffsetDiagnostic
2142
2093
  layoutManager.onBeforeDataLayout = {
2143
2094
  if (pendingBodyStartEpoch == readingIntentEpoch && adapter.itemCount > 0 && pendingScrollRequest == null) {
2144
2095
  layoutManager.scrollToPositionWithOffset(0, 0)
2145
2096
  pendingBodyStartEpoch = null
2146
- homeOffsetDiagnostic("first-fill-body-start")
2147
2097
  }
2148
2098
  pendingStructuralTransition?.let(::alignPendingStructuralAnchor)
2149
2099
  }
@@ -2437,7 +2387,6 @@ class NativeListView(
2437
2387
  } catch (_: Exception) {
2438
2388
  return
2439
2389
  }
2440
- homeOffsetDiagnostic("snapshot-before-nextCount=${next.items.size}")
2441
2390
  invalidateActionAnchor("snapshot")
2442
2391
  val previous = config
2443
2392
  val transition = next.structuralTransition
@@ -2560,7 +2509,6 @@ class NativeListView(
2560
2509
  if (previous.listStyle?.toString() != next.listStyle?.toString()) bindFooter(next)
2561
2510
  adapter.submitList(next.items) {
2562
2511
  val committed: () -> Unit = {
2563
- homeOffsetDiagnostic("snapshot-stable-submit-commit")
2564
2512
  // OneKey patch: DiffUtil has dispatched its payloads; release the old serialized rows.
2565
2513
  next.items.forEach { it.selectionUpdateFromContent = null }
2566
2514
  recyclerView.post {
@@ -2647,7 +2595,6 @@ class NativeListView(
2647
2595
  pendingStructuralTransition = it.copy(spacerInserted = true)
2648
2596
  pendingStructuralTransition?.let(::alignPendingStructuralAnchor)
2649
2597
  }
2650
- homeOffsetDiagnostic("snapshot-submit-commit-marketAnchor=${marketStartOffset != null}")
2651
2598
  if (marketStartOffset != null) {
2652
2599
  layoutManager.scrollToPositionWithOffset(scrollPositionForRow(0), marketStartOffset)
2653
2600
  }
@@ -3058,7 +3005,6 @@ class NativeListView(
3058
3005
  commandLayoutRequest = null
3059
3006
  commandAlignmentRequest = null
3060
3007
  acceptedScrollRequest = request
3061
- commandFinishDiagnosticReason = null
3062
3008
  readingIntentEpoch++
3063
3009
  pendingBodyStartEpoch = null
3064
3010
  val explicitTop = when (request) {
@@ -3100,15 +3046,6 @@ class NativeListView(
3100
3046
 
3101
3047
  private fun finishScrollCommandIfSettled() {
3102
3048
  val request = acceptedScrollRequest ?: return
3103
- if (homeOffsetDiagnosticEnabled && executingScrollCommand) {
3104
- val reason = "pendingOwn=${pendingScrollRequest === request}-dispatchOwn=${dispatchingScrollRequest === request}" +
3105
- "-layoutOwn=${commandLayoutRequest === request}-alignOwn=${commandAlignmentRequest === request}" +
3106
- "-computing=${recyclerView.isComputingLayout}-scrollState=${recyclerView.scrollState}-smooth=${layoutManager.isSmoothScrolling}"
3107
- if (commandFinishDiagnosticReason != reason) {
3108
- commandFinishDiagnosticReason = reason
3109
- homeOffsetDiagnostic("command-finish-gates-$reason")
3110
- }
3111
- }
3112
3049
  if (
3113
3050
  !executingScrollCommand || pendingScrollRequest === request ||
3114
3051
  dispatchingScrollRequest === request || commandLayoutRequest === request ||
@@ -3124,7 +3061,6 @@ class NativeListView(
3124
3061
  private fun requestScroll(request: ScrollRequest) {
3125
3062
  acceptScrollRequest(request)
3126
3063
  if (config != null && acceptedScrollRequest !== request) return
3127
- homeOffsetDiagnostic("command-request-kind=${request.javaClass.simpleName}")
3128
3064
  if (performScroll(request)) {
3129
3065
  pendingScrollRequest = null
3130
3066
  finishScrollCommandIfSettled()
@@ -3140,7 +3076,6 @@ class NativeListView(
3140
3076
  if (pendingScrollRequest === request) pendingScrollRequest = null
3141
3077
  return
3142
3078
  }
3143
- homeOffsetDiagnostic("command-pending-kind=${request.javaClass.simpleName}")
3144
3079
  if (performScroll(request)) {
3145
3080
  pendingScrollRequest = null
3146
3081
  finishScrollCommandIfSettled()
@@ -3148,7 +3083,6 @@ class NativeListView(
3148
3083
  }
3149
3084
 
3150
3085
  private fun performScroll(request: ScrollRequest): Boolean {
3151
- homeOffsetDiagnostic("command-perform-kind=${request.javaClass.simpleName}")
3152
3086
  val current = config ?: return false
3153
3087
  if (adapter.itemCount != current.items.size) return false
3154
3088
  if (recyclerView.width <= 0 || recyclerView.height <= 0) return false
@@ -3329,13 +3263,11 @@ class NativeListView(
3329
3263
  val startView = manager.findViewByPosition(0)
3330
3264
  val paddingStart = if (manager.orientation == RecyclerView.VERTICAL) manager.paddingTop else manager.paddingLeft
3331
3265
  val relativeStart = startView?.let { decoratedStart(manager, it) - paddingStart }
3332
- homeOffsetDiagnostic("command-top-dispatch-first=${manager.findFirstVisibleItemPosition()}-relativeStart=$relativeStart-smooth=${manager.isSmoothScrolling}")
3333
3266
  if (
3334
3267
  startView != null && manager.findFirstVisibleItemPosition() == 0 && relativeStart == 0 &&
3335
3268
  recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE &&
3336
3269
  !recyclerView.isComputingLayout && !manager.isSmoothScrolling
3337
3270
  ) {
3338
- homeOffsetDiagnostic("command-top-noop")
3339
3271
  return
3340
3272
  }
3341
3273
  recyclerView.smoothScrollToPosition(0)
@@ -3511,7 +3443,6 @@ class NativeListView(
3511
3443
  visibleEventScheduled = false
3512
3444
  layoutManager.onChildLaidOut = null
3513
3445
  layoutManager.onLayoutPassCompleted = null
3514
- layoutManager.onDiagnosticLayout = null
3515
3446
  layoutManager.onBeforeDataLayout = null
3516
3447
  pendingBodyStartEpoch = null
3517
3448
  executingScrollCommand = false
@@ -2049,44 +2049,112 @@ final class NativeListLifecycleTests: XCTestCase {
2049
2049
  view.setContainerSlotHeightsJson("[0,0,140,0,100,40]")
2050
2050
  let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
2051
2051
  list.contentInsetAdjustmentBehavior = .never
2052
+ let contentHost = try XCTUnwrap(slots[4].superview)
2052
2053
  var settlements: [(String, String)] = []
2054
+ let growSettled = expectation(description: "Disclosure growth settles")
2053
2055
  view.onStructuralTransitionSettled = { payload in
2054
2056
  guard let data = payload.data(using: .utf8),
2055
2057
  let object = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
2056
2058
  let id = object["transitionId"] as? String,
2057
2059
  let status = object["status"] as? String else { return }
2058
2060
  settlements.append((id, status))
2061
+ if id == "grow" && status == "completed" { growSettled.fulfill() }
2059
2062
  }
2060
2063
  view.applySnapshotJson(try structuralRowsSnapshot(count: 6, generation: 1,
2061
2064
  disclosureExpanded: false))
2062
2065
  view.layoutIfNeeded()
2066
+ list.layoutIfNeeded()
2067
+ drainMainQueue()
2068
+ XCTAssertTrue(contentHost.isHidden, "Initial collapsed content must be hidden")
2069
+ XCTAssertNil(Mirror(reflecting: view).descendant("structuralDisplayLink") as? CADisplayLink)
2070
+
2071
+ let growthPhase = expectation(description: "Disclosure growth presents a partial content mask")
2072
+ var growthObserved = false
2073
+ var growthLast = "no frame sampled"
2074
+ let growthStartedAt = CACurrentMediaTime()
2075
+ let growthProbe = Timer(timeInterval: 1.0 / 60, repeats: true) { _ in
2076
+ let clock = Mirror(reflecting: view).descendant("structuralDisplayLink") as? CADisplayLink
2077
+ let tail = Mirror(reflecting: view).descendant("structuralTail")
2078
+ let tailActive = tail.map { !Mirror(reflecting: $0).children.isEmpty } ?? false
2079
+ let maskHeight = contentHost.layer.mask?.frame.height
2080
+ growthLast = "clock=\(clock != nil) tail=\(tailActive) "
2081
+ + "mask=\(String(describing: maskHeight)) bounds=\(contentHost.bounds.height) "
2082
+ + "elapsed=\(CACurrentMediaTime() - growthStartedAt) settlements=\(settlements)"
2083
+ guard !growthObserved, let clock, tailActive, let maskHeight,
2084
+ maskHeight > 0, maskHeight < 100 else { return }
2085
+ growthObserved = true
2086
+ let animationStart = Mirror(reflecting: view).descendant("structuralAnimationStart")
2087
+ as? CFTimeInterval
2088
+ let animationDuration = Mirror(reflecting: view).descendant("structuralAnimationDuration")
2089
+ as? CFTimeInterval
2090
+ XCTAssertNotNil(animationStart, "The active disclosure clock must have a start time")
2091
+ XCTAssertNotNil(animationDuration, "The active disclosure clock must have a duration")
2092
+ view.setContainerSlotHeightsJson("[0,0,140,0,140,40]")
2093
+ XCTAssertTrue(Mirror(reflecting: view).descendant("structuralDisplayLink") as? CADisplayLink
2094
+ === clock, "Content growth must retain the active display link")
2095
+ XCTAssertEqual(Mirror(reflecting: view).descendant("structuralAnimationStart")
2096
+ as? CFTimeInterval, animationStart, "Content growth must keep the original deadline")
2097
+ XCTAssertEqual(Mirror(reflecting: view).descendant("structuralAnimationDuration")
2098
+ as? CFTimeInterval, animationDuration, "Content growth must keep the original duration")
2099
+ XCTAssertEqual(contentHost.layer.mask?.frame.height ?? -1, maskHeight, accuracy: 1,
2100
+ "Content growth must not jump the visible mask")
2101
+ growthPhase.fulfill()
2102
+ }
2103
+ RunLoop.main.add(growthProbe, forMode: .common)
2104
+ defer { growthProbe.invalidate() }
2063
2105
  view.applySnapshotJson(try structuralRowsSnapshot(count: 50, generation: 2,
2064
2106
  transitionID: "grow", durationMs: 800, disclosureExpanded: true))
2065
- waitForStructuralFrames(0.12)
2066
- let contentHost = try XCTUnwrap(slots[4].superview)
2067
- let beforeHeight = try XCTUnwrap(contentHost.layer.mask).frame.height
2068
- let clock = try XCTUnwrap(Mirror(reflecting: view).descendant("structuralDisplayLink")
2069
- as? CADisplayLink)
2070
- view.setContainerSlotHeightsJson("[0,0,140,0,140,40]")
2071
- XCTAssertTrue(Mirror(reflecting: view).descendant("structuralDisplayLink") as? CADisplayLink
2072
- === clock)
2073
- XCTAssertEqual(try XCTUnwrap(contentHost.layer.mask).frame.height,
2074
- beforeHeight, accuracy: 1)
2075
- waitForStructuralFrames(0.75)
2107
+ wait(for: [growthPhase], timeout: 1.5)
2108
+ guard growthObserved else {
2109
+ XCTFail("No partial disclosure growth frame observed: \(growthLast)")
2110
+ return
2111
+ }
2112
+ growthProbe.invalidate()
2113
+ wait(for: [growSettled], timeout: 1.5)
2076
2114
  XCTAssertEqual(contentHost.bounds.height, 140, accuracy: 1)
2077
2115
  XCTAssertNil(contentHost.layer.mask)
2078
2116
  XCTAssertTrue(contentHost.isUserInteractionEnabled)
2079
- XCTAssertEqual(settlements.map(\.0), ["grow"])
2117
+ XCTAssertEqual(settlements.map(\.0), ["grow"], "Growth must settle exactly once")
2080
2118
  XCTAssertEqual(settlements.last?.1, "completed")
2081
2119
 
2120
+ let collapsePhase = expectation(description: "Disclosure collapse presents a partial content mask")
2121
+ var collapseObserved = false
2122
+ var collapseLast = "no frame sampled"
2123
+ let collapseStartedAt = CACurrentMediaTime()
2124
+ let collapseProbe = Timer(timeInterval: 1.0 / 60, repeats: true) { _ in
2125
+ let clock = Mirror(reflecting: view).descendant("structuralDisplayLink") as? CADisplayLink
2126
+ let tail = Mirror(reflecting: view).descendant("structuralTail")
2127
+ let tailActive = tail.map { !Mirror(reflecting: $0).children.isEmpty } ?? false
2128
+ let maskHeight = contentHost.layer.mask?.frame.height
2129
+ collapseLast = "clock=\(clock != nil) tail=\(tailActive) "
2130
+ + "mask=\(String(describing: maskHeight)) bounds=\(contentHost.bounds.height) "
2131
+ + "elapsed=\(CACurrentMediaTime() - collapseStartedAt) settlements=\(settlements)"
2132
+ guard !collapseObserved, clock != nil, tailActive, let maskHeight,
2133
+ maskHeight > 0, maskHeight < 140 else { return }
2134
+ collapseObserved = true
2135
+ view.scrollViewWillBeginDragging(list)
2136
+ XCTAssertNil(Mirror(reflecting: view).descendant("structuralDisplayLink") as? CADisplayLink,
2137
+ "Dragging must stop the active disclosure display link")
2138
+ let remainingTail = Mirror(reflecting: view).descendant("structuralTail")
2139
+ XCTAssertNotNil(remainingTail, "The structural tail field must remain observable")
2140
+ XCTAssertFalse(remainingTail.map { !Mirror(reflecting: $0).children.isEmpty } ?? true,
2141
+ "Dragging must clear the temporary structural tail")
2142
+ XCTAssertTrue(contentHost.isHidden, "Dragging a collapse must hide content")
2143
+ XCTAssertEqual(settlements.map(\.0), ["grow", "drag"],
2144
+ "Dragging must settle the collapse exactly once")
2145
+ XCTAssertEqual(settlements.last?.1, "interrupted")
2146
+ collapsePhase.fulfill()
2147
+ }
2148
+ RunLoop.main.add(collapseProbe, forMode: .common)
2149
+ defer { collapseProbe.invalidate() }
2082
2150
  view.applySnapshotJson(try structuralRowsSnapshot(count: 6, generation: 3,
2083
2151
  transitionID: "drag", durationMs: 800, disclosureExpanded: false))
2084
- waitForStructuralFrames(0.08)
2085
- view.scrollViewWillBeginDragging(list)
2086
- XCTAssertNil(Mirror(reflecting: view).descendant("structuralDisplayLink") as? CADisplayLink)
2087
- XCTAssertTrue(contentHost.isHidden)
2088
- XCTAssertEqual(settlements.map(\.0), ["grow", "drag"])
2089
- XCTAssertEqual(settlements.last?.1, "interrupted")
2152
+ wait(for: [collapsePhase], timeout: 1.5)
2153
+ guard collapseObserved else {
2154
+ XCTFail("No partial disclosure collapse frame observed: \(collapseLast)")
2155
+ return
2156
+ }
2157
+ collapseProbe.invalidate()
2090
2158
  }
2091
2159
 
2092
2160
  func testDisclosureDirectCollapseKeepsToggleVisible() throws {
@@ -157,7 +157,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
157
157
  const containerSlotHeightsJson = JSON.stringify(slotHeights);
158
158
  const defaultSlotInset = snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0;
159
159
  const bandWidth = sidecarLayout ? Math.min(viewportWidth, sidecarLayout.maxContentWidth) : 0;
160
- const slotInset = sidecarLayout ? Math.max(0, (viewportWidth - bandWidth) / 2) : defaultSlotInset;
160
+ const slotInset = sidecarLayout ? Math.max(0, (viewportWidth - bandWidth) / 2) + defaultSlotInset : defaultSlotInset;
161
161
  const sidecarSpace = sidecarLayout ? sidecarLayout.width + sidecarLayout.gap : 0;
162
162
  const slotContents = [listHeader, listEmpty, listFooter, listSidecar, listExpandedContent, listStructureToggle];
163
163
  const recordSlotLayout = (index, height, epoch) => {
@@ -64,7 +64,14 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
64
64
  if (!Number.isFinite(inputStickyInset) || inputStickyInset < 0) throw new Error('webStickyInset must be finite and non-negative');
65
65
  return inputStickyInset;
66
66
  }) ?? 0, [inputStickyInset]);
67
- const preparedSnapshot = useMemo(() => containNativeListInput(() => validateSnapshot(inputSnapshot)), [inputSnapshot]);
67
+ // Freshness is limited to this component invocation; later renders revalidate.
68
+ let freshlyValidatedSnapshot;
69
+ const preparedSnapshot = useMemo(() => {
70
+ const prepared = containNativeListInput(() => validateSnapshot(inputSnapshot));
71
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- The value is intentionally render-local.
72
+ freshlyValidatedSnapshot = prepared;
73
+ return prepared;
74
+ }, [inputSnapshot]);
68
75
  const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
69
76
  const fontFamiliesJson = useNativeListFontFamiliesJson();
70
77
  const fontFamiliesJsonRef = useRef(fontFamiliesJson);
@@ -74,14 +81,16 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
74
81
  hasEmptySlotRef.current = hasEmptySlot;
75
82
  const [viewportWidth, setViewportWidth] = useState(0);
76
83
  const [sidecarHeight, setSidecarHeight] = useState(0);
77
- const normalizeWebSnapshot = (next, hasReactEmpty = hasEmptySlotRef.current, hasSlotLayout = useSlotLayoutRef.current) => {
84
+ const normalizeWebSnapshot = (next, hasReactEmpty = hasEmptySlotRef.current, hasSlotLayout = useSlotLayoutRef.current, validatedInThisRender = false) => {
78
85
  if (hasSlotLayout && next.layout.orientation === 'horizontal') throw new Error('Web parent scrolling and container slots support vertical lists only');
79
86
  const emptySlot = hasReactEmpty && next.rows.length === 0;
80
- const validated = validateSnapshot(emptySlot ? {
87
+ const normalized = emptySlot && next.emptyState !== undefined ? {
81
88
  ...next,
82
89
  emptyState: undefined
83
- } : next);
84
- return emptySlot ? {
90
+ } : next;
91
+ const validated = validatedInThisRender ? normalized : validateSnapshot(normalized);
92
+ // Preserve an already normalized fallback's identity across rerenders.
93
+ return emptySlot && validated.layout.contentPaddingBottom !== 0 ? {
85
94
  ...validated,
86
95
  layout: {
87
96
  ...validated.layout,
@@ -111,14 +120,17 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
111
120
  } = sidecarLayout;
112
121
  if (snapshot.layout.kind !== 'linear' || !Number.isFinite(width) || width <= 0 || !Number.isFinite(gap) || gap < 0 || !Number.isFinite(maxContentWidth) || maxContentWidth <= width + gap) throw new Error('Invalid NativeList sidecar layout');
113
122
  }
114
- return normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout);
115
- }) ?? acceptedSnapshotRef.current, [snapshot, hasEmptySlot, useSlotLayout, listSidecar, sidecarLayout]);
123
+ return normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout, preparedSnapshot !== undefined && preparedSnapshot === freshlyValidatedSnapshot);
124
+ }) ?? acceptedSnapshotRef.current,
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Preserve the existing memo dependencies; freshness is render-local.
126
+ [snapshot, hasEmptySlot, useSlotLayout, listSidecar, sidecarLayout]);
116
127
  const [slotState, setSlotState] = useState(() => ({
117
128
  hasRows: validatedSnapshot.rows.length > 0,
118
129
  emptyBottomPadding: !validatedSnapshot.rows.length && hasEmptySlot ? validatedSnapshot.layout.contentPaddingBottom ?? validatedSnapshot.layout.contentPadding ?? 0 : 0,
119
130
  padding: validatedSnapshot.layout.contentPaddingHorizontal ?? validatedSnapshot.layout.contentPadding ?? 0,
120
131
  disclosurePresent: validatedSnapshot.disclosure !== undefined,
121
132
  disclosureExpanded: validatedSnapshot.disclosure?.expanded === true,
133
+ hasExpandedContent: validatedSnapshot.disclosure?.expanded === true,
122
134
  expandedTrailingInset: validatedSnapshot.disclosure?.expandedTrailingInset ?? 0
123
135
  }));
124
136
  const synchronizeSlots = next => {
@@ -128,13 +140,17 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
128
140
  const disclosurePresent = next.disclosure !== undefined;
129
141
  const disclosureExpanded = next.disclosure?.expanded === true;
130
142
  const expandedTrailingInset = next.disclosure?.expandedTrailingInset ?? 0;
131
- setSlotState(previous => previous.hasRows === hasRows && previous.padding === padding && previous.emptyBottomPadding === emptyBottomPadding && previous.disclosurePresent === disclosurePresent && previous.disclosureExpanded === disclosureExpanded && previous.expandedTrailingInset === expandedTrailingInset ? previous : {
132
- hasRows,
133
- padding,
134
- emptyBottomPadding,
135
- disclosurePresent,
136
- disclosureExpanded,
137
- expandedTrailingInset
143
+ setSlotState(previous => {
144
+ const hasExpandedContent = previous.hasExpandedContent || disclosureExpanded;
145
+ return previous.hasRows === hasRows && previous.padding === padding && previous.emptyBottomPadding === emptyBottomPadding && previous.disclosurePresent === disclosurePresent && previous.disclosureExpanded === disclosureExpanded && previous.hasExpandedContent === hasExpandedContent && previous.expandedTrailingInset === expandedTrailingInset ? previous : {
146
+ hasRows,
147
+ padding,
148
+ emptyBottomPadding,
149
+ disclosurePresent,
150
+ disclosureExpanded,
151
+ hasExpandedContent,
152
+ expandedTrailingInset
153
+ };
138
154
  });
139
155
  };
140
156
  const snapshotRef = useRef(validatedSnapshot);
@@ -362,7 +378,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
362
378
  }) : null, hasFooterBand ? /*#__PURE__*/_jsxs(View, {
363
379
  testID: "native-list-footer-slot",
364
380
  style: footerBandStyle,
365
- children: [listExpandedContent !== undefined ? /*#__PURE__*/_jsx(View, {
381
+ children: [listExpandedContent !== undefined && slotState.hasExpandedContent ? /*#__PURE__*/_jsx(View, {
366
382
  testID: "native-list-expanded-content-slot",
367
383
  "aria-hidden": !slotState.disclosureExpanded,
368
384
  pointerEvents: slotState.disclosureExpanded ? 'auto' : 'none',
@@ -1604,7 +1604,7 @@ export class NativeListWebEngine {
1604
1604
  this.document.fonts?.addEventListener('loadingdone', this.handleWindowResize);
1605
1605
  this.observeSectionIndexTransforms();
1606
1606
  this.applyFontFamilies(fontFamiliesJson);
1607
- this.applySnapshot(this.snapshot);
1607
+ this.applyValidatedSnapshot(this.snapshot);
1608
1608
  }
1609
1609
  validateStickyInset(value = 0) {
1610
1610
  if (!Number.isFinite(value) || value < 0) throw new Error('webStickyInset must be finite and non-negative');
@@ -1674,6 +1674,9 @@ export class NativeListWebEngine {
1674
1674
  return next;
1675
1675
  });
1676
1676
  if (!validated) return;
1677
+ this.applyValidatedSnapshot(validated);
1678
+ }
1679
+ applyValidatedSnapshot(validated) {
1677
1680
  this.pressedHelpElement = undefined;
1678
1681
  this.invalidateActionAnchor('snapshot');
1679
1682
  const transition = validated.structuralTransition;
@@ -189,6 +189,7 @@ export declare class NativeListWebEngine {
189
189
  updateCallbacks(callbacks: NativeListWebCallbacks): void;
190
190
  setVirtualizationEnabled(enabled: boolean): void;
191
191
  applySnapshot(snapshot: NativeListSnapshot): void;
192
+ private applyValidatedSnapshot;
192
193
  private cancelStructuralAnimation;
193
194
  private handleStructuralUserScroll;
194
195
  private updateStructuralTailWindow;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-native-list",
3
- "version": "6.7.0-18",
3
+ "version": "6.7.0-19",
4
4
  "description": "Template-driven native RecyclerView and UICollectionView for React Native",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",
@@ -86,8 +86,8 @@
86
86
  "typescript": "^5.9.2"
87
87
  },
88
88
  "peerDependencies": {
89
- "@onekeyfe/react-native-image": "6.7.0-18",
90
- "@onekeyfe/react-native-native-logger": "6.7.0-18",
89
+ "@onekeyfe/react-native-image": "6.7.0-19",
90
+ "@onekeyfe/react-native-native-logger": "6.7.0-19",
91
91
  "react": "*",
92
92
  "react-native": "*",
93
93
  "react-native-nitro-modules": "0.37.0"
@@ -329,7 +329,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
329
329
  ? Math.min(viewportWidth, sidecarLayout.maxContentWidth)
330
330
  : 0;
331
331
  const slotInset = sidecarLayout
332
- ? Math.max(0, (viewportWidth - bandWidth) / 2)
332
+ ? Math.max(0, (viewportWidth - bandWidth) / 2) + defaultSlotInset
333
333
  : defaultSlotInset;
334
334
  const sidecarSpace = sidecarLayout
335
335
  ? sidecarLayout.width + sidecarLayout.gap
@@ -139,10 +139,16 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
139
139
  }) ?? 0,
140
140
  [inputStickyInset]
141
141
  );
142
- const preparedSnapshot = useMemo(
143
- () => containNativeListInput(() => validateSnapshot(inputSnapshot)),
144
- [inputSnapshot]
145
- );
142
+ // Freshness is limited to this component invocation; later renders revalidate.
143
+ let freshlyValidatedSnapshot: NativeListSnapshot | undefined;
144
+ const preparedSnapshot = useMemo(() => {
145
+ const prepared = containNativeListInput(() =>
146
+ validateSnapshot(inputSnapshot)
147
+ );
148
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- The value is intentionally render-local.
149
+ freshlyValidatedSnapshot = prepared;
150
+ return prepared;
151
+ }, [inputSnapshot]);
146
152
  const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
147
153
  const fontFamiliesJson = useNativeListFontFamiliesJson();
148
154
  const fontFamiliesJsonRef = useRef(fontFamiliesJson);
@@ -155,17 +161,23 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
155
161
  const normalizeWebSnapshot = (
156
162
  next: NativeListSnapshot,
157
163
  hasReactEmpty = hasEmptySlotRef.current,
158
- hasSlotLayout = useSlotLayoutRef.current
164
+ hasSlotLayout = useSlotLayoutRef.current,
165
+ validatedInThisRender = false
159
166
  ) => {
160
167
  if (hasSlotLayout && next.layout.orientation === 'horizontal')
161
168
  throw new Error(
162
169
  'Web parent scrolling and container slots support vertical lists only'
163
170
  );
164
171
  const emptySlot = hasReactEmpty && next.rows.length === 0;
165
- const validated = validateSnapshot(
166
- emptySlot ? { ...next, emptyState: undefined } : next
167
- );
168
- return emptySlot
172
+ const normalized =
173
+ emptySlot && next.emptyState !== undefined
174
+ ? { ...next, emptyState: undefined }
175
+ : next;
176
+ const validated = validatedInThisRender
177
+ ? normalized
178
+ : validateSnapshot(normalized);
179
+ // Preserve an already normalized fallback's identity across rerenders.
180
+ return emptySlot && validated.layout.contentPaddingBottom !== 0
169
181
  ? {
170
182
  ...validated,
171
183
  layout: { ...validated.layout, contentPaddingBottom: 0 },
@@ -218,8 +230,15 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
218
230
  )
219
231
  throw new Error('Invalid NativeList sidecar layout');
220
232
  }
221
- return normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout);
233
+ return normalizeWebSnapshot(
234
+ snapshot,
235
+ hasEmptySlot,
236
+ useSlotLayout,
237
+ preparedSnapshot !== undefined &&
238
+ preparedSnapshot === freshlyValidatedSnapshot
239
+ );
222
240
  }) ?? acceptedSnapshotRef.current,
241
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Preserve the existing memo dependencies; freshness is render-local.
223
242
  [snapshot, hasEmptySlot, useSlotLayout, listSidecar, sidecarLayout]
224
243
  );
225
244
  const [slotState, setSlotState] = useState(() => ({
@@ -236,6 +255,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
236
255
  0,
237
256
  disclosurePresent: validatedSnapshot.disclosure !== undefined,
238
257
  disclosureExpanded: validatedSnapshot.disclosure?.expanded === true,
258
+ hasExpandedContent: validatedSnapshot.disclosure?.expanded === true,
239
259
  expandedTrailingInset:
240
260
  validatedSnapshot.disclosure?.expandedTrailingInset ?? 0,
241
261
  }));
@@ -250,13 +270,16 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
250
270
  const disclosurePresent = next.disclosure !== undefined;
251
271
  const disclosureExpanded = next.disclosure?.expanded === true;
252
272
  const expandedTrailingInset = next.disclosure?.expandedTrailingInset ?? 0;
253
- setSlotState((previous) =>
254
- previous.hasRows === hasRows &&
255
- previous.padding === padding &&
256
- previous.emptyBottomPadding === emptyBottomPadding &&
257
- previous.disclosurePresent === disclosurePresent &&
258
- previous.disclosureExpanded === disclosureExpanded &&
259
- previous.expandedTrailingInset === expandedTrailingInset
273
+ setSlotState((previous) => {
274
+ const hasExpandedContent =
275
+ previous.hasExpandedContent || disclosureExpanded;
276
+ return previous.hasRows === hasRows &&
277
+ previous.padding === padding &&
278
+ previous.emptyBottomPadding === emptyBottomPadding &&
279
+ previous.disclosurePresent === disclosurePresent &&
280
+ previous.disclosureExpanded === disclosureExpanded &&
281
+ previous.hasExpandedContent === hasExpandedContent &&
282
+ previous.expandedTrailingInset === expandedTrailingInset
260
283
  ? previous
261
284
  : {
262
285
  hasRows,
@@ -264,9 +287,10 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
264
287
  emptyBottomPadding,
265
288
  disclosurePresent,
266
289
  disclosureExpanded,
290
+ hasExpandedContent,
267
291
  expandedTrailingInset,
268
- }
269
- );
292
+ };
293
+ });
270
294
  };
271
295
  const snapshotRef = useRef(validatedSnapshot);
272
296
  const snapshotPropRef = useRef(validatedSnapshot);
@@ -575,7 +599,8 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
575
599
  ) : null}
576
600
  {hasFooterBand ? (
577
601
  <View testID="native-list-footer-slot" style={footerBandStyle}>
578
- {listExpandedContent !== undefined ? (
602
+ {listExpandedContent !== undefined &&
603
+ slotState.hasExpandedContent ? (
579
604
  <View
580
605
  testID="native-list-expanded-content-slot"
581
606
  aria-hidden={!slotState.disclosureExpanded}
@@ -2611,7 +2611,7 @@ export class NativeListWebEngine {
2611
2611
  );
2612
2612
  this.observeSectionIndexTransforms();
2613
2613
  this.applyFontFamilies(fontFamiliesJson);
2614
- this.applySnapshot(this.snapshot);
2614
+ this.applyValidatedSnapshot(this.snapshot);
2615
2615
  }
2616
2616
 
2617
2617
  private validateStickyInset(value = 0): number {
@@ -2703,6 +2703,10 @@ export class NativeListWebEngine {
2703
2703
  return next;
2704
2704
  });
2705
2705
  if (!validated) return;
2706
+ this.applyValidatedSnapshot(validated);
2707
+ }
2708
+
2709
+ private applyValidatedSnapshot(validated: NativeListSnapshot) {
2706
2710
  this.pressedHelpElement = undefined;
2707
2711
  this.invalidateActionAnchor('snapshot');
2708
2712
  const transition = validated.structuralTransition;