@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.
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +14 -1
- package/android/src/main/java/com/onekey/nativelist/NativeListAccessoryStack.kt +245 -9
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityDetailsView.kt +7 -4
- package/android/src/main/java/com/onekey/nativelist/NativeListActivityRenderer.kt +29 -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 +193 -10
- package/android/src/main/java/com/onekey/nativelist/NativeListLeadingVisual.kt +147 -33
- package/android/src/main/java/com/onekey/nativelist/NativeListMessageRenderer.kt +25 -0
- package/android/src/main/java/com/onekey/nativelist/NativeListModels.kt +145 -2
- package/android/src/main/java/com/onekey/nativelist/NativeListPrimitives.kt +51 -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 +1920 -109
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListActivityHostClipPolicyTest.kt +29 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListIdentityTrailingAxisTest.kt +36 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingSlotFrameTest.kt +68 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListLeadingVisualClipPolicyTest.kt +44 -0
- package/android/src/test/java/com/margelo/nitro/nativelist/NativeListPressPolicyTest.kt +10 -0
- package/docs/ROW_TEMPLATES.md +60 -9
- package/docs/SPEC.md +1004 -17
- package/docs/STYLE_SPEC.md +6 -0
- package/ios/HybridNativeList.swift +21 -2
- package/ios/NativeListAccessoryStack.swift +235 -39
- package/ios/NativeListActivityDetailsView.swift +18 -8
- package/ios/NativeListActivityRenderer.swift +8 -2
- package/ios/NativeListButtonGroupRenderer.swift +89 -0
- package/ios/NativeListDataRowRenderer.swift +155 -27
- package/ios/NativeListDesignAssets.swift +9 -0
- package/ios/NativeListIdentityRenderer.swift +191 -30
- package/ios/NativeListLeadingVisual.swift +119 -22
- package/ios/NativeListMessageRenderer.swift +34 -1
- package/ios/NativeListModels.swift +42 -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 +1031 -55
- 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_document2.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_document2.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_dot_ver_solid.imageset/icon.svg +1 -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_plus_large.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_plus_large.imageset/icon.svg +1 -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/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_ticket.imageset/icon.svg +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/Contents.json +1 -0
- package/ios/Resources/NativeListIcons.xcassets/onekey_wallet.imageset/icon.svg +1 -0
- package/ios/tests/NativeListAccessoryStackTests.swift +89 -0
- package/ios/tests/NativeListActivityPresentationTests.swift +56 -0
- package/ios/tests/NativeListIdentityTitleIconLayoutTests.swift +81 -0
- package/ios/tests/NativeListLeadingVisualPairBackdropTests.swift +50 -0
- package/ios/tests/NativeListLifecycleTests.swift +2720 -3
- package/lib/module/NativeList.js +200 -32
- package/lib/module/NativeList.web.js +262 -32
- package/lib/module/index.js +1 -1
- package/lib/module/models.js +1 -0
- package/lib/module/selection.js +1 -1
- package/lib/module/validation.js +776 -52
- package/lib/module/web/NativeListWebEngine.js +919 -79
- package/lib/module/web/templates/ActivityRowRenderer.js +487 -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/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/MessageRowRenderer.js +18 -2
- package/lib/module/web/templates/RowContainerStyle.js +1 -0
- package/lib/module/web/templates/RowRendererRegistry.js +8 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +70 -3
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/lib/typescript/src/NativeList.d.ts +3 -3
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -0
- package/lib/typescript/src/NativeList.types.d.ts +29 -1
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/index.d.ts +2 -2
- package/lib/typescript/src/models.d.ts +176 -10
- package/lib/typescript/src/validation.d.ts +15 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +58 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- 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/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 +10 -4
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +26 -0
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +10 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +20 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +14 -0
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +12 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +43 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +4 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +6 -0
- package/nitrogen/generated/shared/json/NativeListConfig.json +2 -0
- package/package.json +3 -3
- package/react-native-native-list.podspec +1 -0
- package/src/NativeList.nitro.ts +2 -0
- package/src/NativeList.tsx +391 -82
- package/src/NativeList.types.ts +34 -1
- package/src/NativeList.web.tsx +420 -65
- package/src/index.ts +2 -0
- package/src/models.ts +210 -3
- package/src/selection.ts +1 -0
- package/src/validation.ts +1635 -76
- package/src/web/NativeListWebEngine.ts +1476 -112
- package/src/web/templates/ActivityRowRenderer.ts +732 -8
- 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/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/MessageRowRenderer.ts +23 -7
- package/src/web/templates/RowContainerStyle.ts +2 -0
- package/src/web/templates/RowRendererRegistry.ts +21 -6
- package/src/web/templates/SectionHeaderRowRenderer.ts +89 -5
package/lib/module/NativeList.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
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);
|
|
15
|
+
const clearedStructuralTransitionSettled = {
|
|
16
|
+
f: undefined
|
|
17
|
+
};
|
|
18
|
+
const disclosureSlotMeasurementStyle = {
|
|
19
|
+
alignSelf: 'stretch'
|
|
20
|
+
};
|
|
15
21
|
export function preloadNativeListAvatarImages(sources) {
|
|
16
22
|
return OneKeyImageCache.preload(sources.map(source => ({
|
|
17
23
|
uri: source.uri,
|
|
@@ -27,14 +33,20 @@ function parsePayload(payloadJson) {
|
|
|
27
33
|
return JSON.parse(payloadJson);
|
|
28
34
|
}
|
|
29
35
|
export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
30
|
-
snapshot,
|
|
36
|
+
snapshot: inputSnapshot,
|
|
31
37
|
listHeader,
|
|
32
38
|
listFooter,
|
|
33
39
|
listEmpty,
|
|
40
|
+
listSidecar,
|
|
41
|
+
listExpandedContent,
|
|
42
|
+
listStructureToggle,
|
|
43
|
+
sidecarLayout,
|
|
34
44
|
topOverlay,
|
|
35
45
|
topScrollEdgeEffect,
|
|
36
46
|
scrollPositionThresholds,
|
|
37
47
|
webVirtualizationEnabled: _webVirtualizationEnabled,
|
|
48
|
+
webScrollHost: _webScrollHost,
|
|
49
|
+
webStickyInset: _webStickyInset,
|
|
38
50
|
webSectionIndexContainerRef: _webSectionIndexContainerRef,
|
|
39
51
|
keyboardDismissMode = 'none',
|
|
40
52
|
keyboardShouldPersistTaps = 'never',
|
|
@@ -44,6 +56,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
44
56
|
onReorder,
|
|
45
57
|
onEndReached,
|
|
46
58
|
onVisibleRangeChanged,
|
|
59
|
+
onStructuralTransitionSettled,
|
|
47
60
|
onScrollPositionThresholdChange,
|
|
48
61
|
onRefresh,
|
|
49
62
|
onScrollToIndexFailed,
|
|
@@ -53,16 +66,119 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
53
66
|
initialScrollViewOffset,
|
|
54
67
|
...viewProps
|
|
55
68
|
}, forwardedRef) {
|
|
69
|
+
const snapshotRef = useRef(emptyNativeListSnapshot());
|
|
70
|
+
const renderedSnapshotRef = useRef(undefined);
|
|
71
|
+
const initializedSnapshot = useRef(false);
|
|
72
|
+
const pendingDisclosureSnapshotRef = useRef(undefined);
|
|
73
|
+
const previousPropInputRef = useRef(inputSnapshot);
|
|
74
|
+
const [pendingDisclosureRevision, setPendingDisclosureRevision] = useState(0);
|
|
75
|
+
const disclosureSlotMounts = useRef({
|
|
76
|
+
expandedPresent: false,
|
|
77
|
+
togglePresent: false,
|
|
78
|
+
expandedEpoch: 0,
|
|
79
|
+
toggleEpoch: 0
|
|
80
|
+
});
|
|
81
|
+
const expandedPresent = listExpandedContent != null;
|
|
82
|
+
const togglePresent = listStructureToggle != null;
|
|
83
|
+
if (disclosureSlotMounts.current.expandedPresent !== expandedPresent) {
|
|
84
|
+
disclosureSlotMounts.current.expandedPresent = expandedPresent;
|
|
85
|
+
disclosureSlotMounts.current.expandedEpoch += 1;
|
|
86
|
+
}
|
|
87
|
+
if (disclosureSlotMounts.current.togglePresent !== togglePresent) {
|
|
88
|
+
disclosureSlotMounts.current.togglePresent = togglePresent;
|
|
89
|
+
disclosureSlotMounts.current.toggleEpoch += 1;
|
|
90
|
+
}
|
|
91
|
+
const expandedEpoch = disclosureSlotMounts.current.expandedEpoch;
|
|
92
|
+
const toggleEpoch = disclosureSlotMounts.current.toggleEpoch;
|
|
93
|
+
const [slotMeasurements, setSlotMeasurements] = useState({
|
|
94
|
+
heights: [0, 0, 0, 0, 0, 0],
|
|
95
|
+
readyEpochs: [-1, -1, -1, -1, -1, -1]
|
|
96
|
+
});
|
|
97
|
+
const hasSidecar = listSidecar !== undefined;
|
|
98
|
+
const sidecarWidth = sidecarLayout?.width;
|
|
99
|
+
const sidecarGap = sidecarLayout?.gap;
|
|
100
|
+
const sidecarMaxContentWidth = sidecarLayout?.maxContentWidth;
|
|
101
|
+
const hasContainerSlots = Boolean(listHeader || listEmpty || listFooter || listSidecar || listExpandedContent || listStructureToggle);
|
|
102
|
+
const validateContainerConfiguration = useCallback(accepted => {
|
|
103
|
+
if (hasContainerSlots && accepted.layout.orientation === 'horizontal') throw new Error('NativeList container slots require vertical orientation');
|
|
104
|
+
if (hasSidecar !== (sidecarWidth !== undefined)) throw new Error('listSidecar and sidecarLayout must be supplied together');
|
|
105
|
+
if (sidecarWidth !== undefined) {
|
|
106
|
+
const width = sidecarWidth;
|
|
107
|
+
const gap = sidecarGap ?? NaN;
|
|
108
|
+
const maxContentWidth = sidecarMaxContentWidth ?? NaN;
|
|
109
|
+
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');
|
|
110
|
+
}
|
|
111
|
+
}, [hasContainerSlots, hasSidecar, sidecarWidth, sidecarGap, sidecarMaxContentWidth]);
|
|
112
|
+
const prepareSnapshot = useCallback(next => {
|
|
113
|
+
const accepted = validateSnapshot(captureNativeListInput(next));
|
|
114
|
+
validateContainerConfiguration(accepted);
|
|
115
|
+
return ownValidatedNativeSnapshot(accepted);
|
|
116
|
+
}, [validateContainerConfiguration]);
|
|
117
|
+
const expandedReadyEpoch = slotMeasurements.readyEpochs[4];
|
|
118
|
+
const toggleReadyEpoch = slotMeasurements.readyEpochs[5];
|
|
119
|
+
const snapshot = useMemo(() => {
|
|
120
|
+
// Imperative pending snapshots use this revision to retry the readiness gate.
|
|
121
|
+
// eslint-disable-next-line no-void -- Reading this revision invalidates the readiness memo.
|
|
122
|
+
void pendingDisclosureRevision;
|
|
123
|
+
const propReplaced = previousPropInputRef.current !== inputSnapshot;
|
|
124
|
+
previousPropInputRef.current = inputSnapshot;
|
|
125
|
+
const pending = pendingDisclosureSnapshotRef.current;
|
|
126
|
+
const retained = pending && !propReplaced && (pending.source === 'imperative' || pending.input === inputSnapshot) && pending.expandedEpoch === expandedEpoch && pending.toggleEpoch === toggleEpoch ? pending : undefined;
|
|
127
|
+
const candidate = retained?.owned ?? (!propReplaced && initializedSnapshot.current ? renderedSnapshotRef.current ?? snapshotRef.current : containNativeListInput(() => prepareSnapshot(inputSnapshot)) ?? snapshotRef.current);
|
|
128
|
+
const acceptedCandidate = !propReplaced && initializedSnapshot.current ? containNativeListInput(() => {
|
|
129
|
+
validateContainerConfiguration(candidate);
|
|
130
|
+
return candidate;
|
|
131
|
+
}) : candidate;
|
|
132
|
+
if (!acceptedCandidate) {
|
|
133
|
+
pendingDisclosureSnapshotRef.current = undefined;
|
|
134
|
+
return renderedSnapshotRef.current ?? snapshotRef.current;
|
|
135
|
+
}
|
|
136
|
+
const transitionId = acceptedCandidate.structuralTransition?.id;
|
|
137
|
+
const newDisclosureCommand = initializedSnapshot.current && acceptedCandidate.disclosure !== undefined && transitionId !== undefined && transitionId !== snapshotRef.current.structuralTransition?.id;
|
|
138
|
+
if (newDisclosureCommand && (expandedPresent && expandedReadyEpoch !== expandedEpoch || togglePresent && toggleReadyEpoch !== toggleEpoch)) {
|
|
139
|
+
pendingDisclosureSnapshotRef.current = retained ?? {
|
|
140
|
+
source: 'prop',
|
|
141
|
+
input: inputSnapshot,
|
|
142
|
+
owned: acceptedCandidate,
|
|
143
|
+
expandedEpoch,
|
|
144
|
+
toggleEpoch
|
|
145
|
+
};
|
|
146
|
+
return snapshotRef.current;
|
|
147
|
+
}
|
|
148
|
+
pendingDisclosureSnapshotRef.current = undefined;
|
|
149
|
+
return acceptedCandidate;
|
|
150
|
+
}, [inputSnapshot, prepareSnapshot, validateContainerConfiguration, expandedPresent, togglePresent, expandedEpoch, toggleEpoch, expandedReadyEpoch, toggleReadyEpoch, pendingDisclosureRevision]);
|
|
151
|
+
renderedSnapshotRef.current = snapshot;
|
|
56
152
|
const fontFamiliesJson = useNativeListFontFamiliesJson();
|
|
57
|
-
const
|
|
153
|
+
const slotHeights = slotMeasurements.heights;
|
|
154
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
58
155
|
const [topOverlayHeight, setTopOverlayHeight] = useState(0);
|
|
59
156
|
const hasTopOverlay = Platform?.OS === 'ios' && parseInt(String(Platform.Version), 10) >= 26 && (topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') && topOverlay != null;
|
|
60
157
|
const containerSlotHeightsJson = JSON.stringify(slotHeights);
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const slotContents = [listHeader, listEmpty, listFooter];
|
|
158
|
+
const defaultSlotInset = snapshot.layout.contentPaddingHorizontal ?? snapshot.layout.contentPadding ?? 0;
|
|
159
|
+
const bandWidth = sidecarLayout ? Math.min(viewportWidth, sidecarLayout.maxContentWidth) : 0;
|
|
160
|
+
const slotInset = sidecarLayout ? Math.max(0, (viewportWidth - bandWidth) / 2) + defaultSlotInset : defaultSlotInset;
|
|
161
|
+
const sidecarSpace = sidecarLayout ? sidecarLayout.width + sidecarLayout.gap : 0;
|
|
162
|
+
const slotContents = [listHeader, listEmpty, listFooter, listSidecar, listExpandedContent, listStructureToggle];
|
|
163
|
+
const recordSlotLayout = (index, height, epoch) => {
|
|
164
|
+
if (index === 4 && epoch !== disclosureSlotMounts.current.expandedEpoch || index === 5 && epoch !== disclosureSlotMounts.current.toggleEpoch) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
setSlotMeasurements(previous => {
|
|
168
|
+
if (previous.heights[index] === height && previous.readyEpochs[index] === epoch) {
|
|
169
|
+
return previous;
|
|
170
|
+
}
|
|
171
|
+
const heights = [...previous.heights];
|
|
172
|
+
const readyEpochs = [...previous.readyEpochs];
|
|
173
|
+
heights[index] = height;
|
|
174
|
+
readyEpochs[index] = epoch;
|
|
175
|
+
return {
|
|
176
|
+
heights,
|
|
177
|
+
readyEpochs
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
const sidecarLayoutJson = sidecarLayout ? JSON.stringify(sidecarLayout) : '';
|
|
66
182
|
const normalizedKeyboardShouldPersistTaps = keyboardShouldPersistTaps === true ? 'always' : keyboardShouldPersistTaps === false ? 'never' : keyboardShouldPersistTaps;
|
|
67
183
|
const nativeRef = useRef(null);
|
|
68
184
|
const callbacksRef = useRef({
|
|
@@ -72,6 +188,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
72
188
|
onReorder,
|
|
73
189
|
onEndReached,
|
|
74
190
|
onVisibleRangeChanged,
|
|
191
|
+
onStructuralTransitionSettled,
|
|
75
192
|
onScrollPositionThresholdChange,
|
|
76
193
|
onRefresh,
|
|
77
194
|
onScrollToIndexFailed
|
|
@@ -83,11 +200,12 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
83
200
|
onReorder,
|
|
84
201
|
onEndReached,
|
|
85
202
|
onVisibleRangeChanged,
|
|
203
|
+
onStructuralTransitionSettled,
|
|
86
204
|
onScrollPositionThresholdChange,
|
|
87
205
|
onRefresh,
|
|
88
206
|
onScrollToIndexFailed
|
|
89
207
|
};
|
|
90
|
-
const scrollPositionThresholdsJson = useMemo(() => {
|
|
208
|
+
const scrollPositionThresholdsJson = useMemo(() => containNativeListInput(() => {
|
|
91
209
|
if (!scrollPositionThresholds || scrollPositionThresholds.enabled === false) return '';
|
|
92
210
|
const {
|
|
93
211
|
start,
|
|
@@ -100,15 +218,18 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
100
218
|
start,
|
|
101
219
|
end
|
|
102
220
|
});
|
|
103
|
-
}, [scrollPositionThresholds]);
|
|
104
|
-
const snapshotJson = useMemo(() =>
|
|
105
|
-
const snapshotRef = useRef(snapshot);
|
|
221
|
+
}) ?? '', [scrollPositionThresholds]);
|
|
222
|
+
const snapshotJson = useMemo(() => JSON.stringify(snapshot), [snapshot]);
|
|
106
223
|
const previousSnapshotJsonRef = useRef(snapshotJson);
|
|
107
224
|
const snapshotChanged = previousSnapshotJsonRef.current !== snapshotJson;
|
|
108
225
|
if (snapshotChanged) {
|
|
109
226
|
snapshotRef.current = snapshot;
|
|
110
227
|
previousSnapshotJsonRef.current = snapshotJson;
|
|
111
228
|
}
|
|
229
|
+
if (!initializedSnapshot.current) {
|
|
230
|
+
snapshotRef.current = snapshot;
|
|
231
|
+
initializedSnapshot.current = true;
|
|
232
|
+
}
|
|
112
233
|
// OneKey patch: range events already cross the bridge only when row indices
|
|
113
234
|
// change. Prefetch is optional work; scrolling and visible loads stay native.
|
|
114
235
|
const avatarQueueRef = useRef(null);
|
|
@@ -140,7 +261,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
140
261
|
useEffect(() => {
|
|
141
262
|
updateAvatarPrefetchRef.current();
|
|
142
263
|
}, [snapshot]);
|
|
143
|
-
const initialScrollRef = useRef(initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
264
|
+
const initialScrollRef = useRef(containNativeListInput(() => initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
144
265
|
index: initialScrollIndex,
|
|
145
266
|
animated: false,
|
|
146
267
|
viewPosition: initialScrollViewPosition,
|
|
@@ -152,7 +273,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
152
273
|
viewPosition: initialScrollViewPosition,
|
|
153
274
|
viewOffset: initialScrollViewOffset
|
|
154
275
|
}, 'start')
|
|
155
|
-
});
|
|
276
|
+
}));
|
|
156
277
|
const didApplyInitialScroll = useRef(false);
|
|
157
278
|
const emitIndexFailure = (index, reason) => {
|
|
158
279
|
callbacksRef.current.onScrollToIndexFailed?.(scrollFailure(snapshotRef.current.rows, index, reason));
|
|
@@ -178,39 +299,70 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
178
299
|
applyInitialScrollCallbackRef.current = applyInitialScroll;
|
|
179
300
|
useImperativeHandle(forwardedRef, () => ({
|
|
180
301
|
applySnapshot(nextSnapshot) {
|
|
181
|
-
const
|
|
302
|
+
const accepted = containNativeListInput(() => prepareSnapshot(nextSnapshot));
|
|
303
|
+
if (!accepted) return;
|
|
304
|
+
const transitionId = accepted.structuralTransition?.id;
|
|
305
|
+
const waitsForSlots = accepted.disclosure !== undefined && transitionId !== undefined && transitionId !== snapshotRef.current.structuralTransition?.id && (expandedPresent && slotMeasurements.readyEpochs[4] !== expandedEpoch || togglePresent && slotMeasurements.readyEpochs[5] !== toggleEpoch);
|
|
306
|
+
if (waitsForSlots) {
|
|
307
|
+
pendingDisclosureSnapshotRef.current = {
|
|
308
|
+
source: 'imperative',
|
|
309
|
+
input: nextSnapshot,
|
|
310
|
+
owned: accepted,
|
|
311
|
+
expandedEpoch,
|
|
312
|
+
toggleEpoch
|
|
313
|
+
};
|
|
314
|
+
setPendingDisclosureRevision(value => value + 1);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
pendingDisclosureSnapshotRef.current = undefined;
|
|
318
|
+
const nextSnapshotJson = JSON.stringify(accepted);
|
|
182
319
|
nativeRef.current?.applySnapshot(nextSnapshotJson);
|
|
183
|
-
snapshotRef.current =
|
|
320
|
+
snapshotRef.current = accepted;
|
|
184
321
|
if (nativeRef.current && avatarLifecycle.current !== 'unmounted') {
|
|
185
|
-
avatarModelRef.current?.replaceSnapshot(
|
|
322
|
+
avatarModelRef.current?.replaceSnapshot(accepted.rows);
|
|
186
323
|
updateAvatarPrefetchRef.current();
|
|
187
324
|
}
|
|
188
325
|
},
|
|
189
326
|
applyPatches(patches) {
|
|
190
|
-
|
|
191
|
-
const
|
|
327
|
+
const pending = pendingDisclosureSnapshotRef.current;
|
|
328
|
+
const accepted = containNativeListInput(() => applyOwnedNativePatches(pending?.owned ?? snapshotRef.current, patches));
|
|
329
|
+
if (!accepted || accepted.patches.length === 0) return;
|
|
330
|
+
const nextSnapshot = accepted.snapshot;
|
|
331
|
+
if (pending) {
|
|
332
|
+
pendingDisclosureSnapshotRef.current = {
|
|
333
|
+
...pending,
|
|
334
|
+
owned: nextSnapshot
|
|
335
|
+
};
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
192
338
|
const native = nativeRef.current;
|
|
193
339
|
const dispatch = native ? () => {
|
|
194
|
-
native.applyPatches(
|
|
340
|
+
native.applyPatches(accepted.json);
|
|
195
341
|
snapshotRef.current = nextSnapshot;
|
|
196
342
|
} : undefined;
|
|
197
343
|
if (avatarLifecycle.current === 'unmounted') {
|
|
198
344
|
dispatch?.();
|
|
199
345
|
return;
|
|
200
346
|
}
|
|
201
|
-
if (avatarModelRef.current?.applyPatches(patches, dispatch)) updateAvatarPrefetchRef.current();
|
|
347
|
+
if (avatarModelRef.current?.applyPatches(accepted.patches, dispatch)) updateAvatarPrefetchRef.current();
|
|
202
348
|
},
|
|
203
349
|
reconcileSelection(selectedKeys) {
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
207
|
-
|
|
350
|
+
const capturedKeys = captureNativeListInput(selectedKeys);
|
|
351
|
+
const pending = pendingDisclosureSnapshotRef.current;
|
|
352
|
+
if (!pending) nativeRef.current?.reconcileSelection(JSON.stringify(capturedKeys));
|
|
353
|
+
const current = pending?.owned ?? snapshotRef.current;
|
|
354
|
+
if (current.selection && (current.selection.mode !== 'single' || capturedKeys.length <= 1) && capturedKeys.every(key => current.rows.some(row => row.key === key && isSelectableRow(row)))) {
|
|
355
|
+
const next = {
|
|
208
356
|
...current,
|
|
209
357
|
selection: {
|
|
210
358
|
...current.selection,
|
|
211
|
-
selectedKeys
|
|
359
|
+
selectedKeys: capturedKeys
|
|
212
360
|
}
|
|
213
361
|
};
|
|
362
|
+
if (pending) pendingDisclosureSnapshotRef.current = {
|
|
363
|
+
...pending,
|
|
364
|
+
owned: next
|
|
365
|
+
};else snapshotRef.current = next;
|
|
214
366
|
}
|
|
215
367
|
},
|
|
216
368
|
scrollToKey(paramsOrKey, animated, alignment) {
|
|
@@ -317,14 +469,23 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
317
469
|
};
|
|
318
470
|
updateAvatarPrefetchRef.current();
|
|
319
471
|
callbacksRef.current.onVisibleRangeChanged?.(payload);
|
|
472
|
+
}),
|
|
473
|
+
onStructuralTransitionSettled: callback(payloadJson => {
|
|
474
|
+
callbacksRef.current.onStructuralTransitionSettled?.(parsePayload(payloadJson));
|
|
320
475
|
})
|
|
321
476
|
}), []);
|
|
322
477
|
return /*#__PURE__*/_jsxs(NativeListHost, {
|
|
323
478
|
...viewProps,
|
|
479
|
+
onLayout: event => {
|
|
480
|
+
setViewportWidth(event.nativeEvent.layout.width);
|
|
481
|
+
viewProps.onLayout?.(event);
|
|
482
|
+
},
|
|
324
483
|
...nativeCallbacks,
|
|
484
|
+
onStructuralTransitionSettled: onStructuralTransitionSettled ? nativeCallbacks.onStructuralTransitionSettled : clearedStructuralTransitionSettled,
|
|
325
485
|
fontFamiliesJson: fontFamiliesJson,
|
|
326
486
|
snapshotJson: snapshotJson,
|
|
327
487
|
containerSlotHeightsJson: containerSlotHeightsJson,
|
|
488
|
+
sidecarLayoutJson: sidecarLayoutJson,
|
|
328
489
|
topScrollEdgeEffect: hasTopOverlay ? topScrollEdgeEffect ?? 'none' : 'none',
|
|
329
490
|
topOverlayHeight: hasTopOverlay ? topOverlayHeight : 0,
|
|
330
491
|
scrollPositionThresholdsJson: scrollPositionThresholdsJson,
|
|
@@ -334,15 +495,22 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
334
495
|
collapsable: false,
|
|
335
496
|
style: {
|
|
336
497
|
position: 'absolute',
|
|
337
|
-
|
|
338
|
-
|
|
498
|
+
start: index === 3 ? 0 : slotInset,
|
|
499
|
+
end: index === 3 ? undefined : slotInset + sidecarSpace,
|
|
500
|
+
width: index === 3 ? sidecarLayout?.width : undefined,
|
|
339
501
|
top: 0
|
|
340
502
|
},
|
|
341
503
|
onLayout: event => {
|
|
342
|
-
|
|
343
|
-
|
|
504
|
+
if (index < 4) {
|
|
505
|
+
recordSlotLayout(index, Math.ceil(event.nativeEvent.layout.height), 0);
|
|
506
|
+
}
|
|
344
507
|
},
|
|
345
|
-
children:
|
|
508
|
+
children: index >= 4 ? /*#__PURE__*/_jsx(View, {
|
|
509
|
+
collapsable: false,
|
|
510
|
+
style: disclosureSlotMeasurementStyle,
|
|
511
|
+
onLayout: event => recordSlotLayout(index, Math.ceil(event.nativeEvent.layout.height), index === 4 ? expandedEpoch : toggleEpoch),
|
|
512
|
+
children: content
|
|
513
|
+
}, index === 4 ? `expanded-${expandedEpoch}` : `toggle-${toggleEpoch}`) : content
|
|
346
514
|
}, index)), hasTopOverlay ? /*#__PURE__*/_jsx(View, {
|
|
347
515
|
collapsable: false,
|
|
348
516
|
style: {
|