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

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 (144) 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 +7 -4
  4. package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +29 -3
  5. package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
  6. package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
  7. package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +87 -7
  8. package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +193 -10
  9. package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
  10. package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
  11. package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +145 -2
  12. package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -0
  13. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
  14. package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
  15. package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
  16. package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
  17. package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
  18. package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +1920 -109
  19. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +29 -0
  20. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
  21. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
  22. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
  23. package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
  24. package/docs/ROW_TEMPLATES.md +60 -9
  25. package/docs/SPEC.md +1004 -17
  26. package/docs/STYLE_SPEC.md +6 -0
  27. package/ios/HybridNativeList.swift +21 -2
  28. package/ios/NativeListAccessoryStack.swift +235 -39
  29. package/ios/NativeListActivityDetailsView.swift +18 -8
  30. package/ios/NativeListActivityRenderer.swift +8 -2
  31. package/ios/NativeListButtonGroupRenderer.swift +89 -0
  32. package/ios/NativeListDataRowRenderer.swift +155 -27
  33. package/ios/NativeListDesignAssets.swift +9 -0
  34. package/ios/NativeListIdentityRenderer.swift +191 -30
  35. package/ios/NativeListLeadingVisual.swift +119 -22
  36. package/ios/NativeListMessageRenderer.swift +34 -1
  37. package/ios/NativeListModels.swift +42 -2
  38. package/ios/NativeListRendererRegistry.swift +1 -0
  39. package/ios/NativeListResolvedText.swift +2 -1
  40. package/ios/NativeListRowHost.swift +14 -0
  41. package/ios/NativeListSectionHeaderRenderer.swift +88 -0
  42. package/ios/RNCNativeListView.swift +1031 -55
  43. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
  44. package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
  45. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/Contents.json +1 -0
  46. package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
  47. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
  48. package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -0
  49. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
  50. package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
  51. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/Contents.json +1 -0
  52. package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -0
  53. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
  54. package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
  55. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
  56. package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
  57. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
  58. package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
  59. package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
  60. package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
  61. package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
  62. package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
  63. package/ios/tests/NativeListLifecycleTests.swift +2720 -3
  64. package/lib/module/NativeList.js +200 -32
  65. package/lib/module/NativeList.web.js +262 -32
  66. package/lib/module/index.js +1 -1
  67. package/lib/module/models.js +1 -0
  68. package/lib/module/selection.js +1 -1
  69. package/lib/module/validation.js +776 -52
  70. package/lib/module/web/NativeListWebEngine.js +919 -79
  71. package/lib/module/web/templates/ActivityRowRenderer.js +487 -7
  72. package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
  73. package/lib/module/web/templates/DataRowRenderer.js +40 -5
  74. package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
  75. package/lib/module/web/templates/MarketRowRenderer.js +8 -3
  76. package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
  77. package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
  78. package/lib/module/web/templates/MessageRowRenderer.js +18 -2
  79. package/lib/module/web/templates/RowContainerStyle.js +1 -0
  80. package/lib/module/web/templates/RowRendererRegistry.js +8 -3
  81. package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
  82. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  83. package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  84. package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  85. package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  86. package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  87. package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  88. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  89. package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  90. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  91. package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  92. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  93. package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  94. package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  95. package/lib/typescript/src/NativeList.d.ts +3 -3
  96. package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
  97. package/lib/typescript/src/NativeList.types.d.ts +29 -1
  98. package/lib/typescript/src/NativeList.web.d.ts +2 -2
  99. package/lib/typescript/src/index.d.ts +2 -2
  100. package/lib/typescript/src/models.d.ts +176 -10
  101. package/lib/typescript/src/validation.d.ts +15 -0
  102. package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
  103. package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
  104. package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
  105. package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
  106. package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
  107. package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
  108. package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +10 -4
  109. package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
  110. package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
  111. package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
  112. package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
  113. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
  114. package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
  115. package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
  116. package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
  117. package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
  118. package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
  119. package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
  120. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
  121. package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
  122. package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
  123. package/package.json +3 -3
  124. package/react-native-native-list.podspec +1 -0
  125. package/src/NativeList.nitro.ts +2 -0
  126. package/src/NativeList.tsx +391 -82
  127. package/src/NativeList.types.ts +34 -1
  128. package/src/NativeList.web.tsx +420 -65
  129. package/src/index.ts +2 -0
  130. package/src/models.ts +210 -3
  131. package/src/selection.ts +1 -0
  132. package/src/validation.ts +1635 -76
  133. package/src/web/NativeListWebEngine.ts +1476 -112
  134. package/src/web/templates/ActivityRowRenderer.ts +732 -8
  135. package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
  136. package/src/web/templates/DataRowRenderer.ts +93 -20
  137. package/src/web/templates/IdentityRowRenderer.ts +150 -5
  138. package/src/web/templates/MarketRowRenderer.ts +19 -3
  139. package/src/web/templates/MarketTableRowRenderer.ts +755 -0
  140. package/src/web/templates/MediaTileRowRenderer.ts +313 -5
  141. package/src/web/templates/MessageRowRenderer.ts +23 -7
  142. package/src/web/templates/RowContainerStyle.ts +2 -0
  143. package/src/web/templates/RowRendererRegistry.ts +21 -6
  144. package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
@@ -1,6 +1,7 @@
1
1
  import { useNativeListFontFamiliesJson } from './fonts';
2
2
  import React, {
3
3
  forwardRef,
4
+ useCallback,
4
5
  useEffect,
5
6
  useImperativeHandle,
6
7
  useMemo,
@@ -24,13 +25,18 @@ import type {
24
25
  import type {
25
26
  ActionAnchorInvalidatedEvent,
26
27
  ImageSource,
28
+ NativeListSnapshot,
27
29
  RowActionEvent,
28
30
  SelectionDeltaEvent,
29
31
  ReorderEvent,
30
32
  EndReachedEvent,
31
33
  VisibleRangeChangedEvent,
32
34
  } from './models';
33
- import type { NativeListProps, NativeListRef } from './NativeList.types';
35
+ import type {
36
+ NativeListProps,
37
+ NativeListRef,
38
+ StructuralTransitionSettledEvent,
39
+ } from './NativeList.types';
34
40
  import { isSelectableRow } from './selection';
35
41
  import {
36
42
  normalizeIndexScroll,
@@ -42,12 +48,19 @@ import {
42
48
  type NormalizedPositionScroll,
43
49
  } from './scrolling';
44
50
  import {
45
- applyRowPatches,
46
- serializePatches,
47
- serializeSnapshot,
51
+ applyOwnedNativePatches,
52
+ captureNativeListInput,
53
+ containNativeListInput,
54
+ emptyNativeListSnapshot,
55
+ ownValidatedNativeSnapshot,
56
+ validateSnapshot,
48
57
  } from './validation';
49
58
 
50
- export type { NativeListProps, NativeListRef } from './NativeList.types';
59
+ export type {
60
+ NativeListProps,
61
+ NativeListRef,
62
+ StructuralTransitionSettledEvent,
63
+ } from './NativeList.types';
51
64
  export type {
52
65
  ActionAnchorState,
53
66
  NativeListKeyboardDismissMode,
@@ -69,6 +82,8 @@ const NativeListHost = getHostComponent<
69
82
  NativeListNativeProps,
70
83
  NativeListMethods
71
84
  >('NativeList', () => NativeListConfig);
85
+ const clearedStructuralTransitionSettled = { f: undefined } as const;
86
+ const disclosureSlotMeasurementStyle = { alignSelf: 'stretch' } as const;
72
87
 
73
88
  export function preloadNativeListAvatarImages(
74
89
  sources: readonly ImageSource[]
@@ -98,14 +113,20 @@ function parsePayload<T>(payloadJson: string): T {
98
113
  export const NativeList = forwardRef<NativeListRef, NativeListProps>(
99
114
  function NativeList(
100
115
  {
101
- snapshot,
116
+ snapshot: inputSnapshot,
102
117
  listHeader,
103
118
  listFooter,
104
119
  listEmpty,
120
+ listSidecar,
121
+ listExpandedContent,
122
+ listStructureToggle,
123
+ sidecarLayout,
105
124
  topOverlay,
106
125
  topScrollEdgeEffect,
107
126
  scrollPositionThresholds,
108
127
  webVirtualizationEnabled: _webVirtualizationEnabled,
128
+ webScrollHost: _webScrollHost,
129
+ webStickyInset: _webStickyInset,
109
130
  webSectionIndexContainerRef: _webSectionIndexContainerRef,
110
131
  keyboardDismissMode = 'none',
111
132
  keyboardShouldPersistTaps = 'never',
@@ -115,6 +136,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
115
136
  onReorder,
116
137
  onEndReached,
117
138
  onVisibleRangeChanged,
139
+ onStructuralTransitionSettled,
118
140
  onScrollPositionThresholdChange,
119
141
  onRefresh,
120
142
  onScrollToIndexFailed,
@@ -126,8 +148,172 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
126
148
  },
127
149
  forwardedRef
128
150
  ) {
151
+ const snapshotRef = useRef<NativeListSnapshot>(emptyNativeListSnapshot());
152
+ const renderedSnapshotRef = useRef<NativeListSnapshot | undefined>(
153
+ undefined
154
+ );
155
+ const initializedSnapshot = useRef(false);
156
+ const pendingDisclosureSnapshotRef = useRef<
157
+ | {
158
+ source: 'prop' | 'imperative';
159
+ input: NativeListSnapshot;
160
+ owned: NativeListSnapshot;
161
+ expandedEpoch: number;
162
+ toggleEpoch: number;
163
+ }
164
+ | undefined
165
+ >(undefined);
166
+ const previousPropInputRef = useRef(inputSnapshot);
167
+ const [pendingDisclosureRevision, setPendingDisclosureRevision] =
168
+ useState(0);
169
+ const disclosureSlotMounts = useRef({
170
+ expandedPresent: false,
171
+ togglePresent: false,
172
+ expandedEpoch: 0,
173
+ toggleEpoch: 0,
174
+ });
175
+ const expandedPresent = listExpandedContent != null;
176
+ const togglePresent = listStructureToggle != null;
177
+ if (disclosureSlotMounts.current.expandedPresent !== expandedPresent) {
178
+ disclosureSlotMounts.current.expandedPresent = expandedPresent;
179
+ disclosureSlotMounts.current.expandedEpoch += 1;
180
+ }
181
+ if (disclosureSlotMounts.current.togglePresent !== togglePresent) {
182
+ disclosureSlotMounts.current.togglePresent = togglePresent;
183
+ disclosureSlotMounts.current.toggleEpoch += 1;
184
+ }
185
+ const expandedEpoch = disclosureSlotMounts.current.expandedEpoch;
186
+ const toggleEpoch = disclosureSlotMounts.current.toggleEpoch;
187
+ const [slotMeasurements, setSlotMeasurements] = useState({
188
+ heights: [0, 0, 0, 0, 0, 0],
189
+ readyEpochs: [-1, -1, -1, -1, -1, -1],
190
+ });
191
+ const hasSidecar = listSidecar !== undefined;
192
+ const sidecarWidth = sidecarLayout?.width;
193
+ const sidecarGap = sidecarLayout?.gap;
194
+ const sidecarMaxContentWidth = sidecarLayout?.maxContentWidth;
195
+ const hasContainerSlots = Boolean(
196
+ listHeader ||
197
+ listEmpty ||
198
+ listFooter ||
199
+ listSidecar ||
200
+ listExpandedContent ||
201
+ listStructureToggle
202
+ );
203
+ const validateContainerConfiguration = useCallback(
204
+ (accepted: NativeListSnapshot) => {
205
+ if (hasContainerSlots && accepted.layout.orientation === 'horizontal')
206
+ throw new Error(
207
+ 'NativeList container slots require vertical orientation'
208
+ );
209
+ if (hasSidecar !== (sidecarWidth !== undefined))
210
+ throw new Error(
211
+ 'listSidecar and sidecarLayout must be supplied together'
212
+ );
213
+ if (sidecarWidth !== undefined) {
214
+ const width = sidecarWidth;
215
+ const gap = sidecarGap ?? NaN;
216
+ const maxContentWidth = sidecarMaxContentWidth ?? NaN;
217
+ if (
218
+ accepted.layout.kind !== 'linear' ||
219
+ !Number.isFinite(width) ||
220
+ width <= 0 ||
221
+ !Number.isFinite(gap) ||
222
+ gap < 0 ||
223
+ !Number.isFinite(maxContentWidth) ||
224
+ maxContentWidth <= width + gap
225
+ )
226
+ throw new Error('Invalid NativeList sidecar layout');
227
+ }
228
+ },
229
+ [
230
+ hasContainerSlots,
231
+ hasSidecar,
232
+ sidecarWidth,
233
+ sidecarGap,
234
+ sidecarMaxContentWidth,
235
+ ]
236
+ );
237
+ const prepareSnapshot = useCallback(
238
+ (next: NativeListSnapshot) => {
239
+ const accepted = validateSnapshot(captureNativeListInput(next));
240
+ validateContainerConfiguration(accepted);
241
+ return ownValidatedNativeSnapshot(accepted);
242
+ },
243
+ [validateContainerConfiguration]
244
+ );
245
+ const expandedReadyEpoch = slotMeasurements.readyEpochs[4];
246
+ const toggleReadyEpoch = slotMeasurements.readyEpochs[5];
247
+ const snapshot = useMemo(() => {
248
+ // Imperative pending snapshots use this revision to retry the readiness gate.
249
+ // eslint-disable-next-line no-void -- Reading this revision invalidates the readiness memo.
250
+ void pendingDisclosureRevision;
251
+ const propReplaced = previousPropInputRef.current !== inputSnapshot;
252
+ previousPropInputRef.current = inputSnapshot;
253
+ const pending = pendingDisclosureSnapshotRef.current;
254
+ const retained =
255
+ pending &&
256
+ !propReplaced &&
257
+ (pending.source === 'imperative' || pending.input === inputSnapshot) &&
258
+ pending.expandedEpoch === expandedEpoch &&
259
+ pending.toggleEpoch === toggleEpoch
260
+ ? pending
261
+ : undefined;
262
+ const candidate =
263
+ retained?.owned ??
264
+ (!propReplaced && initializedSnapshot.current
265
+ ? renderedSnapshotRef.current ?? snapshotRef.current
266
+ : containNativeListInput(() => prepareSnapshot(inputSnapshot)) ??
267
+ snapshotRef.current);
268
+ const acceptedCandidate =
269
+ !propReplaced && initializedSnapshot.current
270
+ ? containNativeListInput(() => {
271
+ validateContainerConfiguration(candidate);
272
+ return candidate;
273
+ })
274
+ : candidate;
275
+ if (!acceptedCandidate) {
276
+ pendingDisclosureSnapshotRef.current = undefined;
277
+ return renderedSnapshotRef.current ?? snapshotRef.current;
278
+ }
279
+ const transitionId = acceptedCandidate.structuralTransition?.id;
280
+ const newDisclosureCommand =
281
+ initializedSnapshot.current &&
282
+ acceptedCandidate.disclosure !== undefined &&
283
+ transitionId !== undefined &&
284
+ transitionId !== snapshotRef.current.structuralTransition?.id;
285
+ if (
286
+ newDisclosureCommand &&
287
+ ((expandedPresent && expandedReadyEpoch !== expandedEpoch) ||
288
+ (togglePresent && toggleReadyEpoch !== toggleEpoch))
289
+ ) {
290
+ pendingDisclosureSnapshotRef.current = retained ?? {
291
+ source: 'prop',
292
+ input: inputSnapshot,
293
+ owned: acceptedCandidate,
294
+ expandedEpoch,
295
+ toggleEpoch,
296
+ };
297
+ return snapshotRef.current;
298
+ }
299
+ pendingDisclosureSnapshotRef.current = undefined;
300
+ return acceptedCandidate;
301
+ }, [
302
+ inputSnapshot,
303
+ prepareSnapshot,
304
+ validateContainerConfiguration,
305
+ expandedPresent,
306
+ togglePresent,
307
+ expandedEpoch,
308
+ toggleEpoch,
309
+ expandedReadyEpoch,
310
+ toggleReadyEpoch,
311
+ pendingDisclosureRevision,
312
+ ]);
313
+ renderedSnapshotRef.current = snapshot;
129
314
  const fontFamiliesJson = useNativeListFontFamiliesJson();
130
- const [slotHeights, setSlotHeights] = useState([0, 0, 0]);
315
+ const slotHeights = slotMeasurements.heights;
316
+ const [viewportWidth, setViewportWidth] = useState(0);
131
317
  const [topOverlayHeight, setTopOverlayHeight] = useState(0);
132
318
  const hasTopOverlay =
133
319
  Platform?.OS === 'ios' &&
@@ -135,19 +321,51 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
135
321
  (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') &&
136
322
  topOverlay != null;
137
323
  const containerSlotHeightsJson = JSON.stringify(slotHeights);
138
- const slotInset =
324
+ const defaultSlotInset =
139
325
  snapshot.layout.contentPaddingHorizontal ??
140
326
  snapshot.layout.contentPadding ??
141
327
  0;
142
- if (
143
- snapshot.layout.orientation === 'horizontal' &&
144
- (listHeader || listEmpty || listFooter)
145
- ) {
146
- throw new Error(
147
- 'NativeList container slots require vertical orientation'
148
- );
149
- }
150
- const slotContents = [listHeader, listEmpty, listFooter];
328
+ const bandWidth = sidecarLayout
329
+ ? Math.min(viewportWidth, sidecarLayout.maxContentWidth)
330
+ : 0;
331
+ const slotInset = sidecarLayout
332
+ ? Math.max(0, (viewportWidth - bandWidth) / 2) + defaultSlotInset
333
+ : defaultSlotInset;
334
+ const sidecarSpace = sidecarLayout
335
+ ? sidecarLayout.width + sidecarLayout.gap
336
+ : 0;
337
+ const slotContents = [
338
+ listHeader,
339
+ listEmpty,
340
+ listFooter,
341
+ listSidecar,
342
+ listExpandedContent,
343
+ listStructureToggle,
344
+ ];
345
+ const recordSlotLayout = (index: number, height: number, epoch: number) => {
346
+ if (
347
+ (index === 4 && epoch !== disclosureSlotMounts.current.expandedEpoch) ||
348
+ (index === 5 && epoch !== disclosureSlotMounts.current.toggleEpoch)
349
+ ) {
350
+ return;
351
+ }
352
+ setSlotMeasurements((previous) => {
353
+ if (
354
+ previous.heights[index] === height &&
355
+ previous.readyEpochs[index] === epoch
356
+ ) {
357
+ return previous;
358
+ }
359
+ const heights = [...previous.heights];
360
+ const readyEpochs = [...previous.readyEpochs];
361
+ heights[index] = height;
362
+ readyEpochs[index] = epoch;
363
+ return { heights, readyEpochs };
364
+ });
365
+ };
366
+ const sidecarLayoutJson = sidecarLayout
367
+ ? JSON.stringify(sidecarLayout)
368
+ : '';
151
369
  const normalizedKeyboardShouldPersistTaps =
152
370
  keyboardShouldPersistTaps === true
153
371
  ? 'always'
@@ -162,6 +380,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
162
380
  onReorder,
163
381
  onEndReached,
164
382
  onVisibleRangeChanged,
383
+ onStructuralTransitionSettled,
165
384
  onScrollPositionThresholdChange,
166
385
  onRefresh,
167
386
  onScrollToIndexFailed,
@@ -173,37 +392,45 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
173
392
  onReorder,
174
393
  onEndReached,
175
394
  onVisibleRangeChanged,
395
+ onStructuralTransitionSettled,
176
396
  onScrollPositionThresholdChange,
177
397
  onRefresh,
178
398
  onScrollToIndexFailed,
179
399
  };
180
- const scrollPositionThresholdsJson = useMemo(() => {
181
- if (
182
- !scrollPositionThresholds ||
183
- scrollPositionThresholds.enabled === false
184
- )
185
- return '';
186
- const { start, end } = scrollPositionThresholds;
187
- if (
188
- !Number.isFinite(start) ||
189
- !Number.isFinite(end) ||
190
- start < 0 ||
191
- end <= start
192
- ) {
193
- throw new Error(
194
- 'scrollPositionThresholds requires 0 <= start < end and finite values'
195
- );
196
- }
197
- return JSON.stringify({ start, end });
198
- }, [scrollPositionThresholds]);
199
- const snapshotJson = useMemo(() => serializeSnapshot(snapshot), [snapshot]);
200
- const snapshotRef = useRef(snapshot);
400
+ const scrollPositionThresholdsJson = useMemo(
401
+ () =>
402
+ containNativeListInput(() => {
403
+ if (
404
+ !scrollPositionThresholds ||
405
+ scrollPositionThresholds.enabled === false
406
+ )
407
+ return '';
408
+ const { start, end } = scrollPositionThresholds;
409
+ if (
410
+ !Number.isFinite(start) ||
411
+ !Number.isFinite(end) ||
412
+ start < 0 ||
413
+ end <= start
414
+ ) {
415
+ throw new Error(
416
+ 'scrollPositionThresholds requires 0 <= start < end and finite values'
417
+ );
418
+ }
419
+ return JSON.stringify({ start, end });
420
+ }) ?? '',
421
+ [scrollPositionThresholds]
422
+ );
423
+ const snapshotJson = useMemo(() => JSON.stringify(snapshot), [snapshot]);
201
424
  const previousSnapshotJsonRef = useRef(snapshotJson);
202
425
  const snapshotChanged = previousSnapshotJsonRef.current !== snapshotJson;
203
426
  if (snapshotChanged) {
204
427
  snapshotRef.current = snapshot;
205
428
  previousSnapshotJsonRef.current = snapshotJson;
206
429
  }
430
+ if (!initializedSnapshot.current) {
431
+ snapshotRef.current = snapshot;
432
+ initializedSnapshot.current = true;
433
+ }
207
434
  // OneKey patch: range events already cross the bridge only when row indices
208
435
  // change. Prefetch is optional work; scrolling and visible loads stay native.
209
436
  const avatarQueueRef = useRef<NativeAvatarPrefetchQueue | null>(null);
@@ -258,26 +485,28 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
258
485
  }>
259
486
  | undefined
260
487
  >(
261
- initialScrollIndex === undefined && initialScrollKey === undefined
262
- ? undefined
263
- : initialScrollIndex !== undefined
264
- ? normalizeIndexScroll({
265
- index: initialScrollIndex,
266
- animated: false,
267
- viewPosition: initialScrollViewPosition,
268
- viewOffset: initialScrollViewOffset,
269
- })
270
- : {
271
- key: initialScrollKey,
272
- scroll: normalizePositionScroll(
273
- {
274
- animated: false,
275
- viewPosition: initialScrollViewPosition,
276
- viewOffset: initialScrollViewOffset,
277
- },
278
- 'start'
279
- ),
280
- }
488
+ containNativeListInput(() =>
489
+ initialScrollIndex === undefined && initialScrollKey === undefined
490
+ ? undefined
491
+ : initialScrollIndex !== undefined
492
+ ? normalizeIndexScroll({
493
+ index: initialScrollIndex,
494
+ animated: false,
495
+ viewPosition: initialScrollViewPosition,
496
+ viewOffset: initialScrollViewOffset,
497
+ })
498
+ : {
499
+ key: initialScrollKey,
500
+ scroll: normalizePositionScroll(
501
+ {
502
+ animated: false,
503
+ viewPosition: initialScrollViewPosition,
504
+ viewOffset: initialScrollViewOffset,
505
+ },
506
+ 'start'
507
+ ),
508
+ }
509
+ )
281
510
  );
282
511
  const didApplyInitialScroll = useRef(false);
283
512
 
@@ -335,21 +564,59 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
335
564
 
336
565
  useImperativeHandle(forwardedRef, () => ({
337
566
  applySnapshot(nextSnapshot) {
338
- const nextSnapshotJson = serializeSnapshot(nextSnapshot);
567
+ const accepted = containNativeListInput(() =>
568
+ prepareSnapshot(nextSnapshot)
569
+ );
570
+ if (!accepted) return;
571
+ const transitionId = accepted.structuralTransition?.id;
572
+ const waitsForSlots =
573
+ accepted.disclosure !== undefined &&
574
+ transitionId !== undefined &&
575
+ transitionId !== snapshotRef.current.structuralTransition?.id &&
576
+ ((expandedPresent &&
577
+ slotMeasurements.readyEpochs[4] !== expandedEpoch) ||
578
+ (togglePresent && slotMeasurements.readyEpochs[5] !== toggleEpoch));
579
+ if (waitsForSlots) {
580
+ pendingDisclosureSnapshotRef.current = {
581
+ source: 'imperative',
582
+ input: nextSnapshot,
583
+ owned: accepted,
584
+ expandedEpoch,
585
+ toggleEpoch,
586
+ };
587
+ setPendingDisclosureRevision((value) => value + 1);
588
+ return;
589
+ }
590
+ pendingDisclosureSnapshotRef.current = undefined;
591
+ const nextSnapshotJson = JSON.stringify(accepted);
339
592
  nativeRef.current?.applySnapshot(nextSnapshotJson);
340
- snapshotRef.current = nextSnapshot;
593
+ snapshotRef.current = accepted;
341
594
  if (nativeRef.current && avatarLifecycle.current !== 'unmounted') {
342
- avatarModelRef.current?.replaceSnapshot(nextSnapshot.rows);
595
+ avatarModelRef.current?.replaceSnapshot(accepted.rows);
343
596
  updateAvatarPrefetchRef.current();
344
597
  }
345
598
  },
346
599
  applyPatches(patches) {
347
- if (patches.length === 0) return;
348
- const nextSnapshot = applyRowPatches(snapshotRef.current, patches);
600
+ const pending = pendingDisclosureSnapshotRef.current;
601
+ const accepted = containNativeListInput(() =>
602
+ applyOwnedNativePatches(
603
+ pending?.owned ?? snapshotRef.current,
604
+ patches
605
+ )
606
+ );
607
+ if (!accepted || accepted.patches.length === 0) return;
608
+ const nextSnapshot = accepted.snapshot;
609
+ if (pending) {
610
+ pendingDisclosureSnapshotRef.current = {
611
+ ...pending,
612
+ owned: nextSnapshot,
613
+ };
614
+ return;
615
+ }
349
616
  const native = nativeRef.current;
350
617
  const dispatch = native
351
618
  ? () => {
352
- native.applyPatches(serializePatches(patches));
619
+ native.applyPatches(accepted.json);
353
620
  snapshotRef.current = nextSnapshot;
354
621
  }
355
622
  : undefined;
@@ -357,23 +624,29 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
357
624
  dispatch?.();
358
625
  return;
359
626
  }
360
- if (avatarModelRef.current?.applyPatches(patches, dispatch))
627
+ if (avatarModelRef.current?.applyPatches(accepted.patches, dispatch))
361
628
  updateAvatarPrefetchRef.current();
362
629
  },
363
630
  reconcileSelection(selectedKeys) {
364
- nativeRef.current?.reconcileSelection(JSON.stringify(selectedKeys));
365
- const current = snapshotRef.current;
631
+ const capturedKeys = captureNativeListInput(selectedKeys);
632
+ const pending = pendingDisclosureSnapshotRef.current;
633
+ if (!pending)
634
+ nativeRef.current?.reconcileSelection(JSON.stringify(capturedKeys));
635
+ const current = pending?.owned ?? snapshotRef.current;
366
636
  if (
367
637
  current.selection &&
368
- (current.selection.mode !== 'single' || selectedKeys.length <= 1) &&
369
- selectedKeys.every((key) =>
638
+ (current.selection.mode !== 'single' || capturedKeys.length <= 1) &&
639
+ capturedKeys.every((key) =>
370
640
  current.rows.some((row) => row.key === key && isSelectableRow(row))
371
641
  )
372
642
  ) {
373
- snapshotRef.current = {
643
+ const next = {
374
644
  ...current,
375
- selection: { ...current.selection, selectedKeys },
645
+ selection: { ...current.selection, selectedKeys: capturedKeys },
376
646
  };
647
+ if (pending)
648
+ pendingDisclosureSnapshotRef.current = { ...pending, owned: next };
649
+ else snapshotRef.current = next;
377
650
  }
378
651
  },
379
652
  scrollToKey(paramsOrKey, animated, alignment) {
@@ -506,6 +779,11 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
506
779
  updateAvatarPrefetchRef.current();
507
780
  callbacksRef.current.onVisibleRangeChanged?.(payload);
508
781
  }),
782
+ onStructuralTransitionSettled: callback((payloadJson: string) => {
783
+ callbacksRef.current.onStructuralTransitionSettled?.(
784
+ parsePayload<StructuralTransitionSettledEvent>(payloadJson)
785
+ );
786
+ }),
509
787
  }),
510
788
  []
511
789
  );
@@ -513,10 +791,20 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
513
791
  return (
514
792
  <NativeListHost
515
793
  {...viewProps}
794
+ onLayout={(event) => {
795
+ setViewportWidth(event.nativeEvent.layout.width);
796
+ viewProps.onLayout?.(event);
797
+ }}
516
798
  {...nativeCallbacks}
799
+ onStructuralTransitionSettled={
800
+ onStructuralTransitionSettled
801
+ ? nativeCallbacks.onStructuralTransitionSettled
802
+ : clearedStructuralTransitionSettled
803
+ }
517
804
  fontFamiliesJson={fontFamiliesJson}
518
805
  snapshotJson={snapshotJson}
519
806
  containerSlotHeightsJson={containerSlotHeightsJson}
807
+ sidecarLayoutJson={sidecarLayoutJson}
520
808
  topScrollEdgeEffect={
521
809
  hasTopOverlay ? topScrollEdgeEffect ?? 'none' : 'none'
522
810
  }
@@ -531,22 +819,43 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
531
819
  collapsable={false}
532
820
  style={{
533
821
  position: 'absolute',
534
- left: slotInset,
535
- right: slotInset,
822
+ start: index === 3 ? 0 : slotInset,
823
+ end: index === 3 ? undefined : slotInset + sidecarSpace,
824
+ width: index === 3 ? sidecarLayout?.width : undefined,
536
825
  top: 0,
537
826
  }}
538
827
  onLayout={(event) => {
539
- const height = Math.ceil(event.nativeEvent.layout.height);
540
- setSlotHeights((previous) =>
541
- previous[index] === height
542
- ? previous
543
- : previous.map((value, slot) =>
544
- slot === index ? height : value
545
- )
546
- );
828
+ if (index < 4) {
829
+ recordSlotLayout(
830
+ index,
831
+ Math.ceil(event.nativeEvent.layout.height),
832
+ 0
833
+ );
834
+ }
547
835
  }}
548
836
  >
549
- {content}
837
+ {index >= 4 ? (
838
+ <View
839
+ key={
840
+ index === 4
841
+ ? `expanded-${expandedEpoch}`
842
+ : `toggle-${toggleEpoch}`
843
+ }
844
+ collapsable={false}
845
+ style={disclosureSlotMeasurementStyle}
846
+ onLayout={(event) =>
847
+ recordSlotLayout(
848
+ index,
849
+ Math.ceil(event.nativeEvent.layout.height),
850
+ index === 4 ? expandedEpoch : toggleEpoch
851
+ )
852
+ }
853
+ >
854
+ {content}
855
+ </View>
856
+ ) : (
857
+ content
858
+ )}
550
859
  </View>
551
860
  ))}
552
861
  {hasTopOverlay ? (