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

Stack.tsx

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