@onekeyfe/react-native-native-list 6.7.0-1 → 6.7.0-12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/onekey/nativelist/HybridNativeList.kt +1 -1
- package/docs/SPEC.md +449 -14
- package/ios/HybridNativeList.swift +11 -3
- package/ios/RNCNativeListView.swift +10 -6
- package/ios/tests/NativeListLifecycleTests.swift +28 -0
- package/lib/module/NativeList.js +42 -21
- package/lib/module/NativeList.web.js +163 -32
- package/lib/module/ScrollEdgeEffect.js +8 -0
- package/lib/module/index.js +1 -0
- package/lib/module/validation.js +358 -47
- package/lib/module/web/NativeListWebEngine.js +373 -67
- package/lib/module/web/templates/ActivityRowRenderer.js +484 -5
- package/lib/module/web/templates/MarketRowRenderer.js +8 -3
- package/lib/module/web/templates/MarketTableRowRenderer.js +577 -0
- package/lib/module/web/templates/MediaTileRowRenderer.js +260 -5
- package/lib/module/web/templates/RowRendererRegistry.js +5 -3
- package/lib/module/web/templates/SectionHeaderRowRenderer.js +34 -1
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/lib/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/lib/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/lib/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/lib/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/lib/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/lib/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/lib/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/lib/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/lib/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/lib/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/lib/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/lib/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/lib/typescript/src/NativeList.d.ts +2 -2
- package/lib/typescript/src/NativeList.nitro.d.ts +2 -1
- package/lib/typescript/src/NativeList.types.d.ts +14 -3
- package/lib/typescript/src/NativeList.web.d.ts +2 -2
- package/lib/typescript/src/ScrollEdgeEffect.d.ts +5 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/models.d.ts +71 -1
- package/lib/typescript/src/validation.d.ts +3 -0
- package/lib/typescript/src/web/NativeListWebEngine.d.ts +26 -1
- package/lib/typescript/src/web/templates/ActivityRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MarketTableRowRenderer.d.ts +17 -0
- package/lib/typescript/src/web/templates/MediaTileRowRenderer.d.ts +3 -3
- package/lib/typescript/src/web/templates/MessageRowRenderer.d.ts +1 -1
- package/lib/typescript/src/web/templates/RowRendererRegistry.d.ts +3 -1
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.cpp +10 -6
- package/nitrogen/generated/android/c++/JHybridNativeListSpec.hpp +2 -2
- package/nitrogen/generated/android/c++/JNativeListScrollEdgeEffect.hpp +61 -0
- package/nitrogen/generated/android/c++/views/JHybridNativeListStateUpdater.cpp +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/HybridNativeListSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nativelist/NativeListScrollEdgeEffect.kt +24 -0
- package/nitrogen/generated/ios/NativeListModule-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridNativeListSpecSwift.hpp +8 -4
- package/nitrogen/generated/ios/c++/views/HybridNativeListComponent.mm +4 -4
- package/nitrogen/generated/ios/swift/HybridNativeListSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativeListSpec_cxx.swift +3 -3
- package/nitrogen/generated/ios/swift/NativeListScrollEdgeEffect.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.cpp +2 -2
- package/nitrogen/generated/shared/c++/HybridNativeListSpec.hpp +5 -2
- package/nitrogen/generated/shared/c++/NativeListScrollEdgeEffect.hpp +80 -0
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.cpp +2 -2
- package/nitrogen/generated/shared/c++/views/HybridNativeListComponent.hpp +4 -3
- package/nitrogen/generated/shared/json/NativeListConfig.json +1 -1
- package/package.json +3 -3
- package/react-native-native-list.podspec +4 -1
- package/src/NativeList.nitro.ts +3 -1
- package/src/NativeList.tsx +102 -60
- package/src/NativeList.types.ts +15 -3
- package/src/NativeList.web.tsx +264 -65
- package/src/ScrollEdgeEffect.ts +4 -0
- package/src/index.ts +2 -0
- package/src/models.ts +93 -0
- package/src/validation.ts +785 -72
- package/src/web/NativeListWebEngine.ts +625 -100
- package/src/web/templates/ActivityRowRenderer.ts +723 -7
- package/src/web/templates/MarketRowRenderer.ts +19 -3
- package/src/web/templates/MarketTableRowRenderer.ts +755 -0
- package/src/web/templates/MediaTileRowRenderer.ts +313 -5
- package/src/web/templates/RowRendererRegistry.ts +10 -5
- package/src/web/templates/SectionHeaderRowRenderer.ts +42 -1
package/src/NativeList.web.tsx
CHANGED
|
@@ -4,13 +4,14 @@ import React, {
|
|
|
4
4
|
useCallback,
|
|
5
5
|
useEffect,
|
|
6
6
|
useImperativeHandle,
|
|
7
|
+
useLayoutEffect,
|
|
7
8
|
useMemo,
|
|
8
9
|
useRef,
|
|
9
10
|
useState,
|
|
10
11
|
} from 'react';
|
|
11
12
|
import { View } from 'react-native';
|
|
12
13
|
import type { NativeListProps, NativeListRef } from './NativeList.types';
|
|
13
|
-
import type { ImageSource, NativeListSnapshot
|
|
14
|
+
import type { ImageSource, NativeListSnapshot } from './models';
|
|
14
15
|
import {
|
|
15
16
|
normalizeIndexScroll,
|
|
16
17
|
normalizeKeyScroll,
|
|
@@ -20,7 +21,13 @@ import {
|
|
|
20
21
|
validateOffset,
|
|
21
22
|
type NormalizedPositionScroll,
|
|
22
23
|
} from './scrolling';
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
applyRowPatches,
|
|
26
|
+
containNativeListInput,
|
|
27
|
+
emptyNativeListSnapshot,
|
|
28
|
+
validatePatches,
|
|
29
|
+
validateSnapshot,
|
|
30
|
+
} from './validation';
|
|
24
31
|
import {
|
|
25
32
|
NativeListWebEngine,
|
|
26
33
|
type NativeListWebCallbacks,
|
|
@@ -82,12 +89,14 @@ export function preloadNativeListAvatarImages(
|
|
|
82
89
|
export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
83
90
|
function NativeList(
|
|
84
91
|
{
|
|
85
|
-
snapshot,
|
|
86
|
-
listHeader
|
|
87
|
-
listEmpty
|
|
88
|
-
listFooter
|
|
92
|
+
snapshot: inputSnapshot,
|
|
93
|
+
listHeader,
|
|
94
|
+
listEmpty,
|
|
95
|
+
listFooter,
|
|
89
96
|
topOverlay: _topOverlay,
|
|
90
97
|
topScrollEdgeEffect: _topScrollEdgeEffect,
|
|
98
|
+
webScrollHost,
|
|
99
|
+
webStickyInset: inputStickyInset = 0,
|
|
91
100
|
scrollPositionThresholds: _scrollPositionThresholds,
|
|
92
101
|
onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
|
|
93
102
|
webVirtualizationEnabled = true,
|
|
@@ -110,16 +119,108 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
110
119
|
},
|
|
111
120
|
forwardedRef
|
|
112
121
|
) {
|
|
122
|
+
const acceptedSnapshotRef = useRef<NativeListSnapshot>(
|
|
123
|
+
emptyNativeListSnapshot()
|
|
124
|
+
);
|
|
125
|
+
const initializedSnapshot = useRef(false);
|
|
126
|
+
const webStickyInset = useMemo(
|
|
127
|
+
() =>
|
|
128
|
+
containNativeListInput(() => {
|
|
129
|
+
if (!Number.isFinite(inputStickyInset) || inputStickyInset < 0)
|
|
130
|
+
throw new Error('webStickyInset must be finite and non-negative');
|
|
131
|
+
return inputStickyInset;
|
|
132
|
+
}) ?? 0,
|
|
133
|
+
[inputStickyInset]
|
|
134
|
+
);
|
|
135
|
+
const preparedSnapshot = useMemo(
|
|
136
|
+
() => containNativeListInput(() => validateSnapshot(inputSnapshot)),
|
|
137
|
+
[inputSnapshot]
|
|
138
|
+
);
|
|
139
|
+
const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
|
|
113
140
|
const fontFamiliesJson = useNativeListFontFamiliesJson();
|
|
114
141
|
const fontFamiliesJsonRef = useRef(fontFamiliesJson);
|
|
115
142
|
fontFamiliesJsonRef.current = fontFamiliesJson;
|
|
143
|
+
const hasEmptySlot = listEmpty !== undefined;
|
|
144
|
+
const hasEmptySlotRef = useRef(hasEmptySlot);
|
|
145
|
+
hasEmptySlotRef.current = hasEmptySlot;
|
|
146
|
+
const [slotState, setSlotState] = useState(() => ({
|
|
147
|
+
hasRows: snapshot.rows.length > 0,
|
|
148
|
+
emptyBottomPadding:
|
|
149
|
+
!snapshot.rows.length && hasEmptySlot
|
|
150
|
+
? snapshot.layout.contentPaddingBottom ??
|
|
151
|
+
snapshot.layout.contentPadding ??
|
|
152
|
+
0
|
|
153
|
+
: 0,
|
|
154
|
+
padding:
|
|
155
|
+
snapshot.layout.contentPaddingHorizontal ??
|
|
156
|
+
snapshot.layout.contentPadding ??
|
|
157
|
+
0,
|
|
158
|
+
}));
|
|
159
|
+
const synchronizeSlots = (next: NativeListSnapshot) => {
|
|
160
|
+
const hasRows = next.rows.length > 0;
|
|
161
|
+
const padding =
|
|
162
|
+
next.layout.contentPaddingHorizontal ?? next.layout.contentPadding ?? 0;
|
|
163
|
+
const emptyBottomPadding =
|
|
164
|
+
!hasRows && hasEmptySlotRef.current
|
|
165
|
+
? next.layout.contentPaddingBottom ?? next.layout.contentPadding ?? 0
|
|
166
|
+
: 0;
|
|
167
|
+
setSlotState((previous) =>
|
|
168
|
+
previous.hasRows === hasRows &&
|
|
169
|
+
previous.padding === padding &&
|
|
170
|
+
previous.emptyBottomPadding === emptyBottomPadding
|
|
171
|
+
? previous
|
|
172
|
+
: { hasRows, padding, emptyBottomPadding }
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
const normalizeWebSnapshot = (
|
|
176
|
+
next: NativeListSnapshot,
|
|
177
|
+
hasReactEmpty = hasEmptySlotRef.current,
|
|
178
|
+
hasSlotLayout = useSlotLayoutRef.current
|
|
179
|
+
) => {
|
|
180
|
+
if (hasSlotLayout && next.layout.orientation === 'horizontal')
|
|
181
|
+
throw new Error(
|
|
182
|
+
'Web parent scrolling and container slots support vertical lists only'
|
|
183
|
+
);
|
|
184
|
+
const emptySlot = hasReactEmpty && next.rows.length === 0;
|
|
185
|
+
const validated = validateSnapshot(
|
|
186
|
+
emptySlot ? { ...next, emptyState: undefined } : next
|
|
187
|
+
);
|
|
188
|
+
return emptySlot
|
|
189
|
+
? {
|
|
190
|
+
...validated,
|
|
191
|
+
layout: { ...validated.layout, contentPaddingBottom: 0 },
|
|
192
|
+
}
|
|
193
|
+
: validated;
|
|
194
|
+
};
|
|
116
195
|
const [host, setHost] = useState<HTMLElement | null>(null);
|
|
196
|
+
const [contentBounds, setContentBounds] = useState<HTMLElement | null>(
|
|
197
|
+
null
|
|
198
|
+
);
|
|
199
|
+
const [ownedScrollHost, setOwnedScrollHost] = useState<HTMLElement | null>(
|
|
200
|
+
null
|
|
201
|
+
);
|
|
202
|
+
const useSlotLayoutRef = useRef(false);
|
|
203
|
+
useSlotLayoutRef.current ||=
|
|
204
|
+
webScrollHost !== undefined ||
|
|
205
|
+
listHeader !== undefined ||
|
|
206
|
+
listEmpty !== undefined ||
|
|
207
|
+
listFooter !== undefined;
|
|
208
|
+
const useSlotLayout = useSlotLayoutRef.current;
|
|
209
|
+
const resolvedScrollHost =
|
|
210
|
+
webScrollHost === undefined
|
|
211
|
+
? useSlotLayout
|
|
212
|
+
? ownedScrollHost
|
|
213
|
+
: undefined
|
|
214
|
+
: webScrollHost;
|
|
117
215
|
const engineRef = useRef<NativeListWebEngine | undefined>(undefined);
|
|
118
216
|
const webVirtualizationEnabledRef = useRef(webVirtualizationEnabled);
|
|
119
217
|
webVirtualizationEnabledRef.current = webVirtualizationEnabled;
|
|
120
218
|
const validatedSnapshot = useMemo(
|
|
121
|
-
() =>
|
|
122
|
-
|
|
219
|
+
() =>
|
|
220
|
+
containNativeListInput(() =>
|
|
221
|
+
normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout)
|
|
222
|
+
) ?? acceptedSnapshotRef.current,
|
|
223
|
+
[snapshot, hasEmptySlot, useSlotLayout]
|
|
123
224
|
);
|
|
124
225
|
const snapshotRef = useRef(validatedSnapshot);
|
|
125
226
|
const snapshotPropRef = useRef(validatedSnapshot);
|
|
@@ -127,15 +228,13 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
127
228
|
if (snapshotPropRef.current !== validatedSnapshot) {
|
|
128
229
|
snapshotPropRef.current = validatedSnapshot;
|
|
129
230
|
snapshotRef.current = validatedSnapshot;
|
|
231
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
232
|
+
synchronizeSlots(snapshot);
|
|
233
|
+
}
|
|
234
|
+
if (!initializedSnapshot.current) {
|
|
235
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
236
|
+
initializedSnapshot.current = true;
|
|
130
237
|
}
|
|
131
|
-
// OneKey patch: React refs can be ready before the DOM engine is mounted.
|
|
132
|
-
const pendingPatchesRef = useRef<
|
|
133
|
-
| {
|
|
134
|
-
snapshot: NativeListSnapshot;
|
|
135
|
-
batches: Array<readonly RowPatch[]>;
|
|
136
|
-
}
|
|
137
|
-
| undefined
|
|
138
|
-
>(undefined);
|
|
139
238
|
const appliedSnapshotRef = useRef<NativeListSnapshot | undefined>(
|
|
140
239
|
undefined
|
|
141
240
|
);
|
|
@@ -158,45 +257,66 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
158
257
|
}>
|
|
159
258
|
| undefined
|
|
160
259
|
>(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
260
|
+
containNativeListInput(() =>
|
|
261
|
+
initialScrollIndex === undefined && initialScrollKey === undefined
|
|
262
|
+
? undefined
|
|
263
|
+
: initialScrollIndex !== undefined
|
|
264
|
+
? normalizeIndexScroll({
|
|
265
|
+
index: initialScrollIndex,
|
|
266
|
+
animated: false,
|
|
267
|
+
viewPosition: initialScrollViewPosition,
|
|
268
|
+
viewOffset: initialScrollViewOffset,
|
|
269
|
+
})
|
|
270
|
+
: {
|
|
271
|
+
key: initialScrollKey,
|
|
272
|
+
scroll: normalizePositionScroll(
|
|
273
|
+
{
|
|
274
|
+
animated: false,
|
|
275
|
+
viewPosition: initialScrollViewPosition,
|
|
276
|
+
viewOffset: initialScrollViewOffset,
|
|
277
|
+
},
|
|
278
|
+
'start'
|
|
279
|
+
),
|
|
280
|
+
}
|
|
281
|
+
)
|
|
181
282
|
);
|
|
182
283
|
const didApplyInitialScroll = useRef(false);
|
|
284
|
+
const scrollOptionsRef = useRef({
|
|
285
|
+
stickyInset: webStickyInset,
|
|
286
|
+
ownsRefresh: webScrollHost === undefined,
|
|
287
|
+
});
|
|
288
|
+
scrollOptionsRef.current = {
|
|
289
|
+
stickyInset: webStickyInset,
|
|
290
|
+
ownsRefresh: webScrollHost === undefined,
|
|
291
|
+
};
|
|
183
292
|
|
|
184
293
|
useEffect(() => {
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
294
|
+
if (
|
|
295
|
+
!host ||
|
|
296
|
+
resolvedScrollHost === null ||
|
|
297
|
+
(useSlotLayout && !contentBounds)
|
|
298
|
+
)
|
|
299
|
+
return;
|
|
300
|
+
const engine = containNativeListInput(
|
|
301
|
+
() =>
|
|
302
|
+
new NativeListWebEngine(
|
|
303
|
+
host,
|
|
304
|
+
snapshotRef.current,
|
|
305
|
+
callbacksRef.current,
|
|
306
|
+
webVirtualizationEnabledRef.current,
|
|
307
|
+
webSectionIndexContainerRef?.current as unknown as HTMLElement | null,
|
|
308
|
+
fontFamiliesJsonRef.current,
|
|
309
|
+
{
|
|
310
|
+
scrollHost: resolvedScrollHost as HTMLElement | undefined,
|
|
311
|
+
contentBounds: contentBounds ?? undefined,
|
|
312
|
+
...scrollOptionsRef.current,
|
|
313
|
+
}
|
|
314
|
+
)
|
|
193
315
|
);
|
|
316
|
+
if (!engine) return;
|
|
317
|
+
host.style.height = '';
|
|
194
318
|
engineRef.current = engine;
|
|
195
319
|
appliedSnapshotRef.current = snapshotRef.current;
|
|
196
|
-
const pending = pendingPatchesRef.current;
|
|
197
|
-
pendingPatchesRef.current = undefined;
|
|
198
|
-
if (pending?.snapshot === snapshotRef.current)
|
|
199
|
-
pending.batches.forEach((patches) => engine.applyPatches(patches));
|
|
200
320
|
const initial = initialScrollRef.current;
|
|
201
321
|
if (initial && !didApplyInitialScroll.current) {
|
|
202
322
|
didApplyInitialScroll.current = true;
|
|
@@ -206,10 +326,22 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
206
326
|
engine.scrollToKey(initial.key, initial.scroll);
|
|
207
327
|
}
|
|
208
328
|
return () => {
|
|
329
|
+
// Keep the paused tab in normal flow until its engine is restored.
|
|
330
|
+
host.style.height = `${engine.currentContentHeight()}px`;
|
|
209
331
|
engine.destroy();
|
|
210
332
|
if (engineRef.current === engine) engineRef.current = undefined;
|
|
211
333
|
};
|
|
212
|
-
}, [
|
|
334
|
+
}, [
|
|
335
|
+
host,
|
|
336
|
+
webSectionIndexContainerRef,
|
|
337
|
+
resolvedScrollHost,
|
|
338
|
+
contentBounds,
|
|
339
|
+
useSlotLayout,
|
|
340
|
+
]);
|
|
341
|
+
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
engineRef.current?.setStickyInset(webStickyInset);
|
|
344
|
+
}, [webStickyInset]);
|
|
213
345
|
|
|
214
346
|
useEffect(() => {
|
|
215
347
|
engineRef.current?.setFontFamiliesJson(fontFamiliesJson);
|
|
@@ -223,7 +355,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
223
355
|
engineRef.current?.updateCallbacks(callbacksRef.current);
|
|
224
356
|
});
|
|
225
357
|
|
|
226
|
-
|
|
358
|
+
useLayoutEffect(() => {
|
|
227
359
|
const engine = engineRef.current;
|
|
228
360
|
if (!engine || appliedSnapshotRef.current === validatedSnapshot) return;
|
|
229
361
|
engine.applySnapshot(validatedSnapshot);
|
|
@@ -241,25 +373,30 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
241
373
|
|
|
242
374
|
useImperativeHandle(forwardedRef, () => ({
|
|
243
375
|
applySnapshot(nextSnapshot) {
|
|
244
|
-
const next =
|
|
245
|
-
|
|
376
|
+
const next = containNativeListInput(() =>
|
|
377
|
+
normalizeWebSnapshot(nextSnapshot)
|
|
378
|
+
);
|
|
379
|
+
if (!next) return;
|
|
380
|
+
engineRef.current?.applySnapshot(next);
|
|
246
381
|
snapshotRef.current = next;
|
|
382
|
+
acceptedSnapshotRef.current = next;
|
|
247
383
|
appliedSnapshotRef.current = next;
|
|
248
|
-
|
|
384
|
+
synchronizeSlots(next);
|
|
249
385
|
},
|
|
250
386
|
applyPatches(patches) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
387
|
+
const accepted = containNativeListInput(() => validatePatches(patches));
|
|
388
|
+
if (accepted && accepted.length > 0) {
|
|
389
|
+
const engine = engineRef.current;
|
|
390
|
+
if (engine) {
|
|
391
|
+
engine.applyPatches(accepted);
|
|
392
|
+
snapshotRef.current = engine.currentSnapshot();
|
|
393
|
+
} else {
|
|
394
|
+
const next = containNativeListInput(() =>
|
|
395
|
+
applyRowPatches(snapshotRef.current, accepted)
|
|
396
|
+
);
|
|
397
|
+
if (next) snapshotRef.current = next;
|
|
262
398
|
}
|
|
399
|
+
acceptedSnapshotRef.current = snapshotRef.current;
|
|
263
400
|
}
|
|
264
401
|
},
|
|
265
402
|
reconcileSelection(selectedKeys) {
|
|
@@ -339,6 +476,68 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
339
476
|
[]
|
|
340
477
|
);
|
|
341
478
|
|
|
342
|
-
|
|
479
|
+
const setBoundsRef = useCallback(
|
|
480
|
+
(value: React.ComponentRef<typeof View> | null) => {
|
|
481
|
+
setContentBounds(value as unknown as HTMLElement | null);
|
|
482
|
+
},
|
|
483
|
+
[]
|
|
484
|
+
);
|
|
485
|
+
const ownedScrollElementRef = useRef<HTMLElement | null>(null);
|
|
486
|
+
const setScrollHostRef = useCallback(
|
|
487
|
+
(value: React.ComponentRef<typeof View> | null) => {
|
|
488
|
+
const element = value as unknown as HTMLElement | null;
|
|
489
|
+
if (ownedScrollElementRef.current !== element)
|
|
490
|
+
ownedScrollElementRef.current?.removeAttribute(
|
|
491
|
+
'data-collapsible-pager-scroll'
|
|
492
|
+
);
|
|
493
|
+
element?.setAttribute('data-collapsible-pager-scroll', 'true');
|
|
494
|
+
ownedScrollElementRef.current = element;
|
|
495
|
+
setOwnedScrollHost(element);
|
|
496
|
+
},
|
|
497
|
+
[]
|
|
498
|
+
);
|
|
499
|
+
if (!useSlotLayout) return <View {...viewProps} ref={setHostRef} />;
|
|
500
|
+
const padding = slotState.padding;
|
|
501
|
+
const content = (
|
|
502
|
+
<View
|
|
503
|
+
ref={setBoundsRef}
|
|
504
|
+
style={{ position: 'relative', flexShrink: 0, minWidth: 0 }}
|
|
505
|
+
>
|
|
506
|
+
{listHeader !== undefined ? (
|
|
507
|
+
<View style={{ paddingHorizontal: padding }}>{listHeader}</View>
|
|
508
|
+
) : null}
|
|
509
|
+
<View ref={setHostRef} style={{ flexShrink: 0, minWidth: 0 }} />
|
|
510
|
+
{!slotState.hasRows && hasEmptySlot ? (
|
|
511
|
+
<View
|
|
512
|
+
style={{
|
|
513
|
+
paddingHorizontal: padding,
|
|
514
|
+
paddingBottom: slotState.emptyBottomPadding,
|
|
515
|
+
}}
|
|
516
|
+
>
|
|
517
|
+
{listEmpty}
|
|
518
|
+
</View>
|
|
519
|
+
) : null}
|
|
520
|
+
{listFooter !== undefined ? (
|
|
521
|
+
<View style={{ paddingHorizontal: padding }}>{listFooter}</View>
|
|
522
|
+
) : null}
|
|
523
|
+
</View>
|
|
524
|
+
);
|
|
525
|
+
return (
|
|
526
|
+
<View
|
|
527
|
+
{...viewProps}
|
|
528
|
+
style={[viewProps.style, { position: 'relative', minHeight: 0 }]}
|
|
529
|
+
>
|
|
530
|
+
{webScrollHost === undefined ? (
|
|
531
|
+
<View
|
|
532
|
+
ref={setScrollHostRef}
|
|
533
|
+
style={{ position: 'absolute', inset: 0, overflow: 'scroll' }}
|
|
534
|
+
>
|
|
535
|
+
{content}
|
|
536
|
+
</View>
|
|
537
|
+
) : (
|
|
538
|
+
content
|
|
539
|
+
)}
|
|
540
|
+
</View>
|
|
541
|
+
);
|
|
343
542
|
}
|
|
344
543
|
);
|
package/src/index.ts
CHANGED
package/src/models.ts
CHANGED
|
@@ -25,6 +25,8 @@ export type ImageSource = Readonly<{
|
|
|
25
25
|
loadingStrategy?: ImageLoadingStrategy;
|
|
26
26
|
// OneKey patch: fallbackUri is Web-only; retryTimes opts all platforms into terminal retries.
|
|
27
27
|
fallbackUri?: string;
|
|
28
|
+
/** Web-only ordered continuation; retries each source before advancing. */
|
|
29
|
+
fallbackUris?: readonly string[];
|
|
28
30
|
retryTimes?: number;
|
|
29
31
|
}>;
|
|
30
32
|
|
|
@@ -592,11 +594,95 @@ export type DataRow = RowBase &
|
|
|
592
594
|
style?: DataRowStyle;
|
|
593
595
|
}>;
|
|
594
596
|
|
|
597
|
+
export type WebMarketTableColumn = Readonly<{
|
|
598
|
+
key: string;
|
|
599
|
+
width?: number;
|
|
600
|
+
minWidth?: number;
|
|
601
|
+
flex?: number;
|
|
602
|
+
alignment?: 'start' | 'center' | 'end';
|
|
603
|
+
paddingStart?: number;
|
|
604
|
+
paddingEnd?: number;
|
|
605
|
+
}>;
|
|
606
|
+
|
|
607
|
+
export type WebMarketTableText = Readonly<{
|
|
608
|
+
text: string;
|
|
609
|
+
segments?: readonly ValueTextSegment[];
|
|
610
|
+
tone?: TextTone;
|
|
611
|
+
style?: Pick<
|
|
612
|
+
NativeListTextStyle,
|
|
613
|
+
'fontSize' | 'fontWeight' | 'lineHeight' | 'color'
|
|
614
|
+
>;
|
|
615
|
+
}>;
|
|
616
|
+
|
|
617
|
+
export type WebMarketTableCell = Readonly<{ key: string }> &
|
|
618
|
+
(
|
|
619
|
+
| Readonly<{
|
|
620
|
+
kind: 'favorite';
|
|
621
|
+
active: boolean;
|
|
622
|
+
disabled?: boolean;
|
|
623
|
+
testID?: string;
|
|
624
|
+
hoverActionKey?: string;
|
|
625
|
+
actionKey: string;
|
|
626
|
+
accessibilityLabel: string;
|
|
627
|
+
}>
|
|
628
|
+
| Readonly<{
|
|
629
|
+
kind: 'asset';
|
|
630
|
+
leading: LeadingVisual;
|
|
631
|
+
title: WebMarketTableText;
|
|
632
|
+
secondary?: readonly WebMarketTableText[];
|
|
633
|
+
lineGap?: number;
|
|
634
|
+
secondaryBadges?: readonly Pick<
|
|
635
|
+
MarketBadgeModel,
|
|
636
|
+
'key' | 'text' | 'style'
|
|
637
|
+
>[];
|
|
638
|
+
hoverImages?: readonly (ImageSource | null)[];
|
|
639
|
+
hoverSecondary?: readonly WebMarketTableText[];
|
|
640
|
+
hoverActionKey?: string;
|
|
641
|
+
hoverActionLabel?: string;
|
|
642
|
+
badges?: readonly Pick<
|
|
643
|
+
MarketBadgeModel,
|
|
644
|
+
| 'key'
|
|
645
|
+
| 'text'
|
|
646
|
+
| 'iconName'
|
|
647
|
+
| 'icon'
|
|
648
|
+
| 'textColor'
|
|
649
|
+
| 'backgroundColor'
|
|
650
|
+
| 'actionKey'
|
|
651
|
+
| 'accessibilityLabel'
|
|
652
|
+
| 'style'
|
|
653
|
+
>[];
|
|
654
|
+
}>
|
|
655
|
+
| Readonly<{
|
|
656
|
+
kind: 'text';
|
|
657
|
+
primary: readonly WebMarketTableText[];
|
|
658
|
+
partGap?: number;
|
|
659
|
+
secondary?: readonly WebMarketTableText[];
|
|
660
|
+
}>
|
|
661
|
+
| Readonly<{
|
|
662
|
+
kind: 'sparkline';
|
|
663
|
+
points: readonly number[];
|
|
664
|
+
width: number;
|
|
665
|
+
height: number;
|
|
666
|
+
strokeColor: string;
|
|
667
|
+
fillColor: string;
|
|
668
|
+
}>
|
|
669
|
+
);
|
|
670
|
+
|
|
671
|
+
export type WebMarketTablePresentation = Readonly<{
|
|
672
|
+
draggable?: boolean;
|
|
673
|
+
contextMenuActionKey?: string;
|
|
674
|
+
testID?: string;
|
|
675
|
+
columns: readonly WebMarketTableColumn[];
|
|
676
|
+
cells: readonly WebMarketTableCell[];
|
|
677
|
+
}>;
|
|
678
|
+
|
|
595
679
|
/** Native Market quote row. All values are already localized/formatted strings. */
|
|
596
680
|
export type MarketRow = RowBase &
|
|
597
681
|
Readonly<{
|
|
598
682
|
type: 'market';
|
|
599
683
|
variant: 'token' | 'stock' | 'perp';
|
|
684
|
+
/** Web-only bounded table presentation; native reads the ordinary Market fields. */
|
|
685
|
+
webTable?: WebMarketTablePresentation;
|
|
600
686
|
leadingAction?: Extract<TrailingAccessory, { kind: 'icon' }>;
|
|
601
687
|
leading: LeadingVisual;
|
|
602
688
|
title: string;
|
|
@@ -604,6 +690,8 @@ export type MarketRow = RowBase &
|
|
|
604
690
|
/** OneKey patch: localized name shrinks independently of the volume. */
|
|
605
691
|
subtitlePrefix?: Readonly<{
|
|
606
692
|
text: string;
|
|
693
|
+
/** Web-only anchored help for a truncated name. */
|
|
694
|
+
hoverActionKey?: string;
|
|
607
695
|
gap?: number;
|
|
608
696
|
maxWidth?: number;
|
|
609
697
|
style?: MarketTextStyle;
|
|
@@ -767,6 +855,8 @@ export type NativeListTheme = Readonly<{
|
|
|
767
855
|
rowPressedBackground?: string;
|
|
768
856
|
subduedBackground?: string;
|
|
769
857
|
strongBackground?: string;
|
|
858
|
+
/** Web-only background for a displayed declared image fallback. */
|
|
859
|
+
imageFallbackBackground?: string;
|
|
770
860
|
primaryText: string;
|
|
771
861
|
secondaryText: string;
|
|
772
862
|
disabledText?: string;
|
|
@@ -979,6 +1069,7 @@ export type RowPatch =
|
|
|
979
1069
|
| 'pressInActionKey'
|
|
980
1070
|
| 'longPressActionKey'
|
|
981
1071
|
| 'diagnostics'
|
|
1072
|
+
| 'webTable'
|
|
982
1073
|
| 'style'
|
|
983
1074
|
>
|
|
984
1075
|
>;
|
|
@@ -1097,6 +1188,8 @@ export type NativeListActionAnchor = Readonly<{
|
|
|
1097
1188
|
}>;
|
|
1098
1189
|
|
|
1099
1190
|
export type RowActionEvent = Readonly<{
|
|
1191
|
+
/** Web-only client/window CSS pixel pointer location. */
|
|
1192
|
+
windowPoint?: Readonly<{ x: number; y: number }>;
|
|
1100
1193
|
rowKey?: string;
|
|
1101
1194
|
actionKey: string;
|
|
1102
1195
|
sectionKey?: string;
|