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