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

Stack.tsx

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