Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

Stack.tsx

813 lines29.5 KB

1import {
2 createPathConfigForStaticNavigation,
3 getPathFromState,
4 NavigationState,
5 StackActions,
6 useNavigation,
7} from "@react-navigation/native";
8import {
9 createNativeStackNavigator,
10 createNativeStackScreen,
11 type NativeStackNavigationOptions,
12} from "@react-navigation/native-stack";
13import { useEffect, useRef } from "react";
14import {
15 Platform,
16 Pressable,
17 ScrollView,
18 StyleSheet,
19 View,
20 useWindowDimensions,
21} from "react-native";
22import { useResolveClassNames } from "uniwind";
23​
24import { AppText as Text } from "./components/AppText";
25import { getCompactBrandHeaderOptions } from "./components/CompactBrandTitle";
26import { ArchivedThreadsRouteScreen } from "./features/archive/ArchivedThreadsRouteScreen";
27import { useAgentNotificationNavigation } from "./features/agent-awareness/notificationNavigation";
28import { ConnectOnboardingRouteScreen } from "./features/cloud/ConnectOnboardingRouteScreen";
29import { useConnectOnboardingNavigation } from "./features/cloud/connectOnboardingNavigation";
30import { AttachmentFileScreen } from "./features/files/AttachmentFileScreen";
31import { ThreadFilesTreeScreen, ThreadFileScreen } from "./features/files/ThreadFilesRouteScreen";
32import { AdaptiveWorkspaceLayout } from "./features/layout/AdaptiveWorkspaceLayout";
33import {
34 HardwareKeyboardCommandOverlay,
35 HardwareKeyboardCommandProvider,
36} from "./features/keyboard/HardwareKeyboardCommandProvider";
37import { ReviewCommentComposerSheet } from "./features/review/ReviewCommentComposerSheet";
38import { ReviewSheet } from "./features/review/ReviewSheet";
39import { ThreadTerminalRouteScreen } from "./features/terminal/ThreadTerminalRouteScreen";
40import { DevicePreviewRouteScreen } from "./features/devices/DevicePreviewRouteScreen";
41import { GitBranchesSheet } from "./features/threads/git/GitBranchesSheet";
42import { GitCommitSheet } from "./features/threads/git/GitCommitSheet";
43import { GitConfirmSheet } from "./features/threads/git/GitConfirmSheet";
44import { GitOverviewSheet } from "./features/threads/git/GitOverviewSheet";
45import { ThreadRouteScreen } from "./features/threads/ThreadRouteScreen";
46import { ConnectionsRouteScreen } from "./features/connection/ConnectionsRouteScreen";
47import { ConnectionsNewRouteScreen } from "./features/connection/ConnectionsNewRouteScreen";
48import { HomeRouteScreen } from "./features/home/HomeRouteScreen";
49import { AddProjectDestinationRoute } from "./features/projects/AddProjectDestinationRoute";
50import { AddProjectLocalRoute } from "./features/projects/AddProjectLocalRoute";
51import { AddProjectRepositoryRoute } from "./features/projects/AddProjectRepositoryRoute";
52import { AddProjectSourceRoute } from "./features/projects/AddProjectSourceRoute";
53import { NewTaskDraftRouteScreen } from "./features/threads/NewTaskDraftRouteScreen";
54import {
55 NewTaskBranchPickerRouteScreen,
56 NewTaskEnvironmentPickerRouteScreen,
57} from "./features/threads/NewTaskContextPickerScreens";
58import {
59 ExistingThreadSettingsRouteProvider,
60 ExistingThreadSettingsRouteScreen,
61 NewTaskThreadSettingsRouteScreen,
62} from "./features/threads/ThreadSettingsSheet";
63import { NewTaskFlowProvider } from "./features/threads/new-task-flow-provider";
64import { NewTaskRouteScreen } from "./features/threads/NewTaskRouteScreen";
65import { SettingsAppearanceRouteScreen } from "./features/settings/SettingsAppearanceRouteScreen";
66import { SettingsClientStorageRouteScreen } from "./features/settings/SettingsClientStorageRouteScreen";
67import { SettingsDiagnosticsRouteScreen } from "./features/diagnostics/SettingsDiagnosticsRouteScreen";
68import { SettingsAuthRouteScreen } from "./features/settings/SettingsAuthRouteScreen";
69import { SettingsEnvironmentsRouteScreen } from "./features/settings/SettingsEnvironmentsRouteScreen";
70import {
71 SettingsEnvironmentAgentBehaviorRouteScreen,
72 SettingsEnvironmentMaintenanceRouteScreen,
73 SettingsEnvironmentNewThreadsRouteScreen,
74 SettingsEnvironmentSourceControlRouteScreen,
75} from "./features/settings/SettingsServerControlsRouteScreen";
76import { SettingsKeyboardRouteScreen } from "./features/settings/SettingsKeyboardRouteScreen";
77import { SettingsLegalRouteScreen } from "./features/settings/SettingsLegalRouteScreen";
78import {
79 SettingsOpenSourceLicenseRouteScreen,
80 SettingsOpenSourceLicensesRouteScreen,
81} from "./features/settings/SettingsOpenSourceLicensesRouteScreen";
82import { SettingsProjectGroupingRouteScreen } from "./features/settings/SettingsProjectGroupingRouteScreen";
83import { SettingsProjectOverviewRouteScreen } from "./features/settings/SettingsProjectOverviewRouteScreen";
84import { UsageLimitAccountScreen } from "./features/usage/UsageLimitsPooled";
85import { UsageRouteScreen } from "./features/usage/UsageRouteScreen";
86import { SettingsAboutRouteScreen } from "./features/settings/SettingsAboutRouteScreen";
87import { SettingsNotificationsRouteScreen } from "./features/settings/SettingsNotificationsRouteScreen";
88import { SettingsRouteScreen } from "./features/settings/SettingsRouteScreen";
89import { SettingsThreadsRouteScreen } from "./features/settings/SettingsThreadsRouteScreen";
90import { SettingsEnvironmentFilterProvider } from "./features/settings/settings-environment-filter";
91import { ShowcaseCaptureCoordinator } from "./features/showcase/ShowcaseCaptureCoordinator";
92import {
93 SettingsLegalDocumentCloseHeaderButton,
94 SettingsLegalDocumentExternalHeaderButton,
95} from "./features/settings/components/SettingsLegalDocumentRouteScreen";
96import { useAppShortcuts } from "./features/shortcuts/useAppShortcuts";
97import { useIncomingShare } from "./features/sharing/IncomingShareProvider";
98import {
99 EMPTY_INCOMING_SHARE_PRESENTATION_STATE,
100 transitionIncomingSharePresentation,
101} from "./features/sharing/incoming-share-presentation";
102import { NATIVE_LIQUID_GLASS_SUPPORTED } from "./native/native-glass";
103import { deriveLayout } from "./lib/layout";
104import { nativeHeaderScrollEdgeEffects } from "./native/StackHeader";
105import { FORM_SHEET_PRESENTATION_OPTIONS } from "./native/sheet-surface";
106import { useThreadOutboxDrain } from "./state/use-thread-outbox-drain";
107import { useComposerAttachmentUploadWorker } from "./state/composer-attachment-uploads";
108​
109const HEADER_SCROLL_EDGE_EFFECTS = nativeHeaderScrollEdgeEffects(Platform.OS, Platform.Version);
110​
111type AppScreenOptions = NativeStackNavigationOptions & {
112 readonly unstable_navigationItemStyle?: "editor";
113};
114​
115// Shared header presets. Screens only override genuinely dynamic values (titles,
116// subtitles, toolbar items, search callbacks) via NativeStackScreenOptions.
117//
118// GLASS: transparent header over the screen's primary scroll view on supported
119// iOS versions. Pre-glass iOS gets the same solid material as internal-scroll
120// surfaces so content is laid out below the bar instead of underlapping it.
121const GLASS_HEADER_OPTIONS: AppScreenOptions = {
122 headerBackButtonDisplayMode: "minimal",
123 headerBackTitle: "",
124 headerLargeTitle: false,
125 headerShadowVisible: false,
126 headerShown: true,
127 headerStyle: NATIVE_LIQUID_GLASS_SUPPORTED ? { backgroundColor: "transparent" } : undefined,
128 headerTitleStyle: { fontSize: 18, fontWeight: "800" },
129 headerTransparent: NATIVE_LIQUID_GLASS_SUPPORTED,
130 scrollEdgeEffects: NATIVE_LIQUID_GLASS_SUPPORTED ? HEADER_SCROLL_EDGE_EFFECTS : undefined,
131 unstable_navigationItemStyle: NATIVE_LIQUID_GLASS_SUPPORTED ? "editor" : undefined,
132};
133​
134// SOLID: opaque sheet-colored header for surfaces whose content scrolls internally
135// (file viewer, terminal, review) — there is nothing for glass to sample there.
136const SOLID_HEADER_OPTIONS: AppScreenOptions = {
137 headerBackButtonDisplayMode: "minimal",
138 headerBackTitle: "",
139 headerLargeTitle: false,
140 headerShadowVisible: false,
141 headerShown: true,
142 headerTitleStyle: { fontSize: 18, fontWeight: "800" },
143 headerTransparent: false,
144 unstable_navigationItemStyle: Platform.OS === "ios" ? "editor" : undefined,
145};
146​
147// Solid header variant for screens inside sheets (centered title, no editor style).
148const SHEET_SOLID_HEADER_OPTIONS: AppScreenOptions = {
149 ...SOLID_HEADER_OPTIONS,
150 unstable_navigationItemStyle: undefined,
151};
152​
153// A native glass header for a sheet screen whose primary child is a scroll
154// view. The centered sheet title stays stable while UIKit supplies scroll-edge
155// fading from that child.
156const SHEET_GLASS_HEADER_OPTIONS: AppScreenOptions = {
157 ...GLASS_HEADER_OPTIONS,
158 unstable_navigationItemStyle: undefined,
159};
160​
161const LEGAL_DOCUMENT_HEADER_OPTIONS: AppScreenOptions = {
162 ...SHEET_SOLID_HEADER_OPTIONS,
163 headerBackVisible: false,
164 headerLeft: SettingsLegalDocumentCloseHeaderButton,
165 headerRight: () => <SettingsLegalDocumentExternalHeaderButton />,
166 presentation: "fullScreenModal",
167};
168​
169const SettingsContentStack = createNativeStackNavigator({
170 initialRouteName: "Settings",
171 screenOptions: {
172 ...GLASS_HEADER_OPTIONS,
173 // Sheets read better with the iOS-default centered title (no editor style).
174 unstable_navigationItemStyle: undefined,
175 },
176 screens: {
177 Settings: createNativeStackScreen({
178 screen: SettingsRouteScreen,
179 linking: "",
180 options: {
181 title: "Settings",
182 },
183 }),
184 SettingsEnvironments: createNativeStackScreen({
185 screen: SettingsEnvironmentsRouteScreen,
186 linking: "environments",
187 options: {
188 title: "Environments",
189 },
190 }),
191 SettingsEnvironmentNewThreads: createNativeStackScreen({
192 screen: SettingsEnvironmentNewThreadsRouteScreen,
193 linking: "new-threads",
194 options: { title: "New threads" },
195 }),
196 SettingsEnvironmentSourceControl: createNativeStackScreen({
197 screen: SettingsEnvironmentSourceControlRouteScreen,
198 linking: "source-control",
199 options: { title: "Source control" },
200 }),
201 SettingsEnvironmentAgentBehavior: createNativeStackScreen({
202 screen: SettingsEnvironmentAgentBehaviorRouteScreen,
203 linking: "agent-behavior",
204 options: { title: "Agent behavior" },
205 }),
206 SettingsEnvironmentMaintenance: createNativeStackScreen({
207 screen: SettingsEnvironmentMaintenanceRouteScreen,
208 linking: "maintenance",
209 options: { title: "Maintenance" },
210 }),
211 SettingsNotifications: createNativeStackScreen({
212 screen: SettingsNotificationsRouteScreen,
213 linking: "notifications",
214 options: { title: "Notifications" },
215 }),
216 SettingsThreads: createNativeStackScreen({
217 screen: SettingsThreadsRouteScreen,
218 linking: "thread-preferences",
219 options: { title: "Thread behavior" },
220 }),
221 SettingsAbout: createNativeStackScreen({
222 screen: SettingsAboutRouteScreen,
223 linking: "about",
224 options: { title: "About T3 Code" },
225 }),
226 SettingsEnvironmentNew: createNativeStackScreen({
227 screen: ConnectionsNewRouteScreen,
228 linking: "environment-new",
229 options: {
230 title: "Add Environment",
231 },
232 }),
233 SettingsArchive: createNativeStackScreen({
234 screen: ArchivedThreadsRouteScreen,
235 linking: "archive",
236 options: {
237 title: "Archived Threads",
238 },
239 }),
240 SettingsAppearance: createNativeStackScreen({
241 screen: SettingsAppearanceRouteScreen,
242 linking: "appearance",
243 options: {
244 title: "Appearance",
245 },
246 }),
247 SettingsProjectGrouping: createNativeStackScreen({
248 screen: SettingsProjectGroupingRouteScreen,
249 linking: "project-grouping",
250 options: {
251 title: "Organization",
252 },
253 }),
254 SettingsOrganization: createNativeStackScreen({
255 screen: SettingsProjectGroupingRouteScreen,
256 linking: "organization",
257 options: {
258 title: "Organization",
259 },
260 }),
261 SettingsProjectOverview: createNativeStackScreen({
262 screen: SettingsProjectOverviewRouteScreen,
263 linking: "project",
264 options: { title: "Project overview" },
265 }),
266 SettingsKeyboard: createNativeStackScreen({
267 screen: SettingsKeyboardRouteScreen,
268 linking: "keyboard",
269 options: {
270 title: "Keyboard",
271 },
272 }),
273 SettingsClientStorage: createNativeStackScreen({
274 screen: SettingsClientStorageRouteScreen,
275 linking: "client-storage",
276 options: {
277 title: "Client Storage",
278 },
279 }),
280 SettingsDiagnostics: createNativeStackScreen({
281 screen: SettingsDiagnosticsRouteScreen,
282 linking: "diagnostics",
283 options: {
284 title: "Diagnostics",
285 },
286 }),
287 SettingsUsageAccount: createNativeStackScreen({
288 screen: UsageLimitAccountScreen,
289 options: { title: "Account" },
290 }),
291 SettingsOpenSourceLicenses: createNativeStackScreen({
292 screen: SettingsOpenSourceLicensesRouteScreen,
293 linking: "open-source-licenses",
294 options: {
295 title: "Open source licenses",
296 },
297 }),
298 SettingsOpenSourceLicense: createNativeStackScreen({
299 screen: SettingsOpenSourceLicenseRouteScreen,
300 linking: "open-source-licenses/:entryKey",
301 options: {
302 title: "License notice",
303 },
304 }),
305 SettingsUsage: createNativeStackScreen({
306 screen: UsageRouteScreen,
307 linking: "usage",
308 options: {
309 title: "Usage",
310 },
311 }),
312 },
313});
314​
315// The outer stack never owns visible chrome. Settings routes render inside a
316// nested stack whose native header remains mounted, while Clerk owns auth chrome.
317// Keeping bar visibility invariant avoids iOS 26's headerless-to-headered jump.
318const SettingsSheetStack = createNativeStackNavigator({
319 initialRouteName: "SettingsContent",
320 screenOptions: {
321 headerShown: false,
322 },
323 screens: {
324 SettingsContent: createNativeStackScreen({
325 screen: SettingsContentStack,
326 linking: "",
327 layout: ({ children }) => (
328 <SettingsEnvironmentFilterProvider>{children}</SettingsEnvironmentFilterProvider>
329 ),
330 }),
331 SettingsAuth: createNativeStackScreen({
332 screen: SettingsAuthRouteScreen,
333 linking: "auth",
334 }),
335 SettingsWaitlist: createNativeStackScreen({
336 // Keep the old deep link working after the Connect GA launch.
337 screen: SettingsAuthRouteScreen,
338 linking: "waitlist",
339 }),
340 },
341});
342​
343// Thread routes live FLAT in the root stack (not in a nested navigator). A nested
344// stack means a second UINavigationController with its own UINavigationBar, which
345// breaks iOS 26's shared-header morphing between Home and Thread (each pair inside
346// one bar morphs; across two bars the whole screen slides). Flat linking paths keep
347// the same deep-link URLs the nested config produced.
348const THREAD_LINKING_PREFIX = "threads/:environmentId/:threadId";
349​
350// New-task / add-project flow: the nested navigator owns the header and pushes
351// whether the flow opens in the workspace or in a compact form sheet.
352const NewTaskSheetStack = createNativeStackNavigator({
353 initialRouteName: "NewTask",
354 screenOptions: {
355 ...SHEET_GLASS_HEADER_OPTIONS,
356 // The form-sheet host owns the one opaque adaptive surface. Child screens
357 // and the navigation bar stay transparent over it, avoiding visible color
358 // slabs as view controllers move horizontally.
359 contentStyle: Platform.OS === "ios" ? { backgroundColor: "transparent" } : undefined,
360 // UIKit's default push adds a dimming shadow and independently transitions
361 // the navigation bar. Both read as mismatched sheet backgrounds here.
362 // simple_push retains native push/pop gestures without either artifact.
363 animation: Platform.OS === "ios" ? "simple_push" : undefined,
364 animationDuration: Platform.OS === "ios" ? 350 : undefined,
365 },
366 screens: {
367 NewTask: createNativeStackScreen({
368 screen: NewTaskRouteScreen,
369 linking: "",
370 options: {
371 title: "Choose project",
372 },
373 }),
374 NewTaskDraft: createNativeStackScreen({
375 screen: NewTaskDraftRouteScreen,
376 linking: "draft",
377 options: {
378 headerBackVisible: false,
379 title: "",
380 },
381 }),
382 NewTaskEnvironment: createNativeStackScreen({
383 screen: NewTaskEnvironmentPickerRouteScreen,
384 linking: "draft/environment",
385 options: {
386 title: "Environment",
387 },
388 }),
389 NewTaskBranch: createNativeStackScreen({
390 screen: NewTaskBranchPickerRouteScreen,
391 linking: "draft/branch",
392 options: {
393 title: "Branch",
394 },
395 }),
396 // The same file view the thread composer pushes. A draft has no thread, so it names its
397 // own workspace through route params instead of resolving one from a selected thread.
398 NewTaskFile: createNativeStackScreen({
399 screen: ThreadFileScreen,
400 linking: "draft/files/:path*",
401 options: SOLID_HEADER_OPTIONS,
402 }),
403 NewTaskAttachment: createNativeStackScreen({
404 screen: AttachmentFileScreen,
405 linking: "draft/attachments/:attachmentId",
406 options: SOLID_HEADER_OPTIONS,
407 }),
408 ThreadSettings: createNativeStackScreen({
409 screen: NewTaskThreadSettingsRouteScreen,
410 linking: "draft/settings",
411 options: {
412 gestureEnabled: true,
413 headerShown: false,
414 ...(Platform.OS === "android"
415 ? { presentation: "card" as const }
416 : {
417 ...FORM_SHEET_PRESENTATION_OPTIONS,
418 sheetAllowedDetents: [1],
419 sheetGrabberVisible: true,
420 }),
421 },
422 }),
423 AddProject: createNativeStackScreen({
424 screen: AddProjectSourceRoute,
425 linking: "add-project",
426 options: {
427 title: "Add Project",
428 },
429 }),
430 AddProjectRepository: createNativeStackScreen({
431 screen: AddProjectRepositoryRoute,
432 linking: "add-project/repository",
433 }),
434 AddProjectDestination: createNativeStackScreen({
435 screen: AddProjectDestinationRoute,
436 linking: "add-project/destination",
437 }),
438 AddProjectLocal: createNativeStackScreen({
439 screen: AddProjectLocalRoute,
440 linking: "add-project/local",
441 }),
442 },
443});
444​
445// Routes presented as sheets/overlays ON TOP of the workspace. They must not
446// influence the adaptive workspace layout: opening Settings over Home should
447// not flip the sidebar in or change the active thread.
448const WORKSPACE_OVERLAY_ROUTES = new Set([
449 "ConnectOnboarding",
450 "Connections",
451 "ConnectionsNew",
452 "GitBranches",
453 "GitCommit",
454 "GitConfirm",
455 "GitOverview",
456 "NewTaskSheet",
457 "SettingsLegal",
458 "SettingsSheet",
459 "ThreadReviewComment",
460 "ThreadDevicePreview",
461 "ThreadSettingsSheet",
462]);
463​
464/**
465 * Location of the topmost non-overlay route, including its key so thread
466 * selection can dismiss sheets without replacing the wrong destination.
467 */
468function workspaceLocationFromState(state: NavigationState) {
469 const routes = state.routes.filter((route) => !WORKSPACE_OVERLAY_ROUTES.has(route.name));
470 const effectiveState =
471 routes.length > 0 && routes.length !== state.routes.length
472 ? ({ ...state, routes, index: routes.length - 1 } as NavigationState)
473 : state;
474 const path = getPathFromState(effectiveState, navigationPathConfig);
475 return {
476 pathname: path.startsWith("/") ? path : `/${path}`,
477 routeKey: effectiveState.routes[effectiveState.index]?.key,
478 };
480​
481// The drain hook subscribes to the outbox, all thread shells, projects, and
482// connection statuses. Hosting it in a null-rendering leaf keeps those
483// updates from re-rendering RootStackLayout (and with it every screen) on
484// each enqueue, shell change, or reconnect.
485function ThreadOutboxDrainWorker() {
486 useThreadOutboxDrain();
487 useComposerAttachmentUploadWorker();
488 return null;
490​
491function RootStackLayout(props: {
492 readonly children: React.ReactNode;
493 readonly state: NavigationState;
494}) {
495 const navigation = useNavigation();
496 const { pendingShare } = useIncomingShare();
497 const sharePresentationRef = useRef(EMPTY_INCOMING_SHARE_PRESENTATION_STATE);
498 useAgentNotificationNavigation();
499 // Presents the T3 Connect onboarding sheet after an in-session sign-in.
500 useConnectOnboardingNavigation();
501 // Launcher app shortcuts: routes shortcut taps and tracks opened threads.
502 useAppShortcuts(props.state);
503 useEffect(() => {
504 const topRouteName = props.state.routes[props.state.index]?.name;
505 const transition = transitionIncomingSharePresentation(sharePresentationRef.current, {
506 isShareSheetPresented: topRouteName === "NewTaskSheet",
507 pendingShareId: pendingShare?.id ?? null,
508 });
509 sharePresentationRef.current = transition.state;
510 if (!transition.shareIdToPresent) {
511 return;
512 }
513 navigation.navigate("NewTaskSheet", {
514 screen: "NewTask",
515 params: { incomingShareId: transition.shareIdToPresent },
516 });
517 }, [navigation, pendingShare, props.state]);
518 // Full pathname (sheets included) for keyboard-command scoping; the
519 // workspace layout only reacts to the underlying non-overlay route.
520 const path = getPathFromState(props.state, navigationPathConfig);
521 const pathname = path.startsWith("/") ? path : `/${path}`;
522 const workspaceLocation = workspaceLocationFromState(props.state);
523​
524 return (
525 <HardwareKeyboardCommandProvider pathname={pathname}>
526 <ThreadOutboxDrainWorker />
527 <ShowcaseCaptureCoordinator pathname={pathname} />
528 <ExistingThreadSettingsRouteProvider>
529 <AdaptiveWorkspaceLayout
530 pathname={workspaceLocation.pathname}
531 workspaceRouteKey={workspaceLocation.routeKey}
532 >
533 {props.children}
534 <HardwareKeyboardCommandOverlay />
535 </AdaptiveWorkspaceLayout>
536 </ExistingThreadSettingsRouteProvider>
537 </HardwareKeyboardCommandProvider>
538 );
540​
541function NotFoundScreen() {
542 const navigation = useNavigation();
543 const screenBgStyle = StyleSheet.flatten(useResolveClassNames("bg-screen"));
544 const primaryBgStyle = StyleSheet.flatten(useResolveClassNames("bg-primary"));
545 const returnHomeButtonStyle = StyleSheet.flatten([
546 {
547 borderRadius: 999,
548 paddingHorizontal: 20,
549 paddingVertical: 14,
550 },
551 primaryBgStyle,
552 ]);
553​
554 return (
555 <ScrollView
556 contentInsetAdjustmentBehavior="automatic"
557 contentContainerStyle={{
558 flexGrow: 1,
559 alignItems: "center",
560 justifyContent: "center",
561 gap: 16,
562 paddingHorizontal: 24,
563 paddingVertical: 32,
564 }}
565 style={[{ flex: 1 }, screenBgStyle]}
566 >
567 <Text className="text-3xl font-t3-bold text-foreground" selectable>
568 Route not found
569 </Text>
570 <Pressable
571 style={returnHomeButtonStyle}
572 onPress={() => navigation.dispatch(StackActions.replace("Home"))}
573 >
574 <Text className="text-base font-t3-bold text-primary-foreground">Return home</Text>
575 </Pressable>
576 </ScrollView>
577 );
579​
580const RootStackConfig = createNativeStackNavigator({
581 initialRouteName: "Home",
582 layout: RootStackLayout,
583 screenOptions: {
584 headerShown: false,
585 },
586 screens: {
587 Home: createNativeStackScreen({
588 screen: HomeRouteScreen,
589 linking: "",
590 options: {
591 ...GLASS_HEADER_OPTIONS,
592 contentStyle: { backgroundColor: "transparent" },
593 headerBackVisible: false,
594 ...getCompactBrandHeaderOptions(),
595 },
596 }),
597 Thread: createNativeStackScreen({
598 screen: ThreadRouteScreen,
599 linking: THREAD_LINKING_PREFIX,
600 options: GLASS_HEADER_OPTIONS,
601 }),
602 ThreadTerminal: createNativeStackScreen({
603 screen: ThreadTerminalRouteScreen,
604 linking: `${THREAD_LINKING_PREFIX}/terminal`,
605 options: SOLID_HEADER_OPTIONS,
606 }),
607 ThreadDevicePreview: createNativeStackScreen({
608 screen: DevicePreviewRouteScreen,
609 linking: `${THREAD_LINKING_PREFIX}/devices`,
610 options: {
611 presentation: "fullScreenModal",
612 headerShown: false,
613 gestureEnabled: false,
614 },
615 }),
616 ThreadReview: createNativeStackScreen({
617 screen: ReviewSheet,
618 linking: `${THREAD_LINKING_PREFIX}/review`,
619 options: SOLID_HEADER_OPTIONS,
620 }),
621 ThreadReviewComment: createNativeStackScreen({
622 screen: ReviewCommentComposerSheet,
623 linking: `${THREAD_LINKING_PREFIX}/review-comment`,
624 options: {
625 // Android cannot host the keyboard-driven comment composer inside a
626 // formSheet; use a full-screen modal there instead.
627 ...(Platform.OS === "android"
628 ? { presentation: "fullScreenModal" as const }
629 : FORM_SHEET_PRESENTATION_OPTIONS),
630 sheetAllowedDetents: Platform.OS === "android" ? undefined : [0.55, 0.92],
631 sheetGrabberVisible: Platform.OS !== "android",
632 },
633 }),
634 ThreadFiles: createNativeStackScreen({
635 screen: ThreadFilesTreeScreen,
636 linking: `${THREAD_LINKING_PREFIX}/files`,
637 options: {
638 ...GLASS_HEADER_OPTIONS,
639 title: "Files",
640 },
641 }),
642 ThreadFile: createNativeStackScreen({
643 screen: ThreadFileScreen,
644 linking: `${THREAD_LINKING_PREFIX}/files/:path*`,
645 options: SOLID_HEADER_OPTIONS,
646 }),
647 ThreadAttachment: createNativeStackScreen({
648 screen: AttachmentFileScreen,
649 linking: `${THREAD_LINKING_PREFIX}/attachments/:attachmentId`,
650 options: SOLID_HEADER_OPTIONS,
651 }),
652 ThreadSettingsSheet: createNativeStackScreen({
653 screen: ExistingThreadSettingsRouteScreen,
654 options: {
655 gestureEnabled: true,
656 headerShown: false,
657 ...(Platform.OS === "android"
658 ? { presentation: "card" as const }
659 : {
660 ...FORM_SHEET_PRESENTATION_OPTIONS,
661 sheetAllowedDetents: [1],
662 sheetGrabberVisible: true,
663 }),
664 },
665 }),
666 GitOverview: createNativeStackScreen({
667 screen: GitOverviewSheet,
668 linking: `${THREAD_LINKING_PREFIX}/git`,
669 options: {
670 ...FORM_SHEET_PRESENTATION_OPTIONS,
671 sheetAllowedDetents: [0.55, 0.92],
672 sheetGrabberVisible: true,
673 },
674 }),
675 GitCommit: createNativeStackScreen({
676 screen: GitCommitSheet,
677 linking: `${THREAD_LINKING_PREFIX}/git/commit`,
678 options: {
679 ...FORM_SHEET_PRESENTATION_OPTIONS,
680 sheetAllowedDetents: [0.55, 0.92],
681 sheetGrabberVisible: true,
682 },
683 }),
684 GitBranches: createNativeStackScreen({
685 screen: GitBranchesSheet,
686 linking: `${THREAD_LINKING_PREFIX}/git/branches`,
687 options: {
688 ...FORM_SHEET_PRESENTATION_OPTIONS,
689 sheetAllowedDetents: [0.55, 0.92],
690 sheetGrabberVisible: true,
691 },
692 }),
693 GitConfirm: createNativeStackScreen({
694 screen: GitConfirmSheet,
695 linking: `${THREAD_LINKING_PREFIX}/git-confirm`,
696 options: {
697 ...FORM_SHEET_PRESENTATION_OPTIONS,
698 sheetAllowedDetents: [0.45, 0.7],
699 sheetGrabberVisible: true,
700 },
701 }),
702 SettingsSheet: createNativeStackScreen({
703 screen: SettingsSheetStack,
704 linking: "settings",
705 options: {
706 gestureEnabled: true,
707 headerShown: false,
708 },
709 }),
710 SettingsLegal: createNativeStackScreen({
711 screen: SettingsLegalRouteScreen,
712 linking: "settings/legal",
713 options: {
714 ...LEGAL_DOCUMENT_HEADER_OPTIONS,
715 title: "Legal",
716 },
717 }),
718 ConnectOnboarding: createNativeStackScreen({
719 screen: ConnectOnboardingRouteScreen,
720 linking: "connect-onboarding",
721 options: {
722 // A root-level Android formSheet does not host the native stack bar;
723 // the route renders an embedded AndroidSheetHeader instead.
724 ...(Platform.OS === "android" ? { headerShown: false } : SHEET_SOLID_HEADER_OPTIONS),
725 title: "Set up T3 Connect",
726 gestureEnabled: true,
727 ...FORM_SHEET_PRESENTATION_OPTIONS,
728 sheetAllowedDetents: [0.6, 0.95],
729 sheetGrabberVisible: true,
730 },
731 }),
732 Connections: createNativeStackScreen({
733 screen: ConnectionsRouteScreen,
734 linking: "connections",
735 options: {
736 title: "Environments",
737 // Android: full page; the screen renders its own AndroidScreenHeader,
738 // so the native bar stays hidden. iOS keeps the sheet.
739 ...(Platform.OS === "android"
740 ? { presentation: "card" as const, headerShown: false }
741 : {
742 ...FORM_SHEET_PRESENTATION_OPTIONS,
743 sheetAllowedDetents: [0.55, 0.7],
744 sheetGrabberVisible: true,
745 }),
746 },
747 }),
748 ConnectionsNew: createNativeStackScreen({
749 screen: ConnectionsNewRouteScreen,
750 linking: "connections/new",
751 options: {
752 ...FORM_SHEET_PRESENTATION_OPTIONS,
753 sheetAllowedDetents: [0.55, 0.7],
754 sheetGrabberVisible: true,
755 },
756 }),
757 NewTaskSheet: createNativeStackScreen({
758 screen: NewTaskSheetStack,
759 linking: "new",
760 // The whole new-task flow (choose project → draft → add project) shares
761 // draft state via NewTaskFlowProvider. The expo-router era mounted it in
762 // app/new/_layout.tsx; this layout wrapper is the native-stack equivalent.
763 layout: ({ children }) => (
764 <NewTaskFlowProvider>
765 <View className="flex-1 bg-sheet-solid">{children}</View>
766 </NewTaskFlowProvider>
767 ),
768 options: {
769 gestureEnabled: true,
770 headerShown: false,
771 },
772 }),
773 NotFound: createNativeStackScreen({
774 screen: NotFoundScreen,
775 linking: "*",
776 }),
777 },
778});
779​
780export const RootStack = RootStackConfig.with(function AdaptiveRootStack({ Navigator }) {
781 const { width, height } = useWindowDimensions();
782 const usesWorkspaceFlowScreens =
783 Platform.OS === "android" || deriveLayout({ width, height }).usesSplitView;
784​
785 return (
786 <Navigator
787 screenOptions={({ route }) => {
788 if (route.name !== "SettingsSheet" && route.name !== "NewTaskSheet") {
789 return {};
790 }
791​
792 // Follow the workspace viewport as it resizes; compact iOS keeps sheets.
793 return usesWorkspaceFlowScreens
794 ? { presentation: "card" }
795 : {
796 ...FORM_SHEET_PRESENTATION_OPTIONS,
797 sheetAllowedDetents: [0.92],
798 sheetGrabberVisible: true,
799 };
800 }}
801 />
802 );
803});
804​
805type RootStackType = typeof RootStack;
806​
807const navigationPathConfig = {
808 screens: createPathConfigForStaticNavigation(RootStack) ?? {},
809};
810​
811declare module "@react-navigation/native" {
812 interface RootNavigator extends RootStackType {}