@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
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { useNativeListFontFamiliesJson } from "./fonts.js";
|
|
4
|
-
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { View } from 'react-native';
|
|
6
6
|
import { normalizeIndexScroll, normalizeKeyScroll, normalizePositionScroll, resolveLocationIndex, scrollFailure, validateOffset } from "./scrolling.js";
|
|
7
|
-
import {
|
|
7
|
+
import { applyRowPatches, containNativeListInput, emptyNativeListSnapshot, validatePatches, validateSnapshot } from "./validation.js";
|
|
8
8
|
import { NativeListWebEngine } from "./web/NativeListWebEngine.js";
|
|
9
9
|
import { acquireNativeListAvatar, canonicalNativeListAvatarUri } from "./web/NativeListWebAvatarCache.js";
|
|
10
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const collapsedExpandedContentStyle = {
|
|
12
|
+
display: 'none'
|
|
13
|
+
};
|
|
11
14
|
export function preloadNativeListAvatarImages(sources) {
|
|
12
15
|
if (typeof document === 'undefined') return Promise.resolve(false);
|
|
13
16
|
const uris = [...new Set(sources.map(source => canonicalNativeListAvatarUri(source.uri)).filter(uri => uri !== undefined))];
|
|
@@ -22,12 +25,18 @@ export function preloadNativeListAvatarImages(sources) {
|
|
|
22
25
|
}))).then(results => results.every(Boolean));
|
|
23
26
|
}
|
|
24
27
|
export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
25
|
-
snapshot,
|
|
26
|
-
listHeader
|
|
27
|
-
listEmpty
|
|
28
|
-
listFooter
|
|
28
|
+
snapshot: inputSnapshot,
|
|
29
|
+
listHeader,
|
|
30
|
+
listEmpty,
|
|
31
|
+
listFooter,
|
|
32
|
+
listExpandedContent,
|
|
33
|
+
listStructureToggle,
|
|
34
|
+
listSidecar,
|
|
35
|
+
sidecarLayout,
|
|
29
36
|
topOverlay: _topOverlay,
|
|
30
37
|
topScrollEdgeEffect: _topScrollEdgeEffect,
|
|
38
|
+
webScrollHost,
|
|
39
|
+
webStickyInset: inputStickyInset = 0,
|
|
31
40
|
scrollPositionThresholds: _scrollPositionThresholds,
|
|
32
41
|
onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
|
|
33
42
|
webVirtualizationEnabled = true,
|
|
@@ -40,6 +49,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
40
49
|
onReorder,
|
|
41
50
|
onEndReached,
|
|
42
51
|
onVisibleRangeChanged,
|
|
52
|
+
onStructuralTransitionSettled: _onStructuralTransitionSettled,
|
|
43
53
|
onRefresh,
|
|
44
54
|
onScrollToIndexFailed,
|
|
45
55
|
initialScrollIndex,
|
|
@@ -48,23 +58,114 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
48
58
|
initialScrollViewOffset,
|
|
49
59
|
...viewProps
|
|
50
60
|
}, forwardedRef) {
|
|
61
|
+
const acceptedSnapshotRef = useRef(emptyNativeListSnapshot());
|
|
62
|
+
const initializedSnapshot = useRef(false);
|
|
63
|
+
const webStickyInset = useMemo(() => containNativeListInput(() => {
|
|
64
|
+
if (!Number.isFinite(inputStickyInset) || inputStickyInset < 0) throw new Error('webStickyInset must be finite and non-negative');
|
|
65
|
+
return inputStickyInset;
|
|
66
|
+
}) ?? 0, [inputStickyInset]);
|
|
67
|
+
// Freshness is limited to this component invocation; later renders revalidate.
|
|
68
|
+
let freshlyValidatedSnapshot;
|
|
69
|
+
const preparedSnapshot = useMemo(() => {
|
|
70
|
+
const prepared = containNativeListInput(() => validateSnapshot(inputSnapshot));
|
|
71
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- The value is intentionally render-local.
|
|
72
|
+
freshlyValidatedSnapshot = prepared;
|
|
73
|
+
return prepared;
|
|
74
|
+
}, [inputSnapshot]);
|
|
75
|
+
const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
|
|
51
76
|
const fontFamiliesJson = useNativeListFontFamiliesJson();
|
|
52
77
|
const fontFamiliesJsonRef = useRef(fontFamiliesJson);
|
|
53
78
|
fontFamiliesJsonRef.current = fontFamiliesJson;
|
|
79
|
+
const hasEmptySlot = listEmpty !== undefined;
|
|
80
|
+
const hasEmptySlotRef = useRef(hasEmptySlot);
|
|
81
|
+
hasEmptySlotRef.current = hasEmptySlot;
|
|
82
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
83
|
+
const [sidecarHeight, setSidecarHeight] = useState(0);
|
|
84
|
+
const normalizeWebSnapshot = (next, hasReactEmpty = hasEmptySlotRef.current, hasSlotLayout = useSlotLayoutRef.current, validatedInThisRender = false) => {
|
|
85
|
+
if (hasSlotLayout && next.layout.orientation === 'horizontal') throw new Error('Web parent scrolling and container slots support vertical lists only');
|
|
86
|
+
const emptySlot = hasReactEmpty && next.rows.length === 0;
|
|
87
|
+
const normalized = emptySlot && next.emptyState !== undefined ? {
|
|
88
|
+
...next,
|
|
89
|
+
emptyState: undefined
|
|
90
|
+
} : next;
|
|
91
|
+
const validated = validatedInThisRender ? normalized : validateSnapshot(normalized);
|
|
92
|
+
// Preserve an already normalized fallback's identity across rerenders.
|
|
93
|
+
return emptySlot && validated.layout.contentPaddingBottom !== 0 ? {
|
|
94
|
+
...validated,
|
|
95
|
+
layout: {
|
|
96
|
+
...validated.layout,
|
|
97
|
+
contentPaddingBottom: 0
|
|
98
|
+
}
|
|
99
|
+
} : validated;
|
|
100
|
+
};
|
|
54
101
|
const [host, setHost] = useState(null);
|
|
102
|
+
const [contentBounds, setContentBounds] = useState(null);
|
|
103
|
+
const [ownedScrollHost, setOwnedScrollHost] = useState(null);
|
|
104
|
+
const useSlotLayoutRef = useRef(false);
|
|
105
|
+
useSlotLayoutRef.current ||= webScrollHost !== undefined || listHeader !== undefined || listEmpty !== undefined || listFooter !== undefined;
|
|
106
|
+
useSlotLayoutRef.current ||= listSidecar !== undefined;
|
|
107
|
+
useSlotLayoutRef.current ||= listExpandedContent !== undefined || listStructureToggle !== undefined;
|
|
108
|
+
const useSlotLayout = useSlotLayoutRef.current;
|
|
109
|
+
const resolvedScrollHost = webScrollHost === undefined ? useSlotLayout ? ownedScrollHost : undefined : webScrollHost;
|
|
55
110
|
const engineRef = useRef(undefined);
|
|
56
111
|
const webVirtualizationEnabledRef = useRef(webVirtualizationEnabled);
|
|
57
112
|
webVirtualizationEnabledRef.current = webVirtualizationEnabled;
|
|
58
|
-
const validatedSnapshot = useMemo(() =>
|
|
113
|
+
const validatedSnapshot = useMemo(() => containNativeListInput(() => {
|
|
114
|
+
if (listSidecar !== undefined !== (sidecarLayout !== undefined)) throw new Error('listSidecar and sidecarLayout must be supplied together');
|
|
115
|
+
if (sidecarLayout) {
|
|
116
|
+
const {
|
|
117
|
+
width,
|
|
118
|
+
gap,
|
|
119
|
+
maxContentWidth
|
|
120
|
+
} = sidecarLayout;
|
|
121
|
+
if (snapshot.layout.kind !== 'linear' || !Number.isFinite(width) || width <= 0 || !Number.isFinite(gap) || gap < 0 || !Number.isFinite(maxContentWidth) || maxContentWidth <= width + gap) throw new Error('Invalid NativeList sidecar layout');
|
|
122
|
+
}
|
|
123
|
+
return normalizeWebSnapshot(snapshot, hasEmptySlot, useSlotLayout, preparedSnapshot !== undefined && preparedSnapshot === freshlyValidatedSnapshot);
|
|
124
|
+
}) ?? acceptedSnapshotRef.current,
|
|
125
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- Preserve the existing memo dependencies; freshness is render-local.
|
|
126
|
+
[snapshot, hasEmptySlot, useSlotLayout, listSidecar, sidecarLayout]);
|
|
127
|
+
const [slotState, setSlotState] = useState(() => ({
|
|
128
|
+
hasRows: validatedSnapshot.rows.length > 0,
|
|
129
|
+
emptyBottomPadding: !validatedSnapshot.rows.length && hasEmptySlot ? validatedSnapshot.layout.contentPaddingBottom ?? validatedSnapshot.layout.contentPadding ?? 0 : 0,
|
|
130
|
+
padding: validatedSnapshot.layout.contentPaddingHorizontal ?? validatedSnapshot.layout.contentPadding ?? 0,
|
|
131
|
+
disclosurePresent: validatedSnapshot.disclosure !== undefined,
|
|
132
|
+
disclosureExpanded: validatedSnapshot.disclosure?.expanded === true,
|
|
133
|
+
hasExpandedContent: validatedSnapshot.disclosure?.expanded === true,
|
|
134
|
+
expandedTrailingInset: validatedSnapshot.disclosure?.expandedTrailingInset ?? 0
|
|
135
|
+
}));
|
|
136
|
+
const synchronizeSlots = next => {
|
|
137
|
+
const hasRows = next.rows.length > 0;
|
|
138
|
+
const padding = next.layout.contentPaddingHorizontal ?? next.layout.contentPadding ?? 0;
|
|
139
|
+
const emptyBottomPadding = !hasRows && hasEmptySlotRef.current ? next.layout.contentPaddingBottom ?? next.layout.contentPadding ?? 0 : 0;
|
|
140
|
+
const disclosurePresent = next.disclosure !== undefined;
|
|
141
|
+
const disclosureExpanded = next.disclosure?.expanded === true;
|
|
142
|
+
const expandedTrailingInset = next.disclosure?.expandedTrailingInset ?? 0;
|
|
143
|
+
setSlotState(previous => {
|
|
144
|
+
const hasExpandedContent = previous.hasExpandedContent || disclosureExpanded;
|
|
145
|
+
return previous.hasRows === hasRows && previous.padding === padding && previous.emptyBottomPadding === emptyBottomPadding && previous.disclosurePresent === disclosurePresent && previous.disclosureExpanded === disclosureExpanded && previous.hasExpandedContent === hasExpandedContent && previous.expandedTrailingInset === expandedTrailingInset ? previous : {
|
|
146
|
+
hasRows,
|
|
147
|
+
padding,
|
|
148
|
+
emptyBottomPadding,
|
|
149
|
+
disclosurePresent,
|
|
150
|
+
disclosureExpanded,
|
|
151
|
+
hasExpandedContent,
|
|
152
|
+
expandedTrailingInset
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
};
|
|
59
156
|
const snapshotRef = useRef(validatedSnapshot);
|
|
60
157
|
const snapshotPropRef = useRef(validatedSnapshot);
|
|
61
158
|
// An imperative snapshot survives host mounting until the snapshot prop changes.
|
|
62
159
|
if (snapshotPropRef.current !== validatedSnapshot) {
|
|
63
160
|
snapshotPropRef.current = validatedSnapshot;
|
|
64
161
|
snapshotRef.current = validatedSnapshot;
|
|
162
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
163
|
+
synchronizeSlots(validatedSnapshot);
|
|
164
|
+
}
|
|
165
|
+
if (!initializedSnapshot.current) {
|
|
166
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
167
|
+
initializedSnapshot.current = true;
|
|
65
168
|
}
|
|
66
|
-
// OneKey patch: React refs can be ready before the DOM engine is mounted.
|
|
67
|
-
const pendingPatchesRef = useRef(undefined);
|
|
68
169
|
const appliedSnapshotRef = useRef(undefined);
|
|
69
170
|
const callbacksRef = useRef({});
|
|
70
171
|
callbacksRef.current = {
|
|
@@ -77,7 +178,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
77
178
|
onRefresh,
|
|
78
179
|
onScrollToIndexFailed
|
|
79
180
|
};
|
|
80
|
-
const initialScrollRef = useRef(initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
181
|
+
const initialScrollRef = useRef(containNativeListInput(() => initialScrollIndex === undefined && initialScrollKey === undefined ? undefined : initialScrollIndex !== undefined ? normalizeIndexScroll({
|
|
81
182
|
index: initialScrollIndex,
|
|
82
183
|
animated: false,
|
|
83
184
|
viewPosition: initialScrollViewPosition,
|
|
@@ -89,26 +190,42 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
89
190
|
viewPosition: initialScrollViewPosition,
|
|
90
191
|
viewOffset: initialScrollViewOffset
|
|
91
192
|
}, 'start')
|
|
92
|
-
});
|
|
193
|
+
}));
|
|
93
194
|
const didApplyInitialScroll = useRef(false);
|
|
195
|
+
const scrollOptionsRef = useRef({
|
|
196
|
+
stickyInset: webStickyInset,
|
|
197
|
+
ownsRefresh: webScrollHost === undefined
|
|
198
|
+
});
|
|
199
|
+
scrollOptionsRef.current = {
|
|
200
|
+
stickyInset: webStickyInset,
|
|
201
|
+
ownsRefresh: webScrollHost === undefined
|
|
202
|
+
};
|
|
94
203
|
useEffect(() => {
|
|
95
|
-
if (!host) return;
|
|
96
|
-
const engine = new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current
|
|
204
|
+
if (!host || resolvedScrollHost === null || useSlotLayout && !contentBounds) return;
|
|
205
|
+
const engine = containNativeListInput(() => new NativeListWebEngine(host, snapshotRef.current, callbacksRef.current, webVirtualizationEnabledRef.current, webSectionIndexContainerRef?.current, fontFamiliesJsonRef.current, {
|
|
206
|
+
scrollHost: resolvedScrollHost,
|
|
207
|
+
contentBounds: contentBounds ?? undefined,
|
|
208
|
+
...scrollOptionsRef.current
|
|
209
|
+
}));
|
|
210
|
+
if (!engine) return;
|
|
211
|
+
host.style.height = '';
|
|
97
212
|
engineRef.current = engine;
|
|
98
213
|
appliedSnapshotRef.current = snapshotRef.current;
|
|
99
|
-
const pending = pendingPatchesRef.current;
|
|
100
|
-
pendingPatchesRef.current = undefined;
|
|
101
|
-
if (pending?.snapshot === snapshotRef.current) pending.batches.forEach(patches => engine.applyPatches(patches));
|
|
102
214
|
const initial = initialScrollRef.current;
|
|
103
215
|
if (initial && !didApplyInitialScroll.current) {
|
|
104
216
|
didApplyInitialScroll.current = true;
|
|
105
217
|
if (initial.index !== undefined) engine.scrollToIndex(initial.index, initial.scroll);else if (initial.key !== undefined) engine.scrollToKey(initial.key, initial.scroll);
|
|
106
218
|
}
|
|
107
219
|
return () => {
|
|
220
|
+
// Keep the paused tab in normal flow until its engine is restored.
|
|
221
|
+
host.style.height = `${engine.currentContentHeight()}px`;
|
|
108
222
|
engine.destroy();
|
|
109
223
|
if (engineRef.current === engine) engineRef.current = undefined;
|
|
110
224
|
};
|
|
111
|
-
}, [host, webSectionIndexContainerRef]);
|
|
225
|
+
}, [host, webSectionIndexContainerRef, resolvedScrollHost, contentBounds, useSlotLayout]);
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
engineRef.current?.setStickyInset(webStickyInset);
|
|
228
|
+
}, [webStickyInset]);
|
|
112
229
|
useEffect(() => {
|
|
113
230
|
engineRef.current?.setFontFamiliesJson(fontFamiliesJson);
|
|
114
231
|
}, [fontFamiliesJson]);
|
|
@@ -118,7 +235,7 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
118
235
|
useEffect(() => {
|
|
119
236
|
engineRef.current?.updateCallbacks(callbacksRef.current);
|
|
120
237
|
});
|
|
121
|
-
|
|
238
|
+
useLayoutEffect(() => {
|
|
122
239
|
const engine = engineRef.current;
|
|
123
240
|
if (!engine || appliedSnapshotRef.current === validatedSnapshot) return;
|
|
124
241
|
engine.applySnapshot(validatedSnapshot);
|
|
@@ -129,23 +246,26 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
129
246
|
};
|
|
130
247
|
useImperativeHandle(forwardedRef, () => ({
|
|
131
248
|
applySnapshot(nextSnapshot) {
|
|
132
|
-
const next =
|
|
133
|
-
|
|
249
|
+
const next = containNativeListInput(() => normalizeWebSnapshot(nextSnapshot));
|
|
250
|
+
if (!next) return;
|
|
251
|
+
engineRef.current?.applySnapshot(next);
|
|
134
252
|
snapshotRef.current = next;
|
|
253
|
+
acceptedSnapshotRef.current = next;
|
|
135
254
|
appliedSnapshotRef.current = next;
|
|
136
|
-
|
|
255
|
+
synchronizeSlots(next);
|
|
137
256
|
},
|
|
138
257
|
applyPatches(patches) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
258
|
+
const accepted = containNativeListInput(() => validatePatches(patches));
|
|
259
|
+
if (accepted && accepted.length > 0) {
|
|
260
|
+
const engine = engineRef.current;
|
|
261
|
+
if (engine) {
|
|
262
|
+
engine.applyPatches(accepted);
|
|
263
|
+
snapshotRef.current = engine.currentSnapshot();
|
|
264
|
+
} else {
|
|
265
|
+
const next = containNativeListInput(() => applyRowPatches(snapshotRef.current, accepted));
|
|
266
|
+
if (next) snapshotRef.current = next;
|
|
148
267
|
}
|
|
268
|
+
acceptedSnapshotRef.current = snapshotRef.current;
|
|
149
269
|
}
|
|
150
270
|
},
|
|
151
271
|
reconcileSelection(selectedKeys) {
|
|
@@ -208,9 +328,119 @@ export const NativeList = /*#__PURE__*/forwardRef(function NativeList({
|
|
|
208
328
|
const setHostRef = useCallback(value => {
|
|
209
329
|
setHost(value);
|
|
210
330
|
}, []);
|
|
211
|
-
|
|
331
|
+
const setBoundsRef = useCallback(value => {
|
|
332
|
+
setContentBounds(value);
|
|
333
|
+
}, []);
|
|
334
|
+
const ownedScrollElementRef = useRef(null);
|
|
335
|
+
const setScrollHostRef = useCallback(value => {
|
|
336
|
+
const element = value;
|
|
337
|
+
if (ownedScrollElementRef.current !== element) ownedScrollElementRef.current?.removeAttribute('data-collapsible-pager-scroll');
|
|
338
|
+
element?.setAttribute('data-collapsible-pager-scroll', 'true');
|
|
339
|
+
ownedScrollElementRef.current = element;
|
|
340
|
+
setOwnedScrollHost(element);
|
|
341
|
+
}, []);
|
|
342
|
+
if (!useSlotLayout) return /*#__PURE__*/_jsx(View, {
|
|
212
343
|
...viewProps,
|
|
213
344
|
ref: setHostRef
|
|
214
345
|
});
|
|
346
|
+
const padding = slotState.padding;
|
|
347
|
+
const footerBandStyle = {
|
|
348
|
+
paddingHorizontal: padding
|
|
349
|
+
};
|
|
350
|
+
const trailingInsetStyle = {
|
|
351
|
+
height: slotState.disclosureExpanded ? slotState.expandedTrailingInset : 0
|
|
352
|
+
};
|
|
353
|
+
const hasFooterBand = listFooter !== undefined || listExpandedContent !== undefined || listStructureToggle !== undefined;
|
|
354
|
+
const content = /*#__PURE__*/_jsxs(View, {
|
|
355
|
+
ref: sidecarLayout ? undefined : setBoundsRef,
|
|
356
|
+
style: {
|
|
357
|
+
position: 'relative',
|
|
358
|
+
flexShrink: 0,
|
|
359
|
+
minWidth: 0
|
|
360
|
+
},
|
|
361
|
+
children: [listHeader !== undefined ? /*#__PURE__*/_jsx(View, {
|
|
362
|
+
style: {
|
|
363
|
+
paddingHorizontal: padding
|
|
364
|
+
},
|
|
365
|
+
children: listHeader
|
|
366
|
+
}) : null, /*#__PURE__*/_jsx(View, {
|
|
367
|
+
ref: setHostRef,
|
|
368
|
+
style: {
|
|
369
|
+
flexShrink: 0,
|
|
370
|
+
minWidth: 0
|
|
371
|
+
}
|
|
372
|
+
}), !slotState.hasRows && hasEmptySlot ? /*#__PURE__*/_jsx(View, {
|
|
373
|
+
style: {
|
|
374
|
+
paddingHorizontal: padding,
|
|
375
|
+
paddingBottom: slotState.emptyBottomPadding
|
|
376
|
+
},
|
|
377
|
+
children: listEmpty
|
|
378
|
+
}) : null, hasFooterBand ? /*#__PURE__*/_jsxs(View, {
|
|
379
|
+
testID: "native-list-footer-slot",
|
|
380
|
+
style: footerBandStyle,
|
|
381
|
+
children: [listExpandedContent !== undefined && slotState.hasExpandedContent ? /*#__PURE__*/_jsx(View, {
|
|
382
|
+
testID: "native-list-expanded-content-slot",
|
|
383
|
+
"aria-hidden": !slotState.disclosureExpanded,
|
|
384
|
+
pointerEvents: slotState.disclosureExpanded ? 'auto' : 'none',
|
|
385
|
+
style: slotState.disclosureExpanded ? undefined : collapsedExpandedContentStyle,
|
|
386
|
+
children: listExpandedContent
|
|
387
|
+
}) : null, listStructureToggle !== undefined ? /*#__PURE__*/_jsx(View, {
|
|
388
|
+
testID: "native-list-structure-toggle-slot",
|
|
389
|
+
"aria-hidden": !slotState.disclosurePresent,
|
|
390
|
+
pointerEvents: slotState.disclosurePresent ? 'auto' : 'none',
|
|
391
|
+
style: slotState.disclosurePresent ? undefined : collapsedExpandedContentStyle,
|
|
392
|
+
children: listStructureToggle
|
|
393
|
+
}) : null, slotState.expandedTrailingInset > 0 && (listExpandedContent !== undefined || listStructureToggle !== undefined) ? /*#__PURE__*/_jsx(View, {
|
|
394
|
+
testID: "native-list-trailing-inset-slot",
|
|
395
|
+
style: trailingInsetStyle
|
|
396
|
+
}) : null, listFooter]
|
|
397
|
+
}) : null]
|
|
398
|
+
});
|
|
399
|
+
const bandWidth = sidecarLayout ? Math.min(viewportWidth, sidecarLayout.maxContentWidth) : 0;
|
|
400
|
+
const sidecarMargin = Math.max(0, (viewportWidth - bandWidth) / 2);
|
|
401
|
+
const leftWidth = Math.max(0, bandWidth - (sidecarLayout?.width ?? 0) - (sidecarLayout?.gap ?? 0));
|
|
402
|
+
const scrollContent = sidecarLayout ? /*#__PURE__*/_jsxs(View, {
|
|
403
|
+
ref: setBoundsRef,
|
|
404
|
+
style: {
|
|
405
|
+
position: 'relative',
|
|
406
|
+
minHeight: sidecarHeight
|
|
407
|
+
},
|
|
408
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
409
|
+
style: {
|
|
410
|
+
marginStart: sidecarMargin,
|
|
411
|
+
width: leftWidth
|
|
412
|
+
},
|
|
413
|
+
children: content
|
|
414
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
415
|
+
style: {
|
|
416
|
+
position: 'absolute',
|
|
417
|
+
end: sidecarMargin,
|
|
418
|
+
top: 0,
|
|
419
|
+
width: sidecarLayout.width
|
|
420
|
+
},
|
|
421
|
+
onLayout: event => setSidecarHeight(event.nativeEvent.layout.height),
|
|
422
|
+
children: listSidecar
|
|
423
|
+
})]
|
|
424
|
+
}) : content;
|
|
425
|
+
return /*#__PURE__*/_jsx(View, {
|
|
426
|
+
...viewProps,
|
|
427
|
+
onLayout: event => {
|
|
428
|
+
setViewportWidth(event.nativeEvent.layout.width);
|
|
429
|
+
viewProps.onLayout?.(event);
|
|
430
|
+
},
|
|
431
|
+
style: [viewProps.style, {
|
|
432
|
+
position: 'relative',
|
|
433
|
+
minHeight: 0
|
|
434
|
+
}],
|
|
435
|
+
children: webScrollHost === undefined ? /*#__PURE__*/_jsx(View, {
|
|
436
|
+
ref: setScrollHostRef,
|
|
437
|
+
style: {
|
|
438
|
+
position: 'absolute',
|
|
439
|
+
inset: 0,
|
|
440
|
+
overflow: 'scroll'
|
|
441
|
+
},
|
|
442
|
+
children: scrollContent
|
|
443
|
+
}) : scrollContent
|
|
444
|
+
});
|
|
215
445
|
});
|
|
216
446
|
//# sourceMappingURL=NativeList.web.js.map
|
package/lib/module/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export { NativeList, preloadNativeListAvatarImages } from './NativeList';
|
|
4
|
-
export { applyRowPatches, serializePatches, serializeSnapshot, validatePatches, validateSnapshot } from "./validation.js";
|
|
4
|
+
export { applyRowPatches, planNativeListPatches, serializePatches, serializeSnapshot, validatePatches, validateSnapshot } from "./validation.js";
|
|
5
5
|
export { checkboxStateForKeys, checkboxStateForSection, isSelectableRow, reduceSelection, selectionStateFromSnapshot } from "./selection.js";
|
|
6
6
|
export { configureNativeListFonts } from "./fonts.js";
|
|
7
7
|
export { ScrollEdgeEffect } from "./ScrollEdgeEffect.js";
|
package/lib/module/models.js
CHANGED
|
@@ -24,6 +24,7 @@ export const ROW_BOX_STYLE_KEYS_BY_TYPE = {
|
|
|
24
24
|
metricCard: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'lineGap', 'image'],
|
|
25
25
|
sectionHeader: ['horizontalPadding', 'verticalPadding', 'lineGap', 'trailingGap'],
|
|
26
26
|
action: ['horizontalPadding', 'verticalPadding', 'leadingGap', 'trailingGap', 'image'],
|
|
27
|
+
buttonGroup: [],
|
|
27
28
|
system: ['horizontalPadding', 'verticalPadding', 'lineGap']
|
|
28
29
|
};
|
|
29
30
|
|
package/lib/module/selection.js
CHANGED
|
@@ -4,7 +4,7 @@ export function isSelectableRow(row) {
|
|
|
4
4
|
return !row.disabled && (row.type === 'identity' || row.type === 'rail' || row.type === 'activity' || row.type === 'message' || row.type === 'dataRow' || row.type === 'mediaTile' || row.type === 'metricCard');
|
|
5
5
|
}
|
|
6
6
|
export function isRowPressEnabled(row) {
|
|
7
|
-
return !row.disabled && !row.pressDisabled && (row.type !== 'system' || row.variant === 'retry');
|
|
7
|
+
return !row.disabled && !row.pressDisabled && row.type !== 'buttonGroup' && (row.type !== 'system' || row.variant === 'retry');
|
|
8
8
|
}
|
|
9
9
|
function deltaBetween(before, after, source, sourceKey) {
|
|
10
10
|
return {
|