@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.
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +1 -1
- package/docs/SPEC.md +449 -14
- package/ios/HybridNativeList.swift +11 -3
- package/ios/RNCNativeListView.swift +10 -6
- package/ios/tests/NativeListLifecycleTests.swift +28 -0
- package/lib/module/NativeList.js +42 -21
- package/lib/module/NativeList.web.js +163 -32
- package/lib/module/ScrollEdgeEffect.js +8 -0
- package/lib/module/index.js +1 -0
- package/lib/module/validation.js +358 -47
- package/lib/module/web/NativeListWebEngine.js +373 -67
- package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- package/lib/module/web/templates/RowRendererRegistry.js +5 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/lib/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/lib/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/lib/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -1
- package/lib/typescript/src/NativeList.types.d.ts +14 -3
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/ScrollEdgeEffect.d.ts +5 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/models.d.ts +71 -1
- package/lib/typescript/src/validation.d.ts +3 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +4 -1
- package/src/NativeList.nitro.ts +3 -1
- package/src/NativeList.tsx +102 -60
- package/src/NativeList.types.ts +15 -3
- package/src/NativeList.web.tsx +264 -65
- package/src/ScrollEdgeEffect.ts +4 -0
- package/src/index.ts +2 -0
- package/src/models.ts +93 -0
- package/src/validation.ts +785 -72
- package/src/web/NativeListWebEngine.ts +625 -100
- package/src/web/templates/ActivityRowRenderer.ts +723 -7
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/RowRendererRegistry.ts +10 -5
- package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
package/src/NativeList.tsx
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
|
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 =
|
|
372
|
+
snapshotRef.current = accepted;
|
|
341
373
|
if (nativeRef.current && avatarLifecycle.current !== 'unmounted') {
|
|
342
|
-
avatarModelRef.current?.replaceSnapshot(
|
|
374
|
+
avatarModelRef.current?.replaceSnapshot(accepted.rows);
|
|
343
375
|
updateAvatarPrefetchRef.current();
|
|
344
376
|
}
|
|
345
377
|
},
|
|
346
378
|
applyPatches(patches) {
|
|
347
|
-
|
|
348
|
-
|
|
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(
|
|
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
|
-
|
|
560
|
+
topScrollEdgeEffect={
|
|
561
|
+
hasTopOverlay ? topScrollEdgeEffect ?? 'none' : 'none'
|
|
562
|
+
}
|
|
521
563
|
topOverlayHeight={hasTopOverlay ? topOverlayHeight : 0}
|
|
522
564
|
scrollPositionThresholdsJson={scrollPositionThresholdsJson}
|
|
523
565
|
keyboardDismissMode={keyboardDismissMode}
|
package/src/NativeList.types.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
129
|
-
topScrollEdgeEffect?:
|
|
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. */
|