@onekeyfe/react-native-native-list 6.7.0-1 → 6.7.0-12

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
@@ -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,6 +25,7 @@ import type {
24
25
  import type {
25
26
  ActionAnchorInvalidatedEvent,
26
27
  ImageSource,
28
+ NativeListSnapshot,
27
29
  RowActionEvent,
28
30
  SelectionDeltaEvent,
29
31
  ReorderEvent,
@@ -43,8 +45,11 @@ import {
43
45
  } from './scrolling';
44
46
  import {
45
47
  applyRowPatches,
48
+ containNativeListInput,
49
+ emptyNativeListSnapshot,
46
50
  serializePatches,
47
- serializeSnapshot,
51
+ validatePatches,
52
+ validateSnapshot,
48
53
  } from './validation';
49
54
 
50
55
  export type { NativeListProps, NativeListRef } from './NativeList.types';
@@ -98,7 +103,7 @@ function parsePayload<T>(payloadJson: string): T {
98
103
  export const NativeList = forwardRef<NativeListRef, NativeListProps>(
99
104
  function NativeList(
100
105
  {
101
- snapshot,
106
+ snapshot: inputSnapshot,
102
107
  listHeader,
103
108
  listFooter,
104
109
  listEmpty,
@@ -106,6 +111,8 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
106
111
  topScrollEdgeEffect,
107
112
  scrollPositionThresholds,
108
113
  webVirtualizationEnabled: _webVirtualizationEnabled,
114
+ webScrollHost: _webScrollHost,
115
+ webStickyInset: _webStickyInset,
109
116
  webSectionIndexContainerRef: _webSectionIndexContainerRef,
110
117
  keyboardDismissMode = 'none',
111
118
  keyboardShouldPersistTaps = 'never',
@@ -126,27 +133,39 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
126
133
  },
127
134
  forwardedRef
128
135
  ) {
136
+ const snapshotRef = useRef<NativeListSnapshot>(emptyNativeListSnapshot());
137
+ const initializedSnapshot = useRef(false);
138
+ const hasContainerSlots = Boolean(listHeader || listEmpty || listFooter);
139
+ const prepareSnapshot = useCallback(
140
+ (next: NativeListSnapshot) => {
141
+ const accepted = validateSnapshot(next);
142
+ if (hasContainerSlots && accepted.layout.orientation === 'horizontal')
143
+ throw new Error(
144
+ 'NativeList container slots require vertical orientation'
145
+ );
146
+ return accepted;
147
+ },
148
+ [hasContainerSlots]
149
+ );
150
+ const snapshot = useMemo(
151
+ () =>
152
+ containNativeListInput(() => prepareSnapshot(inputSnapshot)) ??
153
+ snapshotRef.current,
154
+ [inputSnapshot, prepareSnapshot]
155
+ );
129
156
  const fontFamiliesJson = useNativeListFontFamiliesJson();
130
157
  const [slotHeights, setSlotHeights] = useState([0, 0, 0]);
131
158
  const [topOverlayHeight, setTopOverlayHeight] = useState(0);
132
159
  const hasTopOverlay =
133
160
  Platform?.OS === 'ios' &&
134
161
  parseInt(String(Platform.Version), 10) >= 26 &&
135
- topScrollEdgeEffect === 'hard' &&
162
+ (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') &&
136
163
  topOverlay != null;
137
164
  const containerSlotHeightsJson = JSON.stringify(slotHeights);
138
165
  const slotInset =
139
166
  snapshot.layout.contentPaddingHorizontal ??
140
167
  snapshot.layout.contentPadding ??
141
168
  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
169
  const slotContents = [listHeader, listEmpty, listFooter];
151
170
  const normalizedKeyboardShouldPersistTaps =
152
171
  keyboardShouldPersistTaps === true
@@ -177,33 +196,40 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
177
196
  onRefresh,
178
197
  onScrollToIndexFailed,
179
198
  };
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);
199
+ const scrollPositionThresholdsJson = useMemo(
200
+ () =>
201
+ containNativeListInput(() => {
202
+ if (
203
+ !scrollPositionThresholds ||
204
+ scrollPositionThresholds.enabled === false
205
+ )
206
+ return '';
207
+ const { start, end } = scrollPositionThresholds;
208
+ if (
209
+ !Number.isFinite(start) ||
210
+ !Number.isFinite(end) ||
211
+ start < 0 ||
212
+ end <= start
213
+ ) {
214
+ throw new Error(
215
+ 'scrollPositionThresholds requires 0 <= start < end and finite values'
216
+ );
217
+ }
218
+ return JSON.stringify({ start, end });
219
+ }) ?? '',
220
+ [scrollPositionThresholds]
221
+ );
222
+ const snapshotJson = useMemo(() => JSON.stringify(snapshot), [snapshot]);
201
223
  const previousSnapshotJsonRef = useRef(snapshotJson);
202
224
  const snapshotChanged = previousSnapshotJsonRef.current !== snapshotJson;
203
225
  if (snapshotChanged) {
204
226
  snapshotRef.current = snapshot;
205
227
  previousSnapshotJsonRef.current = snapshotJson;
206
228
  }
229
+ if (!initializedSnapshot.current) {
230
+ snapshotRef.current = snapshot;
231
+ initializedSnapshot.current = true;
232
+ }
207
233
  // OneKey patch: range events already cross the bridge only when row indices
208
234
  // change. Prefetch is optional work; scrolling and visible loads stay native.
209
235
  const avatarQueueRef = useRef<NativeAvatarPrefetchQueue | null>(null);
@@ -258,26 +284,28 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
258
284
  }>
259
285
  | undefined
260
286
  >(
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
- }
287
+ containNativeListInput(() =>
288
+ initialScrollIndex === undefined && initialScrollKey === undefined
289
+ ? undefined
290
+ : initialScrollIndex !== undefined
291
+ ? normalizeIndexScroll({
292
+ index: initialScrollIndex,
293
+ animated: false,
294
+ viewPosition: initialScrollViewPosition,
295
+ viewOffset: initialScrollViewOffset,
296
+ })
297
+ : {
298
+ key: initialScrollKey,
299
+ scroll: normalizePositionScroll(
300
+ {
301
+ animated: false,
302
+ viewPosition: initialScrollViewPosition,
303
+ viewOffset: initialScrollViewOffset,
304
+ },
305
+ 'start'
306
+ ),
307
+ }
308
+ )
281
309
  );
282
310
  const didApplyInitialScroll = useRef(false);
283
311
 
@@ -335,21 +363,33 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
335
363
 
336
364
  useImperativeHandle(forwardedRef, () => ({
337
365
  applySnapshot(nextSnapshot) {
338
- const nextSnapshotJson = serializeSnapshot(nextSnapshot);
366
+ const accepted = containNativeListInput(() =>
367
+ prepareSnapshot(nextSnapshot)
368
+ );
369
+ if (!accepted) return;
370
+ const nextSnapshotJson = JSON.stringify(accepted);
339
371
  nativeRef.current?.applySnapshot(nextSnapshotJson);
340
- snapshotRef.current = nextSnapshot;
372
+ snapshotRef.current = accepted;
341
373
  if (nativeRef.current && avatarLifecycle.current !== 'unmounted') {
342
- avatarModelRef.current?.replaceSnapshot(nextSnapshot.rows);
374
+ avatarModelRef.current?.replaceSnapshot(accepted.rows);
343
375
  updateAvatarPrefetchRef.current();
344
376
  }
345
377
  },
346
378
  applyPatches(patches) {
347
- if (patches.length === 0) return;
348
- const nextSnapshot = applyRowPatches(snapshotRef.current, patches);
379
+ const accepted = containNativeListInput(() => {
380
+ const normalized = validatePatches(patches);
381
+ return {
382
+ patches: normalized,
383
+ snapshot: applyRowPatches(snapshotRef.current, normalized),
384
+ json: serializePatches(normalized),
385
+ };
386
+ });
387
+ if (!accepted || accepted.patches.length === 0) return;
388
+ const nextSnapshot = accepted.snapshot;
349
389
  const native = nativeRef.current;
350
390
  const dispatch = native
351
391
  ? () => {
352
- native.applyPatches(serializePatches(patches));
392
+ native.applyPatches(accepted.json);
353
393
  snapshotRef.current = nextSnapshot;
354
394
  }
355
395
  : undefined;
@@ -357,7 +397,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
357
397
  dispatch?.();
358
398
  return;
359
399
  }
360
- if (avatarModelRef.current?.applyPatches(patches, dispatch))
400
+ if (avatarModelRef.current?.applyPatches(accepted.patches, dispatch))
361
401
  updateAvatarPrefetchRef.current();
362
402
  },
363
403
  reconcileSelection(selectedKeys) {
@@ -517,7 +557,9 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
517
557
  fontFamiliesJson={fontFamiliesJson}
518
558
  snapshotJson={snapshotJson}
519
559
  containerSlotHeightsJson={containerSlotHeightsJson}
520
- topScrollEdgeHard={hasTopOverlay}
560
+ topScrollEdgeEffect={
561
+ hasTopOverlay ? topScrollEdgeEffect ?? 'none' : 'none'
562
+ }
521
563
  topOverlayHeight={hasTopOverlay ? topOverlayHeight : 0}
522
564
  scrollPositionThresholdsJson={scrollPositionThresholdsJson}
523
565
  keyboardDismissMode={keyboardDismissMode}
@@ -1,3 +1,4 @@
1
+ import type { ScrollEdgeEffect } from './ScrollEdgeEffect';
1
2
  import type { ReactNode, RefObject } from 'react';
2
3
  import type { View, ViewProps } from 'react-native';
3
4
  import type {
@@ -70,6 +71,13 @@ export type ScrollToIndexFailedInfo = Readonly<{
70
71
  | 'item-not-found';
71
72
  }>;
72
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
+
73
81
  type InitialScrollProps =
74
82
  | Readonly<{
75
83
  initialScrollIndex?: never;
@@ -119,16 +127,20 @@ export type NativeListRef = Readonly<{
119
127
  export type NativeListProps = Omit<ViewProps, 'children'> &
120
128
  Readonly<{
121
129
  snapshot: NativeListSnapshot;
122
- /** Native-only, container-owned scroll content. Never rendered as a data row. */
130
+ /** Container-owned scroll content. Never rendered as a data row. */
123
131
  listHeader?: ReactNode;
124
132
  listFooter?: ReactNode;
125
133
  listEmpty?: ReactNode;
126
134
  /** Fixed overlay above scrolling rows on iOS 26 and newer. */
127
135
  topOverlay?: ReactNode;
128
- /** Enables UIKit's hard top scroll-edge effect on iOS 26 and newer. */
129
- topScrollEdgeEffect?: 'hard';
136
+ /** Selects UIKit's top scroll-edge effect on iOS 26 and newer. */
137
+ topScrollEdgeEffect?: `${ScrollEdgeEffect}`;
130
138
  /** Web only. Defaults to true and is ignored by the native host. */
131
139
  webVirtualizationEnabled?: boolean;
140
+ /** Web only: undefined owns scrolling, null waits for a host element. */
141
+ webScrollHost?: NativeListWebScrollHost | null;
142
+ /** Web only: visible sticky chrome above the parent's list viewport. */
143
+ webStickyInset?: number;
132
144
  /** Web only. Hosts the section index inside this container. */
133
145
  webSectionIndexContainerRef?: RefObject<View | null>;
134
146
  /** Defaults to `none`. `interactive` behaves as `none` on Android. */