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

Stack.tsx

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