Open History to see the last commit
1import {
2 createNavigatorFactory,
3 NavigationContext,
4 NavigationRouteContext,
5 StackRouter,
6 useNavigationBuilder,
7 type NavigatorTypeBagBase,
8 type ParamListBase,
9 type StackActionHelpers,
10 type StackNavigationState,
11 type StackRouterOptions,
12 type StaticConfig,
13 type TypedNavigator,
14} from "@react-navigation/native";
15import {
16 NativeStackView,
17 type NativeStackNavigationEventMap,
18 type NativeStackNavigationOptions,
19 type NativeStackNavigatorProps,
20 type NativeStackTypeBag,
21} from "@react-navigation/native-stack";
22import { Fragment, use, useEffect, useRef, useState, type ComponentProps } from "react";
23import { StyleSheet, useWindowDimensions, View } from "react-native";
24import { Split, type SplitHostCommands } from "react-native-screens";
25import { SafeAreaView } from "react-native-safe-area-context";
26import { GestureHandlerRootView } from "react-native-gesture-handler";
27import { EnvironmentId, ThreadId } from "@t3tools/contracts";
28import { scopedThreadKey } from "../../lib/scopedEntities";
29import { WorkspaceTabsProvider, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
30import { WorkspaceNativeTabs } from "../workspace/WorkspaceNativeTabs.ios";
31import { workspaceUsesColumns } from "../workspace/workspace-tabs-state";
32import { isSettingsRoute, settingsOpenIn } from "../settings/settings-navigation";
33import { workspaceRoutesOf } from "./workspace-overlay-routes";
34import { setNativelyPoppingWorkspaceRoute } from "../workspace/workspace-detail-selection";
35import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
36
37import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
38import { WorkspacePaneDivider } from "./workspace-pane-divider";
39import { WorkspaceEmptyDetail } from "./WorkspaceEmptyDetail";
40import { NativeColumnContent as ColumnContent } from "../../native/NativeColumnContent.ios";
41import {
42 modalEnvelopeOptions,
43 V5CardStackView,
44 V5StackView,
45} from "../../native/createV5StackNavigator.ios";
46import {
47 useNativeWorkspaceColumnsReady,
48 useNativeWorkspaceColumnsSupported,
49} from "../../native/NativeWorkspaceColumns";
50import { V5StackHeader } from "../../native/V5StackHeader.ios";
51import type { AppNativeStackNavigationOptions } from "../../native/StackHeader";
52import {
53 collapsedSplitTransition,
54 nativeWorkspacePopAction,
55 projectWorkspaceStack,
56 partitionStackPresentations,
57 reconcileStackScreens,
58 type CollapsedSplitColumn,
59} from "../../native/workspace-stack-projection";
60import {
61 NativePrimaryColumnContext,
62 NativeWorkspaceInspectorContext,
63 NativeWorkspaceModeContext,
64 WorkspaceSlotOptionsContext,
65 slotScreenOptions,
66} from "../../native/v5-workspace-context";
67
68type ViewProps = ComponentProps<typeof NativeStackView>;
69type Descriptor = ViewProps["descriptors"][string];
70type Route = ViewProps["state"]["routes"][number];
71
72const isPullRequestRoute = (route: Route) =>
73 route.name === "PullRequest" ||
74 route.name === "PullRequestFile" ||
75 route.name === "PullRequestFiles";
76
77/** Beside the list, the first Settings page shows on one native screen that swaps its content. */
78const SETTINGS_DETAIL_SCREEN = "settings-detail";
79
80function ColumnScreen(props: {
81 readonly descriptor: Descriptor;
82 readonly screenKey?: string;
83 readonly primary?: boolean;
84 readonly attached?: boolean;
85 readonly selectedThreadKey?: string | null;
86 readonly selectedPullRequestKey?: string | null;
87 readonly onDismiss: (routeKey: string, native: boolean) => void;
88 readonly onAppearance: (type: "willAppear" | "didAppear" | "willDisappear", key: string) => void;
89 readonly onCompose?: () => void;
90 readonly navigation: ViewProps["navigation"];
91}) {
92 const { descriptor } = props;
93 // Options a screen set inside this workspace tab slot, over its route's.
94 const options = slotScreenOptions(
95 use(WorkspaceSlotOptionsContext),
96 descriptor.route.key,
97 descriptor.options,
98 );
99 const [presented, setPresented] = useState(false);
100 const primaryColumn = props.primary
101 ? {
102 presented,
103 selectedThreadKey: props.selectedThreadKey ?? null,
104 selectedPullRequestKey: props.selectedPullRequestKey ?? null,
105 }
106 : null;
107 const key = descriptor.route.key;
108 return (
109 <Split.Screen
110 screenKey={props.screenKey ?? key}
111 activityMode={props.attached === false ? "detached" : "attached"}
112 onDismiss={(event) => {
113 props.onDismiss(key, event.nativeEvent.isNativeDismiss);
114 }}
115 onWillAppear={() => {
116 props.onAppearance("willAppear", key);
117 props.navigation.emit({ type: "transitionStart", target: key, data: { closing: false } });
118 }}
119 onDidAppear={() => {
120 setPresented(true);
121 props.onAppearance("didAppear", key);
122 props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: false } });
123 }}
124 onWillDisappear={() => {
125 setPresented(false);
126 props.onAppearance("willDisappear", key);
127 props.navigation.emit({ type: "transitionStart", target: key, data: { closing: true } });
128 }}
129 onDidDisappear={() =>
130 props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: true } })
131 }
132 >
133 <NavigationContext value={descriptor.navigation}>
134 <NavigationRouteContext value={descriptor.route}>
135 <V5StackHeader
136 options={options}
137 canGoBack={!props.primary}
138 column={props.primary ? "primary" : "detail"}
139 onCompose={
140 descriptor.route.params &&
141 "draft" in descriptor.route.params &&
142 descriptor.route.params.draft
143 ? undefined
144 : props.onCompose
145 }
146 />
147 <ColumnContent
148 primary={props.primary}
149 insetHorizontally={
150 (options as AppNativeStackNavigationOptions).nativeContentInsetHorizontally
151 }
152 >
153 <NativePrimaryColumnContext value={primaryColumn}>
154 {/* The Settings slot swaps pages here; its column keeps its measured insets. */}
155 <Fragment key={key}>{descriptor.render()}</Fragment>
156 </NativePrimaryColumnContext>
157 </ColumnContent>
158 </NavigationRouteContext>
159 </NavigationContext>
160 </Split.Screen>
161 );
162}
163
164function WorkspaceColumns(
165 props: ViewProps & { readonly primary: Route; readonly detail: Route[] },
166) {
167 const {
168 layout,
169 panes,
170 togglePrimarySidebar,
171 setPrimarySidebarVisible,
172 toggleAuxiliaryPane,
173 startNewTask,
174 openWorkspaceTab,
175 sidebarByOrientation,
176 } = useAdaptiveWorkspaceLayout();
177 const deviceType = useDeviceType();
178 const windowDimensions = useWindowDimensions();
179 const nativeMetrics = useNativeLayoutMetrics();
180 const viewportWidth = nativeMetrics?.width ?? windowDimensions.width;
181 const [inspectorWidthFraction, setInspectorWidthFraction] = useState(0.4);
182 const inspectorWidth = Math.max(
183 260,
184 Math.min(viewportWidth * 0.6, viewportWidth * inspectorWidthFraction),
185 );
186 const resizeStartWidth = useRef(inspectorWidth);
187 const settingsDetailIn = (detail: readonly Route[]) =>
188 layout.usesSplitView && detail[0] && isSettingsRoute(detail[0].name) ? detail[0] : undefined;
189 // Split screens must remain mounted while UIKit animates a detached route away.
190 const [screens, setScreens] = useState({
191 routes: props.detail,
192 descriptors: props.descriptors,
193 observedRoutes: props.detail,
194 observedDescriptors: props.descriptors,
195 completed: new Set<string>(),
196 });
197 if (
198 screens.observedRoutes !== props.detail ||
199 screens.observedDescriptors !== props.descriptors
200 ) {
201 const active = new Set(props.detail.map((route) => route.key));
202 const settingsSlot = settingsDetailIn(props.detail);
203 const routes = reconcileStackScreens(screens.routes, props.detail, screens.completed).filter(
204 // The slot's native screen stays; the pages it showed, and any above them, just go.
205 (route) => !settingsSlot || active.has(route.key) || !isSettingsRoute(route.name),
206 );
207 const retained = new Set(routes.map((route) => route.key));
208 setScreens({
209 routes,
210 descriptors: Object.fromEntries(
211 Object.entries({ ...screens.descriptors, ...props.descriptors }).filter(([key]) =>
212 retained.has(key),
213 ),
214 ),
215 observedRoutes: props.detail,
216 observedDescriptors: props.descriptors,
217 completed: new Set([...screens.completed].filter((key) => active.has(key))),
218 });
219 }
220
221 const workspaceTabs = useWorkspaceTabs();
222 const selectedTab = workspaceTabs?.state.selectedTab;
223 const settingsOpen = workspaceTabs?.settingsOpen ?? false;
224 const openNewTask = startNewTask;
225 // The cover detail rail needs room for thread tools above the fixed tabs.
226 // The unfolded Duo keeps compose in its detail bar.
227 const detailCompose =
228 deviceType === "duo-unfolded" && selectedTab !== "pullRequests" && !settingsOpen
229 ? openNewTask
230 : undefined;
231 const inspector = use(NativeWorkspaceInspectorContext);
232 const hostRef = useRef<SplitHostCommands>(null);
233 const activeDetailKey = props.detail.at(-1)?.key;
234 const compactColumn = activeDetailKey ? "secondary" : "primary";
235 const collapsed = useRef(!layout.usesSplitView);
236 const collapsedColumn = useRef<CollapsedSplitColumn>({ visible: compactColumn, leaving: null });
237 const threadParams = props.detail.findLast((route) => route.name === "Thread")?.params;
238 const pullRequestParams = props.detail.findLast(isPullRequestRoute)?.params;
239 const selectedPullRequestKey =
240 pullRequestParams &&
241 "environmentId" in pullRequestParams &&
242 "host" in pullRequestParams &&
243 "repository" in pullRequestParams &&
244 "number" in pullRequestParams &&
245 typeof pullRequestParams.environmentId === "string" &&
246 typeof pullRequestParams.host === "string" &&
247 typeof pullRequestParams.repository === "string" &&
248 typeof pullRequestParams.number === "number"
249 ? `${pullRequestParams.environmentId}:${pullRequestParams.host}:${pullRequestParams.repository}:${pullRequestParams.number}`
250 : null;
251 const selectedThreadKey =
252 threadParams &&
253 "environmentId" in threadParams &&
254 "threadId" in threadParams &&
255 typeof threadParams.environmentId === "string" &&
256 typeof threadParams.threadId === "string"
257 ? scopedThreadKey(
258 EnvironmentId.make(threadParams.environmentId),
259 ThreadId.make(threadParams.threadId),
260 )
261 : null;
262 const handleNativeDismiss = (key: string, native: boolean) => {
263 setScreens((current) => ({
264 ...current,
265 routes: current.routes.filter((route) => route.key !== key),
266 completed: new Set([...current.completed, key]),
267 }));
268 if (native) {
269 const state = props.navigation.getState();
270 const action = nativeWorkspacePopAction(state, key);
271 if (action) props.navigation.dispatch(action);
272 }
273 };
274 const followCollapsedSplit = (
275 type: "willAppear" | "didAppear" | "willDisappear",
276 key: string,
277 ) => {
278 if (!collapsed.current || layout.usesSplitView) return;
279 const transition = collapsedSplitTransition(
280 collapsedColumn.current,
281 { type, key },
282 props.navigation.getState(),
283 props.primary.key,
284 );
285 collapsedColumn.current = transition.column;
286 setNativelyPoppingWorkspaceRoute(transition.column.leaving);
287 if (transition.pop) props.navigation.dispatch(transition.pop);
288 };
289
290 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- tells the native split host which column to show while collapsed
291 useEffect(() => {
292 if (layout.usesSplitView || collapsedColumn.current.visible === compactColumn) return;
293 collapsedColumn.current = { ...collapsedColumn.current, visible: compactColumn };
294 hostRef.current?.show(compactColumn);
295 }, [compactColumn, layout.usesSplitView]);
296
297 const primary = props.descriptors[props.primary.key];
298 if (!primary) return null;
299 return (
300 <Split.Host
301 ref={hostRef}
302 testID="adaptive-workspace-layout"
303 preferredSplitBehavior={
304 !sidebarByOrientation && layout.primarySidebarOverlaysContent ? "overlay" : "tile"
305 }
306 portraitPreferredSplitBehavior={sidebarByOrientation ? "overlay" : undefined}
307 portraitPreferredDisplayMode={
308 sidebarByOrientation ? sidebarDisplayMode(sidebarByOrientation.portrait, true) : undefined
309 }
310 primaryBackgroundStyle={deviceType === "pad" ? "none" : "default"}
311 topColumnForCollapsing={compactColumn}
312 onCollapse={() => {
313 collapsed.current = true;
314 collapsedColumn.current = { visible: compactColumn, leaving: null };
315 setNativelyPoppingWorkspaceRoute(null);
316 }}
317 onExpand={() => {
318 collapsed.current = false;
319 setNativelyPoppingWorkspaceRoute(null);
320 // Native callbacks can outlive the render that created them, so decide from the live
321 // router state. An expanded split has columns, so its tab gets a page beside the list.
322 const live = props.navigation.getState();
323 const { workspace } = workspaceRoutesOf(live.routes.slice(0, live.index + 1));
324 if (workspace.some((route) => route.name !== "Home" && route.name !== "Settings")) return;
325 const tab = workspace.some((route) => route.name === "Settings")
326 ? "settings"
327 : (["threads", "pullRequests", "usage"] as const).find((candidate) =>
328 workspaceTabs?.isTabActive(candidate),
329 );
330 openWorkspaceTab(tab ?? "threads", { columns: true });
331 }}
332 preferredDisplayMode={
333 sidebarByOrientation
334 ? sidebarDisplayMode(sidebarByOrientation.landscape, false)
335 : sidebarDisplayMode(
336 // UIKit applies the mode as a collapsed split expands, before the new width reaches
337 // JS, so a collapsed split already carries the sidebar the expanded one will show.
338 (layout.usesSplitView
339 ? panes.primarySidebarVisible
340 : panes.primarySidebarWhenExpanded) ||
341 (!layout.usesSplitView && !activeDetailKey),
342 layout.primarySidebarOverlaysContent,
343 )
344 }
345 onDisplayModeWillChange={({ nativeEvent }) => {
346 if (!layout.primarySidebarOverlaysContent) return;
347 if (nativeEvent.nextDisplayMode === "oneOverSecondary") setPrimarySidebarVisible(true);
348 else if (nativeEvent.nextDisplayMode === "secondaryOnly") setPrimarySidebarVisible(false);
349 }}
350 displayModeButtonVisibility="never"
351 presentsWithGesture
352 showInspector={inspector.visible}
353 onInspectorHide={() => {
354 if (inspector.visible) toggleAuxiliaryPane();
355 }}
356 columnMetrics={{
357 minimumPrimaryColumnWidth: 280,
358 maximumPrimaryColumnWidth: Math.max(380, layout.listPaneWidth ?? 0),
359 preferredPrimaryColumnWidthOrFraction: layout.listPaneWidth ?? 320,
360 minimumSecondaryColumnWidth: 320,
361 // UIKit can retain its automatic width despite a new preference; constrain both edges.
362 minimumInspectorColumnWidth: inspectorWidth,
363 maximumInspectorColumnWidth: inspectorWidth,
364 preferredInspectorColumnWidthOrFraction: inspectorWidth,
365 }}
366 >
367 <Split.Column>
368 <Split.Stack>
369 <ColumnScreen
370 descriptor={primary}
371 primary
372 selectedThreadKey={selectedThreadKey}
373 selectedPullRequestKey={selectedPullRequestKey}
374 onDismiss={handleNativeDismiss}
375 onAppearance={followCollapsedSplit}
376 navigation={props.navigation}
377 />
378 </Split.Stack>
379 </Split.Column>
380 <Split.Column>
381 <Split.Stack>
382 <Split.Screen
383 screenKey="workspace-empty"
384 activityMode={layout.usesSplitView && !activeDetailKey ? "attached" : "detached"}
385 >
386 <V5StackHeader
387 options={{
388 headerShown: true,
389 title: "",
390 unstable_headerLeftItems: () => [
391 {
392 type: "button",
393 label: "",
394 icon: { type: "sfSymbol", name: "sidebar.left" },
395 onPress: togglePrimarySidebar,
396 },
397 ],
398 }}
399 canGoBack={false}
400 column="detail"
401 onCompose={detailCompose}
402 />
403 <ColumnContent>
404 <WorkspaceEmptyDetail
405 tab={settingsOpen ? "settings" : selectedTab}
406 onStartNewTask={
407 // Duo provides compose in the detail bar; iPad uses the empty-state action.
408 detailCompose ? undefined : openNewTask
409 }
410 />
411 </ColumnContent>
412 </Split.Screen>
413 {screens.routes.map((route) => {
414 const descriptor = props.descriptors[route.key] ?? screens.descriptors[route.key];
415 const inSettingsSlot = settingsDetailIn(props.detail)?.key === route.key;
416 const screenKey = inSettingsSlot ? SETTINGS_DETAIL_SCREEN : route.key;
417 return descriptor ? (
418 <ColumnScreen
419 key={screenKey}
420 screenKey={screenKey}
421 descriptor={descriptor}
422 attached={props.detail.some((current) => current.key === route.key)}
423 onDismiss={handleNativeDismiss}
424 onAppearance={followCollapsedSplit}
425 onCompose={isPullRequestRoute(route) ? undefined : detailCompose}
426 navigation={props.navigation}
427 />
428 ) : null;
429 })}
430 </Split.Stack>
431 </Split.Column>
432 <Split.Inspector>
433 <Split.HeaderConfig hidden />
434 {/* Inspector panes host their own native stacks, which UIKit insets for the Duo's
435 vertical bar wherever they sit, so each pane insets its own content instead. */}
436 <ColumnContent insetHorizontally={false}>
437 <View className="flex-1 bg-screen">
438 {inspector.render?.()}
439 {inspector.visible ? (
440 <GestureHandlerRootView
441 style={[StyleSheet.absoluteFill, { zIndex: 100 }]}
442 pointerEvents="box-none"
443 collapsable={false}
444 >
445 <SafeAreaView
446 style={{ flex: 1 }}
447 edges={["left", "right"]}
448 pointerEvents="box-none"
449 >
450 <View className="flex-1" pointerEvents="box-none">
451 <View
452 className="absolute inset-y-0 left-0 w-[22px] flex-row"
453 pointerEvents="box-none"
454 >
455 <WorkspacePaneDivider
456 accessibilityLabel="Resize inspector"
457 currentWidth={inspectorWidth}
458 resizeDirection={-1}
459 onResizeStart={() => {
460 resizeStartWidth.current = inspectorWidth;
461 }}
462 onResizeBy={(delta) => {
463 const width = Math.max(
464 260,
465 Math.min(viewportWidth * 0.6, resizeStartWidth.current + delta),
466 );
467 setInspectorWidthFraction(width / viewportWidth);
468 }}
469 />
470 </View>
471 </View>
472 </SafeAreaView>
473 </GestureHandlerRootView>
474 ) : null}
475 </View>
476 </ColumnContent>
477 </Split.Inspector>
478 </Split.Host>
479 );
480}
481
482function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean }) {
483 const { layout } = useAdaptiveWorkspaceLayout();
484 const workspace = useWorkspaceTabs()!;
485 // Native dismiss commits the route pop after the transition. Restore the dock
486 // when the primary screen starts appearing, including interactive back gestures.
487 const [primaryVisible, setPrimaryVisible] = useState(false);
488 const metrics = useNativeLayoutMetrics();
489 const projection = projectWorkspaceStack(props.state, (route) => {
490 const presentation = props.descriptors[route.key]?.options.presentation;
491 return presentation !== undefined && presentation !== "card";
492 });
493 // The root's willDisappear reaches JS frames into the push, so hide the dock in the commit that
494 // pushes; the native events still own every later change, including back gestures.
495 const topDetailKey = projection.detail.at(-1)?.key;
496 const [pushedDetailKey, setPushedDetailKey] = useState(topDetailKey);
497 if (pushedDetailKey !== topDetailKey) {
498 setPushedDetailKey(topDetailKey);
499 if (topDetailKey !== undefined && primaryVisible) setPrimaryVisible(false);
500 }
501 // Detail-only histories must stay single-stack: placeholder descriptors cannot own sidebar actions or setOptions.
502 const primaryRoute = projection.primary;
503 if (!primaryRoute) return <V5StackView {...props} />;
504 const primaryDescriptor = props.descriptors[primaryRoute.key]!;
505 const descriptors = props.descriptors;
506 const baseRoute = { key: `${props.state.key}:workspace`, name: "Workspace" };
507 const visibleRoute = projection.detail.at(-1) ?? primaryRoute;
508 const workspacePage = !workspaceUsesColumns(workspace.state.selectedTab, workspace.settingsOpen);
509 const baseDescriptor: Descriptor = {
510 ...primaryDescriptor,
511 navigation: props.descriptors[visibleRoute.key]!.navigation,
512 // Identify the real visible route under the stable envelope key, or useIsFocused closes media viewers.
513 route: visibleRoute,
514 options: { headerShown: false },
515 render: () => (
516 <WorkspaceNativeTabs
517 hidden={
518 !workspacePage &&
519 projection.detail.length > 0 &&
520 !primaryVisible &&
521 !layout.usesSplitView &&
522 (metrics?.verticalBarEdge ?? "none") === "none"
523 }
524 >
525 {props.nativeColumns && !workspacePage ? (
526 <WorkspaceColumns
527 {...props}
528 descriptors={descriptors}
529 primary={primaryRoute}
530 detail={projection.detail}
531 />
532 ) : (
533 <V5CardStackView
534 {...props}
535 onRootVisibilityChange={setPrimaryVisible}
536 onNativePopChange={setNativelyPoppingWorkspaceRoute}
537 descriptors={descriptors}
538 state={{
539 ...props.state,
540 routes: [primaryRoute, ...projection.detail],
541 index: projection.detail.length,
542 preloadedRoutes: [],
543 }}
544 />
545 )}
546 </WorkspaceNativeTabs>
547 ),
548 };
549 const overlays = partitionStackPresentations(projection.overlays, (route) => {
550 const presentation = props.descriptors[route.key]?.options.presentation;
551 return presentation !== undefined && presentation !== "card";
552 });
553 const routes = [baseRoute, ...overlays.map((group) => group[0]!)];
554 return (
555 <NativeStackView
556 presentationEnvelope
557 {...props}
558 state={{ ...props.state, routes, index: routes.length - 1, preloadedRoutes: [] }}
559 descriptors={{
560 ...Object.fromEntries(
561 overlays.map((group) => {
562 const route = group[0]!;
563 const descriptor = props.descriptors[route.key]!;
564 const visibleRoute = group.at(-1)!;
565 return [
566 route.key,
567 {
568 ...descriptor,
569 navigation: props.descriptors[visibleRoute.key]!.navigation,
570 route: visibleRoute,
571 options: modalEnvelopeOptions(descriptor.options),
572 render: () => (
573 <V5CardStackView
574 {...props}
575 state={{
576 ...props.state,
577 routes: group,
578 index: group.length - 1,
579 preloadedRoutes: [],
580 }}
581 />
582 ),
583 },
584 ];
585 }),
586 ),
587 [baseRoute.key]: baseDescriptor,
588 }}
589 />
590 );
591}
592
593function WorkspaceStackNavigator({
594 id,
595 initialRouteName,
596 UNSTABLE_routeNamesChangeBehavior,
597 children,
598 layout,
599 screenListeners,
600 screenOptions,
601 screenLayout,
602 UNSTABLE_router,
603 ...rest
604}: NativeStackNavigatorProps) {
605 const usesNativeWorkspaceColumns = useNativeWorkspaceColumnsSupported();
606 const nativeWorkspaceColumnsReady = useNativeWorkspaceColumnsReady();
607 const { state, describe, descriptors, navigation, NavigationContent } = useNavigationBuilder<
608 StackNavigationState<ParamListBase>,
609 StackRouterOptions,
610 StackActionHelpers<ParamListBase>,
611 NativeStackNavigationOptions,
612 NativeStackNavigationEventMap
613 >(StackRouter, {
614 id,
615 initialRouteName,
616 UNSTABLE_routeNamesChangeBehavior,
617 children,
618 layout,
619 screenListeners,
620 screenOptions,
621 screenLayout,
622 UNSTABLE_router,
623 });
624 if (!nativeWorkspaceColumnsReady) return null;
625 const settingsOpen = settingsOpenIn(
626 state.routes.slice(0, state.index + 1).filter((route) => {
627 const presentation = descriptors[route.key]?.options.presentation;
628 return presentation === undefined || presentation === "card";
629 }),
630 );
631 return (
632 <NativeWorkspaceModeContext value={usesNativeWorkspaceColumns}>
633 <NavigationContent>
634 <WorkspaceTabsProvider settingsOpen={settingsOpen}>
635 <WorkspaceStackView
636 nativeColumns={usesNativeWorkspaceColumns}
637 {...rest}
638 state={state}
639 describe={describe}
640 descriptors={descriptors}
641 navigation={navigation}
642 />
643 </WorkspaceTabsProvider>
644 </NavigationContent>
645 </NativeWorkspaceModeContext>
646 );
647}
648
649type WorkspaceTypeBag<
650 ParamList extends ParamListBase,
651 NavigatorID extends string | undefined,
652> = Omit<NativeStackTypeBag<ParamList, NavigatorID>, "Navigator"> & {
653 Navigator: typeof WorkspaceStackNavigator;
654};
655
656export function createWorkspaceStackNavigator<
657 const ParamList extends ParamListBase,
658 const NavigatorID extends string | undefined = string | undefined,
659 const TypeBag extends NavigatorTypeBagBase = WorkspaceTypeBag<ParamList, NavigatorID>,
660 const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
661>(config?: Config): TypedNavigator<TypeBag, Config> {
662 return createNavigatorFactory(WorkspaceStackNavigator)(config);
663}
664
665function sidebarDisplayMode(visible: boolean, overlay: boolean) {
666 if (!visible) return "secondaryOnly";
667 return overlay ? "oneOverSecondary" : "oneBesideSecondary";
668}