@onekeyfe/react-native-native-list 6.7.0-alpha.343 → 6.7.0-alpha.354
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 +7 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +240 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +6 -3
- package/android/src/main/java/com/onekey/nativelist/NativeListButtonGroupRenderer.kt +102 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListContainerSlotAdapter.kt +12 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListDataRowRenderer.kt +87 -7
- package/android/src/main/java/com/onekey/nativelist/NativeListIdentityRenderer.kt +135 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +43 -14
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +17 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +22 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRegistry.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListRendererRowView.kt +2 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListResolvedText.kt +3 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListSectionHeaderRenderer.kt +69 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListTextView.kt +55 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListView.kt +585 -21
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +1 -0
- package/docs/ROW_TEMPLATES.md +60 -9
- package/docs/SPEC.md +361 -8
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +10 -0
- package/ios/NativeListAccessoryStack.swift +220 -37
- package/ios/NativeListActivityDetailsView.swift +18 -8
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +105 -8
- package/ios/NativeListDesignAssets.swift +3 -0
- package/ios/NativeListIdentityRenderer.swift +119 -4
- package/ios/NativeListLeadingVisual.swift +49 -14
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListModels.swift +16 -2
- package/ios/NativeListRendererRegistry.swift +1 -0
- package/ios/NativeListResolvedText.swift +2 -1
- package/ios/NativeListRowHost.swift +14 -0
- package/ios/NativeListSectionHeaderRenderer.swift +88 -0
- package/ios/RNCNativeListView.swift +331 -29
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_crypto_coin_outline.imageset/icon.svg +4 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_gas_solid.imageset/icon.svg +3 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/Contents.json +15 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_refresh_ccw_outline.imageset/icon.svg +3 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
- package/ios/tests/NativeListLifecycleTests.swift +890 -3
- package/lib/module/NativeList.js +64 -27
- package/lib/module/NativeList.web.js +84 -17
- package/lib/module/models.js +1 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +532 -18
- package/lib/module/web/NativeListWebEngine.js +391 -24
- package/lib/module/web/templates/ActivityRowRenderer.js +8 -7
- package/lib/module/web/templates/ButtonGroupRowRenderer.js +47 -0
- package/lib/module/web/templates/DataRowRenderer.js +40 -5
- package/lib/module/web/templates/IdentityRowRenderer.js +90 -4
- package/lib/module/web/templates/MessageRowRenderer.js +18 -2
- package/lib/module/web/templates/RowContainerStyle.js +1 -0
- package/lib/module/web/templates/RowRendererRegistry.js +3 -0
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +36 -2
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +1 -0
- package/lib/typescript/src/NativeList.types.d.ts +8 -0
- package/lib/typescript/src/models.d.ts +101 -9
- package/lib/typescript/src/validation.d.ts +13 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -0
- package/lib/typescript/src/web/templates/ButtonGroupRowRenderer.d.ts +14 -0
- package/lib/typescript/src/web/templates/IdentityRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +9 -3
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +9 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +5 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +6 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +7 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +6 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +11 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +3 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -0
- package/package.json +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +1 -0
- package/src/NativeList.tsx +155 -69
- package/src/NativeList.types.ts +9 -0
- package/src/NativeList.web.tsx +159 -49
- package/src/models.ts +113 -3
- package/src/selection.ts +1 -0
- package/src/validation.ts +1156 -18
- package/src/web/NativeListWebEngine.ts +594 -28
- package/src/web/templates/ActivityRowRenderer.ts +14 -6
- package/src/web/templates/ButtonGroupRowRenderer.ts +58 -0
- package/src/web/templates/DataRowRenderer.ts +93 -20
- package/src/web/templates/IdentityRowRenderer.ts +150 -5
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +11 -1
- package/src/web/templates/SectionHeaderRowRenderer.ts +47 -4
package/lib/module/NativeList.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { useNativeListFontFamiliesJson } from "./fonts.js";
|
|
4
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { OneKeyImageCache, OneKeyImageCachePolicy } from '@onekeyfe/react-native-image';
|
|
6
6
|
import { NativeAvatarPrefetchModel, NativeAvatarPrefetchQueue } from "./avatarPrefetch.js";
|
|
7
7
|
import { Platform, View } from 'react-native';
|
|
8
8
|
import { callback, getHostComponent } from 'react-native-nitro-modules';
|
|
9
9
|
import { isSelectableRow } from "./selection.js";
|
|
10
10
|
import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
|
|
11
|
-
import {
|
|
11
|
+
import { applyOwnedNativePatches, captureNativeListInput, containNativeListInput, emptyNativeListSnapshot, ownValidatedNativeSnapshot, validateSnapshot } from "./validation.js";
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
const NativeListConfig = require('../nitrogen/generated/shared/json/NativeListConfig.json');
|
|
14
14
|
const NativeListHost = getHostComponent('NativeList', () => NativeListConfig);
|
|
@@ -27,10 +27,12 @@ function parsePayload(payloadJson) {
|
|
|
27
27
|
return JSON.parse(payloadJson);
|
|
28
28
|
}
|
|
29
29
|
export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
30
|
-
snapshot,
|
|
30
|
+
snapshot: inputSnapshot,
|
|
31
31
|
listHeader,
|
|
32
32
|
listFooter,
|
|
33
33
|
listEmpty,
|
|
34
|
+
listSidecar,
|
|
35
|
+
sidecarLayout,
|
|
34
36
|
topOverlay,
|
|
35
37
|
topScrollEdgeEffect,
|
|
36
38
|
scrollPositionThresholds,
|
|
@@ -55,16 +57,38 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
55
57
|
initialScrollViewOffset,
|
|
56
58
|
...viewProps
|
|
57
59
|
}, forwardedRef) {
|
|
60
|
+
const snapshotRef = useRef(emptyNativeListSnapshot());
|
|
61
|
+
const initializedSnapshot = useRef(false);
|
|
62
|
+
const hasSidecar = listSidecar !== undefined;
|
|
63
|
+
const sidecarWidth = sidecarLayout?.width;
|
|
64
|
+
const sidecarGap = sidecarLayout?.gap;
|
|
65
|
+
const sidecarMaxContentWidth = sidecarLayout?.maxContentWidth;
|
|
66
|
+
const hasContainerSlots = Boolean(listHeader || listEmpty || listFooter || listSidecar);
|
|
67
|
+
const prepareSnapshot = useCallback(next => {
|
|
68
|
+
const accepted = validateSnapshot(captureNativeListInput(next));
|
|
69
|
+
if (hasContainerSlots && accepted.layout.orientation === 'horizontal') throw new Error('NativeList container slots require vertical orientation');
|
|
70
|
+
if (hasSidecar !== (sidecarWidth !== undefined)) throw new Error('listSidecar and sidecarLayout must be supplied together');
|
|
71
|
+
if (sidecarWidth !== undefined) {
|
|
72
|
+
const width = sidecarWidth;
|
|
73
|
+
const gap = sidecarGap ?? NaN;
|
|
74
|
+
const maxContentWidth = sidecarMaxContentWidth ?? NaN;
|
|
75
|
+
if (accepted.layout.kind !== 'linear' || !Number.isFinite(width) || width <= 0 || !Number.isFinite(gap) || gap < 0 || !Number.isFinite(maxContentWidth) || maxContentWidth <= width + gap) throw new Error('Invalid NativeList sidecar layout');
|
|
76
|
+
}
|
|
77
|
+
return ownValidatedNativeSnapshot(accepted);
|
|
78
|
+
}, [hasContainerSlots, hasSidecar, sidecarWidth, sidecarGap, sidecarMaxContentWidth]);
|
|
79
|
+
const snapshot = useMemo(() => containNativeListInput(() => prepareSnapshot(inputSnapshot)) ?? snapshotRef.current, [inputSnapshot, prepareSnapshot]);
|
|
58
80
|
const fontFamiliesJson = useNativeListFontFamiliesJson();
|
|
59
|
-
const [slotHeights, setSlotHeights] = useState([0, 0, 0]);
|
|
81
|
+
const [slotHeights, setSlotHeights] = useState([0, 0, 0, 0]);
|
|
82
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
60
83
|
const [topOverlayHeight, setTopOverlayHeight] = useState(0);
|
|
61
84
|
const hasTopOverlay = Platform?.OS === 'ios' && parseInt(String(Platform.Version), 10) >= 26 && (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') && topOverlay != null;
|
|
62
85
|
const containerSlotHeightsJson = JSON.stringify(slotHeights);
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const slotContents = [listHeader, listEmpty, listFooter];
|
|
86
|
+
const defaultSlotInset = snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0;
|
|
87
|
+
const bandWidth = sidecarLayout ? Math.min(viewportWidth, sidecarLayout.maxContentWidth) : 0;
|
|
88
|
+
const slotInset = sidecarLayout ? Math.max(0, (viewportWidth - bandWidth) / 2) : defaultSlotInset;
|
|
89
|
+
const sidecarSpace = sidecarLayout ? sidecarLayout.width + sidecarLayout.gap : 0;
|
|
90
|
+
const slotContents = [listHeader, listEmpty, listFooter, listSidecar];
|
|
91
|
+
const sidecarLayoutJson = sidecarLayout ? JSON.stringify(sidecarLayout) : '';
|
|
68
92
|
const normalizedKeyboardShouldPersistTaps = keyboardShouldPersistTaps === true ? 'always' : keyboardShouldPersistTaps === false ? 'never' : keyboardShouldPersistTaps;
|
|
69
93
|
const nativeRef = useRef(null);
|
|
70
94
|
const callbacksRef = useRef({
|
|
@@ -89,7 +113,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
89
113
|
onRefresh,
|
|
90
114
|
onScrollToIndexFailed
|
|
91
115
|
};
|
|
92
|
-
const scrollPositionThresholdsJson = useMemo(() => {
|
|
116
|
+
const scrollPositionThresholdsJson = useMemo(() => containNativeListInput(() => {
|
|
93
117
|
if (!scrollPositionThresholds || scrollPositionThresholds.enabled === false) return '';
|
|
94
118
|
const {
|
|
95
119
|
start,
|
|
@@ -102,15 +126,18 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
102
126
|
start,
|
|
103
127
|
end
|
|
104
128
|
});
|
|
105
|
-
}, [scrollPositionThresholds]);
|
|
106
|
-
const snapshotJson = useMemo(() =>
|
|
107
|
-
const snapshotRef = useRef(snapshot);
|
|
129
|
+
}) ?? '', [scrollPositionThresholds]);
|
|
130
|
+
const snapshotJson = useMemo(() => JSON.stringify(snapshot), [snapshot]);
|
|
108
131
|
const previousSnapshotJsonRef = useRef(snapshotJson);
|
|
109
132
|
const snapshotChanged = previousSnapshotJsonRef.current !== snapshotJson;
|
|
110
133
|
if (snapshotChanged) {
|
|
111
134
|
snapshotRef.current = snapshot;
|
|
112
135
|
previousSnapshotJsonRef.current = snapshotJson;
|
|
113
136
|
}
|
|
137
|
+
if (!initializedSnapshot.current) {
|
|
138
|
+
snapshotRef.current = snapshot;
|
|
139
|
+
initializedSnapshot.current = true;
|
|
140
|
+
}
|
|
114
141
|
// OneKey patch: range events already cross the bridge only when row indices
|
|
115
142
|
// change. Prefetch is optional work; scrolling and visible loads stay native.
|
|
116
143
|
const avatarQueueRef = useRef(null);
|
|
@@ -142,7 +169,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
142
169
|
useEffect(() => {
|
|
143
170
|
updateAvatarPrefetchRef.current();
|
|
144
171
|
}, [snapshot]);
|
|
145
|
-
const initialScrollRef = useRef(initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
172
|
+
const initialScrollRef = useRef(containNativeListInput(() => initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
146
173
|
index: initialScrollIndex,
|
|
147
174
|
animated: false,
|
|
148
175
|
viewPosition: initialScrollViewPosition,
|
|
@@ -154,7 +181,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
154
181
|
viewPosition: initialScrollViewPosition,
|
|
155
182
|
viewOffset: initialScrollViewOffset
|
|
156
183
|
}, 'start')
|
|
157
|
-
});
|
|
184
|
+
}));
|
|
158
185
|
const didApplyInitialScroll = useRef(false);
|
|
159
186
|
const emitIndexFailure = (index, reason) => {
|
|
160
187
|
callbacksRef.current.onScrollToIndexFailed?.(scrollFailure(snapshotRef.current.rows, index, reason));
|
|
@@ -180,37 +207,41 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
180
207
|
applyInitialScrollCallbackRef.current = applyInitialScroll;
|
|
181
208
|
useImperativeHandle(forwardedRef, () => ({
|
|
182
209
|
applySnapshot(nextSnapshot) {
|
|
183
|
-
const
|
|
210
|
+
const accepted = containNativeListInput(() => prepareSnapshot(nextSnapshot));
|
|
211
|
+
if (!accepted) return;
|
|
212
|
+
const nextSnapshotJson = JSON.stringify(accepted);
|
|
184
213
|
nativeRef.current?.applySnapshot(nextSnapshotJson);
|
|
185
|
-
snapshotRef.current =
|
|
214
|
+
snapshotRef.current = accepted;
|
|
186
215
|
if (nativeRef.current && avatarLifecycle.current !== 'unmounted') {
|
|
187
|
-
avatarModelRef.current?.replaceSnapshot(
|
|
216
|
+
avatarModelRef.current?.replaceSnapshot(accepted.rows);
|
|
188
217
|
updateAvatarPrefetchRef.current();
|
|
189
218
|
}
|
|
190
219
|
},
|
|
191
220
|
applyPatches(patches) {
|
|
192
|
-
|
|
193
|
-
|
|
221
|
+
const accepted = containNativeListInput(() => applyOwnedNativePatches(snapshotRef.current, patches));
|
|
222
|
+
if (!accepted || accepted.patches.length === 0) return;
|
|
223
|
+
const nextSnapshot = accepted.snapshot;
|
|
194
224
|
const native = nativeRef.current;
|
|
195
225
|
const dispatch = native ? () => {
|
|
196
|
-
native.applyPatches(
|
|
226
|
+
native.applyPatches(accepted.json);
|
|
197
227
|
snapshotRef.current = nextSnapshot;
|
|
198
228
|
} : undefined;
|
|
199
229
|
if (avatarLifecycle.current === 'unmounted') {
|
|
200
230
|
dispatch?.();
|
|
201
231
|
return;
|
|
202
232
|
}
|
|
203
|
-
if (avatarModelRef.current?.applyPatches(patches, dispatch)) updateAvatarPrefetchRef.current();
|
|
233
|
+
if (avatarModelRef.current?.applyPatches(accepted.patches, dispatch)) updateAvatarPrefetchRef.current();
|
|
204
234
|
},
|
|
205
235
|
reconcileSelection(selectedKeys) {
|
|
206
|
-
|
|
236
|
+
const capturedKeys = captureNativeListInput(selectedKeys);
|
|
237
|
+
nativeRef.current?.reconcileSelection(JSON.stringify(capturedKeys));
|
|
207
238
|
const current = snapshotRef.current;
|
|
208
|
-
if (current.selection && (current.selection.mode !== 'single' ||
|
|
239
|
+
if (current.selection && (current.selection.mode !== 'single' || capturedKeys.length <= 1) && capturedKeys.every(key => current.rows.some(row => row.key === key && isSelectableRow(row)))) {
|
|
209
240
|
snapshotRef.current = {
|
|
210
241
|
...current,
|
|
211
242
|
selection: {
|
|
212
243
|
...current.selection,
|
|
213
|
-
selectedKeys
|
|
244
|
+
selectedKeys: capturedKeys
|
|
214
245
|
}
|
|
215
246
|
};
|
|
216
247
|
}
|
|
@@ -323,10 +354,15 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
323
354
|
}), []);
|
|
324
355
|
return /*#__PURE__*/_jsxs(NativeListHost, {
|
|
325
356
|
...viewProps,
|
|
357
|
+
onLayout: event => {
|
|
358
|
+
setViewportWidth(event.nativeEvent.layout.width);
|
|
359
|
+
viewProps.onLayout?.(event);
|
|
360
|
+
},
|
|
326
361
|
...nativeCallbacks,
|
|
327
362
|
fontFamiliesJson: fontFamiliesJson,
|
|
328
363
|
snapshotJson: snapshotJson,
|
|
329
364
|
containerSlotHeightsJson: containerSlotHeightsJson,
|
|
365
|
+
sidecarLayoutJson: sidecarLayoutJson,
|
|
330
366
|
topScrollEdgeEffect: hasTopOverlay ? topScrollEdgeEffect ?? 'none' : 'none',
|
|
331
367
|
topOverlayHeight: hasTopOverlay ? topOverlayHeight : 0,
|
|
332
368
|
scrollPositionThresholdsJson: scrollPositionThresholdsJson,
|
|
@@ -336,8 +372,9 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
336
372
|
collapsable: false,
|
|
337
373
|
style: {
|
|
338
374
|
position: 'absolute',
|
|
339
|
-
|
|
340
|
-
|
|
375
|
+
start: index === 3 ? 0 : slotInset,
|
|
376
|
+
end: index === 3 ? undefined : slotInset + sidecarSpace,
|
|
377
|
+
width: index === 3 ? sidecarLayout?.width : undefined,
|
|
341
378
|
top: 0
|
|
342
379
|
},
|
|
343
380
|
onLayout: event => {
|
|
@@ -4,7 +4,7 @@ import { useNativeListFontFamiliesJson } from "./fonts.js";
|
|
|
4
4
|
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
6
|
import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
|
|
7
|
-
import { applyRowPatches, validateSnapshot } from "./validation.js";
|
|
7
|
+
import { applyRowPatches, containNativeListInput, emptyNativeListSnapshot, validatePatches, validateSnapshot } from "./validation.js";
|
|
8
8
|
import { NativeListWebEngine } from "./web/NativeListWebEngine.js";
|
|
9
9
|
import { acquireNativeListAvatar, canonicalNativeListAvatarUri } from "./web/NativeListWebAvatarCache.js";
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -22,14 +22,16 @@ export function preloadNativeListAvatarImages(sources) {
|
|
|
22
22
|
}))).then(results => results.every(Boolean));
|
|
23
23
|
}
|
|
24
24
|
export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
25
|
-
snapshot,
|
|
25
|
+
snapshot: inputSnapshot,
|
|
26
26
|
listHeader,
|
|
27
27
|
listEmpty,
|
|
28
28
|
listFooter,
|
|
29
|
+
listSidecar,
|
|
30
|
+
sidecarLayout,
|
|
29
31
|
topOverlay: _topOverlay,
|
|
30
32
|
topScrollEdgeEffect: _topScrollEdgeEffect,
|
|
31
33
|
webScrollHost,
|
|
32
|
-
webStickyInset = 0,
|
|
34
|
+
webStickyInset: inputStickyInset = 0,
|
|
33
35
|
scrollPositionThresholds: _scrollPositionThresholds,
|
|
34
36
|
onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
|
|
35
37
|
webVirtualizationEnabled = true,
|
|
@@ -50,6 +52,14 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
50
52
|
initialScrollViewOffset,
|
|
51
53
|
...viewProps
|
|
52
54
|
}, forwardedRef) {
|
|
55
|
+
const acceptedSnapshotRef = useRef(emptyNativeListSnapshot());
|
|
56
|
+
const initializedSnapshot = useRef(false);
|
|
57
|
+
const webStickyInset = useMemo(() => containNativeListInput(() => {
|
|
58
|
+
if (!Number.isFinite(inputStickyInset) || inputStickyInset < 0) throw new Error('webStickyInset must be finite and non-negative');
|
|
59
|
+
return inputStickyInset;
|
|
60
|
+
}) ?? 0, [inputStickyInset]);
|
|
61
|
+
const preparedSnapshot = useMemo(() => containNativeListInput(() => validateSnapshot(inputSnapshot)), [inputSnapshot]);
|
|
62
|
+
const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
|
|
53
63
|
const fontFamiliesJson = useNativeListFontFamiliesJson();
|
|
54
64
|
const fontFamiliesJsonRef = useRef(fontFamiliesJson);
|
|
55
65
|
fontFamiliesJsonRef.current = fontFamiliesJson;
|
|
@@ -61,6 +71,8 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
61
71
|
emptyBottomPadding: !snapshot.rows.length && hasEmptySlot ? snapshot.layout.contentPaddingBottom ?? snapshot.layout.contentPadding ?? 0 : 0,
|
|
62
72
|
padding: snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0
|
|
63
73
|
}));
|
|
74
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
75
|
+
const [sidecarHeight, setSidecarHeight] = useState(0);
|
|
64
76
|
const synchronizeSlots = next => {
|
|
65
77
|
const hasRows = next.rows.length > 0;
|
|
66
78
|
const padding = next.layout.contentPaddingHorizontal ?? next.layout.contentPadding ?? 0;
|
|
@@ -91,21 +103,37 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
91
103
|
const [ownedScrollHost, setOwnedScrollHost] = useState(null);
|
|
92
104
|
const useSlotLayoutRef = useRef(false);
|
|
93
105
|
useSlotLayoutRef.current ||= webScrollHost !== undefined || listHeader !== undefined || listEmpty !== undefined || listFooter !== undefined;
|
|
106
|
+
useSlotLayoutRef.current ||= listSidecar !== undefined;
|
|
94
107
|
const useSlotLayout = useSlotLayoutRef.current;
|
|
95
108
|
const resolvedScrollHost = webScrollHost === undefined ? useSlotLayout ? ownedScrollHost : undefined : webScrollHost;
|
|
96
|
-
if (!Number.isFinite(webStickyInset) || webStickyInset < 0) throw new Error('webStickyInset must be finite and non-negative');
|
|
97
109
|
const engineRef = useRef(undefined);
|
|
98
110
|
const webVirtualizationEnabledRef = useRef(webVirtualizationEnabled);
|
|
99
111
|
webVirtualizationEnabledRef.current = webVirtualizationEnabled;
|
|
100
|
-
const validatedSnapshot = useMemo(() =>
|
|
112
|
+
const validatedSnapshot = useMemo(() => containNativeListInput(() => {
|
|
113
|
+
if (listSidecar !== undefined !== (sidecarLayout !== undefined)) throw new Error('listSidecar and sidecarLayout must be supplied together');
|
|
114
|
+
if (sidecarLayout) {
|
|
115
|
+
const {
|
|
116
|
+
width,
|
|
117
|
+
gap,
|
|
118
|
+
maxContentWidth
|
|
119
|
+
} = sidecarLayout;
|
|
120
|
+
if (snapshot.layout.kind !== 'linear' || !Number.isFinite(width) || width <= 0 || !Number.isFinite(gap) || gap < 0 || !Number.isFinite(maxContentWidth) || maxContentWidth <= width + gap) throw new Error('Invalid NativeList sidecar layout');
|
|
121
|
+
}
|
|
122
|
+
return normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout);
|
|
123
|
+
}) ?? acceptedSnapshotRef.current, [snapshot, hasEmptySlot, useSlotLayout, listSidecar, sidecarLayout]);
|
|
101
124
|
const snapshotRef = useRef(validatedSnapshot);
|
|
102
125
|
const snapshotPropRef = useRef(validatedSnapshot);
|
|
103
126
|
// An imperative snapshot survives host mounting until the snapshot prop changes.
|
|
104
127
|
if (snapshotPropRef.current !== validatedSnapshot) {
|
|
105
128
|
snapshotPropRef.current = validatedSnapshot;
|
|
106
129
|
snapshotRef.current = validatedSnapshot;
|
|
130
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
107
131
|
synchronizeSlots(snapshot);
|
|
108
132
|
}
|
|
133
|
+
if (!initializedSnapshot.current) {
|
|
134
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
135
|
+
initializedSnapshot.current = true;
|
|
136
|
+
}
|
|
109
137
|
const appliedSnapshotRef = useRef(undefined);
|
|
110
138
|
const callbacksRef = useRef({});
|
|
111
139
|
callbacksRef.current = {
|
|
@@ -118,7 +146,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
118
146
|
onRefresh,
|
|
119
147
|
onScrollToIndexFailed
|
|
120
148
|
};
|
|
121
|
-
const initialScrollRef = useRef(initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
149
|
+
const initialScrollRef = useRef(containNativeListInput(() => initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
122
150
|
index: initialScrollIndex,
|
|
123
151
|
animated: false,
|
|
124
152
|
viewPosition: initialScrollViewPosition,
|
|
@@ -130,7 +158,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
130
158
|
viewPosition: initialScrollViewPosition,
|
|
131
159
|
viewOffset: initialScrollViewOffset
|
|
132
160
|
}, 'start')
|
|
133
|
-
});
|
|
161
|
+
}));
|
|
134
162
|
const didApplyInitialScroll = useRef(false);
|
|
135
163
|
const scrollOptionsRef = useRef({
|
|
136
164
|
stickyInset: webStickyInset,
|
|
@@ -142,11 +170,12 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
142
170
|
};
|
|
143
171
|
useEffect(() => {
|
|
144
172
|
if (!host || resolvedScrollHost === null || useSlotLayout && !contentBounds) return;
|
|
145
|
-
const engine = new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current, {
|
|
173
|
+
const engine = containNativeListInput(() => new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current, {
|
|
146
174
|
scrollHost: resolvedScrollHost,
|
|
147
175
|
contentBounds: contentBounds ?? undefined,
|
|
148
176
|
...scrollOptionsRef.current
|
|
149
|
-
});
|
|
177
|
+
}));
|
|
178
|
+
if (!engine) return;
|
|
150
179
|
host.style.height = '';
|
|
151
180
|
engineRef.current = engine;
|
|
152
181
|
appliedSnapshotRef.current = snapshotRef.current;
|
|
@@ -185,19 +214,26 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
185
214
|
};
|
|
186
215
|
useImperativeHandle(forwardedRef, () => ({
|
|
187
216
|
applySnapshot(nextSnapshot) {
|
|
188
|
-
const next = normalizeWebSnapshot(nextSnapshot);
|
|
217
|
+
const next = containNativeListInput(() => normalizeWebSnapshot(nextSnapshot));
|
|
218
|
+
if (!next) return;
|
|
189
219
|
engineRef.current?.applySnapshot(next);
|
|
190
220
|
snapshotRef.current = next;
|
|
221
|
+
acceptedSnapshotRef.current = next;
|
|
191
222
|
appliedSnapshotRef.current = next;
|
|
192
|
-
synchronizeSlots(
|
|
223
|
+
synchronizeSlots(next);
|
|
193
224
|
},
|
|
194
225
|
applyPatches(patches) {
|
|
195
|
-
|
|
226
|
+
const accepted = containNativeListInput(() => validatePatches(patches));
|
|
227
|
+
if (accepted && accepted.length > 0) {
|
|
196
228
|
const engine = engineRef.current;
|
|
197
229
|
if (engine) {
|
|
198
|
-
engine.applyPatches(
|
|
230
|
+
engine.applyPatches(accepted);
|
|
199
231
|
snapshotRef.current = engine.currentSnapshot();
|
|
200
|
-
} else
|
|
232
|
+
} else {
|
|
233
|
+
const next = containNativeListInput(() => applyRowPatches(snapshotRef.current, accepted));
|
|
234
|
+
if (next) snapshotRef.current = next;
|
|
235
|
+
}
|
|
236
|
+
acceptedSnapshotRef.current = snapshotRef.current;
|
|
201
237
|
}
|
|
202
238
|
},
|
|
203
239
|
reconcileSelection(selectedKeys) {
|
|
@@ -277,7 +313,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
277
313
|
});
|
|
278
314
|
const padding = slotState.padding;
|
|
279
315
|
const content = /*#__PURE__*/_jsxs(View, {
|
|
280
|
-
ref: setBoundsRef,
|
|
316
|
+
ref: sidecarLayout ? undefined : setBoundsRef,
|
|
281
317
|
style: {
|
|
282
318
|
position: 'relative',
|
|
283
319
|
flexShrink: 0,
|
|
@@ -301,14 +337,45 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
301
337
|
},
|
|
302
338
|
children: listEmpty
|
|
303
339
|
}) : null, listFooter !== undefined ? /*#__PURE__*/_jsx(View, {
|
|
340
|
+
testID: "native-list-footer-slot",
|
|
304
341
|
style: {
|
|
305
342
|
paddingHorizontal: padding
|
|
306
343
|
},
|
|
307
344
|
children: listFooter
|
|
308
345
|
}) : null]
|
|
309
346
|
});
|
|
347
|
+
const bandWidth = sidecarLayout ? Math.min(viewportWidth, sidecarLayout.maxContentWidth) : 0;
|
|
348
|
+
const sidecarMargin = Math.max(0, (viewportWidth - bandWidth) / 2);
|
|
349
|
+
const leftWidth = Math.max(0, bandWidth - (sidecarLayout?.width ?? 0) - (sidecarLayout?.gap ?? 0));
|
|
350
|
+
const scrollContent = sidecarLayout ? /*#__PURE__*/_jsxs(View, {
|
|
351
|
+
ref: setBoundsRef,
|
|
352
|
+
style: {
|
|
353
|
+
position: 'relative',
|
|
354
|
+
minHeight: sidecarHeight
|
|
355
|
+
},
|
|
356
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
357
|
+
style: {
|
|
358
|
+
marginStart: sidecarMargin,
|
|
359
|
+
width: leftWidth
|
|
360
|
+
},
|
|
361
|
+
children: content
|
|
362
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
363
|
+
style: {
|
|
364
|
+
position: 'absolute',
|
|
365
|
+
end: sidecarMargin,
|
|
366
|
+
top: 0,
|
|
367
|
+
width: sidecarLayout.width
|
|
368
|
+
},
|
|
369
|
+
onLayout: event => setSidecarHeight(event.nativeEvent.layout.height),
|
|
370
|
+
children: listSidecar
|
|
371
|
+
})]
|
|
372
|
+
}) : content;
|
|
310
373
|
return /*#__PURE__*/_jsx(View, {
|
|
311
374
|
...viewProps,
|
|
375
|
+
onLayout: event => {
|
|
376
|
+
setViewportWidth(event.nativeEvent.layout.width);
|
|
377
|
+
viewProps.onLayout?.(event);
|
|
378
|
+
},
|
|
312
379
|
style: [viewProps.style, {
|
|
313
380
|
position: 'relative',
|
|
314
381
|
minHeight: 0
|
|
@@ -320,8 +387,8 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
320
387
|
inset: 0,
|
|
321
388
|
overflow: 'scroll'
|
|
322
389
|
},
|
|
323
|
-
children:
|
|
324
|
-
}) :
|
|
390
|
+
children: scrollContent
|
|
391
|
+
}) : scrollContent
|
|
325
392
|
});
|
|
326
393
|
});
|
|
327
394
|
//# sourceMappingURL=NativeList.web.js.map
|
package/lib/module/models.js
CHANGED
|
@@ -24,6 +24,7 @@ export const ROW_BOX_STYLE_KEYS_BY_TYPE = {
|
|
|
24
24
|
metricCard: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'image'],
|
|
25
25
|
sectionHeader: ['horizontalPadding', 'verticalPadding', 'lineGap', 'trailingGap'],
|
|
26
26
|
action: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'trailingGap', 'image'],
|
|
27
|
+
buttonGroup: [],
|
|
27
28
|
system: ['horizontalPadding', 'verticalPadding', 'lineGap']
|
|
28
29
|
};
|
|
29
30
|
|
package/lib/module/selection.js
CHANGED
|
@@ -4,7 +4,7 @@ export function isSelectableRow(row) {
|
|
|
4
4
|
return !row.disabled && (row.type === 'identity' || row.type === 'rail' || row.type === 'activity' || row.type === 'message' || row.type === 'dataRow' || row.type === 'mediaTile' || row.type === 'metricCard');
|
|
5
5
|
}
|
|
6
6
|
export function isRowPressEnabled(row) {
|
|
7
|
-
return !row.disabled && !row.pressDisabled && (row.type !== 'system' || row.variant === 'retry');
|
|
7
|
+
return !row.disabled && !row.pressDisabled && row.type !== 'buttonGroup' && (row.type !== 'system' || row.variant === 'retry');
|
|
8
8
|
}
|
|
9
9
|
function deltaBetween(before, after, source, sourceKey) {
|
|
10
10
|
return {
|