@onekeyfe/react-native-native-list 3.0.180 → 6.7.0-11

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.
Files changed (84) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +1 -1
  2. package/docs/SPEC.md +449 -14
  3. package/ios/HybridNativeList.swift +11 -3
  4. package/ios/RNCNativeListView.swift +10 -6
  5. package/ios/tests/NativeListLifecycleTests.swift +28 -0
  6. package/lib/module/NativeList.js +42 -21
  7. package/lib/module/NativeList.web.js +163 -32
  8. package/lib/module/ScrollEdgeEffect.js +8 -0
  9. package/lib/module/index.js +1 -0
  10. package/lib/module/validation.js +358 -47
  11. package/lib/module/web/NativeListWebEngine.js +373 -67
  12. package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
  13. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  14. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  15. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  16. package/lib/module/web/templates/RowRendererRegistry.js +5 -3
  17. package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
  18. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
  19. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
  20. package/lib/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
  21. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
  22. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
  23. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
  24. package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
  25. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
  26. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
  27. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
  28. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
  29. package/lib/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
  30. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
  31. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
  32. package/lib/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
  33. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
  34. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
  35. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
  36. package/lib/typescript/src/NativeList.d.ts +2 -2
  37. package/lib/typescript/src/NativeList.nitro.d.ts +2 -1
  38. package/lib/typescript/src/NativeList.types.d.ts +14 -3
  39. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  40. package/lib/typescript/src/ScrollEdgeEffect.d.ts +5 -0
  41. package/lib/typescript/src/index.d.ts +1 -0
  42. package/lib/typescript/src/models.d.ts +71 -1
  43. package/lib/typescript/src/validation.d.ts +3 -0
  44. package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
  45. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  46. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  47. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  48. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
  49. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  50. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
  51. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
  52. package/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
  53. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
  56. package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
  57. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
  58. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
  59. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
  60. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
  61. package/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
  62. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
  63. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
  64. package/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
  65. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
  66. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
  67. package/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
  68. package/package.json +3 -3
  69. package/react-native-native-list.podspec +4 -1
  70. package/src/NativeList.nitro.ts +3 -1
  71. package/src/NativeList.tsx +102 -60
  72. package/src/NativeList.types.ts +15 -3
  73. package/src/NativeList.web.tsx +264 -65
  74. package/src/ScrollEdgeEffect.ts +4 -0
  75. package/src/index.ts +2 -0
  76. package/src/models.ts +93 -0
  77. package/src/validation.ts +785 -72
  78. package/src/web/NativeListWebEngine.ts +625 -100
  79. package/src/web/templates/ActivityRowRenderer.ts +723 -7
  80. package/src/web/templates/MarketRowRenderer.ts +19 -3
  81. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  82. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  83. package/src/web/templates/RowRendererRegistry.ts +10 -5
  84. package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
@@ -4,6 +4,34 @@ import XCTest
4
4
 
5
5
  @MainActor
6
6
  final class NativeListLifecycleTests: XCTestCase {
7
+ func testScrollEdgeStylesPreserveOverlayGeometryAndRestoreOriginalStyle() throws {
8
+ guard #available(iOS 26.0, *) else {
9
+ throw XCTSkip("Scroll-edge styles require iOS 26 or newer")
10
+ }
11
+ let view = try makeScrollingList()
12
+ let window = UIWindow(frame: view.frame)
13
+ window.addSubview(view)
14
+ let list = try XCTUnwrap(view.subviews.compactMap { $0 as? UICollectionView }.first)
15
+ let originalStyle = list.topEdgeEffect.style
16
+ let originalInset = list.contentInset.top
17
+ let overlay = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 64))
18
+ view.mountContainerSlot(overlay, atIndex: 3)
19
+ view.setTopScrollEdge(effect: .hard, overlayHeight: 64)
20
+ XCTAssertEqual(list.topEdgeEffect.style, .hard)
21
+ XCTAssertEqual(list.contentInset.top, originalInset + 64, accuracy: 0.01)
22
+ let offset = list.contentOffset
23
+ view.setTopScrollEdge(effect: .soft, overlayHeight: 64)
24
+ XCTAssertEqual(list.topEdgeEffect.style, .soft)
25
+ XCTAssertEqual(list.contentInset.top, originalInset + 64, accuracy: 0.01)
26
+ XCTAssertEqual(list.contentOffset, offset)
27
+ XCTAssertNotNil(overlay.superview)
28
+ view.setTopScrollEdge(effect: .none, overlayHeight: 0)
29
+ XCTAssertEqual(list.topEdgeEffect.style, originalStyle)
30
+ XCTAssertEqual(list.contentInset.top, originalInset, accuracy: 0.01)
31
+ view.unmountContainerSlot(overlay)
32
+ view.removeFromSuperview()
33
+ }
34
+
7
35
  func testInvalidCommandsPreserveAcceptedAnimationCompletion() throws {
8
36
  for invalid in 0..<3 {
9
37
  let view = try makeScrollingList()
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  import { useNativeListFontFamiliesJson } from "./fonts.js";
4
- import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
4
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
5
5
  import { OneKeyImageCache, OneKeyImageCachePolicy } from '@onekeyfe/react-native-image';
6
6
  import { NativeAvatarPrefetchModel, NativeAvatarPrefetchQueue } from "./avatarPrefetch.js";
7
7
  import { Platform, View } from 'react-native';
8
8
  import { callback, getHostComponent } from 'react-native-nitro-modules';
9
9
  import { isSelectableRow } from "./selection.js";
10
10
  import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
11
- import { applyRowPatches, serializePatches, serializeSnapshot } from "./validation.js";
11
+ import { applyRowPatches, containNativeListInput, emptyNativeListSnapshot, serializePatches, validatePatches, validateSnapshot } from "./validation.js";
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  const NativeListConfig = require('../nitrogen/generated/shared/json/NativeListConfig.json');
14
14
  const NativeListHost = getHostComponent('NativeList', () => NativeListConfig);
@@ -27,7 +27,7 @@ function parsePayload(payloadJson) {
27
27
  return JSON.parse(payloadJson);
28
28
  }
29
29
  export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
30
- snapshot,
30
+ snapshot: inputSnapshot,
31
31
  listHeader,
32
32
  listFooter,
33
33
  listEmpty,
@@ -35,6 +35,8 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
35
35
  topScrollEdgeEffect,
36
36
  scrollPositionThresholds,
37
37
  webVirtualizationEnabled: _webVirtualizationEnabled,
38
+ webScrollHost: _webScrollHost,
39
+ webStickyInset: _webStickyInset,
38
40
  webSectionIndexContainerRef: _webSectionIndexContainerRef,
39
41
  keyboardDismissMode = 'none',
40
42
  keyboardShouldPersistTaps = 'never',
@@ -53,15 +55,21 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
53
55
  initialScrollViewOffset,
54
56
  ...viewProps
55
57
  }, forwardedRef) {
58
+ const snapshotRef = useRef(emptyNativeListSnapshot());
59
+ const initializedSnapshot = useRef(false);
60
+ const hasContainerSlots = Boolean(listHeader || listEmpty || listFooter);
61
+ const prepareSnapshot = useCallback(next => {
62
+ const accepted = validateSnapshot(next);
63
+ if (hasContainerSlots && accepted.layout.orientation === 'horizontal') throw new Error('NativeList container slots require vertical orientation');
64
+ return accepted;
65
+ }, [hasContainerSlots]);
66
+ const snapshot = useMemo(() => containNativeListInput(() => prepareSnapshot(inputSnapshot)) ?? snapshotRef.current, [inputSnapshot, prepareSnapshot]);
56
67
  const fontFamiliesJson = useNativeListFontFamiliesJson();
57
68
  const [slotHeights, setSlotHeights] = useState([0, 0, 0]);
58
69
  const [topOverlayHeight, setTopOverlayHeight] = useState(0);
59
- const hasTopOverlay = Platform?.OS === 'ios' && parseInt(String(Platform.Version), 10) >= 26 && topScrollEdgeEffect === 'hard' && topOverlay != null;
70
+ const hasTopOverlay = Platform?.OS === 'ios' && parseInt(String(Platform.Version), 10) >= 26 && (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') && topOverlay != null;
60
71
  const containerSlotHeightsJson = JSON.stringify(slotHeights);
61
72
  const slotInset = snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0;
62
- if (snapshot.layout.orientation === 'horizontal' && (listHeader || listEmpty || listFooter)) {
63
- throw new Error('NativeList container slots require vertical orientation');
64
- }
65
73
  const slotContents = [listHeader, listEmpty, listFooter];
66
74
  const normalizedKeyboardShouldPersistTaps = keyboardShouldPersistTaps === true ? 'always' : keyboardShouldPersistTaps === false ? 'never' : keyboardShouldPersistTaps;
67
75
  const nativeRef = useRef(null);
@@ -87,7 +95,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
87
95
  onRefresh,
88
96
  onScrollToIndexFailed
89
97
  };
90
- const scrollPositionThresholdsJson = useMemo(() => {
98
+ const scrollPositionThresholdsJson = useMemo(() => containNativeListInput(() => {
91
99
  if (!scrollPositionThresholds || scrollPositionThresholds.enabled === false) return '';
92
100
  const {
93
101
  start,
@@ -100,15 +108,18 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
100
108
  start,
101
109
  end
102
110
  });
103
- }, [scrollPositionThresholds]);
104
- const snapshotJson = useMemo(() => serializeSnapshot(snapshot), [snapshot]);
105
- const snapshotRef = useRef(snapshot);
111
+ }) ?? '', [scrollPositionThresholds]);
112
+ const snapshotJson = useMemo(() => JSON.stringify(snapshot), [snapshot]);
106
113
  const previousSnapshotJsonRef = useRef(snapshotJson);
107
114
  const snapshotChanged = previousSnapshotJsonRef.current !== snapshotJson;
108
115
  if (snapshotChanged) {
109
116
  snapshotRef.current = snapshot;
110
117
  previousSnapshotJsonRef.current = snapshotJson;
111
118
  }
119
+ if (!initializedSnapshot.current) {
120
+ snapshotRef.current = snapshot;
121
+ initializedSnapshot.current = true;
122
+ }
112
123
  // OneKey patch: range events already cross the bridge only when row indices
113
124
  // change. Prefetch is optional work; scrolling and visible loads stay native.
114
125
  const avatarQueueRef = useRef(null);
@@ -140,7 +151,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
140
151
  useEffect(() => {
141
152
  updateAvatarPrefetchRef.current();
142
153
  }, [snapshot]);
143
- const initialScrollRef = useRef(initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
154
+ const initialScrollRef = useRef(containNativeListInput(() => initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
144
155
  index: initialScrollIndex,
145
156
  animated: false,
146
157
  viewPosition: initialScrollViewPosition,
@@ -152,7 +163,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
152
163
  viewPosition: initialScrollViewPosition,
153
164
  viewOffset: initialScrollViewOffset
154
165
  }, 'start')
155
- });
166
+ }));
156
167
  const didApplyInitialScroll = useRef(false);
157
168
  const emitIndexFailure = (index, reason) => {
158
169
  callbacksRef.current.onScrollToIndexFailed?.(scrollFailure(snapshotRef.current.rows, index, reason));
@@ -178,27 +189,37 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
178
189
  applyInitialScrollCallbackRef.current = applyInitialScroll;
179
190
  useImperativeHandle(forwardedRef, () => ({
180
191
  applySnapshot(nextSnapshot) {
181
- const nextSnapshotJson = serializeSnapshot(nextSnapshot);
192
+ const accepted = containNativeListInput(() => prepareSnapshot(nextSnapshot));
193
+ if (!accepted) return;
194
+ const nextSnapshotJson = JSON.stringify(accepted);
182
195
  nativeRef.current?.applySnapshot(nextSnapshotJson);
183
- snapshotRef.current = nextSnapshot;
196
+ snapshotRef.current = accepted;
184
197
  if (nativeRef.current && avatarLifecycle.current !== 'unmounted') {
185
- avatarModelRef.current?.replaceSnapshot(nextSnapshot.rows);
198
+ avatarModelRef.current?.replaceSnapshot(accepted.rows);
186
199
  updateAvatarPrefetchRef.current();
187
200
  }
188
201
  },
189
202
  applyPatches(patches) {
190
- if (patches.length === 0) return;
191
- const nextSnapshot = applyRowPatches(snapshotRef.current, patches);
203
+ const accepted = containNativeListInput(() => {
204
+ const normalized = validatePatches(patches);
205
+ return {
206
+ patches: normalized,
207
+ snapshot: applyRowPatches(snapshotRef.current, normalized),
208
+ json: serializePatches(normalized)
209
+ };
210
+ });
211
+ if (!accepted || accepted.patches.length === 0) return;
212
+ const nextSnapshot = accepted.snapshot;
192
213
  const native = nativeRef.current;
193
214
  const dispatch = native ? () => {
194
- native.applyPatches(serializePatches(patches));
215
+ native.applyPatches(accepted.json);
195
216
  snapshotRef.current = nextSnapshot;
196
217
  } : undefined;
197
218
  if (avatarLifecycle.current === 'unmounted') {
198
219
  dispatch?.();
199
220
  return;
200
221
  }
201
- if (avatarModelRef.current?.applyPatches(patches, dispatch)) updateAvatarPrefetchRef.current();
222
+ if (avatarModelRef.current?.applyPatches(accepted.patches, dispatch)) updateAvatarPrefetchRef.current();
202
223
  },
203
224
  reconcileSelection(selectedKeys) {
204
225
  nativeRef.current?.reconcileSelection(JSON.stringify(selectedKeys));
@@ -325,7 +346,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
325
346
  fontFamiliesJson: fontFamiliesJson,
326
347
  snapshotJson: snapshotJson,
327
348
  containerSlotHeightsJson: containerSlotHeightsJson,
328
- topScrollEdgeHard: hasTopOverlay,
349
+ topScrollEdgeEffect: hasTopOverlay ? topScrollEdgeEffect ?? 'none' : 'none',
329
350
  topOverlayHeight: hasTopOverlay ? topOverlayHeight : 0,
330
351
  scrollPositionThresholdsJson: scrollPositionThresholdsJson,
331
352
  keyboardDismissMode: keyboardDismissMode,
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  import { useNativeListFontFamiliesJson } from "./fonts.js";
4
- import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
4
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
5
5
  import { View } from 'react-native';
6
6
  import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
7
- import { serializePatches, validateSnapshot } from "./validation.js";
7
+ import { applyRowPatches, containNativeListInput, emptyNativeListSnapshot, validatePatches, validateSnapshot } from "./validation.js";
8
8
  import { NativeListWebEngine } from "./web/NativeListWebEngine.js";
9
9
  import { acquireNativeListAvatar, canonicalNativeListAvatarUri } from "./web/NativeListWebAvatarCache.js";
10
- import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  export function preloadNativeListAvatarImages(sources) {
12
12
  if (typeof document === 'undefined') return Promise.resolve(false);
13
13
  const uris = [...new Set(sources.map(source => canonicalNativeListAvatarUri(source.uri)).filter(uri => uri !== undefined))];
@@ -22,12 +22,14 @@ export function preloadNativeListAvatarImages(sources) {
22
22
  }))).then(results => results.every(Boolean));
23
23
  }
24
24
  export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
25
- snapshot,
26
- listHeader: _listHeader,
27
- listEmpty: _listEmpty,
28
- listFooter: _listFooter,
25
+ snapshot: inputSnapshot,
26
+ listHeader,
27
+ listEmpty,
28
+ listFooter,
29
29
  topOverlay: _topOverlay,
30
30
  topScrollEdgeEffect: _topScrollEdgeEffect,
31
+ webScrollHost,
32
+ webStickyInset: inputStickyInset = 0,
31
33
  scrollPositionThresholds: _scrollPositionThresholds,
32
34
  onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
33
35
  webVirtualizationEnabled = true,
@@ -48,23 +50,74 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
48
50
  initialScrollViewOffset,
49
51
  ...viewProps
50
52
  }, forwardedRef) {
53
+ const acceptedSnapshotRef = useRef(emptyNativeListSnapshot());
54
+ const initializedSnapshot = useRef(false);
55
+ const webStickyInset = useMemo(() => containNativeListInput(() => {
56
+ if (!Number.isFinite(inputStickyInset) || inputStickyInset < 0) throw new Error('webStickyInset must be finite and non-negative');
57
+ return inputStickyInset;
58
+ }) ?? 0, [inputStickyInset]);
59
+ const preparedSnapshot = useMemo(() => containNativeListInput(() => validateSnapshot(inputSnapshot)), [inputSnapshot]);
60
+ const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
51
61
  const fontFamiliesJson = useNativeListFontFamiliesJson();
52
62
  const fontFamiliesJsonRef = useRef(fontFamiliesJson);
53
63
  fontFamiliesJsonRef.current = fontFamiliesJson;
64
+ const hasEmptySlot = listEmpty !== undefined;
65
+ const hasEmptySlotRef = useRef(hasEmptySlot);
66
+ hasEmptySlotRef.current = hasEmptySlot;
67
+ const [slotState, setSlotState] = useState(() => ({
68
+ hasRows: snapshot.rows.length > 0,
69
+ emptyBottomPadding: !snapshot.rows.length && hasEmptySlot ? snapshot.layout.contentPaddingBottom ?? snapshot.layout.contentPadding ?? 0 : 0,
70
+ padding: snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0
71
+ }));
72
+ const synchronizeSlots = next => {
73
+ const hasRows = next.rows.length > 0;
74
+ const padding = next.layout.contentPaddingHorizontal ?? next.layout.contentPadding ?? 0;
75
+ const emptyBottomPadding = !hasRows && hasEmptySlotRef.current ? next.layout.contentPaddingBottom ?? next.layout.contentPadding ?? 0 : 0;
76
+ setSlotState(previous => previous.hasRows === hasRows && previous.padding === padding && previous.emptyBottomPadding === emptyBottomPadding ? previous : {
77
+ hasRows,
78
+ padding,
79
+ emptyBottomPadding
80
+ });
81
+ };
82
+ const normalizeWebSnapshot = (next, hasReactEmpty = hasEmptySlotRef.current, hasSlotLayout = useSlotLayoutRef.current) => {
83
+ if (hasSlotLayout && next.layout.orientation === 'horizontal') throw new Error('Web parent scrolling and container slots support vertical lists only');
84
+ const emptySlot = hasReactEmpty && next.rows.length === 0;
85
+ const validated = validateSnapshot(emptySlot ? {
86
+ ...next,
87
+ emptyState: undefined
88
+ } : next);
89
+ return emptySlot ? {
90
+ ...validated,
91
+ layout: {
92
+ ...validated.layout,
93
+ contentPaddingBottom: 0
94
+ }
95
+ } : validated;
96
+ };
54
97
  const [host, setHost] = useState(null);
98
+ const [contentBounds, setContentBounds] = useState(null);
99
+ const [ownedScrollHost, setOwnedScrollHost] = useState(null);
100
+ const useSlotLayoutRef = useRef(false);
101
+ useSlotLayoutRef.current ||= webScrollHost !== undefined || listHeader !== undefined || listEmpty !== undefined || listFooter !== undefined;
102
+ const useSlotLayout = useSlotLayoutRef.current;
103
+ const resolvedScrollHost = webScrollHost === undefined ? useSlotLayout ? ownedScrollHost : undefined : webScrollHost;
55
104
  const engineRef = useRef(undefined);
56
105
  const webVirtualizationEnabledRef = useRef(webVirtualizationEnabled);
57
106
  webVirtualizationEnabledRef.current = webVirtualizationEnabled;
58
- const validatedSnapshot = useMemo(() => validateSnapshot(snapshot), [snapshot]);
107
+ const validatedSnapshot = useMemo(() => containNativeListInput(() => normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout)) ?? acceptedSnapshotRef.current, [snapshot, hasEmptySlot, useSlotLayout]);
59
108
  const snapshotRef = useRef(validatedSnapshot);
60
109
  const snapshotPropRef = useRef(validatedSnapshot);
61
110
  // An imperative snapshot survives host mounting until the snapshot prop changes.
62
111
  if (snapshotPropRef.current !== validatedSnapshot) {
63
112
  snapshotPropRef.current = validatedSnapshot;
64
113
  snapshotRef.current = validatedSnapshot;
114
+ acceptedSnapshotRef.current = validatedSnapshot;
115
+ synchronizeSlots(snapshot);
116
+ }
117
+ if (!initializedSnapshot.current) {
118
+ acceptedSnapshotRef.current = validatedSnapshot;
119
+ initializedSnapshot.current = true;
65
120
  }
66
- // OneKey patch: React refs can be ready before the DOM engine is mounted.
67
- const pendingPatchesRef = useRef(undefined);
68
121
  const appliedSnapshotRef = useRef(undefined);
69
122
  const callbacksRef = useRef({});
70
123
  callbacksRef.current = {
@@ -77,7 +130,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
77
130
  onRefresh,
78
131
  onScrollToIndexFailed
79
132
  };
80
- const initialScrollRef = useRef(initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
133
+ const initialScrollRef = useRef(containNativeListInput(() => initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
81
134
  index: initialScrollIndex,
82
135
  animated: false,
83
136
  viewPosition: initialScrollViewPosition,
@@ -89,26 +142,42 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
89
142
  viewPosition: initialScrollViewPosition,
90
143
  viewOffset: initialScrollViewOffset
91
144
  }, 'start')
92
- });
145
+ }));
93
146
  const didApplyInitialScroll = useRef(false);
147
+ const scrollOptionsRef = useRef({
148
+ stickyInset: webStickyInset,
149
+ ownsRefresh: webScrollHost === undefined
150
+ });
151
+ scrollOptionsRef.current = {
152
+ stickyInset: webStickyInset,
153
+ ownsRefresh: webScrollHost === undefined
154
+ };
94
155
  useEffect(() => {
95
- if (!host) return;
96
- const engine = new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current);
156
+ if (!host || resolvedScrollHost === null || useSlotLayout && !contentBounds) return;
157
+ const engine = containNativeListInput(() => new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current, {
158
+ scrollHost: resolvedScrollHost,
159
+ contentBounds: contentBounds ?? undefined,
160
+ ...scrollOptionsRef.current
161
+ }));
162
+ if (!engine) return;
163
+ host.style.height = '';
97
164
  engineRef.current = engine;
98
165
  appliedSnapshotRef.current = snapshotRef.current;
99
- const pending = pendingPatchesRef.current;
100
- pendingPatchesRef.current = undefined;
101
- if (pending?.snapshot === snapshotRef.current) pending.batches.forEach(patches => engine.applyPatches(patches));
102
166
  const initial = initialScrollRef.current;
103
167
  if (initial && !didApplyInitialScroll.current) {
104
168
  didApplyInitialScroll.current = true;
105
169
  if (initial.index !== undefined) engine.scrollToIndex(initial.index, initial.scroll);else if (initial.key !== undefined) engine.scrollToKey(initial.key, initial.scroll);
106
170
  }
107
171
  return () => {
172
+ // Keep the paused tab in normal flow until its engine is restored.
173
+ host.style.height = `${engine.currentContentHeight()}px`;
108
174
  engine.destroy();
109
175
  if (engineRef.current === engine) engineRef.current = undefined;
110
176
  };
111
- }, [host, webSectionIndexContainerRef]);
177
+ }, [host, webSectionIndexContainerRef, resolvedScrollHost, contentBounds, useSlotLayout]);
178
+ useEffect(() => {
179
+ engineRef.current?.setStickyInset(webStickyInset);
180
+ }, [webStickyInset]);
112
181
  useEffect(() => {
113
182
  engineRef.current?.setFontFamiliesJson(fontFamiliesJson);
114
183
  }, [fontFamiliesJson]);
@@ -118,7 +187,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
118
187
  useEffect(() => {
119
188
  engineRef.current?.updateCallbacks(callbacksRef.current);
120
189
  });
121
- useEffect(() => {
190
+ useLayoutEffect(() => {
122
191
  const engine = engineRef.current;
123
192
  if (!engine || appliedSnapshotRef.current === validatedSnapshot) return;
124
193
  engine.applySnapshot(validatedSnapshot);
@@ -129,23 +198,26 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
129
198
  };
130
199
  useImperativeHandle(forwardedRef, () => ({
131
200
  applySnapshot(nextSnapshot) {
132
- const next = validateSnapshot(nextSnapshot);
133
- pendingPatchesRef.current = undefined;
201
+ const next = containNativeListInput(() => normalizeWebSnapshot(nextSnapshot));
202
+ if (!next) return;
203
+ engineRef.current?.applySnapshot(next);
134
204
  snapshotRef.current = next;
205
+ acceptedSnapshotRef.current = next;
135
206
  appliedSnapshotRef.current = next;
136
- engineRef.current?.applySnapshot(next);
207
+ synchronizeSlots(next);
137
208
  },
138
209
  applyPatches(patches) {
139
- if (patches.length > 0) {
140
- serializePatches(patches);
141
- // engineRef.current?.applyPatches(patches);
142
- if (engineRef.current) engineRef.current.applyPatches(patches);else {
143
- if (pendingPatchesRef.current?.snapshot !== snapshotRef.current) pendingPatchesRef.current = {
144
- snapshot: snapshotRef.current,
145
- batches: []
146
- };
147
- pendingPatchesRef.current.batches.push(patches);
210
+ const accepted = containNativeListInput(() => validatePatches(patches));
211
+ if (accepted && accepted.length > 0) {
212
+ const engine = engineRef.current;
213
+ if (engine) {
214
+ engine.applyPatches(accepted);
215
+ snapshotRef.current = engine.currentSnapshot();
216
+ } else {
217
+ const next = containNativeListInput(() => applyRowPatches(snapshotRef.current, accepted));
218
+ if (next) snapshotRef.current = next;
148
219
  }
220
+ acceptedSnapshotRef.current = snapshotRef.current;
149
221
  }
150
222
  },
151
223
  reconcileSelection(selectedKeys) {
@@ -208,9 +280,68 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
208
280
  const setHostRef = useCallback(value => {
209
281
  setHost(value);
210
282
  }, []);
211
- return /*#__PURE__*/_jsx(View, {
283
+ const setBoundsRef = useCallback(value => {
284
+ setContentBounds(value);
285
+ }, []);
286
+ const ownedScrollElementRef = useRef(null);
287
+ const setScrollHostRef = useCallback(value => {
288
+ const element = value;
289
+ if (ownedScrollElementRef.current !== element) ownedScrollElementRef.current?.removeAttribute('data-collapsible-pager-scroll');
290
+ element?.setAttribute('data-collapsible-pager-scroll', 'true');
291
+ ownedScrollElementRef.current = element;
292
+ setOwnedScrollHost(element);
293
+ }, []);
294
+ if (!useSlotLayout) return /*#__PURE__*/_jsx(View, {
212
295
  ...viewProps,
213
296
  ref: setHostRef
214
297
  });
298
+ const padding = slotState.padding;
299
+ const content = /*#__PURE__*/_jsxs(View, {
300
+ ref: setBoundsRef,
301
+ style: {
302
+ position: 'relative',
303
+ flexShrink: 0,
304
+ minWidth: 0
305
+ },
306
+ children: [listHeader !== undefined ? /*#__PURE__*/_jsx(View, {
307
+ style: {
308
+ paddingHorizontal: padding
309
+ },
310
+ children: listHeader
311
+ }) : null, /*#__PURE__*/_jsx(View, {
312
+ ref: setHostRef,
313
+ style: {
314
+ flexShrink: 0,
315
+ minWidth: 0
316
+ }
317
+ }), !slotState.hasRows && hasEmptySlot ? /*#__PURE__*/_jsx(View, {
318
+ style: {
319
+ paddingHorizontal: padding,
320
+ paddingBottom: slotState.emptyBottomPadding
321
+ },
322
+ children: listEmpty
323
+ }) : null, listFooter !== undefined ? /*#__PURE__*/_jsx(View, {
324
+ style: {
325
+ paddingHorizontal: padding
326
+ },
327
+ children: listFooter
328
+ }) : null]
329
+ });
330
+ return /*#__PURE__*/_jsx(View, {
331
+ ...viewProps,
332
+ style: [viewProps.style, {
333
+ position: 'relative',
334
+ minHeight: 0
335
+ }],
336
+ children: webScrollHost === undefined ? /*#__PURE__*/_jsx(View, {
337
+ ref: setScrollHostRef,
338
+ style: {
339
+ position: 'absolute',
340
+ inset: 0,
341
+ overflow: 'scroll'
342
+ },
343
+ children: content
344
+ }) : content
345
+ });
215
346
  });
216
347
  //# sourceMappingURL=NativeList.web.js.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ export let ScrollEdgeEffect = /*#__PURE__*/function (ScrollEdgeEffect) {
4
+ ScrollEdgeEffect["Hard"] = "hard";
5
+ ScrollEdgeEffect["Soft"] = "soft";
6
+ return ScrollEdgeEffect;
7
+ }({});
8
+ //# sourceMappingURL=ScrollEdgeEffect.js.map
@@ -4,4 +4,5 @@ export { NativeList, preloadNativeListAvatarImages } from './NativeList';
4
4
  export { applyRowPatches, serializePatches, serializeSnapshot, validatePatches, validateSnapshot } from "./validation.js";
5
5
  export { checkboxStateForKeys, checkboxStateForSection, isSelectableRow, reduceSelection, selectionStateFromSnapshot } from "./selection.js";
6
6
  export { configureNativeListFonts } from "./fonts.js";
7
+ export { ScrollEdgeEffect } from "./ScrollEdgeEffect.js";
7
8
  //# sourceMappingURL=index.js.map