@onekeyfe/react-native-native-list 6.7.0-2 → 6.7.0-21

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 (148) hide show
  1. package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
  2. package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
  3. package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +35 -7
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +25 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListAdapter.kt +17 -1
  6. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  8. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +102 -7
  9. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +225 -11
  10. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  11. package/android/src/main/java/com/onekey/nativelist/NativeListMarketRenderer.kt +92 -28
  12. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +149 -3
  14. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  16. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  18. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  19. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  20. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1953 -117
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +35 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  24. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  25. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  26. package/docs/ROW_TEMPLATES.md +70 -11
  27. package/docs/SPEC.md +1235 -20
  28. package/docs/STYLE_SPEC.md +6 -0
  29. package/ios/HybridNativeList.swift +21 -2
  30. package/ios/NativeListAccessoryStack.swift +235 -39
  31. package/ios/NativeListActivityDetailsView.swift +30 -11
  32. package/ios/NativeListActivityRenderer.swift +8 -2
  33. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  34. package/ios/NativeListDataRowRenderer.swift +155 -27
  35. package/ios/NativeListDesignAssets.swift +9 -0
  36. package/ios/NativeListIdentityRenderer.swift +239 -31
  37. package/ios/NativeListLeadingVisual.swift +119 -22
  38. package/ios/NativeListMarketRenderer.swift +113 -18
  39. package/ios/NativeListMessageRenderer.swift +34 -1
  40. package/ios/NativeListModels.swift +42 -2
  41. package/ios/NativeListRendererRegistry.swift +1 -0
  42. package/ios/NativeListResolvedText.swift +2 -1
  43. package/ios/NativeListRowHost.swift +14 -0
  44. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  45. package/ios/RNCNativeListView.swift +1052 -58
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  59. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  60. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  61. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  62. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  63. package/ios/tests/NativeListActivityPresentationTests.swift +153 -0
  64. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  65. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  66. package/ios/tests/NativeListLifecycleTests.swift +2789 -3
  67. package/ios/tests/NativeListMarketMetricsTests.swift +117 -0
  68. package/lib/module/NativeList.js +223 -36
  69. package/lib/module/NativeList.web.js +260 -33
  70. package/lib/module/index.js +1 -1
  71. package/lib/module/models.js +3 -0
  72. package/lib/module/selection.js +1 -1
  73. package/lib/module/validation.js +1386 -81
  74. package/lib/module/web/NativeListWebEngine.js +914 -80
  75. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  76. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  77. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  78. package/lib/module/web/templates/IdentityRowRenderer.js +145 -5
  79. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  80. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  81. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  82. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  83. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  84. package/lib/module/web/templates/RowRendererRegistry.js +8 -3
  85. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  86. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  87. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  88. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  89. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  90. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  91. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  92. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  93. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  94. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  95. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  96. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  97. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  98. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  99. package/lib/typescript/src/NativeList.d.ts +3 -3
  100. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  101. package/lib/typescript/src/NativeList.types.d.ts +29 -1
  102. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  103. package/lib/typescript/src/index.d.ts +2 -2
  104. package/lib/typescript/src/models.d.ts +196 -17
  105. package/lib/typescript/src/validation.d.ts +20 -0
  106. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  107. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  109. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  110. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  111. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  112. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  113. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  114. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  115. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  116. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  117. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  118. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  119. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  120. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  121. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  122. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  123. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  124. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  125. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  126. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  127. package/package.json +3 -3
  128. package/react-native-native-list.podspec +1 -0
  129. package/src/NativeList.nitro.ts +2 -0
  130. package/src/NativeList.tsx +418 -89
  131. package/src/NativeList.types.ts +34 -1
  132. package/src/NativeList.web.tsx +417 -66
  133. package/src/index.ts +2 -0
  134. package/src/models.ts +355 -143
  135. package/src/selection.ts +1 -0
  136. package/src/validation.ts +3315 -166
  137. package/src/web/NativeListWebEngine.ts +1473 -113
  138. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  139. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  140. package/src/web/templates/DataRowRenderer.ts +93 -20
  141. package/src/web/templates/IdentityRowRenderer.ts +217 -6
  142. package/src/web/templates/MarketRowRenderer.ts +19 -3
  143. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  144. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  145. package/src/web/templates/MessageRowRenderer.ts +23 -7
  146. package/src/web/templates/RowContainerStyle.ts +2 -0
  147. package/src/web/templates/RowRendererRegistry.ts +21 -6
  148. package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
@@ -71,6 +71,25 @@ export type ScrollToIndexFailedInfo = Readonly<{
71
71
  | 'item-not-found';
72
72
  }>;
73
73
 
74
+ /** Minimal DOM-free structural surface for an explicit Web scroll element. */
75
+ export type NativeListWebScrollHost = Readonly<{
76
+ clientWidth: number;
77
+ clientHeight: number;
78
+ scrollTop: number;
79
+ }>;
80
+
81
+ export type NativeListSidecarLayout = Readonly<{
82
+ width: number;
83
+ gap: number;
84
+ maxContentWidth: number;
85
+ }>;
86
+
87
+ export type StructuralTransitionSettledEvent = Readonly<{
88
+ transitionId: string;
89
+ status: 'completed' | 'interrupted';
90
+ settledExpanded: boolean;
91
+ }>;
92
+
74
93
  type InitialScrollProps =
75
94
  | Readonly<{
76
95
  initialScrollIndex?: never;
@@ -120,16 +139,27 @@ export type NativeListRef = Readonly<{
120
139
  export type NativeListProps = Omit<ViewProps, 'children'> &
121
140
  Readonly<{
122
141
  snapshot: NativeListSnapshot;
123
- /** Native-only, container-owned scroll content. Never rendered as a data row. */
142
+ /** Container-owned scroll content. Never rendered as a data row. */
124
143
  listHeader?: ReactNode;
125
144
  listFooter?: ReactNode;
126
145
  listEmpty?: ReactNode;
146
+ /** Native disclosure content, retained until its transition settles. */
147
+ listExpandedContent?: ReactNode;
148
+ /** Stable native disclosure toggle after expanded content. */
149
+ listStructureToggle?: ReactNode;
150
+ /** Scrolling right column for a vertical linear list. Requires sidecarLayout. */
151
+ listSidecar?: ReactNode;
152
+ sidecarLayout?: NativeListSidecarLayout;
127
153
  /** Fixed overlay above scrolling rows on iOS 26 and newer. */
128
154
  topOverlay?: ReactNode;
129
155
  /** Selects UIKit's top scroll-edge effect on iOS 26 and newer. */
130
156
  topScrollEdgeEffect?: `${ScrollEdgeEffect}`;
131
157
  /** Web only. Defaults to true and is ignored by the native host. */
132
158
  webVirtualizationEnabled?: boolean;
159
+ /** Web only: undefined owns scrolling, null waits for a host element. */
160
+ webScrollHost?: NativeListWebScrollHost | null;
161
+ /** Web only: visible sticky chrome above the parent's list viewport. */
162
+ webStickyInset?: number;
133
163
  /** Web only. Hosts the section index inside this container. */
134
164
  webSectionIndexContainerRef?: RefObject<View | null>;
135
165
  /** Defaults to `none`. `interactive` behaves as `none` on Android. */
@@ -145,6 +175,9 @@ export type NativeListProps = Omit<ViewProps, 'children'> &
145
175
  onReorder?: (event: ReorderEvent) => void;
146
176
  onEndReached?: (event: EndReachedEvent) => void;
147
177
  onVisibleRangeChanged?: (event: VisibleRangeChangedEvent) => void;
178
+ onStructuralTransitionSettled?: (
179
+ event: StructuralTransitionSettledEvent
180
+ ) => void;
148
181
  /** Native only. Emits initial state and hysteresis transitions, not scroll frames. */
149
182
  scrollPositionThresholds?: Readonly<{
150
183
  start: number;
@@ -4,13 +4,14 @@ import React, {
4
4
  useCallback,
5
5
  useEffect,
6
6
  useImperativeHandle,
7
+ useLayoutEffect,
7
8
  useMemo,
8
9
  useRef,
9
10
  useState,
10
11
  } from 'react';
11
12
  import { View } from 'react-native';
12
13
  import type { NativeListProps, NativeListRef } from './NativeList.types';
13
- import type { ImageSource, NativeListSnapshot, RowPatch } from './models';
14
+ import type { ImageSource, NativeListSnapshot } from './models';
14
15
  import {
15
16
  normalizeIndexScroll,
16
17
  normalizeKeyScroll,
@@ -20,7 +21,12 @@ import {
20
21
  validateOffset,
21
22
  type NormalizedPositionScroll,
22
23
  } from './scrolling';
23
- import { serializePatches, validateSnapshot } from './validation';
24
+ import {
25
+ applyRowPatches,
26
+ containNativeListInput,
27
+ emptyNativeListSnapshot,
28
+ validateSnapshot,
29
+ } from './validation';
24
30
  import {
25
31
  NativeListWebEngine,
26
32
  type NativeListWebCallbacks,
@@ -30,6 +36,8 @@ import {
30
36
  canonicalNativeListAvatarUri,
31
37
  } from './web/NativeListWebAvatarCache';
32
38
 
39
+ const collapsedExpandedContentStyle = { display: 'none' } as const;
40
+
33
41
  export type { NativeListProps, NativeListRef } from './NativeList.types';
34
42
  export type {
35
43
  ActionAnchorState,
@@ -82,12 +90,18 @@ export function preloadNativeListAvatarImages(
82
90
  export const NativeList = forwardRef<NativeListRef, NativeListProps>(
83
91
  function NativeList(
84
92
  {
85
- snapshot,
86
- listHeader: _listHeader,
87
- listEmpty: _listEmpty,
88
- listFooter: _listFooter,
93
+ snapshot: inputSnapshot,
94
+ listHeader,
95
+ listEmpty,
96
+ listFooter,
97
+ listExpandedContent,
98
+ listStructureToggle,
99
+ listSidecar,
100
+ sidecarLayout,
89
101
  topOverlay: _topOverlay,
90
102
  topScrollEdgeEffect: _topScrollEdgeEffect,
103
+ webScrollHost,
104
+ webStickyInset: inputStickyInset = 0,
91
105
  scrollPositionThresholds: _scrollPositionThresholds,
92
106
  onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
93
107
  webVirtualizationEnabled = true,
@@ -100,6 +114,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
100
114
  onReorder,
101
115
  onEndReached,
102
116
  onVisibleRangeChanged,
117
+ onStructuralTransitionSettled: _onStructuralTransitionSettled,
103
118
  onRefresh,
104
119
  onScrollToIndexFailed,
105
120
  initialScrollIndex,
@@ -110,32 +125,185 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
110
125
  },
111
126
  forwardedRef
112
127
  ) {
128
+ const acceptedSnapshotRef = useRef<NativeListSnapshot>(
129
+ emptyNativeListSnapshot()
130
+ );
131
+ const initializedSnapshot = useRef(false);
132
+ const webStickyInset = useMemo(
133
+ () =>
134
+ containNativeListInput(() => {
135
+ if (!Number.isFinite(inputStickyInset) || inputStickyInset < 0)
136
+ throw new Error('webStickyInset must be finite and non-negative');
137
+ return inputStickyInset;
138
+ }) ?? 0,
139
+ [inputStickyInset]
140
+ );
141
+ // Freshness is limited to this component invocation; later renders revalidate.
142
+ let freshlyValidatedSnapshot: NativeListSnapshot | undefined;
143
+ const preparedSnapshot = useMemo(() => {
144
+ const prepared = containNativeListInput(() =>
145
+ validateSnapshot(inputSnapshot)
146
+ );
147
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- The value is intentionally render-local.
148
+ freshlyValidatedSnapshot = prepared;
149
+ return prepared;
150
+ }, [inputSnapshot]);
151
+ const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
113
152
  const fontFamiliesJson = useNativeListFontFamiliesJson();
114
153
  const fontFamiliesJsonRef = useRef(fontFamiliesJson);
115
154
  fontFamiliesJsonRef.current = fontFamiliesJson;
155
+ const hasEmptySlot = listEmpty !== undefined;
156
+ const hasEmptySlotRef = useRef(hasEmptySlot);
157
+ hasEmptySlotRef.current = hasEmptySlot;
158
+ const [viewportWidth, setViewportWidth] = useState(0);
159
+ const [sidecarHeight, setSidecarHeight] = useState(0);
160
+ const normalizeWebSnapshot = (
161
+ next: NativeListSnapshot,
162
+ hasReactEmpty = hasEmptySlotRef.current,
163
+ hasSlotLayout = useSlotLayoutRef.current,
164
+ validatedInThisRender = false
165
+ ) => {
166
+ if (hasSlotLayout && next.layout.orientation === 'horizontal')
167
+ throw new Error(
168
+ 'Web parent scrolling and container slots support vertical lists only'
169
+ );
170
+ const emptySlot = hasReactEmpty && next.rows.length === 0;
171
+ const normalized =
172
+ emptySlot && next.emptyState !== undefined
173
+ ? { ...next, emptyState: undefined }
174
+ : next;
175
+ const validated = validatedInThisRender
176
+ ? normalized
177
+ : validateSnapshot(normalized);
178
+ // Preserve an already normalized fallback's identity across rerenders.
179
+ return emptySlot && validated.layout.contentPaddingBottom !== 0
180
+ ? {
181
+ ...validated,
182
+ layout: { ...validated.layout, contentPaddingBottom: 0 },
183
+ }
184
+ : validated;
185
+ };
116
186
  const [host, setHost] = useState<HTMLElement | null>(null);
187
+ const [contentBounds, setContentBounds] = useState<HTMLElement | null>(
188
+ null
189
+ );
190
+ const [ownedScrollHost, setOwnedScrollHost] = useState<HTMLElement | null>(
191
+ null
192
+ );
193
+ const useSlotLayoutRef = useRef(false);
194
+ useSlotLayoutRef.current ||=
195
+ webScrollHost !== undefined ||
196
+ listHeader !== undefined ||
197
+ listEmpty !== undefined ||
198
+ listFooter !== undefined;
199
+ useSlotLayoutRef.current ||= listSidecar !== undefined;
200
+ useSlotLayoutRef.current ||=
201
+ listExpandedContent !== undefined || listStructureToggle !== undefined;
202
+ const useSlotLayout = useSlotLayoutRef.current;
203
+ const resolvedScrollHost =
204
+ webScrollHost === undefined
205
+ ? useSlotLayout
206
+ ? ownedScrollHost
207
+ : undefined
208
+ : webScrollHost;
117
209
  const engineRef = useRef<NativeListWebEngine | undefined>(undefined);
118
210
  const webVirtualizationEnabledRef = useRef(webVirtualizationEnabled);
119
211
  webVirtualizationEnabledRef.current = webVirtualizationEnabled;
120
212
  const validatedSnapshot = useMemo(
121
- () => validateSnapshot(snapshot),
122
- [snapshot]
213
+ () =>
214
+ containNativeListInput(() => {
215
+ if ((listSidecar !== undefined) !== (sidecarLayout !== undefined))
216
+ throw new Error(
217
+ 'listSidecar and sidecarLayout must be supplied together'
218
+ );
219
+ if (sidecarLayout) {
220
+ const { width, gap, maxContentWidth } = sidecarLayout;
221
+ if (
222
+ snapshot.layout.kind !== 'linear' ||
223
+ !Number.isFinite(width) ||
224
+ width <= 0 ||
225
+ !Number.isFinite(gap) ||
226
+ gap < 0 ||
227
+ !Number.isFinite(maxContentWidth) ||
228
+ maxContentWidth <= width + gap
229
+ )
230
+ throw new Error('Invalid NativeList sidecar layout');
231
+ }
232
+ return normalizeWebSnapshot(
233
+ snapshot,
234
+ hasEmptySlot,
235
+ useSlotLayout,
236
+ preparedSnapshot !== undefined &&
237
+ preparedSnapshot === freshlyValidatedSnapshot
238
+ );
239
+ }) ?? acceptedSnapshotRef.current,
240
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Preserve the existing memo dependencies; freshness is render-local.
241
+ [snapshot, hasEmptySlot, useSlotLayout, listSidecar, sidecarLayout]
123
242
  );
243
+ const [slotState, setSlotState] = useState(() => ({
244
+ hasRows: validatedSnapshot.rows.length > 0,
245
+ emptyBottomPadding:
246
+ !validatedSnapshot.rows.length && hasEmptySlot
247
+ ? validatedSnapshot.layout.contentPaddingBottom ??
248
+ validatedSnapshot.layout.contentPadding ??
249
+ 0
250
+ : 0,
251
+ padding:
252
+ validatedSnapshot.layout.contentPaddingHorizontal ??
253
+ validatedSnapshot.layout.contentPadding ??
254
+ 0,
255
+ disclosurePresent: validatedSnapshot.disclosure !== undefined,
256
+ disclosureExpanded: validatedSnapshot.disclosure?.expanded === true,
257
+ hasExpandedContent: validatedSnapshot.disclosure?.expanded === true,
258
+ expandedTrailingInset:
259
+ validatedSnapshot.disclosure?.expandedTrailingInset ?? 0,
260
+ }));
261
+ const synchronizeSlots = (next: NativeListSnapshot) => {
262
+ const hasRows = next.rows.length > 0;
263
+ const padding =
264
+ next.layout.contentPaddingHorizontal ?? next.layout.contentPadding ?? 0;
265
+ const emptyBottomPadding =
266
+ !hasRows && hasEmptySlotRef.current
267
+ ? next.layout.contentPaddingBottom ?? next.layout.contentPadding ?? 0
268
+ : 0;
269
+ const disclosurePresent = next.disclosure !== undefined;
270
+ const disclosureExpanded = next.disclosure?.expanded === true;
271
+ const expandedTrailingInset = next.disclosure?.expandedTrailingInset ?? 0;
272
+ setSlotState((previous) => {
273
+ const hasExpandedContent =
274
+ previous.hasExpandedContent || disclosureExpanded;
275
+ return previous.hasRows === hasRows &&
276
+ previous.padding === padding &&
277
+ previous.emptyBottomPadding === emptyBottomPadding &&
278
+ previous.disclosurePresent === disclosurePresent &&
279
+ previous.disclosureExpanded === disclosureExpanded &&
280
+ previous.hasExpandedContent === hasExpandedContent &&
281
+ previous.expandedTrailingInset === expandedTrailingInset
282
+ ? previous
283
+ : {
284
+ hasRows,
285
+ padding,
286
+ emptyBottomPadding,
287
+ disclosurePresent,
288
+ disclosureExpanded,
289
+ hasExpandedContent,
290
+ expandedTrailingInset,
291
+ };
292
+ });
293
+ };
124
294
  const snapshotRef = useRef(validatedSnapshot);
125
295
  const snapshotPropRef = useRef(validatedSnapshot);
126
296
  // An imperative snapshot survives host mounting until the snapshot prop changes.
127
297
  if (snapshotPropRef.current !== validatedSnapshot) {
128
298
  snapshotPropRef.current = validatedSnapshot;
129
299
  snapshotRef.current = validatedSnapshot;
300
+ acceptedSnapshotRef.current = validatedSnapshot;
301
+ synchronizeSlots(validatedSnapshot);
302
+ }
303
+ if (!initializedSnapshot.current) {
304
+ acceptedSnapshotRef.current = validatedSnapshot;
305
+ initializedSnapshot.current = true;
130
306
  }
131
- // OneKey patch: React refs can be ready before the DOM engine is mounted.
132
- const pendingPatchesRef = useRef<
133
- | {
134
- snapshot: NativeListSnapshot;
135
- batches: Array<readonly RowPatch[]>;
136
- }
137
- | undefined
138
- >(undefined);
139
307
  const appliedSnapshotRef = useRef<NativeListSnapshot | undefined>(
140
308
  undefined
141
309
  );
@@ -158,45 +326,66 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
158
326
  }>
159
327
  | undefined
160
328
  >(
161
- initialScrollIndex === undefined && initialScrollKey === undefined
162
- ? undefined
163
- : initialScrollIndex !== undefined
164
- ? normalizeIndexScroll({
165
- index: initialScrollIndex,
166
- animated: false,
167
- viewPosition: initialScrollViewPosition,
168
- viewOffset: initialScrollViewOffset,
169
- })
170
- : {
171
- key: initialScrollKey,
172
- scroll: normalizePositionScroll(
173
- {
174
- animated: false,
175
- viewPosition: initialScrollViewPosition,
176
- viewOffset: initialScrollViewOffset,
177
- },
178
- 'start'
179
- ),
180
- }
329
+ containNativeListInput(() =>
330
+ initialScrollIndex === undefined && initialScrollKey === undefined
331
+ ? undefined
332
+ : initialScrollIndex !== undefined
333
+ ? normalizeIndexScroll({
334
+ index: initialScrollIndex,
335
+ animated: false,
336
+ viewPosition: initialScrollViewPosition,
337
+ viewOffset: initialScrollViewOffset,
338
+ })
339
+ : {
340
+ key: initialScrollKey,
341
+ scroll: normalizePositionScroll(
342
+ {
343
+ animated: false,
344
+ viewPosition: initialScrollViewPosition,
345
+ viewOffset: initialScrollViewOffset,
346
+ },
347
+ 'start'
348
+ ),
349
+ }
350
+ )
181
351
  );
182
352
  const didApplyInitialScroll = useRef(false);
353
+ const scrollOptionsRef = useRef({
354
+ stickyInset: webStickyInset,
355
+ ownsRefresh: webScrollHost === undefined,
356
+ });
357
+ scrollOptionsRef.current = {
358
+ stickyInset: webStickyInset,
359
+ ownsRefresh: webScrollHost === undefined,
360
+ };
183
361
 
184
362
  useEffect(() => {
185
- if (!host) return;
186
- const engine = new NativeListWebEngine(
187
- host,
188
- snapshotRef.current,
189
- callbacksRef.current,
190
- webVirtualizationEnabledRef.current,
191
- webSectionIndexContainerRef?.current as unknown as HTMLElement | null,
192
- fontFamiliesJsonRef.current
363
+ if (
364
+ !host ||
365
+ resolvedScrollHost === null ||
366
+ (useSlotLayout && !contentBounds)
367
+ )
368
+ return;
369
+ const engine = containNativeListInput(
370
+ () =>
371
+ new NativeListWebEngine(
372
+ host,
373
+ snapshotRef.current,
374
+ callbacksRef.current,
375
+ webVirtualizationEnabledRef.current,
376
+ webSectionIndexContainerRef?.current as unknown as HTMLElement | null,
377
+ fontFamiliesJsonRef.current,
378
+ {
379
+ scrollHost: resolvedScrollHost as HTMLElement | undefined,
380
+ contentBounds: contentBounds ?? undefined,
381
+ ...scrollOptionsRef.current,
382
+ }
383
+ )
193
384
  );
385
+ if (!engine) return;
386
+ host.style.height = '';
194
387
  engineRef.current = engine;
195
388
  appliedSnapshotRef.current = snapshotRef.current;
196
- const pending = pendingPatchesRef.current;
197
- pendingPatchesRef.current = undefined;
198
- if (pending?.snapshot === snapshotRef.current)
199
- pending.batches.forEach((patches) => engine.applyPatches(patches));
200
389
  const initial = initialScrollRef.current;
201
390
  if (initial && !didApplyInitialScroll.current) {
202
391
  didApplyInitialScroll.current = true;
@@ -206,10 +395,22 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
206
395
  engine.scrollToKey(initial.key, initial.scroll);
207
396
  }
208
397
  return () => {
398
+ // Keep the paused tab in normal flow until its engine is restored.
399
+ host.style.height = `${engine.currentContentHeight()}px`;
209
400
  engine.destroy();
210
401
  if (engineRef.current === engine) engineRef.current = undefined;
211
402
  };
212
- }, [host, webSectionIndexContainerRef]);
403
+ }, [
404
+ host,
405
+ webSectionIndexContainerRef,
406
+ resolvedScrollHost,
407
+ contentBounds,
408
+ useSlotLayout,
409
+ ]);
410
+
411
+ useEffect(() => {
412
+ engineRef.current?.setStickyInset(webStickyInset);
413
+ }, [webStickyInset]);
213
414
 
214
415
  useEffect(() => {
215
416
  engineRef.current?.setFontFamiliesJson(fontFamiliesJson);
@@ -223,7 +424,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
223
424
  engineRef.current?.updateCallbacks(callbacksRef.current);
224
425
  });
225
426
 
226
- useEffect(() => {
427
+ useLayoutEffect(() => {
227
428
  const engine = engineRef.current;
228
429
  if (!engine || appliedSnapshotRef.current === validatedSnapshot) return;
229
430
  engine.applySnapshot(validatedSnapshot);
@@ -241,26 +442,28 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
241
442
 
242
443
  useImperativeHandle(forwardedRef, () => ({
243
444
  applySnapshot(nextSnapshot) {
244
- const next = validateSnapshot(nextSnapshot);
245
- pendingPatchesRef.current = undefined;
445
+ const next = containNativeListInput(() =>
446
+ normalizeWebSnapshot(nextSnapshot)
447
+ );
448
+ if (!next) return;
449
+ engineRef.current?.applySnapshot(next);
246
450
  snapshotRef.current = next;
451
+ acceptedSnapshotRef.current = next;
247
452
  appliedSnapshotRef.current = next;
248
- engineRef.current?.applySnapshot(next);
453
+ synchronizeSlots(next);
249
454
  },
250
455
  applyPatches(patches) {
251
- if (patches.length > 0) {
252
- serializePatches(patches);
253
- // engineRef.current?.applyPatches(patches);
254
- if (engineRef.current) engineRef.current.applyPatches(patches);
255
- else {
256
- if (pendingPatchesRef.current?.snapshot !== snapshotRef.current)
257
- pendingPatchesRef.current = {
258
- snapshot: snapshotRef.current,
259
- batches: [],
260
- };
261
- pendingPatchesRef.current.batches.push(patches);
262
- }
456
+ const engine = engineRef.current;
457
+ if (engine) {
458
+ engine.applyPatches(patches);
459
+ snapshotRef.current = engine.currentSnapshot();
460
+ } else {
461
+ const next = containNativeListInput(() =>
462
+ applyRowPatches(snapshotRef.current, patches)
463
+ );
464
+ if (next) snapshotRef.current = next;
263
465
  }
466
+ acceptedSnapshotRef.current = snapshotRef.current;
264
467
  },
265
468
  reconcileSelection(selectedKeys) {
266
469
  engineRef.current?.reconcileSelection(selectedKeys);
@@ -339,6 +542,154 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
339
542
  []
340
543
  );
341
544
 
342
- return <View {...viewProps} ref={setHostRef} />;
545
+ const setBoundsRef = useCallback(
546
+ (value: React.ComponentRef<typeof View> | null) => {
547
+ setContentBounds(value as unknown as HTMLElement | null);
548
+ },
549
+ []
550
+ );
551
+ const ownedScrollElementRef = useRef<HTMLElement | null>(null);
552
+ const setScrollHostRef = useCallback(
553
+ (value: React.ComponentRef<typeof View> | null) => {
554
+ const element = value as unknown as HTMLElement | null;
555
+ if (ownedScrollElementRef.current !== element)
556
+ ownedScrollElementRef.current?.removeAttribute(
557
+ 'data-collapsible-pager-scroll'
558
+ );
559
+ element?.setAttribute('data-collapsible-pager-scroll', 'true');
560
+ ownedScrollElementRef.current = element;
561
+ setOwnedScrollHost(element);
562
+ },
563
+ []
564
+ );
565
+ if (!useSlotLayout) return <View {...viewProps} ref={setHostRef} />;
566
+ const padding = slotState.padding;
567
+ const footerBandStyle = { paddingHorizontal: padding };
568
+ const trailingInsetStyle = {
569
+ height: slotState.disclosureExpanded
570
+ ? slotState.expandedTrailingInset
571
+ : 0,
572
+ };
573
+ const hasFooterBand =
574
+ listFooter !== undefined ||
575
+ listExpandedContent !== undefined ||
576
+ listStructureToggle !== undefined;
577
+ const content = (
578
+ <View
579
+ ref={sidecarLayout ? undefined : setBoundsRef}
580
+ style={{ position: 'relative', flexShrink: 0, minWidth: 0 }}
581
+ >
582
+ {listHeader !== undefined ? (
583
+ <View style={{ paddingHorizontal: padding }}>{listHeader}</View>
584
+ ) : null}
585
+ <View ref={setHostRef} style={{ flexShrink: 0, minWidth: 0 }} />
586
+ {!slotState.hasRows && hasEmptySlot ? (
587
+ <View
588
+ style={{
589
+ paddingHorizontal: padding,
590
+ paddingBottom: slotState.emptyBottomPadding,
591
+ }}
592
+ >
593
+ {listEmpty}
594
+ </View>
595
+ ) : null}
596
+ {hasFooterBand ? (
597
+ <View testID="native-list-footer-slot" style={footerBandStyle}>
598
+ {listExpandedContent !== undefined &&
599
+ slotState.hasExpandedContent ? (
600
+ <View
601
+ testID="native-list-expanded-content-slot"
602
+ aria-hidden={!slotState.disclosureExpanded}
603
+ pointerEvents={slotState.disclosureExpanded ? 'auto' : 'none'}
604
+ style={
605
+ slotState.disclosureExpanded
606
+ ? undefined
607
+ : collapsedExpandedContentStyle
608
+ }
609
+ >
610
+ {listExpandedContent}
611
+ </View>
612
+ ) : null}
613
+ {listStructureToggle !== undefined ? (
614
+ <View
615
+ testID="native-list-structure-toggle-slot"
616
+ aria-hidden={!slotState.disclosurePresent}
617
+ pointerEvents={slotState.disclosurePresent ? 'auto' : 'none'}
618
+ style={
619
+ slotState.disclosurePresent
620
+ ? undefined
621
+ : collapsedExpandedContentStyle
622
+ }
623
+ >
624
+ {listStructureToggle}
625
+ </View>
626
+ ) : null}
627
+ {slotState.expandedTrailingInset > 0 &&
628
+ (listExpandedContent !== undefined ||
629
+ listStructureToggle !== undefined) ? (
630
+ <View
631
+ testID="native-list-trailing-inset-slot"
632
+ style={trailingInsetStyle}
633
+ />
634
+ ) : null}
635
+ {listFooter}
636
+ </View>
637
+ ) : null}
638
+ </View>
639
+ );
640
+ const bandWidth = sidecarLayout
641
+ ? Math.min(viewportWidth, sidecarLayout.maxContentWidth)
642
+ : 0;
643
+ const sidecarMargin = Math.max(0, (viewportWidth - bandWidth) / 2);
644
+ const leftWidth = Math.max(
645
+ 0,
646
+ bandWidth - (sidecarLayout?.width ?? 0) - (sidecarLayout?.gap ?? 0)
647
+ );
648
+ const scrollContent = sidecarLayout ? (
649
+ <View
650
+ ref={setBoundsRef}
651
+ style={{ position: 'relative', minHeight: sidecarHeight }}
652
+ >
653
+ <View style={{ marginStart: sidecarMargin, width: leftWidth }}>
654
+ {content}
655
+ </View>
656
+ <View
657
+ style={{
658
+ position: 'absolute',
659
+ end: sidecarMargin,
660
+ top: 0,
661
+ width: sidecarLayout.width,
662
+ }}
663
+ onLayout={(event) =>
664
+ setSidecarHeight(event.nativeEvent.layout.height)
665
+ }
666
+ >
667
+ {listSidecar}
668
+ </View>
669
+ </View>
670
+ ) : (
671
+ content
672
+ );
673
+ return (
674
+ <View
675
+ {...viewProps}
676
+ onLayout={(event) => {
677
+ setViewportWidth(event.nativeEvent.layout.width);
678
+ viewProps.onLayout?.(event);
679
+ }}
680
+ style={[viewProps.style, { position: 'relative', minHeight: 0 }]}
681
+ >
682
+ {webScrollHost === undefined ? (
683
+ <View
684
+ ref={setScrollHostRef}
685
+ style={{ position: 'absolute', inset: 0, overflow: 'scroll' }}
686
+ >
687
+ {scrollContent}
688
+ </View>
689
+ ) : (
690
+ scrollContent
691
+ )}
692
+ </View>
693
+ );
343
694
  }
344
695
  );
package/src/index.ts CHANGED
@@ -14,10 +14,12 @@ export type {
14
14
  ScrollToKeyParams,
15
15
  ScrollToLocationParams,
16
16
  ScrollToOffsetParams,
17
+ StructuralTransitionSettledEvent,
17
18
  } from './NativeList';
18
19
  export type * from './models';
19
20
  export {
20
21
  applyRowPatches,
22
+ planNativeListPatches,
21
23
  serializePatches,
22
24
  serializeSnapshot,
23
25
  validatePatches,