@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/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,172 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
126
148
|
},
|
|
127
149
|
forwardedRef
|
|
128
150
|
) {
|
|
151
|
+
const snapshotRef = useRef<NativeListSnapshot>(emptyNativeListSnapshot());
|
|
152
|
+
const renderedSnapshotRef = useRef<NativeListSnapshot | undefined>(
|
|
153
|
+
undefined
|
|
154
|
+
);
|
|
155
|
+
const initializedSnapshot = useRef(false);
|
|
156
|
+
const pendingDisclosureSnapshotRef = useRef<
|
|
157
|
+
| {
|
|
158
|
+
source: 'prop' | 'imperative';
|
|
159
|
+
input: NativeListSnapshot;
|
|
160
|
+
owned: NativeListSnapshot;
|
|
161
|
+
expandedEpoch: number;
|
|
162
|
+
toggleEpoch: number;
|
|
163
|
+
}
|
|
164
|
+
| undefined
|
|
165
|
+
>(undefined);
|
|
166
|
+
const previousPropInputRef = useRef(inputSnapshot);
|
|
167
|
+
const [pendingDisclosureRevision, setPendingDisclosureRevision] =
|
|
168
|
+
useState(0);
|
|
169
|
+
const disclosureSlotMounts = useRef({
|
|
170
|
+
expandedPresent: false,
|
|
171
|
+
togglePresent: false,
|
|
172
|
+
expandedEpoch: 0,
|
|
173
|
+
toggleEpoch: 0,
|
|
174
|
+
});
|
|
175
|
+
const expandedPresent = listExpandedContent != null;
|
|
176
|
+
const togglePresent = listStructureToggle != null;
|
|
177
|
+
if (disclosureSlotMounts.current.expandedPresent !== expandedPresent) {
|
|
178
|
+
disclosureSlotMounts.current.expandedPresent = expandedPresent;
|
|
179
|
+
disclosureSlotMounts.current.expandedEpoch += 1;
|
|
180
|
+
}
|
|
181
|
+
if (disclosureSlotMounts.current.togglePresent !== togglePresent) {
|
|
182
|
+
disclosureSlotMounts.current.togglePresent = togglePresent;
|
|
183
|
+
disclosureSlotMounts.current.toggleEpoch += 1;
|
|
184
|
+
}
|
|
185
|
+
const expandedEpoch = disclosureSlotMounts.current.expandedEpoch;
|
|
186
|
+
const toggleEpoch = disclosureSlotMounts.current.toggleEpoch;
|
|
187
|
+
const [slotMeasurements, setSlotMeasurements] = useState({
|
|
188
|
+
heights: [0, 0, 0, 0, 0, 0],
|
|
189
|
+
readyEpochs: [-1, -1, -1, -1, -1, -1],
|
|
190
|
+
});
|
|
191
|
+
const hasSidecar = listSidecar !== undefined;
|
|
192
|
+
const sidecarWidth = sidecarLayout?.width;
|
|
193
|
+
const sidecarGap = sidecarLayout?.gap;
|
|
194
|
+
const sidecarMaxContentWidth = sidecarLayout?.maxContentWidth;
|
|
195
|
+
const hasContainerSlots = Boolean(
|
|
196
|
+
listHeader ||
|
|
197
|
+
listEmpty ||
|
|
198
|
+
listFooter ||
|
|
199
|
+
listSidecar ||
|
|
200
|
+
listExpandedContent ||
|
|
201
|
+
listStructureToggle
|
|
202
|
+
);
|
|
203
|
+
const validateContainerConfiguration = useCallback(
|
|
204
|
+
(accepted: NativeListSnapshot) => {
|
|
205
|
+
if (hasContainerSlots && accepted.layout.orientation === 'horizontal')
|
|
206
|
+
throw new Error(
|
|
207
|
+
'NativeList container slots require vertical orientation'
|
|
208
|
+
);
|
|
209
|
+
if (hasSidecar !== (sidecarWidth !== undefined))
|
|
210
|
+
throw new Error(
|
|
211
|
+
'listSidecar and sidecarLayout must be supplied together'
|
|
212
|
+
);
|
|
213
|
+
if (sidecarWidth !== undefined) {
|
|
214
|
+
const width = sidecarWidth;
|
|
215
|
+
const gap = sidecarGap ?? NaN;
|
|
216
|
+
const maxContentWidth = sidecarMaxContentWidth ?? NaN;
|
|
217
|
+
if (
|
|
218
|
+
accepted.layout.kind !== 'linear' ||
|
|
219
|
+
!Number.isFinite(width) ||
|
|
220
|
+
width <= 0 ||
|
|
221
|
+
!Number.isFinite(gap) ||
|
|
222
|
+
gap < 0 ||
|
|
223
|
+
!Number.isFinite(maxContentWidth) ||
|
|
224
|
+
maxContentWidth <= width + gap
|
|
225
|
+
)
|
|
226
|
+
throw new Error('Invalid NativeList sidecar layout');
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
[
|
|
230
|
+
hasContainerSlots,
|
|
231
|
+
hasSidecar,
|
|
232
|
+
sidecarWidth,
|
|
233
|
+
sidecarGap,
|
|
234
|
+
sidecarMaxContentWidth,
|
|
235
|
+
]
|
|
236
|
+
);
|
|
237
|
+
const prepareSnapshot = useCallback(
|
|
238
|
+
(next: NativeListSnapshot) => {
|
|
239
|
+
const accepted = validateSnapshot(captureNativeListInput(next));
|
|
240
|
+
validateContainerConfiguration(accepted);
|
|
241
|
+
return ownValidatedNativeSnapshot(accepted);
|
|
242
|
+
},
|
|
243
|
+
[validateContainerConfiguration]
|
|
244
|
+
);
|
|
245
|
+
const expandedReadyEpoch = slotMeasurements.readyEpochs[4];
|
|
246
|
+
const toggleReadyEpoch = slotMeasurements.readyEpochs[5];
|
|
247
|
+
const snapshot = useMemo(() => {
|
|
248
|
+
// Imperative pending snapshots use this revision to retry the readiness gate.
|
|
249
|
+
// eslint-disable-next-line no-void -- Reading this revision invalidates the readiness memo.
|
|
250
|
+
void pendingDisclosureRevision;
|
|
251
|
+
const propReplaced = previousPropInputRef.current !== inputSnapshot;
|
|
252
|
+
previousPropInputRef.current = inputSnapshot;
|
|
253
|
+
const pending = pendingDisclosureSnapshotRef.current;
|
|
254
|
+
const retained =
|
|
255
|
+
pending &&
|
|
256
|
+
!propReplaced &&
|
|
257
|
+
(pending.source === 'imperative' || pending.input === inputSnapshot) &&
|
|
258
|
+
pending.expandedEpoch === expandedEpoch &&
|
|
259
|
+
pending.toggleEpoch === toggleEpoch
|
|
260
|
+
? pending
|
|
261
|
+
: undefined;
|
|
262
|
+
const candidate =
|
|
263
|
+
retained?.owned ??
|
|
264
|
+
(!propReplaced && initializedSnapshot.current
|
|
265
|
+
? renderedSnapshotRef.current ?? snapshotRef.current
|
|
266
|
+
: containNativeListInput(() => prepareSnapshot(inputSnapshot)) ??
|
|
267
|
+
snapshotRef.current);
|
|
268
|
+
const acceptedCandidate =
|
|
269
|
+
!propReplaced && initializedSnapshot.current
|
|
270
|
+
? containNativeListInput(() => {
|
|
271
|
+
validateContainerConfiguration(candidate);
|
|
272
|
+
return candidate;
|
|
273
|
+
})
|
|
274
|
+
: candidate;
|
|
275
|
+
if (!acceptedCandidate) {
|
|
276
|
+
pendingDisclosureSnapshotRef.current = undefined;
|
|
277
|
+
return renderedSnapshotRef.current ?? snapshotRef.current;
|
|
278
|
+
}
|
|
279
|
+
const transitionId = acceptedCandidate.structuralTransition?.id;
|
|
280
|
+
const newDisclosureCommand =
|
|
281
|
+
initializedSnapshot.current &&
|
|
282
|
+
acceptedCandidate.disclosure !== undefined &&
|
|
283
|
+
transitionId !== undefined &&
|
|
284
|
+
transitionId !== snapshotRef.current.structuralTransition?.id;
|
|
285
|
+
if (
|
|
286
|
+
newDisclosureCommand &&
|
|
287
|
+
((expandedPresent && expandedReadyEpoch !== expandedEpoch) ||
|
|
288
|
+
(togglePresent && toggleReadyEpoch !== toggleEpoch))
|
|
289
|
+
) {
|
|
290
|
+
pendingDisclosureSnapshotRef.current = retained ?? {
|
|
291
|
+
source: 'prop',
|
|
292
|
+
input: inputSnapshot,
|
|
293
|
+
owned: acceptedCandidate,
|
|
294
|
+
expandedEpoch,
|
|
295
|
+
toggleEpoch,
|
|
296
|
+
};
|
|
297
|
+
return snapshotRef.current;
|
|
298
|
+
}
|
|
299
|
+
pendingDisclosureSnapshotRef.current = undefined;
|
|
300
|
+
return acceptedCandidate;
|
|
301
|
+
}, [
|
|
302
|
+
inputSnapshot,
|
|
303
|
+
prepareSnapshot,
|
|
304
|
+
validateContainerConfiguration,
|
|
305
|
+
expandedPresent,
|
|
306
|
+
togglePresent,
|
|
307
|
+
expandedEpoch,
|
|
308
|
+
toggleEpoch,
|
|
309
|
+
expandedReadyEpoch,
|
|
310
|
+
toggleReadyEpoch,
|
|
311
|
+
pendingDisclosureRevision,
|
|
312
|
+
]);
|
|
313
|
+
renderedSnapshotRef.current = snapshot;
|
|
129
314
|
const fontFamiliesJson = useNativeListFontFamiliesJson();
|
|
130
|
-
const
|
|
315
|
+
const slotHeights = slotMeasurements.heights;
|
|
316
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
131
317
|
const [topOverlayHeight, setTopOverlayHeight] = useState(0);
|
|
132
318
|
const hasTopOverlay =
|
|
133
319
|
Platform?.OS === 'ios' &&
|
|
@@ -135,19 +321,51 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
135
321
|
(topScrollEdgeEffect === 'hard' || topScrollEdgeEffect === 'soft') &&
|
|
136
322
|
topOverlay != null;
|
|
137
323
|
const containerSlotHeightsJson = JSON.stringify(slotHeights);
|
|
138
|
-
const
|
|
324
|
+
const defaultSlotInset =
|
|
139
325
|
snapshot.layout.contentPaddingHorizontal ??
|
|
140
326
|
snapshot.layout.contentPadding ??
|
|
141
327
|
0;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
328
|
+
const bandWidth = sidecarLayout
|
|
329
|
+
? Math.min(viewportWidth, sidecarLayout.maxContentWidth)
|
|
330
|
+
: 0;
|
|
331
|
+
const slotInset = sidecarLayout
|
|
332
|
+
? Math.max(0, (viewportWidth - bandWidth) / 2) + defaultSlotInset
|
|
333
|
+
: defaultSlotInset;
|
|
334
|
+
const sidecarSpace = sidecarLayout
|
|
335
|
+
? sidecarLayout.width + sidecarLayout.gap
|
|
336
|
+
: 0;
|
|
337
|
+
const slotContents = [
|
|
338
|
+
listHeader,
|
|
339
|
+
listEmpty,
|
|
340
|
+
listFooter,
|
|
341
|
+
listSidecar,
|
|
342
|
+
listExpandedContent,
|
|
343
|
+
listStructureToggle,
|
|
344
|
+
];
|
|
345
|
+
const recordSlotLayout = (index: number, height: number, epoch: number) => {
|
|
346
|
+
if (
|
|
347
|
+
(index === 4 && epoch !== disclosureSlotMounts.current.expandedEpoch) ||
|
|
348
|
+
(index === 5 && epoch !== disclosureSlotMounts.current.toggleEpoch)
|
|
349
|
+
) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
setSlotMeasurements((previous) => {
|
|
353
|
+
if (
|
|
354
|
+
previous.heights[index] === height &&
|
|
355
|
+
previous.readyEpochs[index] === epoch
|
|
356
|
+
) {
|
|
357
|
+
return previous;
|
|
358
|
+
}
|
|
359
|
+
const heights = [...previous.heights];
|
|
360
|
+
const readyEpochs = [...previous.readyEpochs];
|
|
361
|
+
heights[index] = height;
|
|
362
|
+
readyEpochs[index] = epoch;
|
|
363
|
+
return { heights, readyEpochs };
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
const sidecarLayoutJson = sidecarLayout
|
|
367
|
+
? JSON.stringify(sidecarLayout)
|
|
368
|
+
: '';
|
|
151
369
|
const normalizedKeyboardShouldPersistTaps =
|
|
152
370
|
keyboardShouldPersistTaps === true
|
|
153
371
|
? 'always'
|
|
@@ -162,6 +380,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
162
380
|
onReorder,
|
|
163
381
|
onEndReached,
|
|
164
382
|
onVisibleRangeChanged,
|
|
383
|
+
onStructuralTransitionSettled,
|
|
165
384
|
onScrollPositionThresholdChange,
|
|
166
385
|
onRefresh,
|
|
167
386
|
onScrollToIndexFailed,
|
|
@@ -173,37 +392,45 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
173
392
|
onReorder,
|
|
174
393
|
onEndReached,
|
|
175
394
|
onVisibleRangeChanged,
|
|
395
|
+
onStructuralTransitionSettled,
|
|
176
396
|
onScrollPositionThresholdChange,
|
|
177
397
|
onRefresh,
|
|
178
398
|
onScrollToIndexFailed,
|
|
179
399
|
};
|
|
180
|
-
const scrollPositionThresholdsJson = useMemo(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
400
|
+
const scrollPositionThresholdsJson = useMemo(
|
|
401
|
+
() =>
|
|
402
|
+
containNativeListInput(() => {
|
|
403
|
+
if (
|
|
404
|
+
!scrollPositionThresholds ||
|
|
405
|
+
scrollPositionThresholds.enabled === false
|
|
406
|
+
)
|
|
407
|
+
return '';
|
|
408
|
+
const { start, end } = scrollPositionThresholds;
|
|
409
|
+
if (
|
|
410
|
+
!Number.isFinite(start) ||
|
|
411
|
+
!Number.isFinite(end) ||
|
|
412
|
+
start < 0 ||
|
|
413
|
+
end <= start
|
|
414
|
+
) {
|
|
415
|
+
throw new Error(
|
|
416
|
+
'scrollPositionThresholds requires 0 <= start < end and finite values'
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
return JSON.stringify({ start, end });
|
|
420
|
+
}) ?? '',
|
|
421
|
+
[scrollPositionThresholds]
|
|
422
|
+
);
|
|
423
|
+
const snapshotJson = useMemo(() => JSON.stringify(snapshot), [snapshot]);
|
|
201
424
|
const previousSnapshotJsonRef = useRef(snapshotJson);
|
|
202
425
|
const snapshotChanged = previousSnapshotJsonRef.current !== snapshotJson;
|
|
203
426
|
if (snapshotChanged) {
|
|
204
427
|
snapshotRef.current = snapshot;
|
|
205
428
|
previousSnapshotJsonRef.current = snapshotJson;
|
|
206
429
|
}
|
|
430
|
+
if (!initializedSnapshot.current) {
|
|
431
|
+
snapshotRef.current = snapshot;
|
|
432
|
+
initializedSnapshot.current = true;
|
|
433
|
+
}
|
|
207
434
|
// OneKey patch: range events already cross the bridge only when row indices
|
|
208
435
|
// change. Prefetch is optional work; scrolling and visible loads stay native.
|
|
209
436
|
const avatarQueueRef = useRef<NativeAvatarPrefetchQueue | null>(null);
|
|
@@ -258,26 +485,28 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
258
485
|
}>
|
|
259
486
|
| undefined
|
|
260
487
|
>(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
488
|
+
containNativeListInput(() =>
|
|
489
|
+
initialScrollIndex === undefined && initialScrollKey === undefined
|
|
490
|
+
? undefined
|
|
491
|
+
: initialScrollIndex !== undefined
|
|
492
|
+
? normalizeIndexScroll({
|
|
493
|
+
index: initialScrollIndex,
|
|
494
|
+
animated: false,
|
|
495
|
+
viewPosition: initialScrollViewPosition,
|
|
496
|
+
viewOffset: initialScrollViewOffset,
|
|
497
|
+
})
|
|
498
|
+
: {
|
|
499
|
+
key: initialScrollKey,
|
|
500
|
+
scroll: normalizePositionScroll(
|
|
501
|
+
{
|
|
502
|
+
animated: false,
|
|
503
|
+
viewPosition: initialScrollViewPosition,
|
|
504
|
+
viewOffset: initialScrollViewOffset,
|
|
505
|
+
},
|
|
506
|
+
'start'
|
|
507
|
+
),
|
|
508
|
+
}
|
|
509
|
+
)
|
|
281
510
|
);
|
|
282
511
|
const didApplyInitialScroll = useRef(false);
|
|
283
512
|
|
|
@@ -335,21 +564,59 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
335
564
|
|
|
336
565
|
useImperativeHandle(forwardedRef, () => ({
|
|
337
566
|
applySnapshot(nextSnapshot) {
|
|
338
|
-
const
|
|
567
|
+
const accepted = containNativeListInput(() =>
|
|
568
|
+
prepareSnapshot(nextSnapshot)
|
|
569
|
+
);
|
|
570
|
+
if (!accepted) return;
|
|
571
|
+
const transitionId = accepted.structuralTransition?.id;
|
|
572
|
+
const waitsForSlots =
|
|
573
|
+
accepted.disclosure !== undefined &&
|
|
574
|
+
transitionId !== undefined &&
|
|
575
|
+
transitionId !== snapshotRef.current.structuralTransition?.id &&
|
|
576
|
+
((expandedPresent &&
|
|
577
|
+
slotMeasurements.readyEpochs[4] !== expandedEpoch) ||
|
|
578
|
+
(togglePresent && slotMeasurements.readyEpochs[5] !== toggleEpoch));
|
|
579
|
+
if (waitsForSlots) {
|
|
580
|
+
pendingDisclosureSnapshotRef.current = {
|
|
581
|
+
source: 'imperative',
|
|
582
|
+
input: nextSnapshot,
|
|
583
|
+
owned: accepted,
|
|
584
|
+
expandedEpoch,
|
|
585
|
+
toggleEpoch,
|
|
586
|
+
};
|
|
587
|
+
setPendingDisclosureRevision((value) => value + 1);
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
pendingDisclosureSnapshotRef.current = undefined;
|
|
591
|
+
const nextSnapshotJson = JSON.stringify(accepted);
|
|
339
592
|
nativeRef.current?.applySnapshot(nextSnapshotJson);
|
|
340
|
-
snapshotRef.current =
|
|
593
|
+
snapshotRef.current = accepted;
|
|
341
594
|
if (nativeRef.current && avatarLifecycle.current !== 'unmounted') {
|
|
342
|
-
avatarModelRef.current?.replaceSnapshot(
|
|
595
|
+
avatarModelRef.current?.replaceSnapshot(accepted.rows);
|
|
343
596
|
updateAvatarPrefetchRef.current();
|
|
344
597
|
}
|
|
345
598
|
},
|
|
346
599
|
applyPatches(patches) {
|
|
347
|
-
|
|
348
|
-
const
|
|
600
|
+
const pending = pendingDisclosureSnapshotRef.current;
|
|
601
|
+
const accepted = containNativeListInput(() =>
|
|
602
|
+
applyOwnedNativePatches(
|
|
603
|
+
pending?.owned ?? snapshotRef.current,
|
|
604
|
+
patches
|
|
605
|
+
)
|
|
606
|
+
);
|
|
607
|
+
if (!accepted || accepted.patches.length === 0) return;
|
|
608
|
+
const nextSnapshot = accepted.snapshot;
|
|
609
|
+
if (pending) {
|
|
610
|
+
pendingDisclosureSnapshotRef.current = {
|
|
611
|
+
...pending,
|
|
612
|
+
owned: nextSnapshot,
|
|
613
|
+
};
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
349
616
|
const native = nativeRef.current;
|
|
350
617
|
const dispatch = native
|
|
351
618
|
? () => {
|
|
352
|
-
native.applyPatches(
|
|
619
|
+
native.applyPatches(accepted.json);
|
|
353
620
|
snapshotRef.current = nextSnapshot;
|
|
354
621
|
}
|
|
355
622
|
: undefined;
|
|
@@ -357,23 +624,29 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
357
624
|
dispatch?.();
|
|
358
625
|
return;
|
|
359
626
|
}
|
|
360
|
-
if (avatarModelRef.current?.applyPatches(patches, dispatch))
|
|
627
|
+
if (avatarModelRef.current?.applyPatches(accepted.patches, dispatch))
|
|
361
628
|
updateAvatarPrefetchRef.current();
|
|
362
629
|
},
|
|
363
630
|
reconcileSelection(selectedKeys) {
|
|
364
|
-
|
|
365
|
-
const
|
|
631
|
+
const capturedKeys = captureNativeListInput(selectedKeys);
|
|
632
|
+
const pending = pendingDisclosureSnapshotRef.current;
|
|
633
|
+
if (!pending)
|
|
634
|
+
nativeRef.current?.reconcileSelection(JSON.stringify(capturedKeys));
|
|
635
|
+
const current = pending?.owned ?? snapshotRef.current;
|
|
366
636
|
if (
|
|
367
637
|
current.selection &&
|
|
368
|
-
(current.selection.mode !== 'single' ||
|
|
369
|
-
|
|
638
|
+
(current.selection.mode !== 'single' || capturedKeys.length <= 1) &&
|
|
639
|
+
capturedKeys.every((key) =>
|
|
370
640
|
current.rows.some((row) => row.key === key && isSelectableRow(row))
|
|
371
641
|
)
|
|
372
642
|
) {
|
|
373
|
-
|
|
643
|
+
const next = {
|
|
374
644
|
...current,
|
|
375
|
-
selection: { ...current.selection, selectedKeys },
|
|
645
|
+
selection: { ...current.selection, selectedKeys: capturedKeys },
|
|
376
646
|
};
|
|
647
|
+
if (pending)
|
|
648
|
+
pendingDisclosureSnapshotRef.current = { ...pending, owned: next };
|
|
649
|
+
else snapshotRef.current = next;
|
|
377
650
|
}
|
|
378
651
|
},
|
|
379
652
|
scrollToKey(paramsOrKey, animated, alignment) {
|
|
@@ -506,6 +779,11 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
506
779
|
updateAvatarPrefetchRef.current();
|
|
507
780
|
callbacksRef.current.onVisibleRangeChanged?.(payload);
|
|
508
781
|
}),
|
|
782
|
+
onStructuralTransitionSettled: callback((payloadJson: string) => {
|
|
783
|
+
callbacksRef.current.onStructuralTransitionSettled?.(
|
|
784
|
+
parsePayload<StructuralTransitionSettledEvent>(payloadJson)
|
|
785
|
+
);
|
|
786
|
+
}),
|
|
509
787
|
}),
|
|
510
788
|
[]
|
|
511
789
|
);
|
|
@@ -513,10 +791,20 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
513
791
|
return (
|
|
514
792
|
<NativeListHost
|
|
515
793
|
{...viewProps}
|
|
794
|
+
onLayout={(event) => {
|
|
795
|
+
setViewportWidth(event.nativeEvent.layout.width);
|
|
796
|
+
viewProps.onLayout?.(event);
|
|
797
|
+
}}
|
|
516
798
|
{...nativeCallbacks}
|
|
799
|
+
onStructuralTransitionSettled={
|
|
800
|
+
onStructuralTransitionSettled
|
|
801
|
+
? nativeCallbacks.onStructuralTransitionSettled
|
|
802
|
+
: clearedStructuralTransitionSettled
|
|
803
|
+
}
|
|
517
804
|
fontFamiliesJson={fontFamiliesJson}
|
|
518
805
|
snapshotJson={snapshotJson}
|
|
519
806
|
containerSlotHeightsJson={containerSlotHeightsJson}
|
|
807
|
+
sidecarLayoutJson={sidecarLayoutJson}
|
|
520
808
|
topScrollEdgeEffect={
|
|
521
809
|
hasTopOverlay ? topScrollEdgeEffect ?? 'none' : 'none'
|
|
522
810
|
}
|
|
@@ -531,22 +819,43 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
531
819
|
collapsable={false}
|
|
532
820
|
style={{
|
|
533
821
|
position: 'absolute',
|
|
534
|
-
|
|
535
|
-
|
|
822
|
+
start: index === 3 ? 0 : slotInset,
|
|
823
|
+
end: index === 3 ? undefined : slotInset + sidecarSpace,
|
|
824
|
+
width: index === 3 ? sidecarLayout?.width : undefined,
|
|
536
825
|
top: 0,
|
|
537
826
|
}}
|
|
538
827
|
onLayout={(event) => {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
);
|
|
828
|
+
if (index < 4) {
|
|
829
|
+
recordSlotLayout(
|
|
830
|
+
index,
|
|
831
|
+
Math.ceil(event.nativeEvent.layout.height),
|
|
832
|
+
0
|
|
833
|
+
);
|
|
834
|
+
}
|
|
547
835
|
}}
|
|
548
836
|
>
|
|
549
|
-
{
|
|
837
|
+
{index >= 4 ? (
|
|
838
|
+
<View
|
|
839
|
+
key={
|
|
840
|
+
index === 4
|
|
841
|
+
? `expanded-${expandedEpoch}`
|
|
842
|
+
: `toggle-${toggleEpoch}`
|
|
843
|
+
}
|
|
844
|
+
collapsable={false}
|
|
845
|
+
style={disclosureSlotMeasurementStyle}
|
|
846
|
+
onLayout={(event) =>
|
|
847
|
+
recordSlotLayout(
|
|
848
|
+
index,
|
|
849
|
+
Math.ceil(event.nativeEvent.layout.height),
|
|
850
|
+
index === 4 ? expandedEpoch : toggleEpoch
|
|
851
|
+
)
|
|
852
|
+
}
|
|
853
|
+
>
|
|
854
|
+
{content}
|
|
855
|
+
</View>
|
|
856
|
+
) : (
|
|
857
|
+
content
|
|
858
|
+
)}
|
|
550
859
|
</View>
|
|
551
860
|
))}
|
|
552
861
|
{hasTopOverlay ? (
|