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

Stack.tsx

830 lines30.7 KB

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