@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.types.ts
CHANGED
|
@@ -71,6 +71,25 @@ export type ScrollToIndexFailedInfo = Readonly<{
|
|
|
71
71
|
| 'item-not-found';
|
|
72
72
|
}>;
|
|
73
73
|
|
|
74
|
+
/** Minimal DOM-free structural surface for an explicit Web scroll element. */
|
|
75
|
+
export type NativeListWebScrollHost = Readonly<{
|
|
76
|
+
clientWidth: number;
|
|
77
|
+
clientHeight: number;
|
|
78
|
+
scrollTop: number;
|
|
79
|
+
}>;
|
|
80
|
+
|
|
81
|
+
export type NativeListSidecarLayout = Readonly<{
|
|
82
|
+
width: number;
|
|
83
|
+
gap: number;
|
|
84
|
+
maxContentWidth: number;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
87
|
+
export type StructuralTransitionSettledEvent = Readonly<{
|
|
88
|
+
transitionId: string;
|
|
89
|
+
status: 'completed' | 'interrupted';
|
|
90
|
+
settledExpanded: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
|
|
74
93
|
type InitialScrollProps =
|
|
75
94
|
| Readonly<{
|
|
76
95
|
initialScrollIndex?: never;
|
|
@@ -120,16 +139,27 @@ export type NativeListRef = Readonly<{
|
|
|
120
139
|
export type NativeListProps = Omit<ViewProps, 'children'> &
|
|
121
140
|
Readonly<{
|
|
122
141
|
snapshot: NativeListSnapshot;
|
|
123
|
-
/**
|
|
142
|
+
/** Container-owned scroll content. Never rendered as a data row. */
|
|
124
143
|
listHeader?: ReactNode;
|
|
125
144
|
listFooter?: ReactNode;
|
|
126
145
|
listEmpty?: ReactNode;
|
|
146
|
+
/** Native disclosure content, retained until its transition settles. */
|
|
147
|
+
listExpandedContent?: ReactNode;
|
|
148
|
+
/** Stable native disclosure toggle after expanded content. */
|
|
149
|
+
listStructureToggle?: ReactNode;
|
|
150
|
+
/** Scrolling right column for a vertical linear list. Requires sidecarLayout. */
|
|
151
|
+
listSidecar?: ReactNode;
|
|
152
|
+
sidecarLayout?: NativeListSidecarLayout;
|
|
127
153
|
/** Fixed overlay above scrolling rows on iOS 26 and newer. */
|
|
128
154
|
topOverlay?: ReactNode;
|
|
129
155
|
/** Selects UIKit's top scroll-edge effect on iOS 26 and newer. */
|
|
130
156
|
topScrollEdgeEffect?: `${ScrollEdgeEffect}`;
|
|
131
157
|
/** Web only. Defaults to true and is ignored by the native host. */
|
|
132
158
|
webVirtualizationEnabled?: boolean;
|
|
159
|
+
/** Web only: undefined owns scrolling, null waits for a host element. */
|
|
160
|
+
webScrollHost?: NativeListWebScrollHost | null;
|
|
161
|
+
/** Web only: visible sticky chrome above the parent's list viewport. */
|
|
162
|
+
webStickyInset?: number;
|
|
133
163
|
/** Web only. Hosts the section index inside this container. */
|
|
134
164
|
webSectionIndexContainerRef?: RefObject<View | null>;
|
|
135
165
|
/** Defaults to `none`. `interactive` behaves as `none` on Android. */
|
|
@@ -145,6 +175,9 @@ export type NativeListProps = Omit<ViewProps, 'children'> &
|
|
|
145
175
|
onReorder?: (event: ReorderEvent) => void;
|
|
146
176
|
onEndReached?: (event: EndReachedEvent) => void;
|
|
147
177
|
onVisibleRangeChanged?: (event: VisibleRangeChangedEvent) => void;
|
|
178
|
+
onStructuralTransitionSettled?: (
|
|
179
|
+
event: StructuralTransitionSettledEvent
|
|
180
|
+
) => void;
|
|
148
181
|
/** Native only. Emits initial state and hysteresis transitions, not scroll frames. */
|
|
149
182
|
scrollPositionThresholds?: Readonly<{
|
|
150
183
|
start: number;
|
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,
|
|
@@ -30,6 +37,8 @@ import {
|
|
|
30
37
|
canonicalNativeListAvatarUri,
|
|
31
38
|
} from './web/NativeListWebAvatarCache';
|
|
32
39
|
|
|
40
|
+
const collapsedExpandedContentStyle = { display: 'none' } as const;
|
|
41
|
+
|
|
33
42
|
export type { NativeListProps, NativeListRef } from './NativeList.types';
|
|
34
43
|
export type {
|
|
35
44
|
ActionAnchorState,
|
|
@@ -82,12 +91,18 @@ export function preloadNativeListAvatarImages(
|
|
|
82
91
|
export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
83
92
|
function NativeList(
|
|
84
93
|
{
|
|
85
|
-
snapshot,
|
|
86
|
-
listHeader
|
|
87
|
-
listEmpty
|
|
88
|
-
listFooter
|
|
94
|
+
snapshot: inputSnapshot,
|
|
95
|
+
listHeader,
|
|
96
|
+
listEmpty,
|
|
97
|
+
listFooter,
|
|
98
|
+
listExpandedContent,
|
|
99
|
+
listStructureToggle,
|
|
100
|
+
listSidecar,
|
|
101
|
+
sidecarLayout,
|
|
89
102
|
topOverlay: _topOverlay,
|
|
90
103
|
topScrollEdgeEffect: _topScrollEdgeEffect,
|
|
104
|
+
webScrollHost,
|
|
105
|
+
webStickyInset: inputStickyInset = 0,
|
|
91
106
|
scrollPositionThresholds: _scrollPositionThresholds,
|
|
92
107
|
onScrollPositionThresholdChange: _onScrollPositionThresholdChange,
|
|
93
108
|
webVirtualizationEnabled = true,
|
|
@@ -100,6 +115,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
100
115
|
onReorder,
|
|
101
116
|
onEndReached,
|
|
102
117
|
onVisibleRangeChanged,
|
|
118
|
+
onStructuralTransitionSettled: _onStructuralTransitionSettled,
|
|
103
119
|
onRefresh,
|
|
104
120
|
onScrollToIndexFailed,
|
|
105
121
|
initialScrollIndex,
|
|
@@ -110,32 +126,185 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
110
126
|
},
|
|
111
127
|
forwardedRef
|
|
112
128
|
) {
|
|
129
|
+
const acceptedSnapshotRef = useRef<NativeListSnapshot>(
|
|
130
|
+
emptyNativeListSnapshot()
|
|
131
|
+
);
|
|
132
|
+
const initializedSnapshot = useRef(false);
|
|
133
|
+
const webStickyInset = useMemo(
|
|
134
|
+
() =>
|
|
135
|
+
containNativeListInput(() => {
|
|
136
|
+
if (!Number.isFinite(inputStickyInset) || inputStickyInset < 0)
|
|
137
|
+
throw new Error('webStickyInset must be finite and non-negative');
|
|
138
|
+
return inputStickyInset;
|
|
139
|
+
}) ?? 0,
|
|
140
|
+
[inputStickyInset]
|
|
141
|
+
);
|
|
142
|
+
// Freshness is limited to this component invocation; later renders revalidate.
|
|
143
|
+
let freshlyValidatedSnapshot: NativeListSnapshot | undefined;
|
|
144
|
+
const preparedSnapshot = useMemo(() => {
|
|
145
|
+
const prepared = containNativeListInput(() =>
|
|
146
|
+
validateSnapshot(inputSnapshot)
|
|
147
|
+
);
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- The value is intentionally render-local.
|
|
149
|
+
freshlyValidatedSnapshot = prepared;
|
|
150
|
+
return prepared;
|
|
151
|
+
}, [inputSnapshot]);
|
|
152
|
+
const snapshot = preparedSnapshot ?? acceptedSnapshotRef.current;
|
|
113
153
|
const fontFamiliesJson = useNativeListFontFamiliesJson();
|
|
114
154
|
const fontFamiliesJsonRef = useRef(fontFamiliesJson);
|
|
115
155
|
fontFamiliesJsonRef.current = fontFamiliesJson;
|
|
156
|
+
const hasEmptySlot = listEmpty !== undefined;
|
|
157
|
+
const hasEmptySlotRef = useRef(hasEmptySlot);
|
|
158
|
+
hasEmptySlotRef.current = hasEmptySlot;
|
|
159
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
160
|
+
const [sidecarHeight, setSidecarHeight] = useState(0);
|
|
161
|
+
const normalizeWebSnapshot = (
|
|
162
|
+
next: NativeListSnapshot,
|
|
163
|
+
hasReactEmpty = hasEmptySlotRef.current,
|
|
164
|
+
hasSlotLayout = useSlotLayoutRef.current,
|
|
165
|
+
validatedInThisRender = false
|
|
166
|
+
) => {
|
|
167
|
+
if (hasSlotLayout && next.layout.orientation === 'horizontal')
|
|
168
|
+
throw new Error(
|
|
169
|
+
'Web parent scrolling and container slots support vertical lists only'
|
|
170
|
+
);
|
|
171
|
+
const emptySlot = hasReactEmpty && next.rows.length === 0;
|
|
172
|
+
const normalized =
|
|
173
|
+
emptySlot && next.emptyState !== undefined
|
|
174
|
+
? { ...next, emptyState: undefined }
|
|
175
|
+
: next;
|
|
176
|
+
const validated = validatedInThisRender
|
|
177
|
+
? normalized
|
|
178
|
+
: validateSnapshot(normalized);
|
|
179
|
+
// Preserve an already normalized fallback's identity across rerenders.
|
|
180
|
+
return emptySlot && validated.layout.contentPaddingBottom !== 0
|
|
181
|
+
? {
|
|
182
|
+
...validated,
|
|
183
|
+
layout: { ...validated.layout, contentPaddingBottom: 0 },
|
|
184
|
+
}
|
|
185
|
+
: validated;
|
|
186
|
+
};
|
|
116
187
|
const [host, setHost] = useState<HTMLElement | null>(null);
|
|
188
|
+
const [contentBounds, setContentBounds] = useState<HTMLElement | null>(
|
|
189
|
+
null
|
|
190
|
+
);
|
|
191
|
+
const [ownedScrollHost, setOwnedScrollHost] = useState<HTMLElement | null>(
|
|
192
|
+
null
|
|
193
|
+
);
|
|
194
|
+
const useSlotLayoutRef = useRef(false);
|
|
195
|
+
useSlotLayoutRef.current ||=
|
|
196
|
+
webScrollHost !== undefined ||
|
|
197
|
+
listHeader !== undefined ||
|
|
198
|
+
listEmpty !== undefined ||
|
|
199
|
+
listFooter !== undefined;
|
|
200
|
+
useSlotLayoutRef.current ||= listSidecar !== undefined;
|
|
201
|
+
useSlotLayoutRef.current ||=
|
|
202
|
+
listExpandedContent !== undefined || listStructureToggle !== undefined;
|
|
203
|
+
const useSlotLayout = useSlotLayoutRef.current;
|
|
204
|
+
const resolvedScrollHost =
|
|
205
|
+
webScrollHost === undefined
|
|
206
|
+
? useSlotLayout
|
|
207
|
+
? ownedScrollHost
|
|
208
|
+
: undefined
|
|
209
|
+
: webScrollHost;
|
|
117
210
|
const engineRef = useRef<NativeListWebEngine | undefined>(undefined);
|
|
118
211
|
const webVirtualizationEnabledRef = useRef(webVirtualizationEnabled);
|
|
119
212
|
webVirtualizationEnabledRef.current = webVirtualizationEnabled;
|
|
120
213
|
const validatedSnapshot = useMemo(
|
|
121
|
-
() =>
|
|
122
|
-
|
|
214
|
+
() =>
|
|
215
|
+
containNativeListInput(() => {
|
|
216
|
+
if ((listSidecar !== undefined) !== (sidecarLayout !== undefined))
|
|
217
|
+
throw new Error(
|
|
218
|
+
'listSidecar and sidecarLayout must be supplied together'
|
|
219
|
+
);
|
|
220
|
+
if (sidecarLayout) {
|
|
221
|
+
const { width, gap, maxContentWidth } = sidecarLayout;
|
|
222
|
+
if (
|
|
223
|
+
snapshot.layout.kind !== 'linear' ||
|
|
224
|
+
!Number.isFinite(width) ||
|
|
225
|
+
width <= 0 ||
|
|
226
|
+
!Number.isFinite(gap) ||
|
|
227
|
+
gap < 0 ||
|
|
228
|
+
!Number.isFinite(maxContentWidth) ||
|
|
229
|
+
maxContentWidth <= width + gap
|
|
230
|
+
)
|
|
231
|
+
throw new Error('Invalid NativeList sidecar layout');
|
|
232
|
+
}
|
|
233
|
+
return normalizeWebSnapshot(
|
|
234
|
+
snapshot,
|
|
235
|
+
hasEmptySlot,
|
|
236
|
+
useSlotLayout,
|
|
237
|
+
preparedSnapshot !== undefined &&
|
|
238
|
+
preparedSnapshot === freshlyValidatedSnapshot
|
|
239
|
+
);
|
|
240
|
+
}) ?? acceptedSnapshotRef.current,
|
|
241
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- Preserve the existing memo dependencies; freshness is render-local.
|
|
242
|
+
[snapshot, hasEmptySlot, useSlotLayout, listSidecar, sidecarLayout]
|
|
123
243
|
);
|
|
244
|
+
const [slotState, setSlotState] = useState(() => ({
|
|
245
|
+
hasRows: validatedSnapshot.rows.length > 0,
|
|
246
|
+
emptyBottomPadding:
|
|
247
|
+
!validatedSnapshot.rows.length && hasEmptySlot
|
|
248
|
+
? validatedSnapshot.layout.contentPaddingBottom ??
|
|
249
|
+
validatedSnapshot.layout.contentPadding ??
|
|
250
|
+
0
|
|
251
|
+
: 0,
|
|
252
|
+
padding:
|
|
253
|
+
validatedSnapshot.layout.contentPaddingHorizontal ??
|
|
254
|
+
validatedSnapshot.layout.contentPadding ??
|
|
255
|
+
0,
|
|
256
|
+
disclosurePresent: validatedSnapshot.disclosure !== undefined,
|
|
257
|
+
disclosureExpanded: validatedSnapshot.disclosure?.expanded === true,
|
|
258
|
+
hasExpandedContent: validatedSnapshot.disclosure?.expanded === true,
|
|
259
|
+
expandedTrailingInset:
|
|
260
|
+
validatedSnapshot.disclosure?.expandedTrailingInset ?? 0,
|
|
261
|
+
}));
|
|
262
|
+
const synchronizeSlots = (next: NativeListSnapshot) => {
|
|
263
|
+
const hasRows = next.rows.length > 0;
|
|
264
|
+
const padding =
|
|
265
|
+
next.layout.contentPaddingHorizontal ?? next.layout.contentPadding ?? 0;
|
|
266
|
+
const emptyBottomPadding =
|
|
267
|
+
!hasRows && hasEmptySlotRef.current
|
|
268
|
+
? next.layout.contentPaddingBottom ?? next.layout.contentPadding ?? 0
|
|
269
|
+
: 0;
|
|
270
|
+
const disclosurePresent = next.disclosure !== undefined;
|
|
271
|
+
const disclosureExpanded = next.disclosure?.expanded === true;
|
|
272
|
+
const expandedTrailingInset = next.disclosure?.expandedTrailingInset ?? 0;
|
|
273
|
+
setSlotState((previous) => {
|
|
274
|
+
const hasExpandedContent =
|
|
275
|
+
previous.hasExpandedContent || disclosureExpanded;
|
|
276
|
+
return previous.hasRows === hasRows &&
|
|
277
|
+
previous.padding === padding &&
|
|
278
|
+
previous.emptyBottomPadding === emptyBottomPadding &&
|
|
279
|
+
previous.disclosurePresent === disclosurePresent &&
|
|
280
|
+
previous.disclosureExpanded === disclosureExpanded &&
|
|
281
|
+
previous.hasExpandedContent === hasExpandedContent &&
|
|
282
|
+
previous.expandedTrailingInset === expandedTrailingInset
|
|
283
|
+
? previous
|
|
284
|
+
: {
|
|
285
|
+
hasRows,
|
|
286
|
+
padding,
|
|
287
|
+
emptyBottomPadding,
|
|
288
|
+
disclosurePresent,
|
|
289
|
+
disclosureExpanded,
|
|
290
|
+
hasExpandedContent,
|
|
291
|
+
expandedTrailingInset,
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
};
|
|
124
295
|
const snapshotRef = useRef(validatedSnapshot);
|
|
125
296
|
const snapshotPropRef = useRef(validatedSnapshot);
|
|
126
297
|
// An imperative snapshot survives host mounting until the snapshot prop changes.
|
|
127
298
|
if (snapshotPropRef.current !== validatedSnapshot) {
|
|
128
299
|
snapshotPropRef.current = validatedSnapshot;
|
|
129
300
|
snapshotRef.current = validatedSnapshot;
|
|
301
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
302
|
+
synchronizeSlots(validatedSnapshot);
|
|
303
|
+
}
|
|
304
|
+
if (!initializedSnapshot.current) {
|
|
305
|
+
acceptedSnapshotRef.current = validatedSnapshot;
|
|
306
|
+
initializedSnapshot.current = true;
|
|
130
307
|
}
|
|
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
308
|
const appliedSnapshotRef = useRef<NativeListSnapshot | undefined>(
|
|
140
309
|
undefined
|
|
141
310
|
);
|
|
@@ -158,45 +327,66 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
158
327
|
}>
|
|
159
328
|
| undefined
|
|
160
329
|
>(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
330
|
+
containNativeListInput(() =>
|
|
331
|
+
initialScrollIndex === undefined && initialScrollKey === undefined
|
|
332
|
+
? undefined
|
|
333
|
+
: initialScrollIndex !== undefined
|
|
334
|
+
? normalizeIndexScroll({
|
|
335
|
+
index: initialScrollIndex,
|
|
336
|
+
animated: false,
|
|
337
|
+
viewPosition: initialScrollViewPosition,
|
|
338
|
+
viewOffset: initialScrollViewOffset,
|
|
339
|
+
})
|
|
340
|
+
: {
|
|
341
|
+
key: initialScrollKey,
|
|
342
|
+
scroll: normalizePositionScroll(
|
|
343
|
+
{
|
|
344
|
+
animated: false,
|
|
345
|
+
viewPosition: initialScrollViewPosition,
|
|
346
|
+
viewOffset: initialScrollViewOffset,
|
|
347
|
+
},
|
|
348
|
+
'start'
|
|
349
|
+
),
|
|
350
|
+
}
|
|
351
|
+
)
|
|
181
352
|
);
|
|
182
353
|
const didApplyInitialScroll = useRef(false);
|
|
354
|
+
const scrollOptionsRef = useRef({
|
|
355
|
+
stickyInset: webStickyInset,
|
|
356
|
+
ownsRefresh: webScrollHost === undefined,
|
|
357
|
+
});
|
|
358
|
+
scrollOptionsRef.current = {
|
|
359
|
+
stickyInset: webStickyInset,
|
|
360
|
+
ownsRefresh: webScrollHost === undefined,
|
|
361
|
+
};
|
|
183
362
|
|
|
184
363
|
useEffect(() => {
|
|
185
|
-
if (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
364
|
+
if (
|
|
365
|
+
!host ||
|
|
366
|
+
resolvedScrollHost === null ||
|
|
367
|
+
(useSlotLayout && !contentBounds)
|
|
368
|
+
)
|
|
369
|
+
return;
|
|
370
|
+
const engine = containNativeListInput(
|
|
371
|
+
() =>
|
|
372
|
+
new NativeListWebEngine(
|
|
373
|
+
host,
|
|
374
|
+
snapshotRef.current,
|
|
375
|
+
callbacksRef.current,
|
|
376
|
+
webVirtualizationEnabledRef.current,
|
|
377
|
+
webSectionIndexContainerRef?.current as unknown as HTMLElement | null,
|
|
378
|
+
fontFamiliesJsonRef.current,
|
|
379
|
+
{
|
|
380
|
+
scrollHost: resolvedScrollHost as HTMLElement | undefined,
|
|
381
|
+
contentBounds: contentBounds ?? undefined,
|
|
382
|
+
...scrollOptionsRef.current,
|
|
383
|
+
}
|
|
384
|
+
)
|
|
193
385
|
);
|
|
386
|
+
if (!engine) return;
|
|
387
|
+
host.style.height = '';
|
|
194
388
|
engineRef.current = engine;
|
|
195
389
|
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
390
|
const initial = initialScrollRef.current;
|
|
201
391
|
if (initial && !didApplyInitialScroll.current) {
|
|
202
392
|
didApplyInitialScroll.current = true;
|
|
@@ -206,10 +396,22 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
206
396
|
engine.scrollToKey(initial.key, initial.scroll);
|
|
207
397
|
}
|
|
208
398
|
return () => {
|
|
399
|
+
// Keep the paused tab in normal flow until its engine is restored.
|
|
400
|
+
host.style.height = `${engine.currentContentHeight()}px`;
|
|
209
401
|
engine.destroy();
|
|
210
402
|
if (engineRef.current === engine) engineRef.current = undefined;
|
|
211
403
|
};
|
|
212
|
-
}, [
|
|
404
|
+
}, [
|
|
405
|
+
host,
|
|
406
|
+
webSectionIndexContainerRef,
|
|
407
|
+
resolvedScrollHost,
|
|
408
|
+
contentBounds,
|
|
409
|
+
useSlotLayout,
|
|
410
|
+
]);
|
|
411
|
+
|
|
412
|
+
useEffect(() => {
|
|
413
|
+
engineRef.current?.setStickyInset(webStickyInset);
|
|
414
|
+
}, [webStickyInset]);
|
|
213
415
|
|
|
214
416
|
useEffect(() => {
|
|
215
417
|
engineRef.current?.setFontFamiliesJson(fontFamiliesJson);
|
|
@@ -223,7 +425,7 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
223
425
|
engineRef.current?.updateCallbacks(callbacksRef.current);
|
|
224
426
|
});
|
|
225
427
|
|
|
226
|
-
|
|
428
|
+
useLayoutEffect(() => {
|
|
227
429
|
const engine = engineRef.current;
|
|
228
430
|
if (!engine || appliedSnapshotRef.current === validatedSnapshot) return;
|
|
229
431
|
engine.applySnapshot(validatedSnapshot);
|
|
@@ -241,25 +443,30 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
241
443
|
|
|
242
444
|
useImperativeHandle(forwardedRef, () => ({
|
|
243
445
|
applySnapshot(nextSnapshot) {
|
|
244
|
-
const next =
|
|
245
|
-
|
|
446
|
+
const next = containNativeListInput(() =>
|
|
447
|
+
normalizeWebSnapshot(nextSnapshot)
|
|
448
|
+
);
|
|
449
|
+
if (!next) return;
|
|
450
|
+
engineRef.current?.applySnapshot(next);
|
|
246
451
|
snapshotRef.current = next;
|
|
452
|
+
acceptedSnapshotRef.current = next;
|
|
247
453
|
appliedSnapshotRef.current = next;
|
|
248
|
-
|
|
454
|
+
synchronizeSlots(next);
|
|
249
455
|
},
|
|
250
456
|
applyPatches(patches) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
457
|
+
const accepted = containNativeListInput(() => validatePatches(patches));
|
|
458
|
+
if (accepted && accepted.length > 0) {
|
|
459
|
+
const engine = engineRef.current;
|
|
460
|
+
if (engine) {
|
|
461
|
+
engine.applyPatches(accepted);
|
|
462
|
+
snapshotRef.current = engine.currentSnapshot();
|
|
463
|
+
} else {
|
|
464
|
+
const next = containNativeListInput(() =>
|
|
465
|
+
applyRowPatches(snapshotRef.current, accepted)
|
|
466
|
+
);
|
|
467
|
+
if (next) snapshotRef.current = next;
|
|
262
468
|
}
|
|
469
|
+
acceptedSnapshotRef.current = snapshotRef.current;
|
|
263
470
|
}
|
|
264
471
|
},
|
|
265
472
|
reconcileSelection(selectedKeys) {
|
|
@@ -339,6 +546,154 @@ export const NativeList = forwardRef<NativeListRef, NativeListProps>(
|
|
|
339
546
|
[]
|
|
340
547
|
);
|
|
341
548
|
|
|
342
|
-
|
|
549
|
+
const setBoundsRef = useCallback(
|
|
550
|
+
(value: React.ComponentRef<typeof View> | null) => {
|
|
551
|
+
setContentBounds(value as unknown as HTMLElement | null);
|
|
552
|
+
},
|
|
553
|
+
[]
|
|
554
|
+
);
|
|
555
|
+
const ownedScrollElementRef = useRef<HTMLElement | null>(null);
|
|
556
|
+
const setScrollHostRef = useCallback(
|
|
557
|
+
(value: React.ComponentRef<typeof View> | null) => {
|
|
558
|
+
const element = value as unknown as HTMLElement | null;
|
|
559
|
+
if (ownedScrollElementRef.current !== element)
|
|
560
|
+
ownedScrollElementRef.current?.removeAttribute(
|
|
561
|
+
'data-collapsible-pager-scroll'
|
|
562
|
+
);
|
|
563
|
+
element?.setAttribute('data-collapsible-pager-scroll', 'true');
|
|
564
|
+
ownedScrollElementRef.current = element;
|
|
565
|
+
setOwnedScrollHost(element);
|
|
566
|
+
},
|
|
567
|
+
[]
|
|
568
|
+
);
|
|
569
|
+
if (!useSlotLayout) return <View {...viewProps} ref={setHostRef} />;
|
|
570
|
+
const padding = slotState.padding;
|
|
571
|
+
const footerBandStyle = { paddingHorizontal: padding };
|
|
572
|
+
const trailingInsetStyle = {
|
|
573
|
+
height: slotState.disclosureExpanded
|
|
574
|
+
? slotState.expandedTrailingInset
|
|
575
|
+
: 0,
|
|
576
|
+
};
|
|
577
|
+
const hasFooterBand =
|
|
578
|
+
listFooter !== undefined ||
|
|
579
|
+
listExpandedContent !== undefined ||
|
|
580
|
+
listStructureToggle !== undefined;
|
|
581
|
+
const content = (
|
|
582
|
+
<View
|
|
583
|
+
ref={sidecarLayout ? undefined : setBoundsRef}
|
|
584
|
+
style={{ position: 'relative', flexShrink: 0, minWidth: 0 }}
|
|
585
|
+
>
|
|
586
|
+
{listHeader !== undefined ? (
|
|
587
|
+
<View style={{ paddingHorizontal: padding }}>{listHeader}</View>
|
|
588
|
+
) : null}
|
|
589
|
+
<View ref={setHostRef} style={{ flexShrink: 0, minWidth: 0 }} />
|
|
590
|
+
{!slotState.hasRows && hasEmptySlot ? (
|
|
591
|
+
<View
|
|
592
|
+
style={{
|
|
593
|
+
paddingHorizontal: padding,
|
|
594
|
+
paddingBottom: slotState.emptyBottomPadding,
|
|
595
|
+
}}
|
|
596
|
+
>
|
|
597
|
+
{listEmpty}
|
|
598
|
+
</View>
|
|
599
|
+
) : null}
|
|
600
|
+
{hasFooterBand ? (
|
|
601
|
+
<View testID="native-list-footer-slot" style={footerBandStyle}>
|
|
602
|
+
{listExpandedContent !== undefined &&
|
|
603
|
+
slotState.hasExpandedContent ? (
|
|
604
|
+
<View
|
|
605
|
+
testID="native-list-expanded-content-slot"
|
|
606
|
+
aria-hidden={!slotState.disclosureExpanded}
|
|
607
|
+
pointerEvents={slotState.disclosureExpanded ? 'auto' : 'none'}
|
|
608
|
+
style={
|
|
609
|
+
slotState.disclosureExpanded
|
|
610
|
+
? undefined
|
|
611
|
+
: collapsedExpandedContentStyle
|
|
612
|
+
}
|
|
613
|
+
>
|
|
614
|
+
{listExpandedContent}
|
|
615
|
+
</View>
|
|
616
|
+
) : null}
|
|
617
|
+
{listStructureToggle !== undefined ? (
|
|
618
|
+
<View
|
|
619
|
+
testID="native-list-structure-toggle-slot"
|
|
620
|
+
aria-hidden={!slotState.disclosurePresent}
|
|
621
|
+
pointerEvents={slotState.disclosurePresent ? 'auto' : 'none'}
|
|
622
|
+
style={
|
|
623
|
+
slotState.disclosurePresent
|
|
624
|
+
? undefined
|
|
625
|
+
: collapsedExpandedContentStyle
|
|
626
|
+
}
|
|
627
|
+
>
|
|
628
|
+
{listStructureToggle}
|
|
629
|
+
</View>
|
|
630
|
+
) : null}
|
|
631
|
+
{slotState.expandedTrailingInset > 0 &&
|
|
632
|
+
(listExpandedContent !== undefined ||
|
|
633
|
+
listStructureToggle !== undefined) ? (
|
|
634
|
+
<View
|
|
635
|
+
testID="native-list-trailing-inset-slot"
|
|
636
|
+
style={trailingInsetStyle}
|
|
637
|
+
/>
|
|
638
|
+
) : null}
|
|
639
|
+
{listFooter}
|
|
640
|
+
</View>
|
|
641
|
+
) : null}
|
|
642
|
+
</View>
|
|
643
|
+
);
|
|
644
|
+
const bandWidth = sidecarLayout
|
|
645
|
+
? Math.min(viewportWidth, sidecarLayout.maxContentWidth)
|
|
646
|
+
: 0;
|
|
647
|
+
const sidecarMargin = Math.max(0, (viewportWidth - bandWidth) / 2);
|
|
648
|
+
const leftWidth = Math.max(
|
|
649
|
+
0,
|
|
650
|
+
bandWidth - (sidecarLayout?.width ?? 0) - (sidecarLayout?.gap ?? 0)
|
|
651
|
+
);
|
|
652
|
+
const scrollContent = sidecarLayout ? (
|
|
653
|
+
<View
|
|
654
|
+
ref={setBoundsRef}
|
|
655
|
+
style={{ position: 'relative', minHeight: sidecarHeight }}
|
|
656
|
+
>
|
|
657
|
+
<View style={{ marginStart: sidecarMargin, width: leftWidth }}>
|
|
658
|
+
{content}
|
|
659
|
+
</View>
|
|
660
|
+
<View
|
|
661
|
+
style={{
|
|
662
|
+
position: 'absolute',
|
|
663
|
+
end: sidecarMargin,
|
|
664
|
+
top: 0,
|
|
665
|
+
width: sidecarLayout.width,
|
|
666
|
+
}}
|
|
667
|
+
onLayout={(event) =>
|
|
668
|
+
setSidecarHeight(event.nativeEvent.layout.height)
|
|
669
|
+
}
|
|
670
|
+
>
|
|
671
|
+
{listSidecar}
|
|
672
|
+
</View>
|
|
673
|
+
</View>
|
|
674
|
+
) : (
|
|
675
|
+
content
|
|
676
|
+
);
|
|
677
|
+
return (
|
|
678
|
+
<View
|
|
679
|
+
{...viewProps}
|
|
680
|
+
onLayout={(event) => {
|
|
681
|
+
setViewportWidth(event.nativeEvent.layout.width);
|
|
682
|
+
viewProps.onLayout?.(event);
|
|
683
|
+
}}
|
|
684
|
+
style={[viewProps.style, { position: 'relative', minHeight: 0 }]}
|
|
685
|
+
>
|
|
686
|
+
{webScrollHost === undefined ? (
|
|
687
|
+
<View
|
|
688
|
+
ref={setScrollHostRef}
|
|
689
|
+
style={{ position: 'absolute', inset: 0, overflow: 'scroll' }}
|
|
690
|
+
>
|
|
691
|
+
{scrollContent}
|
|
692
|
+
</View>
|
|
693
|
+
) : (
|
|
694
|
+
scrollContent
|
|
695
|
+
)}
|
|
696
|
+
</View>
|
|
697
|
+
);
|
|
343
698
|
}
|
|
344
699
|
);
|
package/src/index.ts
CHANGED
|
@@ -14,10 +14,12 @@ export type {
|
|
|
14
14
|
ScrollToKeyParams,
|
|
15
15
|
ScrollToLocationParams,
|
|
16
16
|
ScrollToOffsetParams,
|
|
17
|
+
StructuralTransitionSettledEvent,
|
|
17
18
|
} from './NativeList';
|
|
18
19
|
export type * from './models';
|
|
19
20
|
export {
|
|
20
21
|
applyRowPatches,
|
|
22
|
+
planNativeListPatches,
|
|
21
23
|
serializePatches,
|
|
22
24
|
serializeSnapshot,
|
|
23
25
|
validatePatches,
|