@oxyhq/services 22.8.7 → 22.9.0
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/lib/commonjs/ui/components/OxyAccountDialog.js +30 -39
- package/lib/commonjs/ui/components/OxyAccountDialog.js.map +1 -1
- package/lib/commonjs/ui/components/OxyProvider.js +9 -29
- package/lib/commonjs/ui/components/OxyProvider.js.map +1 -1
- package/lib/commonjs/ui/components/SurfaceScreen.js +146 -0
- package/lib/commonjs/ui/components/SurfaceScreen.js.map +1 -0
- package/lib/commonjs/ui/context/OxyContext.js +32 -1
- package/lib/commonjs/ui/context/OxyContext.js.map +1 -1
- package/lib/commonjs/ui/navigation/bottomSheetManager.js +38 -56
- package/lib/commonjs/ui/navigation/bottomSheetManager.js.map +1 -1
- package/lib/commonjs/ui/navigation/routes.js +7 -57
- package/lib/commonjs/ui/navigation/routes.js.map +1 -1
- package/lib/commonjs/ui/navigation/surfaceNavStack.js +98 -0
- package/lib/commonjs/ui/navigation/surfaceNavStack.js.map +1 -0
- package/lib/commonjs/ui/navigation/surfaceRegistry.js +108 -0
- package/lib/commonjs/ui/navigation/surfaceRegistry.js.map +1 -0
- package/lib/commonjs/ui/navigation/surfaces.js +219 -0
- package/lib/commonjs/ui/navigation/surfaces.js.map +1 -0
- package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js +9 -7
- package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
- package/lib/commonjs/ui/types/surfaceScreen.js +6 -0
- package/lib/commonjs/ui/types/surfaceScreen.js.map +1 -0
- package/lib/module/ui/components/OxyAccountDialog.js +31 -40
- package/lib/module/ui/components/OxyAccountDialog.js.map +1 -1
- package/lib/module/ui/components/OxyProvider.js +10 -30
- package/lib/module/ui/components/OxyProvider.js.map +1 -1
- package/lib/module/ui/components/SurfaceScreen.js +141 -0
- package/lib/module/ui/components/SurfaceScreen.js.map +1 -0
- package/lib/module/ui/context/OxyContext.js +32 -1
- package/lib/module/ui/context/OxyContext.js.map +1 -1
- package/lib/module/ui/navigation/bottomSheetManager.js +37 -53
- package/lib/module/ui/navigation/bottomSheetManager.js.map +1 -1
- package/lib/module/ui/navigation/routes.js +6 -56
- package/lib/module/ui/navigation/routes.js.map +1 -1
- package/lib/module/ui/navigation/surfaceNavStack.js +95 -0
- package/lib/module/ui/navigation/surfaceNavStack.js.map +1 -0
- package/lib/module/ui/navigation/surfaceRegistry.js +102 -0
- package/lib/module/ui/navigation/surfaceRegistry.js.map +1 -0
- package/lib/module/ui/navigation/surfaces.js +207 -0
- package/lib/module/ui/navigation/surfaces.js.map +1 -0
- package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js +8 -7
- package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
- package/lib/module/ui/types/surfaceScreen.js +4 -0
- package/lib/module/ui/types/surfaceScreen.js.map +1 -0
- package/lib/typescript/commonjs/ui/components/OxyAccountDialog.d.ts +29 -27
- package/lib/typescript/commonjs/ui/components/OxyAccountDialog.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts +3 -2
- package/lib/typescript/commonjs/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/SurfaceScreen.d.ts +24 -0
- package/lib/typescript/commonjs/ui/components/SurfaceScreen.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/navigation/bottomSheetManager.d.ts +24 -16
- package/lib/typescript/commonjs/ui/navigation/bottomSheetManager.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/navigation/routes.d.ts +2 -60
- package/lib/typescript/commonjs/ui/navigation/routes.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/navigation/surfaceNavStack.d.ts +51 -0
- package/lib/typescript/commonjs/ui/navigation/surfaceNavStack.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/navigation/surfaceRegistry.d.ts +117 -0
- package/lib/typescript/commonjs/ui/navigation/surfaceRegistry.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/navigation/surfaces.d.ts +79 -0
- package/lib/typescript/commonjs/ui/navigation/surfaces.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/types/surfaceScreen.d.ts +38 -0
- package/lib/typescript/commonjs/ui/types/surfaceScreen.d.ts.map +1 -0
- package/lib/typescript/module/ui/components/OxyAccountDialog.d.ts +29 -27
- package/lib/typescript/module/ui/components/OxyAccountDialog.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/OxyProvider.d.ts +3 -2
- package/lib/typescript/module/ui/components/OxyProvider.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/SurfaceScreen.d.ts +24 -0
- package/lib/typescript/module/ui/components/SurfaceScreen.d.ts.map +1 -0
- package/lib/typescript/module/ui/context/OxyContext.d.ts.map +1 -1
- package/lib/typescript/module/ui/navigation/bottomSheetManager.d.ts +24 -16
- package/lib/typescript/module/ui/navigation/bottomSheetManager.d.ts.map +1 -1
- package/lib/typescript/module/ui/navigation/routes.d.ts +2 -60
- package/lib/typescript/module/ui/navigation/routes.d.ts.map +1 -1
- package/lib/typescript/module/ui/navigation/surfaceNavStack.d.ts +51 -0
- package/lib/typescript/module/ui/navigation/surfaceNavStack.d.ts.map +1 -0
- package/lib/typescript/module/ui/navigation/surfaceRegistry.d.ts +117 -0
- package/lib/typescript/module/ui/navigation/surfaceRegistry.d.ts.map +1 -0
- package/lib/typescript/module/ui/navigation/surfaces.d.ts +79 -0
- package/lib/typescript/module/ui/navigation/surfaces.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
- package/lib/typescript/module/ui/types/surfaceScreen.d.ts +38 -0
- package/lib/typescript/module/ui/types/surfaceScreen.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/ui/components/OxyAccountDialog.tsx +32 -38
- package/src/ui/components/OxyProvider.tsx +12 -34
- package/src/ui/components/SurfaceScreen.tsx +166 -0
- package/src/ui/context/OxyContext.tsx +27 -1
- package/src/ui/navigation/__tests__/getSurfaceConfig.test.ts +39 -0
- package/src/ui/navigation/bottomSheetManager.ts +46 -73
- package/src/ui/navigation/routes.ts +7 -106
- package/src/ui/navigation/surfaceNavStack.ts +110 -0
- package/src/ui/navigation/surfaceRegistry.ts +174 -0
- package/src/ui/navigation/surfaces.ts +244 -0
- package/src/ui/screens/fileManagement/hooks/useFileUploadState.ts +9 -7
- package/src/ui/types/surfaceScreen.ts +38 -0
- package/lib/commonjs/ui/components/BottomSheet.js +0 -49
- package/lib/commonjs/ui/components/BottomSheet.js.map +0 -1
- package/lib/commonjs/ui/components/BottomSheetRouter.js +0 -298
- package/lib/commonjs/ui/components/BottomSheetRouter.js.map +0 -1
- package/lib/module/ui/components/BottomSheet.js +0 -45
- package/lib/module/ui/components/BottomSheet.js.map +0 -1
- package/lib/module/ui/components/BottomSheetRouter.js +0 -292
- package/lib/module/ui/components/BottomSheetRouter.js.map +0 -1
- package/lib/typescript/commonjs/ui/components/BottomSheet.d.ts +0 -29
- package/lib/typescript/commonjs/ui/components/BottomSheet.d.ts.map +0 -1
- package/lib/typescript/commonjs/ui/components/BottomSheetRouter.d.ts +0 -9
- package/lib/typescript/commonjs/ui/components/BottomSheetRouter.d.ts.map +0 -1
- package/lib/typescript/module/ui/components/BottomSheet.d.ts +0 -29
- package/lib/typescript/module/ui/components/BottomSheet.d.ts.map +0 -1
- package/lib/typescript/module/ui/components/BottomSheetRouter.d.ts +0 -9
- package/lib/typescript/module/ui/components/BottomSheetRouter.d.ts.map +0 -1
- package/src/ui/components/BottomSheet.tsx +0 -48
- package/src/ui/components/BottomSheetRouter.tsx +0 -310
- package/src/ui/navigation/__tests__/getSheetConfig.test.ts +0 -36
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentType
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
2
|
import type { BaseScreenProps } from '../types/navigation';
|
|
3
3
|
|
|
4
4
|
// Lazy loading: Screens are loaded on-demand to break require cycles
|
|
@@ -42,7 +42,8 @@ export type RouteName =
|
|
|
42
42
|
| 'AvatarCrop' // Square-crop editor presented before avatar upload
|
|
43
43
|
| 'Notifications' // Per-channel notification preferences
|
|
44
44
|
| 'ConnectedApps' // OAuth-authorized third-party apps the user can revoke
|
|
45
|
-
| 'Preferences'
|
|
45
|
+
| 'Preferences' // General user preferences (theme, reduce-motion, etc.)
|
|
46
|
+
| 'AccountDialog'; // Unified account switcher + sign-in surface (folded OxyAccountDialog body)
|
|
46
47
|
|
|
47
48
|
// Lazy screen loaders - functions that return screen components on-demand
|
|
48
49
|
// This breaks the require cycle by deferring imports until screens are actually needed
|
|
@@ -86,6 +87,10 @@ const screenLoaders: Record<RouteName, () => ComponentType<BaseScreenProps>> = {
|
|
|
86
87
|
Notifications: () => require('../screens/NotificationsScreen').default,
|
|
87
88
|
ConnectedApps: () => require('../screens/ConnectedAppsScreen').default,
|
|
88
89
|
Preferences: () => require('../screens/PreferencesScreen').default,
|
|
90
|
+
// Unified account switcher + sign-in surface. Its body lives in the
|
|
91
|
+
// `OxyAccountDialog` component (folded from the standalone dialog); the
|
|
92
|
+
// surface stack provides the Dialog chrome around it.
|
|
93
|
+
AccountDialog: () => require('../components/OxyAccountDialog').default,
|
|
89
94
|
};
|
|
90
95
|
|
|
91
96
|
// Cache loaded components to avoid re-requiring
|
|
@@ -121,107 +126,3 @@ export const getScreenComponent = (routeName: RouteName): ComponentType<BaseScre
|
|
|
121
126
|
export const isValidRoute = (routeName: string): routeName is RouteName => {
|
|
122
127
|
return routeName in screenLoaders;
|
|
123
128
|
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Configuration that BottomSheetRouter applies to the underlying BottomSheet
|
|
127
|
-
* for a given route. Adding new options here is additive — never rename or
|
|
128
|
-
* remove fields without bumping the consumer surface as a breaking change.
|
|
129
|
-
*/
|
|
130
|
-
export interface SheetRouteConfig {
|
|
131
|
-
/**
|
|
132
|
-
* Which surface hosts the route. `'sheet'` (default) renders the screen in
|
|
133
|
-
* the in-tree `BottomSheet`. `'dialog'` renders it in a responsive Bloom
|
|
134
|
-
* `<Dialog>` (bottom-sheet on narrow, centered card on `md+`) — used for the
|
|
135
|
-
* flagship image picker, which reads better as a centered panel on wide
|
|
136
|
-
* viewports than a full-width sheet. `BottomSheetRouter` keeps BOTH surfaces
|
|
137
|
-
* mounted and routes the active screen into exactly one based on this value.
|
|
138
|
-
*/
|
|
139
|
-
presentation: 'sheet' | 'dialog';
|
|
140
|
-
/**
|
|
141
|
-
* When `false`, BottomSheet skips its internal ScrollView and lets the
|
|
142
|
-
* screen own scrolling. Required for screens that render a FlatList,
|
|
143
|
-
* SectionList, or any other VirtualizedList — nesting one inside a
|
|
144
|
-
* plain ScrollView breaks windowing and triggers a RN warning.
|
|
145
|
-
*
|
|
146
|
-
* Ignored for `presentation: 'dialog'` routes — those don't render in the
|
|
147
|
-
* in-tree `BottomSheet` at all.
|
|
148
|
-
*/
|
|
149
|
-
scrollable: boolean;
|
|
150
|
-
/**
|
|
151
|
-
* Controls the body-pan activation strategy on the underlying bloom
|
|
152
|
-
* `BottomSheet`. `true` uses RNGH's `manualActivation` with scroll-handoff
|
|
153
|
-
* (recommended for scrollable content — the only RNGH 2.x pattern that
|
|
154
|
-
* doesn't steal vertical events from the inner scroller on Android).
|
|
155
|
-
* `false` uses an always-active body pan that gates on scroll offset.
|
|
156
|
-
*
|
|
157
|
-
* Defaults to `true` for all routes — matches the historical in-tree
|
|
158
|
-
* BottomSheet behavior. Per-route opt-out is possible if a screen needs
|
|
159
|
-
* the always-active pan instead.
|
|
160
|
-
*/
|
|
161
|
-
manualActivation: boolean;
|
|
162
|
-
/**
|
|
163
|
-
* When `true`, the backdrop dims proportionally with drag distance (iOS
|
|
164
|
-
* Photos style). Defaults to `true` for all routes — matches the
|
|
165
|
-
* historical in-tree BottomSheet behavior.
|
|
166
|
-
*/
|
|
167
|
-
dynamicBackdrop: boolean;
|
|
168
|
-
/**
|
|
169
|
-
* Optional custom handle slot. When provided, replaces the default
|
|
170
|
-
* 36×5 pill drag handle. The handle remains unconditionally draggable
|
|
171
|
-
* via the dedicated handle gesture (when `manualActivation` is `true`).
|
|
172
|
-
* Use sparingly — screens should default to the standard handle for
|
|
173
|
-
* platform consistency.
|
|
174
|
-
*/
|
|
175
|
-
handleComponent?: () => ReactNode;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Predicate matching FileManagementScreen's internal `isImageOnlyPicker`
|
|
180
|
-
* derivation. When the consumer restricts to image MIME types (no videos,
|
|
181
|
-
* no audio, no documents), FileManagement renders the flagship PhotoPickerView
|
|
182
|
-
* which owns its own FlatList. The sheet must therefore stop scrolling
|
|
183
|
-
* children. Kept in sync with `FileManagementScreen` — both check the same
|
|
184
|
-
* disabled MIME type families.
|
|
185
|
-
*/
|
|
186
|
-
const isFileManagementImageOnlyPicker = (props: Record<string, unknown>): boolean => {
|
|
187
|
-
if (!props.selectMode) return false;
|
|
188
|
-
const disabled = props.disabledMimeTypes;
|
|
189
|
-
if (!Array.isArray(disabled) || disabled.length === 0) return false;
|
|
190
|
-
const has = (predicate: (mt: string) => boolean): boolean =>
|
|
191
|
-
disabled.some((mt) => typeof mt === 'string' && predicate(mt));
|
|
192
|
-
const blocksVideos = has((mt) => mt === 'video/' || mt.startsWith('video/'));
|
|
193
|
-
const blocksAudio = has((mt) => mt === 'audio/' || mt.startsWith('audio/'));
|
|
194
|
-
const blocksDocs = has(
|
|
195
|
-
(mt) => mt === 'application/pdf' || mt === 'application/' || mt.startsWith('application/'),
|
|
196
|
-
);
|
|
197
|
-
return blocksVideos && blocksAudio && blocksDocs;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
/** Defaults shared across all routes — preserves the historical in-tree BS UX. */
|
|
201
|
-
const DEFAULT_SHEET_CONFIG: SheetRouteConfig = {
|
|
202
|
-
presentation: 'sheet',
|
|
203
|
-
scrollable: true,
|
|
204
|
-
manualActivation: true,
|
|
205
|
-
dynamicBackdrop: true,
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Returns the bottom-sheet configuration for a route. Defaults match the
|
|
210
|
-
* pre-refactor in-tree `BottomSheet` (scrollable, manualActivation,
|
|
211
|
-
* dynamicBackdrop). Routes opt out per-field as needed.
|
|
212
|
-
*/
|
|
213
|
-
export const getSheetConfig = (
|
|
214
|
-
routeName: RouteName | null,
|
|
215
|
-
screenProps: Record<string, unknown>,
|
|
216
|
-
): SheetRouteConfig => {
|
|
217
|
-
if (!routeName) return DEFAULT_SHEET_CONFIG;
|
|
218
|
-
if (routeName === 'FileManagement' && isFileManagementImageOnlyPicker(screenProps)) {
|
|
219
|
-
// The flagship photo picker renders in a responsive Bloom `<Dialog>`
|
|
220
|
-
// (bottom-sheet on narrow, centered card on `md+`) rather than the
|
|
221
|
-
// in-tree BottomSheet — it owns its own FlatList and reads better as a
|
|
222
|
-
// centered panel on wide viewports. The Dialog surface, not this
|
|
223
|
-
// config's `scrollable`, governs its scrolling.
|
|
224
|
-
return { ...DEFAULT_SHEET_CONFIG, presentation: 'dialog' };
|
|
225
|
-
}
|
|
226
|
-
return DEFAULT_SHEET_CONFIG;
|
|
227
|
-
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createStore, type StoreApi } from 'zustand/vanilla';
|
|
2
|
+
import type { RouteName } from './routes';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Per-surface route history — the NAV-WITHIN axis.
|
|
6
|
+
*
|
|
7
|
+
* Bloom's surface stack owns DEPTH (a surface presented on top of another). This
|
|
8
|
+
* store owns the ORTHOGONAL axis: the route history INSIDE one SDK surface. Each
|
|
9
|
+
* SDK surface holds its own {@link SurfaceNavStack}; `navigate`/`replace`/`goBack`
|
|
10
|
+
* mutate it and the SAME Bloom surface re-renders its content from the new top
|
|
11
|
+
* frame. It is the per-surface reincarnation of the old global
|
|
12
|
+
* `bottomSheetStore`'s `history` + `currentStep`.
|
|
13
|
+
*
|
|
14
|
+
* `closing`/`closeResult` model a pending dismissal: the surface's `SurfaceScreen`
|
|
15
|
+
* watches them and calls the Bloom surface's `dismiss(result)` from an effect —
|
|
16
|
+
* so a dismiss requested BEFORE the surface has mounted still resolves once it
|
|
17
|
+
* does, with no controls-capture race and no render-phase side effect.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** One frame in a surface's route history. */
|
|
21
|
+
export interface NavFrame {
|
|
22
|
+
route: RouteName;
|
|
23
|
+
props: Record<string, unknown>;
|
|
24
|
+
/** Current wizard step for step-based screens (seeded from `props.initialStep`). */
|
|
25
|
+
step: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface NavStackState {
|
|
29
|
+
/** Bottom → top; the last frame is the visible screen. */
|
|
30
|
+
frames: NavFrame[];
|
|
31
|
+
/** Flipped once a dismiss is requested; the host resolves the Bloom surface. */
|
|
32
|
+
closing: boolean;
|
|
33
|
+
/** The value the surface's `present()` promise resolves with on dismissal. */
|
|
34
|
+
closeResult: unknown;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SurfaceNavStack {
|
|
38
|
+
store: StoreApi<NavStackState>;
|
|
39
|
+
/** Drill in: push a new frame. */
|
|
40
|
+
navigate(route: RouteName, props?: Record<string, unknown>): void;
|
|
41
|
+
/** Swap the top frame in place (no history entry). */
|
|
42
|
+
replace(route: RouteName, props?: Record<string, unknown>): void;
|
|
43
|
+
/** Pop one frame. Returns `false` when already at the root frame. */
|
|
44
|
+
goBack(): boolean;
|
|
45
|
+
/** Whether a back is possible (a deeper frame OR a prior wizard step). */
|
|
46
|
+
canGoBack(): boolean;
|
|
47
|
+
/** Set the current frame's wizard step. */
|
|
48
|
+
setStep(step: number): void;
|
|
49
|
+
/** Request dismissal of the whole surface, resolving its promise with `result`. */
|
|
50
|
+
requestDismiss(result?: unknown): void;
|
|
51
|
+
/** The current (top) frame. */
|
|
52
|
+
getTop(): NavFrame;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function makeFrame(route: RouteName, props?: Record<string, unknown>): NavFrame {
|
|
56
|
+
const resolved = props ?? {};
|
|
57
|
+
const step = typeof resolved.initialStep === 'number' ? resolved.initialStep : 0;
|
|
58
|
+
return { route, props: resolved, step };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createSurfaceNavStack(
|
|
62
|
+
route: RouteName,
|
|
63
|
+
props?: Record<string, unknown>,
|
|
64
|
+
): SurfaceNavStack {
|
|
65
|
+
const store = createStore<NavStackState>(() => ({
|
|
66
|
+
frames: [makeFrame(route, props)],
|
|
67
|
+
closing: false,
|
|
68
|
+
closeResult: undefined,
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
const getTop = (): NavFrame => {
|
|
72
|
+
const { frames } = store.getState();
|
|
73
|
+
return frames[frames.length - 1];
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
store,
|
|
78
|
+
getTop,
|
|
79
|
+
navigate(nextRoute, nextProps) {
|
|
80
|
+
store.setState((state) => ({ frames: [...state.frames, makeFrame(nextRoute, nextProps)] }));
|
|
81
|
+
},
|
|
82
|
+
replace(nextRoute, nextProps) {
|
|
83
|
+
store.setState((state) => ({
|
|
84
|
+
frames: [...state.frames.slice(0, -1), makeFrame(nextRoute, nextProps)],
|
|
85
|
+
}));
|
|
86
|
+
},
|
|
87
|
+
goBack() {
|
|
88
|
+
const { frames } = store.getState();
|
|
89
|
+
if (frames.length <= 1) return false;
|
|
90
|
+
store.setState({ frames: frames.slice(0, -1) });
|
|
91
|
+
return true;
|
|
92
|
+
},
|
|
93
|
+
canGoBack() {
|
|
94
|
+
const { frames } = store.getState();
|
|
95
|
+
return frames.length > 1 || (frames[frames.length - 1]?.step ?? 0) > 0;
|
|
96
|
+
},
|
|
97
|
+
setStep(step) {
|
|
98
|
+
store.setState((state) => {
|
|
99
|
+
const frames = state.frames.slice();
|
|
100
|
+
const index = frames.length - 1;
|
|
101
|
+
frames[index] = { ...frames[index], step };
|
|
102
|
+
return { frames };
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
requestDismiss(result) {
|
|
106
|
+
if (store.getState().closing) return;
|
|
107
|
+
store.setState({ closing: true, closeResult: result });
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { AccountDialogView } from '@oxyhq/core';
|
|
3
|
+
import type { RouteName } from './routes';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The SDK's typed surface registry — the contract layer the SDK stacks on top of
|
|
7
|
+
* Bloom's content-agnostic surface stack (`@oxyhq/bloom/surfaces`). One entry per
|
|
8
|
+
* route describing its `props` (what the presenter must pass) and its `result`
|
|
9
|
+
* (what awaiting `present()` resolves with). Hand-maintained, contract-first:
|
|
10
|
+
* adding a route here is the single edit that types it end to end.
|
|
11
|
+
*
|
|
12
|
+
* For P1 most routes keep permissive `Record<string, unknown>` props + a `void`
|
|
13
|
+
* result — the historical grab-bag `showBottomSheet`/`navigate` props are
|
|
14
|
+
* unchanged. Later phases tighten individual routes without changing this shape.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** One registry entry: the props a route is presented with + its dismissal result. */
|
|
18
|
+
type SurfaceRoute<Props = Record<string, unknown>, Result = void> = {
|
|
19
|
+
props: Props;
|
|
20
|
+
result: Result;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export interface SurfaceRegistry {
|
|
24
|
+
ManageAccount: SurfaceRoute;
|
|
25
|
+
AccountVerification: SurfaceRoute;
|
|
26
|
+
PaymentGateway: SurfaceRoute;
|
|
27
|
+
Profile: SurfaceRoute;
|
|
28
|
+
LanguageSelector: SurfaceRoute;
|
|
29
|
+
PrivacySettings: SurfaceRoute;
|
|
30
|
+
SearchSettings: SurfaceRoute;
|
|
31
|
+
FileManagement: SurfaceRoute;
|
|
32
|
+
HelpSupport: SurfaceRoute;
|
|
33
|
+
FAQ: SurfaceRoute;
|
|
34
|
+
Feedback: SurfaceRoute;
|
|
35
|
+
LegalDocuments: SurfaceRoute;
|
|
36
|
+
AppInfo: SurfaceRoute;
|
|
37
|
+
PremiumSubscription: SurfaceRoute;
|
|
38
|
+
WelcomeNewUser: SurfaceRoute;
|
|
39
|
+
UserLinks: SurfaceRoute;
|
|
40
|
+
HistoryView: SurfaceRoute;
|
|
41
|
+
SavesCollections: SurfaceRoute;
|
|
42
|
+
EditProfile: SurfaceRoute;
|
|
43
|
+
EditProfileField: SurfaceRoute;
|
|
44
|
+
LearnMoreUsernames: SurfaceRoute;
|
|
45
|
+
TrustCenter: SurfaceRoute;
|
|
46
|
+
TrustLeaderboard: SurfaceRoute;
|
|
47
|
+
TrustRewards: SurfaceRoute;
|
|
48
|
+
TrustRules: SurfaceRoute;
|
|
49
|
+
AboutTrust: SurfaceRoute;
|
|
50
|
+
TrustFAQ: SurfaceRoute;
|
|
51
|
+
FollowersList: SurfaceRoute;
|
|
52
|
+
FollowingList: SurfaceRoute;
|
|
53
|
+
CreateAccount: SurfaceRoute;
|
|
54
|
+
AccountMembers: SurfaceRoute;
|
|
55
|
+
AccountSettings: SurfaceRoute;
|
|
56
|
+
AvatarCrop: SurfaceRoute;
|
|
57
|
+
Notifications: SurfaceRoute;
|
|
58
|
+
ConnectedApps: SurfaceRoute;
|
|
59
|
+
Preferences: SurfaceRoute;
|
|
60
|
+
/** Unified account switcher + sign-in surface (folded `OxyAccountDialog` body). */
|
|
61
|
+
AccountDialog: SurfaceRoute<{ initialView?: AccountDialogView }>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Compile-time guard: the registry keys must be EXACTLY the route names. If a new
|
|
66
|
+
* `RouteName` is added without a registry entry (or vice-versa) this alias
|
|
67
|
+
* resolves to `never` and the `satisfies` assertion below fails to type-check.
|
|
68
|
+
*/
|
|
69
|
+
type RegistryCoversRoutes = [RouteName] extends [keyof SurfaceRegistry]
|
|
70
|
+
? [keyof SurfaceRegistry] extends [RouteName]
|
|
71
|
+
? true
|
|
72
|
+
: never
|
|
73
|
+
: never;
|
|
74
|
+
const _registryCoversRoutes: RegistryCoversRoutes = true;
|
|
75
|
+
void _registryCoversRoutes;
|
|
76
|
+
|
|
77
|
+
/** Typed props a route is presented with. */
|
|
78
|
+
export type SurfaceProps<K extends RouteName> = SurfaceRegistry[K]['props'];
|
|
79
|
+
/** What awaiting a route's `present()` resolves with when it is dismissed. */
|
|
80
|
+
export type SurfaceResult<K extends RouteName> = SurfaceRegistry[K]['result'];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* How a surface renders — the SDK's presentation taxonomy. Each value maps to a
|
|
84
|
+
* concrete Bloom `Dialog` placement/chrome in `surfaces.ts`:
|
|
85
|
+
*
|
|
86
|
+
* - `'sheet'` → responsive `{ base: 'bottom', md: 'center' }` (the default:
|
|
87
|
+
* a bottom sheet on narrow viewports, a centered card on wide).
|
|
88
|
+
* - `'center'` → a plain centered modal at every width.
|
|
89
|
+
* - `'drawer'` → responsive `{ base: 'bottom', md: 'left' }` side drawer.
|
|
90
|
+
* - `'fullScreen'` → approximated with the shared `Dialog`: a full-height sheet /
|
|
91
|
+
* large centered card, flush (`contentPadding: 0`) content, a
|
|
92
|
+
* black canvas and programmatic-only dismiss (the flagship
|
|
93
|
+
* image picker). A real Bloom `'fullScreen'` placement is a
|
|
94
|
+
* follow-up if the approximation reads wrong on device.
|
|
95
|
+
*/
|
|
96
|
+
export type SurfacePresentation = 'sheet' | 'center' | 'drawer' | 'fullScreen';
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Per-route surface configuration. Merges the historical `SheetRouteConfig`
|
|
100
|
+
* knobs with the new {@link SurfacePresentation}.
|
|
101
|
+
*
|
|
102
|
+
* NOTE: `scrollable` / `manualActivation` / `dynamicBackdrop` / `handleComponent`
|
|
103
|
+
* describe the in-tree bottom-sheet's pan + scroll behaviour. On Bloom's `Dialog`
|
|
104
|
+
* surface those concerns are now owned by the shared `DialogBottomSheet` (it opts
|
|
105
|
+
* pure custom children OUT of its internal ScrollView and manages the pan itself),
|
|
106
|
+
* so for P1 these fields are informational — reserved for a future Bloom
|
|
107
|
+
* bottom-placement passthrough. `presentation` (+ `scrollable` for the picker's
|
|
108
|
+
* flush layout) is what actually drives the surface today.
|
|
109
|
+
*/
|
|
110
|
+
export interface SurfaceRouteConfig {
|
|
111
|
+
/** Which surface hosts the route. */
|
|
112
|
+
presentation: SurfacePresentation;
|
|
113
|
+
/**
|
|
114
|
+
* When `false`, the route owns its own scroll container (a FlatList /
|
|
115
|
+
* SectionList / VirtualizedList) and the host must not wrap it in a ScrollView.
|
|
116
|
+
*/
|
|
117
|
+
scrollable: boolean;
|
|
118
|
+
/** Body-pan activation strategy — reserved (owned by Bloom's Dialog surface). */
|
|
119
|
+
manualActivation: boolean;
|
|
120
|
+
/** Drag-proportional backdrop dim — reserved (owned by Bloom's Dialog surface). */
|
|
121
|
+
dynamicBackdrop: boolean;
|
|
122
|
+
/** Optional custom drag-handle slot — reserved (owned by Bloom's Dialog surface). */
|
|
123
|
+
handleComponent?: () => ReactNode;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Defaults shared across all routes — the canonical responsive "sheet". */
|
|
127
|
+
const DEFAULT_SURFACE_CONFIG: SurfaceRouteConfig = {
|
|
128
|
+
presentation: 'sheet',
|
|
129
|
+
scrollable: true,
|
|
130
|
+
manualActivation: true,
|
|
131
|
+
dynamicBackdrop: true,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Predicate matching `FileManagementScreen`'s internal `isImageOnlyPicker`
|
|
136
|
+
* derivation. When the consumer restricts to image MIME types (no videos, no
|
|
137
|
+
* audio, no documents), FileManagement renders the flagship `PhotoPickerView`,
|
|
138
|
+
* which owns its own FlatList and reads best as a full-bleed picker. Kept in sync
|
|
139
|
+
* with `FileManagementScreen` — both check the same disabled MIME type families.
|
|
140
|
+
*/
|
|
141
|
+
const isFileManagementImageOnlyPicker = (props: Record<string, unknown>): boolean => {
|
|
142
|
+
if (!props.selectMode) return false;
|
|
143
|
+
const disabled = props.disabledMimeTypes;
|
|
144
|
+
if (!Array.isArray(disabled) || disabled.length === 0) return false;
|
|
145
|
+
const has = (predicate: (mt: string) => boolean): boolean =>
|
|
146
|
+
disabled.some((mt) => typeof mt === 'string' && predicate(mt));
|
|
147
|
+
const blocksVideos = has((mt) => mt === 'video/' || mt.startsWith('video/'));
|
|
148
|
+
const blocksAudio = has((mt) => mt === 'audio/' || mt.startsWith('audio/'));
|
|
149
|
+
const blocksDocs = has(
|
|
150
|
+
(mt) => mt === 'application/pdf' || mt === 'application/' || mt.startsWith('application/'),
|
|
151
|
+
);
|
|
152
|
+
return blocksVideos && blocksAudio && blocksDocs;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Resolve the surface configuration for a route + props. Defaults to the
|
|
157
|
+
* responsive sheet; the image-only FileManagement picker upgrades to a full-bleed
|
|
158
|
+
* `'fullScreen'` surface that owns its own scrolling.
|
|
159
|
+
*/
|
|
160
|
+
export const getSurfaceConfig = (
|
|
161
|
+
route: RouteName,
|
|
162
|
+
props: Record<string, unknown>,
|
|
163
|
+
): SurfaceRouteConfig => {
|
|
164
|
+
if (route === 'FileManagement' && isFileManagementImageOnlyPicker(props)) {
|
|
165
|
+
return { ...DEFAULT_SURFACE_CONFIG, presentation: 'fullScreen', scrollable: false };
|
|
166
|
+
}
|
|
167
|
+
return DEFAULT_SURFACE_CONFIG;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** Convenience: just the presentation taxonomy for a route + props. */
|
|
171
|
+
export const getSurfacePresentation = (
|
|
172
|
+
route: RouteName,
|
|
173
|
+
props: Record<string, unknown>,
|
|
174
|
+
): SurfacePresentation => getSurfaceConfig(route, props).presentation;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import type { ViewStyle } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
surfaces as bloomSurfaces,
|
|
5
|
+
type PresentOptions,
|
|
6
|
+
type SurfaceControls,
|
|
7
|
+
} from '@oxyhq/bloom/surfaces';
|
|
8
|
+
import SurfaceScreen from '../components/SurfaceScreen';
|
|
9
|
+
import type { RouteName } from './routes';
|
|
10
|
+
import {
|
|
11
|
+
getSurfaceConfig,
|
|
12
|
+
getSurfacePresentation,
|
|
13
|
+
type SurfacePresentation,
|
|
14
|
+
type SurfaceProps,
|
|
15
|
+
type SurfaceResult,
|
|
16
|
+
type SurfaceRouteConfig,
|
|
17
|
+
} from './surfaceRegistry';
|
|
18
|
+
import { createSurfaceNavStack, type SurfaceNavStack } from './surfaceNavStack';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The SDK's typed surface API — a route registry layered on top of Bloom's
|
|
22
|
+
* content-agnostic surface stack (`@oxyhq/bloom/surfaces`).
|
|
23
|
+
*
|
|
24
|
+
* `present(route)` opens a NEW Bloom surface (the DEPTH axis) whose content is a
|
|
25
|
+
* {@link SurfaceScreen} driven by the route's own {@link SurfaceNavStack} (the
|
|
26
|
+
* NAV-WITHIN axis). Navigating within that surface mutates its nav stack and
|
|
27
|
+
* re-renders the SAME Bloom surface; presenting stacks another surface on top.
|
|
28
|
+
*
|
|
29
|
+
* Bloom coordinates z-order / backdrop / dismiss across every surface (SDK's and
|
|
30
|
+
* apps'), so nothing clashes.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** Responsive "sheet": bottom sheet on narrow, centered card on wide. */
|
|
34
|
+
const SHEET_PLACEMENT = { base: 'bottom', md: 'center' } as const;
|
|
35
|
+
|
|
36
|
+
/** Full-bleed black canvas for the `'fullScreen'` approximation (image picker). */
|
|
37
|
+
const FULLSCREEN_SURFACE_STYLE: ViewStyle = { backgroundColor: '#000000', overflow: 'hidden' };
|
|
38
|
+
|
|
39
|
+
/** Map a route's presentation taxonomy onto concrete Bloom `Dialog` options. */
|
|
40
|
+
function bloomOptionsFor(config: SurfaceRouteConfig): PresentOptions {
|
|
41
|
+
switch (config.presentation) {
|
|
42
|
+
case 'center':
|
|
43
|
+
return { placement: 'center' };
|
|
44
|
+
case 'drawer':
|
|
45
|
+
return { placement: { base: 'bottom', md: 'left' } };
|
|
46
|
+
case 'fullScreen':
|
|
47
|
+
// Approximate a full-screen surface with the shared `Dialog`: a tall
|
|
48
|
+
// sheet / large centered card, flush content, a black canvas and
|
|
49
|
+
// programmatic-only dismiss — matching the shipped image-picker Dialog.
|
|
50
|
+
return {
|
|
51
|
+
placement: SHEET_PLACEMENT,
|
|
52
|
+
contentPadding: 0,
|
|
53
|
+
maxWidth: 640,
|
|
54
|
+
maxHeightRatio: 0.9,
|
|
55
|
+
dismissOnBackdrop: false,
|
|
56
|
+
style: FULLSCREEN_SURFACE_STYLE,
|
|
57
|
+
panelStyle: FULLSCREEN_SURFACE_STYLE,
|
|
58
|
+
};
|
|
59
|
+
default:
|
|
60
|
+
return { placement: SHEET_PLACEMENT };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A live handle to a presented SDK surface. Exposes DEPTH controls (`dismiss`,
|
|
66
|
+
* `result`) and NAV-WITHIN controls (`navigate`/`replace`/`goBack`/`setStep`) that
|
|
67
|
+
* drive this surface's own nav stack. Held by the `showBottomSheet` adapter (base
|
|
68
|
+
* surface) and by `OxyContext` (the AccountDialog surface).
|
|
69
|
+
*/
|
|
70
|
+
export interface SurfaceInstance<K extends RouteName = RouteName> {
|
|
71
|
+
readonly route: RouteName;
|
|
72
|
+
readonly presentation: SurfacePresentation;
|
|
73
|
+
navigate: (route: RouteName, props?: Record<string, unknown>) => void;
|
|
74
|
+
replace: (route: RouteName, props?: Record<string, unknown>) => void;
|
|
75
|
+
goBack: () => boolean;
|
|
76
|
+
canGoBack: () => boolean;
|
|
77
|
+
setStep: (step: number) => void;
|
|
78
|
+
dismiss: (result?: SurfaceResult<K>) => void;
|
|
79
|
+
readonly result: Promise<SurfaceResult<K> | undefined>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The type-erased handle the `showBottomSheet` adapter needs from a tracked
|
|
84
|
+
* surface: what it hosts, and how to drive/dismiss it. Kept result-type-free so
|
|
85
|
+
* the (generic) `SurfaceInstance<K>` never has to be widened into a shared array.
|
|
86
|
+
*/
|
|
87
|
+
interface TrackedSurface {
|
|
88
|
+
readonly route: RouteName;
|
|
89
|
+
readonly presentation: SurfacePresentation;
|
|
90
|
+
navigate: (route: RouteName, props?: Record<string, unknown>) => void;
|
|
91
|
+
goBack: () => boolean;
|
|
92
|
+
dismiss: () => void;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Active SDK "route" surfaces (the `showBottomSheet` lineage), bottom → top.
|
|
97
|
+
* `present`/`presentRoute` register here; `presentDetached` (AccountDialog) does
|
|
98
|
+
* NOT, so the base-sheet navigation logic never treats the account modal as a
|
|
99
|
+
* navigable base. Entries self-remove when their surface is dismissed.
|
|
100
|
+
*/
|
|
101
|
+
const activeRouteSurfaces: TrackedSurface[] = [];
|
|
102
|
+
|
|
103
|
+
function presentInternal<K extends RouteName>(
|
|
104
|
+
route: K,
|
|
105
|
+
props: Record<string, unknown>,
|
|
106
|
+
opts: PresentOptions | undefined,
|
|
107
|
+
track: boolean,
|
|
108
|
+
): SurfaceInstance<K> {
|
|
109
|
+
const navStack = createSurfaceNavStack(route, props);
|
|
110
|
+
const config = getSurfaceConfig(route, props);
|
|
111
|
+
const bloomOpts: PresentOptions = { label: route, ...bloomOptionsFor(config), ...opts };
|
|
112
|
+
|
|
113
|
+
const result = bloomSurfaces.present<SurfaceResult<K>>((surface: SurfaceControls) =>
|
|
114
|
+
createElement(SurfaceScreen, { navStack, surface, presentation: config.presentation }),
|
|
115
|
+
bloomOpts,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const instance: SurfaceInstance<K> = {
|
|
119
|
+
route,
|
|
120
|
+
presentation: config.presentation,
|
|
121
|
+
navigate: (nextRoute, nextProps) => navStack.navigate(nextRoute, nextProps),
|
|
122
|
+
replace: (nextRoute, nextProps) => navStack.replace(nextRoute, nextProps),
|
|
123
|
+
goBack: () => navStack.goBack(),
|
|
124
|
+
canGoBack: () => navStack.canGoBack(),
|
|
125
|
+
setStep: (step) => navStack.setStep(step),
|
|
126
|
+
dismiss: (dismissResult) => navStack.requestDismiss(dismissResult),
|
|
127
|
+
result,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
if (track) {
|
|
131
|
+
const tracked: TrackedSurface = {
|
|
132
|
+
route: instance.route,
|
|
133
|
+
presentation: instance.presentation,
|
|
134
|
+
navigate: instance.navigate,
|
|
135
|
+
goBack: instance.goBack,
|
|
136
|
+
dismiss: () => instance.dismiss(),
|
|
137
|
+
};
|
|
138
|
+
activeRouteSurfaces.push(tracked);
|
|
139
|
+
result.finally(() => {
|
|
140
|
+
const index = activeRouteSurfaces.indexOf(tracked);
|
|
141
|
+
if (index >= 0) activeRouteSurfaces.splice(index, 1);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return instance;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Present a NEW route surface on top of the stack (the DEPTH axis). Resolves with
|
|
150
|
+
* the value the surface is dismissed with. Registered in the route-surface stack.
|
|
151
|
+
*/
|
|
152
|
+
export function present<K extends RouteName>(
|
|
153
|
+
route: K,
|
|
154
|
+
props?: SurfaceProps<K>,
|
|
155
|
+
opts?: PresentOptions,
|
|
156
|
+
): SurfaceInstance<K> {
|
|
157
|
+
return presentInternal(route, (props ?? {}) as Record<string, unknown>, opts, true);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Present a surface that is NOT part of the `showBottomSheet` base-navigation
|
|
162
|
+
* lineage (the AccountDialog modal). Otherwise identical to {@link present}.
|
|
163
|
+
*/
|
|
164
|
+
export function presentDetached<K extends RouteName>(
|
|
165
|
+
route: K,
|
|
166
|
+
props?: SurfaceProps<K>,
|
|
167
|
+
opts?: PresentOptions,
|
|
168
|
+
): SurfaceInstance<K> {
|
|
169
|
+
return presentInternal(route, (props ?? {}) as Record<string, unknown>, opts, false);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Untyped present for the adapter, the nav helpers, and the `SurfaceScreen`
|
|
174
|
+
* binding (where the route is a runtime value and its props are already erased).
|
|
175
|
+
*/
|
|
176
|
+
export function presentRoute(route: RouteName, props?: Record<string, unknown>): SurfaceInstance {
|
|
177
|
+
return presentInternal(route, props ?? {}, undefined, true);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The top-most active route surface, or `undefined` when none are open. */
|
|
181
|
+
export function topRouteSurface(): TrackedSurface | undefined {
|
|
182
|
+
return activeRouteSurfaces[activeRouteSurfaces.length - 1];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Dismiss every active route surface (the whole `showBottomSheet` session). The
|
|
187
|
+
* AccountDialog is untracked, so it is untouched. Iterates a snapshot because
|
|
188
|
+
* `dismiss` mutates `activeRouteSurfaces` asynchronously as surfaces settle.
|
|
189
|
+
*/
|
|
190
|
+
export function closeAllRouteSurfaces(): void {
|
|
191
|
+
for (const instance of [...activeRouteSurfaces].reverse()) instance.dismiss();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Drill in from a screen: navigate WITHIN the current surface when the target's
|
|
196
|
+
* presentation matches, else present the target as a NEW surface on top (so a
|
|
197
|
+
* sheet screen opening the full-bleed picker gets the right chrome).
|
|
198
|
+
*/
|
|
199
|
+
export function navigateWithinOrPresent(
|
|
200
|
+
currentPresentation: SurfacePresentation,
|
|
201
|
+
navStack: SurfaceNavStack,
|
|
202
|
+
route: RouteName,
|
|
203
|
+
props?: Record<string, unknown>,
|
|
204
|
+
): void {
|
|
205
|
+
const nextProps = props ?? {};
|
|
206
|
+
if (getSurfacePresentation(route, nextProps) === currentPresentation) {
|
|
207
|
+
navStack.navigate(route, nextProps);
|
|
208
|
+
} else {
|
|
209
|
+
presentRoute(route, nextProps);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Replace variant of {@link navigateWithinOrPresent}. */
|
|
214
|
+
export function replaceWithinOrPresent(
|
|
215
|
+
currentPresentation: SurfacePresentation,
|
|
216
|
+
navStack: SurfaceNavStack,
|
|
217
|
+
route: RouteName,
|
|
218
|
+
props?: Record<string, unknown>,
|
|
219
|
+
): void {
|
|
220
|
+
const nextProps = props ?? {};
|
|
221
|
+
if (getSurfacePresentation(route, nextProps) === currentPresentation) {
|
|
222
|
+
navStack.replace(route, nextProps);
|
|
223
|
+
} else {
|
|
224
|
+
presentRoute(route, nextProps);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The SDK's imperative surface API (a module singleton). `present` is the typed
|
|
230
|
+
* route presenter; `dismissAll` unwinds the whole session. Not yet exported from
|
|
231
|
+
* the package root — the public `surfaces`/`useSurfaces` API lands in a later
|
|
232
|
+
* phase; for P1 the internal adapters (`showBottomSheet`, `openAccountDialog`)
|
|
233
|
+
* are the only public entry points.
|
|
234
|
+
*/
|
|
235
|
+
export const surfaces = {
|
|
236
|
+
present: <K extends RouteName>(route: K, props?: SurfaceProps<K>, opts?: PresentOptions) =>
|
|
237
|
+
present(route, props, opts).result,
|
|
238
|
+
dismissAll: closeAllRouteSurfaces,
|
|
239
|
+
} as const;
|
|
240
|
+
|
|
241
|
+
/** Hook form of {@link surfaces} (stable singleton). */
|
|
242
|
+
export function useSurfaces(): typeof surfaces {
|
|
243
|
+
return surfaces;
|
|
244
|
+
}
|