Skip to content
TypeScript

refactor(mobile): routes declare page, sheet or modal and presets own the platform options

Julius Marmingeda38f863972b
diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx
index 79f0932b1e9..0877e28ec3e 100644
--- a/apps/mobile/src/Stack.tsx
+++ b/apps/mobile/src/Stack.tsx
@@ -134,307 +134,202 @@ import {
registerPresentedRoutes,
} from "./features/layout/workspace-overlay-routes";
import { ShowcaseReadyMarker } from "./features/showcase/ShowcaseCaptureCoordinator";
-import {
- SettingsLegalDocumentCloseHeaderButton,
- SettingsLegalDocumentExternalHeaderButton,
-} from "./features/settings/components/SettingsLegalDocumentRouteScreen";
-import { GLASS_HEADER_OPTIONS, type AppScreenOptions } from "./native/glass-header-options";
+import { immersiveRoute, modalRoute, pageRoute, sheetRoute } from "./features/layout/route-options";
import { deriveLayout } from "./lib/layout";
import { useNativeLayoutMetrics } from "./native/native-layout-metrics";
-import { HORIZONTAL_FORM_SHEET_OPTIONS, formSheetDetents } from "./native/sheet-surface";
+import { isPresentedRoute } from "./native/workspace-stack-projection";
import { workspaceDetailRouter } from "./features/workspace/workspace-detail-selection";
-// Hiding Android's native header after mount can leave detail panes measured short.
-// These screens render their own Material toolbar, so hide it from the first layout.
-const DETAIL_HEADER_OPTIONS: AppScreenOptions = {
- ...GLASS_HEADER_OPTIONS,
- headerShown: Platform.OS !== "android",
-};
-
-// Like Messages on the Duo: reading back through history (scrolling up) minimizes the
-// header, and reversing toward the latest message restores it. Other devices ignore it.
-const THREAD_HEADER_OPTIONS: AppScreenOptions = {
- ...DETAIL_HEADER_OPTIONS,
- unstable_headerMinimizationBehavior: "onScrollUp",
-};
-
-// The Duo minimizes headers on scroll down by default. Home and the pull request lists
-// stutter against it on hardware (not reproducible in the simulator), so they keep theirs.
-const FIXED_DUO_HEADER: AppScreenOptions = { unstable_headerMinimizationBehavior: "never" };
-
-const SOLID_HEADER_OPTIONS: AppScreenOptions = {
- headerBackButtonDisplayMode: "minimal",
- headerBackTitle: "",
- headerLargeTitle: false,
- headerShadowVisible: false,
- headerShown: true,
- headerTitleStyle: { fontSize: 18, fontWeight: "800" },
- headerTransparent: false,
- unstable_navigationItemStyle: Platform.OS === "ios" ? "editor" : undefined,
-};
-
-const SHEET_SOLID_HEADER_OPTIONS: AppScreenOptions = {
- ...SOLID_HEADER_OPTIONS,
- unstable_navigationItemStyle: undefined,
-};
-
-const SHEET_GLASS_HEADER_OPTIONS: AppScreenOptions = {
- ...GLASS_HEADER_OPTIONS,
- unstable_navigationItemStyle: undefined,
-};
-
-const LEGAL_DOCUMENT_HEADER_OPTIONS: AppScreenOptions = {
- ...SHEET_SOLID_HEADER_OPTIONS,
- headerBackVisible: false,
- headerLeft: SettingsLegalDocumentCloseHeaderButton,
- headerRight: () => <SettingsLegalDocumentExternalHeaderButton />,
- presentation: "fullScreenModal",
-};
+const settingsPage = (title: string) => pageRoute({ title, itemStyle: "standard" });
// Thread settings keep the Duo's vertical bar so cancel, search, filter and confirm sit in the
// rail. The picker stack spans the sheet so its header reaches the rail, and insets its content.
-const THREAD_SETTINGS_SHEET_OPTIONS = {
- presentation: "formSheet" as const,
- sheetAllowedDetents: [1],
- sheetGrabberVisible: true,
- nativeContentInsetHorizontally: false,
-};
+const THREAD_SETTINGS_ROUTE = sheetRoute({
+ detent: "full",
+ header: "none",
+ android: "card",
+ spansRail: true,
+});
-// Settings pages are root routes so they share the workspace's columns and header. The
-// `Settings` route marks the Settings tab as open (see settings-navigation.ts).
-const SETTINGS_PAGE_OPTIONS = SHEET_GLASS_HEADER_OPTIONS;
+// Search sheets push on Android like the branch picker; a formSheet there leaves the list's
+// header peeking above it once the keyboard opens.
+const SEARCH_SHEET_ROUTE = sheetRoute({ detent: 0.75, android: "card", itemStyle: "editor" });
const SETTINGS_SCREENS = {
Settings: createNativeStackScreen({
screen: SettingsRouteScreen,
linking: "settings",
options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Settings",
+ ...pageRoute({ title: "Settings", itemStyle: "standard", root: true }),
...(Platform.OS === "android" ? { animation: "none" as const } : {}),
- // Android draws its own app bar here. Hidden only from inside the screen, the native one
- // showed for the first frame of the Settings tab and pushed the page down.
- headerShown: Platform.OS !== "android",
- headerBackVisible: false,
},
}),
SettingsEnvironments: createNativeStackScreen({
screen: SettingsEnvironmentsRouteScreen,
linking: "settings/environments",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Environments",
- },
+ options: settingsPage("Environments"),
}),
SettingsEnvironmentDetail: createNativeStackScreen({
screen: SettingsEnvironmentDetailRouteScreen,
linking: "settings/environments/:environmentId",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Environment" },
+ options: settingsPage("Environment"),
}),
// Old links to New threads and Agent behavior open Threads, which absorbed them.
SettingsEnvironmentNewThreads: createNativeStackScreen({
screen: SettingsThreadsRouteScreen,
linking: "settings/new-threads",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Threads" },
+ options: settingsPage("Threads"),
}),
SettingsEnvironmentSourceControl: createNativeStackScreen({
screen: SettingsEnvironmentSourceControlRouteScreen,
linking: "settings/source-control",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Source control" },
+ options: settingsPage("Source control"),
}),
SettingsEnvironmentAgentBehavior: createNativeStackScreen({
screen: SettingsThreadsRouteScreen,
linking: "settings/agent-behavior",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Threads" },
+ options: settingsPage("Threads"),
}),
SettingsWorktrees: createNativeStackScreen({
screen: SettingsWorktreesRouteScreen,
linking: "settings/worktrees",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Worktrees" },
+ options: settingsPage("Worktrees"),
}),
SettingsLabs: createNativeStackScreen({
screen: SettingsLabsRouteScreen,
linking: "settings/labs",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Labs" },
+ options: settingsPage("Labs"),
}),
SettingsProviderAccounts: createNativeStackScreen({
screen: SettingsProviderAccountsRouteScreen,
linking: "settings/provider-accounts",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Providers" },
+ options: settingsPage("Providers"),
}),
SettingsEnvironmentMaintenance: createNativeStackScreen({
screen: SettingsEnvironmentMaintenanceRouteScreen,
linking: "settings/maintenance",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Maintenance" },
+ options: settingsPage("Maintenance"),
}),
SettingsNotifications: createNativeStackScreen({
screen: SettingsNotificationsRouteScreen,
linking: "settings/notifications",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Notifications" },
+ options: settingsPage("Notifications"),
}),
SettingsThreads: createNativeStackScreen({
screen: SettingsThreadsRouteScreen,
linking: "settings/thread-preferences",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Threads" },
+ options: settingsPage("Threads"),
}),
SettingsAbout: createNativeStackScreen({
screen: SettingsAboutRouteScreen,
linking: "settings/about",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "About" },
+ options: settingsPage("About"),
}),
SettingsEnvironmentNew: createNativeStackScreen({
screen: ConnectionsNewRouteScreen,
linking: "settings/environment-new",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Add Environment",
- },
+ options: settingsPage("Add Environment"),
}),
SettingsArchive: createNativeStackScreen({
screen: ArchivedThreadsRouteScreen,
linking: "settings/archive",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Archive",
- },
+ options: settingsPage("Archive"),
}),
SettingsNavigation: createNativeStackScreen({
screen: SettingsNavigationRouteScreen,
linking: "settings/navigation-tabs",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Navigation tabs" },
+ options: settingsPage("Navigation tabs"),
}),
SettingsAppearance: createNativeStackScreen({
screen: SettingsAppearanceRouteScreen,
linking: "settings/appearance",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Appearance",
- },
+ options: settingsPage("Appearance"),
}),
SettingsProjectGrouping: createNativeStackScreen({
screen: SettingsProjectGroupingRouteScreen,
linking: "settings/project-grouping",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "General",
- },
+ options: settingsPage("General"),
}),
SettingsOrganization: createNativeStackScreen({
screen: SettingsProjectGroupingRouteScreen,
linking: "settings/organization",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "General",
- },
+ options: settingsPage("General"),
}),
SettingsProjectOverview: createNativeStackScreen({
screen: SettingsProjectOverviewRouteScreen,
linking: "settings/project",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Projects" },
+ options: settingsPage("Projects"),
}),
SettingsKeyboard: createNativeStackScreen({
screen: SettingsKeyboardRouteScreen,
linking: "settings/keyboard",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Keyboard",
- },
+ options: settingsPage("Keyboard"),
}),
SettingsMicrophone: createNativeStackScreen({
screen: SettingsMicrophoneRouteScreen,
linking: "settings/microphone",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Microphone",
- },
+ options: settingsPage("Microphone"),
}),
SettingsFollowUp: createNativeStackScreen({
screen: SettingsFollowUpRouteScreen,
linking: "settings/follow-ups",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Chat",
- },
+ options: settingsPage("Chat"),
}),
SettingsScheduledTasks: createNativeStackScreen({
screen: SettingsScheduledTasksRouteScreen,
linking: "settings/scheduled-tasks",
options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Scheduled tasks",
+ ...settingsPage("Scheduled tasks"),
headerTitleStyle: { fontSize: 16, fontWeight: "800" },
},
}),
SettingsScheduledTaskNew: createNativeStackScreen({
screen: SettingsScheduledTaskNewRouteScreen,
linking: "settings/scheduled-tasks/new",
- options: { ...SETTINGS_PAGE_OPTIONS, title: "New scheduled task" },
+ options: settingsPage("New scheduled task"),
}),
SettingsScheduledTaskEdit: createNativeStackScreen({
screen: SettingsScheduledTaskEditRouteScreen,
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Edit scheduled task" },
+ options: settingsPage("Edit scheduled task"),
}),
SettingsScheduledTaskBranch: createNativeStackScreen({
screen: ScheduledTaskBranchPickerRouteScreen,
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Base branch" },
+ options: settingsPage("Base branch"),
}),
SettingsScheduledTaskModel: createNativeStackScreen({
screen: ScheduledTaskModelPickerRouteScreen,
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- headerShown: false,
- ...(Platform.OS === "android"
- ? { presentation: "card" as const }
- : {
- ...THREAD_SETTINGS_SHEET_OPTIONS,
- }),
- },
+ options: THREAD_SETTINGS_ROUTE,
}),
SettingsClientStorage: createNativeStackScreen({
screen: SettingsClientStorageRouteScreen,
linking: "settings/client-storage",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Client Storage",
- },
+ options: settingsPage("Client Storage"),
}),
SettingsDiagnostics: createNativeStackScreen({
screen: SettingsDiagnosticsRouteScreen,
linking: "settings/diagnostics",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Diagnostics",
- },
+ options: settingsPage("Diagnostics"),
}),
// These params snapshot the tap time, local filters, and freshly aggregated pools.
// A linking path would round-trip them as URL query strings and preserve stale values.
SettingsUsageAccount: createNativeStackScreen({
screen: UsageLimitAccountScreen,
- options: { ...SETTINGS_PAGE_OPTIONS, title: "Account" },
+ options: settingsPage("Account"),
}),
SettingsOpenSourceLicenses: createNativeStackScreen({
screen: SettingsOpenSourceLicensesRouteScreen,
linking: "settings/open-source-licenses",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Open source licenses",
- },
+ options: settingsPage("Open source licenses"),
}),
SettingsOpenSourceLicense: createNativeStackScreen({
screen: SettingsOpenSourceLicenseRouteScreen,
linking: "settings/open-source-licenses/:entryKey",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "License notice",
- },
+ options: settingsPage("License notice"),
}),
SettingsUsage: createNativeStackScreen({
screen: UsageRouteScreen,
linking: "settings/usage",
- options: {
- ...SETTINGS_PAGE_OPTIONS,
- title: "Usage",
- },
+ options: settingsPage("Usage"),
}),
SettingsAuth: createNativeStackScreen({
screen: SettingsAuthRouteScreen,
@@ -588,14 +483,9 @@ const RootStackConfig = createWorkspaceStackNavigator({
focus: recordHomeFocus,
},
options: {
- ...GLASS_HEADER_OPTIONS,
- ...FIXED_DUO_HEADER,
+ ...pageRoute({ duoMinimize: "never", root: true }),
contentStyle: { backgroundColor: "transparent" },
- headerBackVisible: false,
...getCompactBrandHeaderOptions(),
- // Android draws Home's bars itself. Set here, not by the screen: Home also renders in the
- // sidebar column, and that copy clears the route's set options when it unmounts.
- headerShown: Platform.OS !== "android",
},
}),
PullRequest: createNativeStackScreen({
@@ -604,385 +494,229 @@ const RootStackConfig = createWorkspaceStackNavigator({
path: "pull-requests/:environmentId/:projectId/:repository/:number",
parse: { number: Number },
},
- options: { ...DETAIL_HEADER_OPTIONS, ...FIXED_DUO_HEADER },
+ options: pageRoute({ duoMinimize: "never" }),
}),
PullRequestGuideStop: createNativeStackScreen({
screen: PullRequestGuideStopScreen,
- options: DETAIL_HEADER_OPTIONS,
+ options: pageRoute(),
}),
PullRequestFile: createNativeStackScreen({
screen: PullRequestFileRouteScreen,
- options: DETAIL_HEADER_OPTIONS,
+ options: pageRoute(),
}),
PullRequestFiles: createNativeStackScreen({
screen: PullRequestFilesSheet,
- options: {
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.6),
- sheetGrabberVisible: true,
- sheetCornerRadius: Platform.OS === "android" ? 28 : undefined,
- },
+ options: sheetRoute({ detent: 0.6 }),
}),
PullRequestReviewers: createNativeStackScreen({
screen: PullRequestReviewersScreen,
- options: {
- ...DETAIL_HEADER_OPTIONS,
- ...FIXED_DUO_HEADER,
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.75),
- sheetGrabberVisible: true,
- headerBackVisible: false,
- },
+ options: sheetRoute({ detent: 0.75, itemStyle: "editor", duoMinimize: "never" }),
}),
PullRequestLabels: createNativeStackScreen({
screen: PullRequestLabelsScreen,
- // Presented like PullRequestFilterSearch, whose search sheet it shares.
- options:
- Platform.OS === "android"
- ? { presentation: "card", headerShown: false }
- : {
- ...DETAIL_HEADER_OPTIONS,
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.75),
- sheetGrabberVisible: true,
- headerBackVisible: false,
- },
+ options: SEARCH_SHEET_ROUTE,
}),
PullRequestFilterSearch: createNativeStackScreen({
screen: PullRequestFilterSearchScreen,
- // Android pushes it like the branch picker; a formSheet there leaves the list's header
- // peeking above it once the keyboard opens.
- options:
- Platform.OS === "android"
- ? { presentation: "card", headerShown: false }
- : {
- ...DETAIL_HEADER_OPTIONS,
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.75),
- sheetGrabberVisible: true,
- headerBackVisible: false,
- },
+ options: SEARCH_SHEET_ROUTE,
}),
PullRequestDiscussion: createNativeStackScreen({
screen: PullRequestDiscussionScreen,
- options: DETAIL_HEADER_OPTIONS,
+ options: pageRoute(),
}),
PullRequestInlineComment: createNativeStackScreen({
screen: PullRequestInlineCommentScreen,
- options: {
- ...(Platform.OS === "android"
- ? { presentation: "fullScreenModal" as const }
- : { ...SHEET_GLASS_HEADER_OPTIONS, ...HORIZONTAL_FORM_SHEET_OPTIONS }),
- sheetAllowedDetents: Platform.OS === "android" ? undefined : formSheetDetents(0.75),
- sheetGrabberVisible: Platform.OS !== "android",
- },
+ options: sheetRoute({ detent: 0.75, android: "fullScreen" }),
}),
PullRequestReview: createNativeStackScreen({
screen: PullRequestReviewSheet,
- options: {
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.75),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.75, androidFit: true }),
}),
PullRequestEdit: createNativeStackScreen({
screen: PullRequestEditScreen,
- options: {
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.75),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.75, androidFit: true }),
}),
Thread: createNativeStackScreen({
screen: ThreadRouteScreen,
linking: { path: "threads/:environmentId?/:threadId?", alias: ["new/draft"] },
- options: THREAD_HEADER_OPTIONS,
+ options: pageRoute({ duoMinimize: "onScrollUp" }),
}),
NewTaskProject: createNativeStackScreen({
screen: NewTaskRouteScreen,
linking: { path: "new", alias: ["new/project"] },
- options: { ...GLASS_HEADER_OPTIONS, title: "Choose project" },
+ options: pageRoute({ title: "Choose project" }),
}),
NewTaskEnvironment: createNativeStackScreen({
linking: "new/draft/environment",
screen: NewTaskEnvironmentPickerRouteScreen,
- options: { ...GLASS_HEADER_OPTIONS, title: "Environment" },
+ options: pageRoute({ title: "Environment" }),
}),
NewTaskBranch: createNativeStackScreen({
linking: "new/draft/branch",
screen: NewTaskBranchPickerRouteScreen,
- options: { ...GLASS_HEADER_OPTIONS, title: "Branch" },
+ options: pageRoute({ title: "Branch" }),
}),
AddProject: createNativeStackScreen({
linking: "new/add-project",
screen: AddProjectSourceRoute,
- options: {
- ...GLASS_HEADER_OPTIONS,
- title: "Add project",
- },
+ options: pageRoute({ title: "Add project" }),
}),
AddProjectRepository: createNativeStackScreen({
linking: "new/add-project/repository",
screen: AddProjectRepositoryRoute,
- options: GLASS_HEADER_OPTIONS,
+ options: pageRoute(),
}),
AddProjectDestination: createNativeStackScreen({
linking: "new/add-project/destination",
screen: AddProjectDestinationRoute,
- options: GLASS_HEADER_OPTIONS,
+ options: pageRoute(),
}),
AddProjectLocal: createNativeStackScreen({
linking: "new/add-project/local",
screen: AddProjectLocalRoute,
- options: GLASS_HEADER_OPTIONS,
+ options: pageRoute(),
}),
AddProjectNew: createNativeStackScreen({
linking: "new/add-project/new",
screen: AddProjectNewRoute,
- options: GLASS_HEADER_OPTIONS,
+ options: pageRoute(),
}),
NewTaskFiles: createNativeStackScreen({
linking: "new/draft/files",
screen: ThreadFilesTreeScreen,
- options: SOLID_HEADER_OPTIONS,
+ options: pageRoute({ header: "solid" }),
}),
NewTaskFile: createNativeStackScreen({
linking: "new/draft/files/:path*",
screen: ThreadFileScreen,
- options: SOLID_HEADER_OPTIONS,
+ options: pageRoute({ header: "solid" }),
}),
NewTaskAttachment: createNativeStackScreen({
screen: AttachmentFileScreen,
linking: "new/draft/attachments/:attachmentId",
- options: SOLID_HEADER_OPTIONS,
+ options: pageRoute({ header: "solid" }),
}),
NewTaskThreadSettings: createNativeStackScreen({
screen: NewTaskThreadSettingsRouteScreen,
linking: "new/draft/settings",
- options: {
- gestureEnabled: true,
- headerShown: false,
- ...(Platform.OS === "android"
- ? { presentation: "card" as const }
- : THREAD_SETTINGS_SHEET_OPTIONS),
- },
+ options: THREAD_SETTINGS_ROUTE,
}),
ThreadTerminal: createNativeStackScreen({
screen: ThreadTerminalRouteScreen,
linking: `${THREAD_LINKING_PREFIX}/terminal`,
- options: SOLID_HEADER_OPTIONS,
+ options: pageRoute({ header: "solid" }),
}),
ThreadInspectorFullscreen: createNativeStackScreen({
screen: FullscreenThreadRouteScreen,
- options: {
- ...THREAD_HEADER_OPTIONS,
- presentation: "fullScreenModal",
- },
+ options: modalRoute({ header: "glass", itemStyle: "editor", duoMinimize: "onScrollUp" }),
}),
ThreadDevicePreview: createNativeStackScreen({
screen: DevicePreviewRouteScreen,
linking: `${THREAD_LINKING_PREFIX}/devices`,
- options: {
- presentation: "fullScreenModal",
- headerShown: false,
- gestureEnabled: false,
- autoHideHomeIndicator: true,
- navigationBarHidden: true,
- },
+ options: immersiveRoute({ hideSystemBars: true }),
}),
ThreadBrowserPreview: createNativeStackScreen({
screen: BrowserPreviewRouteScreen,
linking: `${THREAD_LINKING_PREFIX}/browser`,
- options: {
- presentation: "fullScreenModal",
- headerShown: false,
- gestureEnabled: false,
- },
+ options: immersiveRoute(),
}),
ThreadReview: createNativeStackScreen({
screen: ReviewSheet,
linking: `${THREAD_LINKING_PREFIX}/review`,
- options: GLASS_HEADER_OPTIONS,
+ options: pageRoute(),
}),
ThreadReviewComment: createNativeStackScreen({
screen: ReviewCommentComposerSheet,
linking: `${THREAD_LINKING_PREFIX}/review-comment`,
- options: {
- // Android formSheets cannot host the keyboard-driven comment composer.
- ...(Platform.OS === "android"
- ? { presentation: "fullScreenModal" as const }
- : HORIZONTAL_FORM_SHEET_OPTIONS),
- sheetAllowedDetents: Platform.OS === "android" ? undefined : formSheetDetents(0.55),
- sheetGrabberVisible: Platform.OS !== "android",
- },
+ options: sheetRoute({ detent: 0.55, header: "none", android: "fullScreen" }),
}),
ThreadFiles: createNativeStackScreen({
screen: ThreadFilesTreeScreen,
linking: `${THREAD_LINKING_PREFIX}/files`,
- options: {
- ...GLASS_HEADER_OPTIONS,
- title: "Files",
- },
+ options: pageRoute({ title: "Files" }),
}),
ThreadFile: createNativeStackScreen({
screen: ThreadFileScreen,
linking: `${THREAD_LINKING_PREFIX}/files/:path*`,
- options: GLASS_HEADER_OPTIONS,
+ options: pageRoute(),
}),
ThreadMcpApp: createNativeStackScreen({
screen: McpAppFullscreenScreen,
linking: `${THREAD_LINKING_PREFIX}/apps/:itemId`,
- options: {
- presentation: "fullScreenModal",
- headerShown: false,
- gestureEnabled: false,
- },
+ options: immersiveRoute(),
}),
ThreadAttachment: createNativeStackScreen({
screen: AttachmentFileScreen,
linking: `${THREAD_LINKING_PREFIX}/attachments/:attachmentId`,
- options: SOLID_HEADER_OPTIONS,
+ options: pageRoute({ header: "solid" }),
}),
ThreadSettingsSheet: createNativeStackScreen({
screen: ExistingThreadSettingsRouteScreen,
- options: {
- gestureEnabled: true,
- headerShown: false,
- ...(Platform.OS === "android"
- ? { presentation: "card" as const }
- : {
- ...THREAD_SETTINGS_SHEET_OPTIONS,
- }),
- },
+ options: THREAD_SETTINGS_ROUTE,
}),
ThreadQueue: createNativeStackScreen({
screen: ThreadQueueSheet,
- options: {
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- headerShown: false,
- sheetAllowedDetents: formSheetDetents(0.65, 0.95),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.65, androidMaxDetent: 0.95, header: "none" }),
}),
ThreadBackgroundWork: createNativeStackScreen({
screen: ThreadBackgroundWorkSheet,
- options: {
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- headerShown: false,
- sheetAllowedDetents: formSheetDetents(0.5, 0.9),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.5, androidMaxDetent: 0.9, header: "none" }),
}),
ThreadAgents: createNativeStackScreen({
screen: ThreadAgentsSheet,
- options: {
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- headerShown: false,
- sheetAllowedDetents: formSheetDetents(0.5, 0.9),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.5, androidMaxDetent: 0.9, header: "none" }),
}),
GitOverview: createNativeStackScreen({
screen: GitOverviewSheet,
linking: `${THREAD_LINKING_PREFIX}/git`,
- options: {
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.55),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.55 }),
}),
ThreadPullRequests: createNativeStackScreen({
screen: ThreadPullRequestsSheet,
linking: `${THREAD_LINKING_PREFIX}/pull-requests`,
- options: {
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.55),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.55 }),
}),
GitCommit: createNativeStackScreen({
screen: GitCommitSheet,
linking: `${THREAD_LINKING_PREFIX}/git/commit`,
- options: {
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.8),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.8, androidFit: true }),
}),
GitBranches: createNativeStackScreen({
screen: GitBranchesSheet,
linking: `${THREAD_LINKING_PREFIX}/git/branches`,
- options: {
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.55),
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.55, androidFit: true }),
}),
GitConfirm: createNativeStackScreen({
screen: GitConfirmSheet,
linking: `${THREAD_LINKING_PREFIX}/git-confirm`,
- options: {
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: [0.55, 0.7],
- sheetGrabberVisible: true,
- },
+ options: sheetRoute({ detent: 0.55, maxDetent: 0.7, header: "none", androidFit: true }),
}),
...SETTINGS_SCREENS,
SettingsLegal: createNativeStackScreen({
screen: SettingsLegalRouteScreen,
linking: "settings/legal",
- options: {
- ...LEGAL_DOCUMENT_HEADER_OPTIONS,
- title: "Legal",
- },
+ options: modalRoute({ header: "solid", title: "Legal" }),
}),
ConnectOnboarding: createNativeStackScreen({
screen: ConnectOnboardingRouteScreen,
linking: "connect-onboarding",
- options: {
- // Android root formSheets lack a native stack bar; the route provides its own sheet AppBar.
- ...(Platform.OS === "android" ? { headerShown: false } : SHEET_SOLID_HEADER_OPTIONS),
+ options: sheetRoute({
title: "Set up T3 Connect",
- gestureEnabled: true,
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: formSheetDetents(0.6, 0.95),
- sheetGrabberVisible: true,
- },
+ header: "solid",
+ detent: 0.6,
+ androidMaxDetent: 0.95,
+ }),
}),
Connections: createNativeStackScreen({
screen: ConnectionsRouteScreen,
linking: "connections",
- options: {
- title: "Environments",
- ...(Platform.OS === "android"
- ? { presentation: "card" as const, headerShown: false }
- : {
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: [0.55, 0.7],
- sheetGrabberVisible: true,
- }),
- },
+ options: sheetRoute({ title: "Environments", detent: 0.55, maxDetent: 0.7, android: "card" }),
}),
ConnectionsNew: createNativeStackScreen({
screen: ConnectionsNewRouteScreen,
linking: "connections/new",
- options: {
- // Mount the iOS header immediately to avoid remounting the pairing form.
- ...(Platform.OS === "ios" ? SHEET_GLASS_HEADER_OPTIONS : undefined),
- title: "Add Environment",
- ...HORIZONTAL_FORM_SHEET_OPTIONS,
- sheetAllowedDetents: [0.55, 0.7],
- sheetGrabberVisible: true,
- sheetCornerRadius: Platform.OS === "android" ? 28 : undefined,
- },
+ options: sheetRoute({ title: "Add Environment", detent: 0.55, maxDetent: 0.7 }),
}),
NotFound: createNativeStackScreen({
screen: NotFoundScreen,
@@ -1025,11 +759,7 @@ function ScreenRenderFallback(props: RenderFailureProps & { readonly routeName:
registerPresentedRoutes(
Object.entries(RootStackConfig.config.screens ?? {}).flatMap(([name, screen]) => {
const options = (screen as { readonly options?: unknown }).options;
- const presentation =
- options && typeof options === "object"
- ? (options as { readonly presentation?: string }).presentation
- : undefined;
- return presentation !== undefined && presentation !== "card" ? [name] : [];
+ return options && typeof options === "object" && isPresentedRoute(options) ? [name] : [];
}),
);
diff --git a/apps/mobile/src/components/ui/SheetHeader.android.tsx b/apps/mobile/src/components/ui/SheetHeader.android.tsx
index 35f4ddd0514..156c7f0e91e 100644
--- a/apps/mobile/src/components/ui/SheetHeader.android.tsx
+++ b/apps/mobile/src/components/ui/SheetHeader.android.tsx
@@ -1,6 +1,7 @@
import { View } from "react-native";
import { AppBar } from "./AppBar";
+import { NativeStackScreenOptions } from "../../native/StackHeader";
import { Button } from "./Button";
import { IconButton } from "./IconButton";
import type { SheetCloseButtonProps, SheetHeaderProps } from "./SheetHeader.types";
@@ -36,20 +37,27 @@ export function SheetHeader(props: SheetHeaderProps) {
) : undefined;
return (
- <AppBar
- embedded
- sheet={props.presentation === "inline"}
- title={props.title}
- subtitle={props.subtitle}
- leading={
- <SheetCloseButton
- {...(props.onCancel ? { onCancel: props.onCancel } : { onClose: props.onClose })}
- accessibilityLabel={props.accessibilityLabel}
- disabled={props.dismissDisabled}
- />
- }
- trailing={trailing}
- hideBottomBorder
- />
+ <>
+ {props.dismissDisabled === undefined ? null : (
+ // A sheet that can't be closed with its button can't be swiped away either.
+ <NativeStackScreenOptions options={{ gestureEnabled: !props.dismissDisabled }} />
+ )}
+ <AppBar
+ embedded
+ sheet={props.presentation === "inline"}
+ title={props.title}
+ subtitle={props.subtitle}
+ actions={props.actions}
+ leading={
+ <SheetCloseButton
+ {...(props.onCancel ? { onCancel: props.onCancel } : { onClose: props.onClose })}
+ accessibilityLabel={props.accessibilityLabel}
+ disabled={props.dismissDisabled}
+ />
+ }
+ trailing={trailing}
+ hideBottomBorder
+ />
+ </>
);
}
diff --git a/apps/mobile/src/components/ui/SheetHeader.tsx b/apps/mobile/src/components/ui/SheetHeader.tsx
index 126ecb58c23..6f2037558c6 100644
--- a/apps/mobile/src/components/ui/SheetHeader.tsx
+++ b/apps/mobile/src/components/ui/SheetHeader.tsx
@@ -21,10 +21,22 @@ export function SheetCloseButton(props: SheetCloseButtonProps) {
}
export function SheetHeader(props: SheetHeaderProps) {
- return props.presentation !== "inline" ? (
- <NativeSheetHeader {...props} />
- ) : (
- <InlineSheetHeader {...props} />
+ return (
+ <>
+ <SheetDismissGuard dismissDisabled={props.dismissDisabled} />
+ {props.presentation !== "inline" ? (
+ <NativeSheetHeader {...props} />
+ ) : (
+ <InlineSheetHeader {...props} />
+ )}
+ </>
+ );
+}
+
+/** A sheet that can't be closed with its button can't be swiped away either. */
+function SheetDismissGuard(props: { readonly dismissDisabled: boolean | undefined }) {
+ return props.dismissDisabled === undefined ? null : (
+ <NativeStackScreenOptions options={{ gestureEnabled: !props.dismissDisabled }} />
);
}
@@ -53,8 +65,18 @@ function NativeSheetHeader(props: SheetHeaderProps) {
disabled={props.dismissDisabled}
/>
</Toolbar>
- {confirmation || props.trailing ? (
+ {confirmation || props.trailing || props.actions?.length ? (
<Toolbar placement="right">
+ {props.actions?.map((action) => (
+ <Toolbar.Button
+ key={action.accessibilityLabel}
+ icon={typeof action.icon === "string" ? action.icon : action.icon.ios}
+ accessibilityLabel={action.accessibilityLabel}
+ disabled={action.disabled || action.loading}
+ tintColor={action.tintColor}
+ onPress={action.onPress}
+ />
+ ))}
{props.trailing ? (
<Toolbar.Custom>
<View>{props.trailing}</View>
@@ -135,8 +157,17 @@ function InlineSheetHeader(props: SheetHeaderProps) {
);
const confirm = props.confirm ? <InlineConfirmation confirmation={props.confirm} /> : null;
const trailing =
- props.trailing || confirm ? (
+ props.trailing || confirm || props.actions?.length ? (
<View className="flex-row items-center gap-2">
+ {props.actions?.map((action) => (
+ <IconButton
+ key={action.accessibilityLabel}
+ icon={action.icon}
+ accessibilityLabel={action.accessibilityLabel}
+ disabled={action.disabled || action.loading}
+ onPress={action.onPress}
+ />
+ ))}
{props.trailing}
{confirm}
</View>
diff --git a/apps/mobile/src/components/ui/SheetHeader.types.ts b/apps/mobile/src/components/ui/SheetHeader.types.ts
index a5b38949fa5..e39442c1fe5 100644
--- a/apps/mobile/src/components/ui/SheetHeader.types.ts
+++ b/apps/mobile/src/components/ui/SheetHeader.types.ts
@@ -1,5 +1,7 @@
import type { ReactNode } from "react";
+import type { AppBarAction } from "./AppBar.types";
+
type SheetDismissAction =
| { readonly onCancel: () => void; readonly onClose?: never }
| { readonly onClose: () => void; readonly onCancel?: never };
@@ -18,6 +20,7 @@ export type SheetHeaderProps = SheetDismissAction & {
readonly dismissDisabled?: boolean;
readonly confirm?: SheetConfirmation;
readonly presentation?: "native" | "inline";
+ readonly actions?: ReadonlyArray<AppBarAction>;
readonly trailing?: ReactNode;
};
diff --git a/apps/mobile/src/features/connection/ConnectionsRouteScreen.tsx b/apps/mobile/src/features/connection/ConnectionsRouteScreen.tsx
index 4b1360d4af5..c1c75f38185 100644
--- a/apps/mobile/src/features/connection/ConnectionsRouteScreen.tsx
+++ b/apps/mobile/src/features/connection/ConnectionsRouteScreen.tsx
@@ -1,10 +1,9 @@
-import { Toolbar } from "../../components/ui/Toolbar";
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
import { useNavigation } from "@react-navigation/native";
import type { EnvironmentId } from "@t3tools/contracts";
import { useState } from "react";
-import { Platform, View } from "react-native";
+import { View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppBar } from "../../components/ui/AppBar";
@@ -30,28 +29,18 @@ export function ConnectionsRouteScreen() {
return (
<View collapsable={false} className="flex-1 bg-sheet">
- {Platform.OS === "android" ? (
- <AppBar
- embedded
- title="Environments"
- onBack={() => navigation.goBack()}
- actions={[
- {
- accessibilityLabel: "Add environment",
- icon: "plus",
- onPress: () => navigation.navigate("ConnectionsNew"),
- },
- ]}
- />
- ) : (
- <Toolbar placement="right">
- <Toolbar.Button
- icon="plus"
- onPress={() => navigation.navigate("ConnectionsNew")}
- separateBackground
- />
- </Toolbar>
- )}
+ <AppBar
+ title="Environments"
+ onClose={() => navigation.goBack()}
+ closeAccessibilityLabel="Close environments"
+ actions={[
+ {
+ accessibilityLabel: "Add environment",
+ icon: "plus",
+ onPress: () => navigation.navigate("ConnectionsNew"),
+ },
+ ]}
+ />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
showsVerticalScrollIndicator={false}
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx
index 46592527501..2ee2000d400 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.android.tsx
@@ -21,7 +21,10 @@ import { use, type ComponentProps } from "react";
import { RoutedFormSheetContext } from "../../components/ui/RoutedFormSheetContext";
-import { projectStackPresentation } from "../../native/workspace-stack-projection";
+import {
+ isPresentedRoute,
+ projectStackPresentation,
+} from "../../native/workspace-stack-projection";
import {
WorkspaceColumnsRendererContext,
WorkspacePresentationHostContext,
@@ -37,8 +40,7 @@ function WorkspaceStackView(props: ViewProps) {
const isOverlay = (route: Route) => {
const descriptor = props.descriptors[route.key] ?? props.describe(route, true);
- const presentation = descriptor.options.presentation;
- return presentation !== undefined && presentation !== "card";
+ return isPresentedRoute(descriptor.options);
};
const projection = projectStackPresentation(props.state, isOverlay);
const workspaceRoutes = projection.workspace;
@@ -121,14 +123,19 @@ function WorkspaceStackNavigator({
descriptors={Object.fromEntries(
Object.entries(descriptors).map(([key, descriptor]) => [
key,
- descriptor.options.presentation === "formSheet"
- ? {
- ...descriptor,
- render: () => (
- <RoutedFormSheetContext value>{descriptor.render()}</RoutedFormSheetContext>
- ),
- }
- : descriptor,
+ {
+ ...descriptor,
+ // Screens draw their bar in-tree; hiding the native one only after mount
+ // shows it for the first frame and leaves the page measured short.
+ options: { ...descriptor.options, headerShown: false },
+ ...(descriptor.options.presentation === "formSheet"
+ ? {
+ render: () => (
+ <RoutedFormSheetContext value>{descriptor.render()}</RoutedFormSheetContext>
+ ),
+ }
+ : undefined),
+ },
]),
)}
navigation={navigation}
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index ea1b37ffb06..49569f9b8e6 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -71,6 +71,7 @@ import {
partitionStackPresentations,
reconcileStackScreens,
type CollapsedSplitColumn,
+ isPresentedRoute,
} from "../../native/workspace-stack-projection";
import {
NativePrimaryColumnContext,
@@ -505,8 +506,7 @@ function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean
const [primaryVisible, setPrimaryVisible] = useState(false);
const metrics = useNativeLayoutMetrics();
const projection = projectWorkspaceStack(props.state, (route) => {
- const presentation = props.descriptors[route.key]?.options.presentation;
- return presentation !== undefined && presentation !== "card";
+ return isPresentedRoute(props.descriptors[route.key]?.options);
});
// The root's willDisappear reaches JS frames into the push, so hide the dock in the commit that
// pushes; the native events still own every later change, including back gestures.
@@ -566,8 +566,7 @@ function WorkspaceStackView(props: ViewProps & { readonly nativeColumns: boolean
),
};
const overlays = partitionStackPresentations(projection.overlays, (route) => {
- const presentation = props.descriptors[route.key]?.options.presentation;
- return presentation !== undefined && presentation !== "card";
+ return isPresentedRoute(props.descriptors[route.key]?.options);
});
const routes = [baseRoute, ...overlays.map((group) => group[0]!)];
return (
@@ -646,8 +645,7 @@ function WorkspaceStackNavigator({
if (!nativeWorkspaceColumnsReady) return null;
const settingsOpen = settingsOpenIn(
state.routes.slice(0, state.index + 1).filter((route) => {
- const presentation = descriptors[route.key]?.options.presentation;
- return presentation === undefined || presentation === "card";
+ return !isPresentedRoute(descriptors[route.key]?.options);
}),
);
return (
diff --git a/apps/mobile/src/features/layout/route-options.ts b/apps/mobile/src/features/layout/route-options.ts
new file mode 100644
index 00000000000..b8b30e2d02a
--- /dev/null
+++ b/apps/mobile/src/features/layout/route-options.ts
@@ -0,0 +1,158 @@
+import { Platform } from "react-native";
+
+import { GLASS_HEADER_OPTIONS, type AppScreenOptions } from "../../native/glass-header-options";
+import { formSheetDetents } from "../../native/sheet-surface";
+
+/**
+ * Route presets for the root stack. A route says what it is (a page, a sheet, a modal); the
+ * preset owns how each platform presents it, so screens never set presentation options.
+ *
+ * Android never shows the native stack header: every screen draws its bar in-tree with AppBar or
+ * SheetHeader, and the Android navigators hide the native one from the first frame.
+ */
+
+type HeaderStyle = "glass" | "solid" | "none";
+
+const SOLID_HEADER_OPTIONS: AppScreenOptions = {
+ headerBackButtonDisplayMode: "minimal",
+ headerBackTitle: "",
+ headerLargeTitle: false,
+ headerShadowVisible: false,
+ headerShown: true,
+ headerTitleStyle: { fontSize: 18, fontWeight: "800" },
+ headerTransparent: false,
+};
+
+function headerOptions(header: HeaderStyle, itemStyle: "editor" | "standard"): AppScreenOptions {
+ if (header === "none") return { headerShown: false };
+ if (header === "glass") {
+ // The editor style needs liquid glass, which GLASS_HEADER_OPTIONS already gates it on.
+ return itemStyle === "editor"
+ ? GLASS_HEADER_OPTIONS
+ : { ...GLASS_HEADER_OPTIONS, unstable_navigationItemStyle: undefined };
+ }
+ return {
+ ...SOLID_HEADER_OPTIONS,
+ unstable_navigationItemStyle:
+ itemStyle === "editor" && Platform.OS === "ios" ? "editor" : undefined,
+ };
+}
+
+export interface PageRouteOptions {
+ readonly title?: string;
+ /** Glass bars let content scroll under them. Defaults to glass. */
+ readonly header?: HeaderStyle;
+ /** iOS 26 groups a page's bar items like an editor; settings pages use the standard look. */
+ readonly itemStyle?: "editor" | "standard";
+ /**
+ * How the Duo minimizes the bar while scrolling. "never" for lists that stutter against the
+ * default on hardware; "onScrollUp" for conversations read backwards, like Messages.
+ */
+ readonly duoMinimize?: "never" | "onScrollUp";
+ /** The page is the root of its column, so it never shows Back. */
+ readonly root?: boolean;
+}
+
+/** A page in the workspace: pushed on compact windows, a column page on wide ones. */
+export function pageRoute(options: PageRouteOptions = {}): AppScreenOptions {
+ return {
+ ...headerOptions(options.header ?? "glass", options.itemStyle ?? "editor"),
+ ...(options.title === undefined ? undefined : { title: options.title }),
+ ...(options.duoMinimize
+ ? { unstable_headerMinimizationBehavior: options.duoMinimize }
+ : undefined),
+ ...(options.root ? { headerBackVisible: false } : undefined),
+ };
+}
+
+export interface SheetRouteOptions {
+ readonly title?: string;
+ /** Defaults to glass. "none" when the sheet draws no bar at all. */
+ readonly header?: HeaderStyle;
+ /** The initial detent, or "full" for a sheet that always covers the window. */
+ readonly detent: number | "full";
+ /** The largest detent. Defaults to the full window on iOS, where the Duo needs it. */
+ readonly maxDetent?: number;
+ /** Android's expanded detent when `maxDetent` is unset. */
+ readonly androidMaxDetent?: number;
+ /** Android sizes the sheet to its content instead of using detents. */
+ readonly androidFit?: boolean;
+ /**
+ * Where an Android formSheet can't host the screen: "card" pushes it, "fullScreen" presents it
+ * full screen (Android formSheets can't host a keyboard-driven composer).
+ */
+ readonly android?: "sheet" | "card" | "fullScreen";
+ /** The sheet spans the Duo's rail, and its content insets itself. */
+ readonly spansRail?: boolean;
+ readonly itemStyle?: "editor" | "standard";
+ readonly duoMinimize?: "never" | "onScrollUp";
+}
+
+function sheetDetents(options: SheetRouteOptions): number[] {
+ if (options.detent === "full") return [1];
+ if (options.maxDetent !== undefined) return [options.detent, options.maxDetent];
+ return formSheetDetents(options.detent, options.androidMaxDetent);
+}
+
+/** A sheet over the workspace: a formSheet with a grabber that closes, never goes back. */
+export function sheetRoute(options: SheetRouteOptions): AppScreenOptions {
+ const header = headerOptions(options.header ?? "glass", options.itemStyle ?? "standard");
+ const shared = {
+ ...header,
+ ...(options.title === undefined ? undefined : { title: options.title }),
+ ...(options.duoMinimize
+ ? { unstable_headerMinimizationBehavior: options.duoMinimize }
+ : undefined),
+ headerBackVisible: false,
+ gestureEnabled: true,
+ } satisfies AppScreenOptions;
+ if (Platform.OS === "android" && options.android === "card") {
+ return { ...shared, presentation: "card" };
+ }
+ if (Platform.OS === "android" && options.android === "fullScreen") {
+ return { ...shared, presentation: "fullScreenModal" };
+ }
+ return {
+ ...shared,
+ presentation: "formSheet",
+ sheetPrefersHorizontalBars: true,
+ sheetGrabberVisible: true,
+ sheetAllowedDetents:
+ Platform.OS === "android" && options.androidFit ? "fitToContents" : sheetDetents(options),
+ ...(Platform.OS === "android" ? { sheetCornerRadius: 28 } : undefined),
+ ...(options.spansRail ? { nativeContentInsetHorizontally: false } : undefined),
+ } as AppScreenOptions;
+}
+
+export interface ModalRouteOptions {
+ readonly title?: string;
+ /** Defaults to "none": the screen draws its own SheetHeader or has no bar. */
+ readonly header?: HeaderStyle;
+ readonly itemStyle?: "editor" | "standard";
+ readonly duoMinimize?: "never" | "onScrollUp";
+}
+
+/** A full-screen modal over the workspace with a close button, not a back button. */
+export function modalRoute(options: ModalRouteOptions = {}): AppScreenOptions {
+ return {
+ ...headerOptions(options.header ?? "none", options.itemStyle ?? "standard"),
+ ...(options.title === undefined ? undefined : { title: options.title }),
+ ...(options.duoMinimize
+ ? { unstable_headerMinimizationBehavior: options.duoMinimize }
+ : undefined),
+ headerBackVisible: false,
+ presentation: "fullScreenModal",
+ };
+}
+
+/** Full-screen media (a device stream, a browser, an app) with no bar and no dismiss gesture. */
+export function immersiveRoute(options: { readonly hideSystemBars?: boolean } = {}) {
+ return {
+ presentation: "fullScreenModal",
+ headerShown: false,
+ gestureEnabled: false,
+ ...(options.hideSystemBars
+ ? { autoHideHomeIndicator: true, navigationBarHidden: true }
+ : undefined),
+ } satisfies AppScreenOptions;
+}
diff --git a/apps/mobile/src/features/pull-requests/PullRequestSheetContent.tsx b/apps/mobile/src/features/pull-requests/PullRequestSheetContent.tsx
index e13fb7e3cf1..d3830ea82ab 100644
--- a/apps/mobile/src/features/pull-requests/PullRequestSheetContent.tsx
+++ b/apps/mobile/src/features/pull-requests/PullRequestSheetContent.tsx
@@ -5,7 +5,6 @@ import { Platform, ScrollView, useWindowDimensions, View } from "react-native";
import { KeyboardAvoidingView } from "react-native-keyboard-controller";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { ScreenContent } from "../../components/ui/ScreenContent";
-import { NativeStackScreenOptions } from "../../native/StackHeader";
export function PullRequestSheetContent(props: {
readonly title: string;
@@ -34,12 +33,6 @@ export function PullRequestSheetContent(props: {
className="bg-sheet ios:flex-1"
style={android ? { maxHeight: windowHeight * 0.92 } : undefined}
>
- <NativeStackScreenOptions
- options={{
- gestureEnabled: !props.busy,
- ...(android ? { sheetCornerRadius: 28, sheetAllowedDetents: "fitToContents" } : {}),
- }}
- />
<SheetHeader
presentation={android ? "inline" : "native"}
title={props.title}
diff --git a/apps/mobile/src/features/settings/components/SettingsLegalDocumentRouteScreen.tsx b/apps/mobile/src/features/settings/components/SettingsLegalDocumentRouteScreen.tsx
index 54819d25b14..ca79a8c66fc 100644
--- a/apps/mobile/src/features/settings/components/SettingsLegalDocumentRouteScreen.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsLegalDocumentRouteScreen.tsx
@@ -1,49 +1,16 @@
-import { SheetCloseButton } from "../../../components/ui/SheetHeader";
+import { SheetHeader } from "../../../components/ui/SheetHeader";
import { useNavigation } from "@react-navigation/native";
import { useState } from "react";
import { Linking, Pressable, View } from "react-native";
import { WebView } from "react-native-webview";
import { Button } from "../../../components/ui/Button";
-import { IconButton } from "../../../components/ui/IconButton";
import { AppActivityIndicator } from "../../../components/ui/AppActivityIndicator";
import { AppText as Text } from "../../../components/ui/AppText";
import { LoadingStrip } from "../../../components/ui/LoadingStrip";
import { SymbolView } from "../../../components/ui/AppSymbol";
-import { NativeStackScreenOptions } from "../../../native/StackHeader";
import { isLegalDocumentUrl, LEGAL_URL } from "../lib/legal-document-url";
-export function SettingsLegalDocumentCloseHeaderButton() {
- const navigation = useNavigation();
-
- return (
- <SheetCloseButton
- accessibilityLabel="Close legal document"
- onClose={() => navigation.goBack()}
- />
- );
-}
-
-export function SettingsLegalDocumentExternalHeaderButton({
- externalUrl = LEGAL_URL,
-}: {
- readonly externalUrl?: string;
-}) {
- const safeExternalUrl = isLegalDocumentUrl(externalUrl) ? externalUrl : LEGAL_URL;
-
- return (
- <IconButton
- accessibilityLabel="Open legal documents in external browser"
- icon="safari"
- onPress={() => void Linking.openURL(safeExternalUrl).catch(() => undefined)}
- />
- );
-}
-
-function externalHeaderButton(externalUrl: string) {
- return () => <SettingsLegalDocumentExternalHeaderButton externalUrl={externalUrl} />;
-}
-
interface SettingsLegalDocumentRouteScreenProps {
readonly documentName: string;
readonly documentUrl: string;
@@ -57,12 +24,20 @@ export function SettingsLegalDocumentRouteScreen({
const [loadProgress, setLoadProgress] = useState(0);
const [loadError, setLoadError] = useState<string | null>(null);
const [externalUrl, setExternalUrl] = useState(documentUrl);
+ const navigation = useNavigation();
+ const safeExternalUrl = isLegalDocumentUrl(externalUrl) ? externalUrl : LEGAL_URL;
const headerOptions = (
- <NativeStackScreenOptions
- options={{
- headerRight: externalHeaderButton(externalUrl),
- }}
- optionsVersion={externalUrl}
+ <SheetHeader
+ title={documentName}
+ accessibilityLabel="Close legal document"
+ onClose={() => navigation.goBack()}
+ actions={[
+ {
+ accessibilityLabel: "Open legal documents in external browser",
+ icon: "safari",
+ onPress: () => void Linking.openURL(safeExternalUrl).catch(() => undefined),
+ },
+ ]}
/>
);
@@ -71,40 +46,44 @@ export function SettingsLegalDocumentRouteScreen({
};
if (loadError) {
return (
- <View className="flex-1 items-center justify-center gap-4 bg-sheet px-8">
+ <View className="flex-1 bg-sheet">
{headerOptions}
- <SymbolView
- name="exclamationmark.triangle"
- size={32}
- tintColorClassName={"accent-icon"}
- type="monochrome"
- weight="regular"
- />
- <View className="items-center gap-2">
- <Text className="text-center font-t3-bold text-lg text-foreground">
- Couldn&apos;t load the {documentName.toLowerCase()}
- </Text>
- <Text selectable className="text-center text-sm leading-normal text-foreground-muted">
- {loadError}
- </Text>
- </View>
- <View className="w-full max-w-[320px] gap-2">
- <Button
- label="Try Again"
- tone="contrast"
- fullWidth
- onPress={() => {
- setLoadError(null);
- setReloadKey((value) => value + 1);
- }}
+ <View className="flex-1 items-center justify-center gap-4 px-8">
+ <SymbolView
+ name="exclamationmark.triangle"
+ size={32}
+ tintColorClassName={"accent-icon"}
+ type="monochrome"
+ weight="regular"
/>
- <Pressable
- accessibilityRole="link"
- onPress={() => openExternalUrl(documentUrl)}
- className="items-center rounded-xl px-4 py-3 active:bg-foreground/5"
- >
- <Text className="font-t3-medium text-base text-foreground-muted">Open in Browser</Text>
- </Pressable>
+ <View className="items-center gap-2">
+ <Text className="text-center font-t3-bold text-lg text-foreground">
+ Couldn&apos;t load the {documentName.toLowerCase()}
+ </Text>
+ <Text selectable className="text-center text-sm leading-normal text-foreground-muted">
+ {loadError}
+ </Text>
+ </View>
+ <View className="w-full max-w-[320px] gap-2">
+ <Button
+ label="Try Again"
+ tone="contrast"
+ fullWidth
+ onPress={() => {
+ setLoadError(null);
+ setReloadKey((value) => value + 1);
+ }}
+ />
+ <Pressable
+ accessibilityRole="link"
+ onPress={() => openExternalUrl(documentUrl)}
+ className="items-center rounded-xl px-4 py-3 active:bg-foreground/5"
+ >
+ <Text className="font-t3-medium text-base text-foreground-muted">
+ Open in Browser
+ </Text>
+ </Pressable>
+ </View>
</View>
</View>
);
diff --git a/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx b/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
index b18da049f5d..e223090c3eb 100644
--- a/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
+++ b/apps/mobile/src/features/threads/ThreadAgentsSheet.tsx
@@ -23,7 +23,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppBar } from "../../components/ui/AppBar";
import { AppText as Text } from "../../components/ui/AppText";
import { environmentThreadDetails } from "../../state/threads";
-import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
+import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
import { useEnvironments } from "../../state/environments";
import { SubagentRow } from "./SubagentRow";
@@ -165,7 +165,6 @@ export function ThreadAgentsSheet({ route }: StaticScreenProps<AgentsTarget>) {
return (
<View collapsable={false} className="flex-1 bg-sheet">
- <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
<AppBar sheet title="Agents" onBack={() => navigation.goBack()} />
<ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
</View>
diff --git a/apps/mobile/src/features/threads/ThreadBackgroundWorkSheet.tsx b/apps/mobile/src/features/threads/ThreadBackgroundWorkSheet.tsx
index 67d657b6578..351e723fbbc 100644
--- a/apps/mobile/src/features/threads/ThreadBackgroundWorkSheet.tsx
+++ b/apps/mobile/src/features/threads/ThreadBackgroundWorkSheet.tsx
@@ -15,7 +15,7 @@ import { AppBar } from "../../components/ui/AppBar";
import { SymbolView } from "../../components/ui/AppSymbol";
import { AppText as Text } from "../../components/ui/AppText";
import { ScreenContent } from "../../components/ui/ScreenContent";
-import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
+import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
import { NativeHeader, NativeScreen } from "../../native/ThemedScreenStack";
import { environmentThreadShells } from "../../state/threads";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
@@ -96,7 +96,6 @@ export function ThreadBackgroundWorkSheet({ route }: StaticScreenProps<Backgroun
}
return (
<View collapsable={false} className="flex-1 bg-sheet">
- <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
<AppBar sheet title="Background work" onBack={() => navigation.goBack()} />
<ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
</View>
diff --git a/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx b/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx
index 21d3c655ab4..0c801eb7601 100644
--- a/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx
+++ b/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx
@@ -9,7 +9,6 @@ import { AppText as Text } from "../../components/ui/AppText";
import { ScreenContent } from "../../components/ui/ScreenContent";
import { SheetHeader } from "../../components/ui/SheetHeader";
import { Toolbar } from "../../components/ui/Toolbar";
-import { NativeStackScreenOptions } from "../../native/StackHeader";
import { useOpenPullRequest } from "../../native/useOpenPullRequest";
import { useThreadSelection } from "../../state/use-thread-selection";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
@@ -110,7 +109,6 @@ export function ThreadPullRequestsSheet(
return (
<View collapsable={false} className="flex-1 bg-header">
- <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
<AppBar
sheet
title={title}
diff --git a/apps/mobile/src/features/threads/ThreadQueueControl.tsx b/apps/mobile/src/features/threads/ThreadQueueControl.tsx
index 82c7df56da2..12e01311148 100644
--- a/apps/mobile/src/features/threads/ThreadQueueControl.tsx
+++ b/apps/mobile/src/features/threads/ThreadQueueControl.tsx
@@ -27,7 +27,7 @@ import { Menu } from "../../components/ui/Menu";
import { ScreenContent } from "../../components/ui/ScreenContent";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
-import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
+import { nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
import { useAssetUrl } from "../../state/assets";
import { useQuietThreadShell } from "../../state/entities";
import { useEnvironmentQuery } from "../../state/query";
@@ -397,7 +397,6 @@ export function ThreadQueueSheet({ route }: StaticScreenProps<QueueTarget>) {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<View collapsable={false} className="flex-1 bg-sheet">
- <NativeStackScreenOptions options={{ sheetCornerRadius: 28 }} />
<AppBar sheet title="Queued" onBack={() => navigation.goBack()} />
<ScreenContent insetHorizontal={layout.usesSplitView}>{content}</ScreenContent>
</View>
diff --git a/apps/mobile/src/features/threads/git/GitBranchesSheet.tsx b/apps/mobile/src/features/threads/git/GitBranchesSheet.tsx
index aceeda2ea58..d2298c64ab8 100644
--- a/apps/mobile/src/features/threads/git/GitBranchesSheet.tsx
+++ b/apps/mobile/src/features/threads/git/GitBranchesSheet.tsx
@@ -7,7 +7,6 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppBar } from "../../../components/ui/AppBar";
import { SheetHeader } from "../../../components/ui/SheetHeader";
import { ScreenContent } from "../../../components/ui/ScreenContent";
-import { NativeStackScreenOptions } from "../../../native/StackHeader";
import { AppText as Text, AppTextInput as TextInput } from "../../../components/ui/AppText";
import { cn } from "../../../lib/cn";
import { useEnvironmentQuery } from "../../../state/query";
@@ -69,14 +68,6 @@ export function GitBranchesSheet(_props: GitBranchesSheetProps) {
className="bg-sheet ios:flex-1"
style={Platform.OS === "android" ? { maxHeight: windowHeight * 0.92 } : undefined}
>
- {Platform.OS === "android" ? (
- <NativeStackScreenOptions
- options={{
- sheetCornerRadius: 28,
- sheetAllowedDetents: "fitToContents",
- }}
- />
- ) : null}
{Platform.OS === "android" ? (
<AppBar
sheet
diff --git a/apps/mobile/src/features/threads/git/GitCommitSheet.tsx b/apps/mobile/src/features/threads/git/GitCommitSheet.tsx
index f833a2ec4ce..6612bf0a5a2 100644
--- a/apps/mobile/src/features/threads/git/GitCommitSheet.tsx
+++ b/apps/mobile/src/features/threads/git/GitCommitSheet.tsx
@@ -8,7 +8,6 @@ import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { SymbolView } from "../../../components/ui/AppSymbol";
-import { NativeStackScreenOptions } from "../../../native/StackHeader";
import { AppText as Text, AppTextInput as TextInput } from "../../../components/ui/AppText";
import { cn } from "../../../lib/cn";
import { useEnvironmentQuery } from "../../../state/query";
@@ -86,11 +85,6 @@ export function GitCommitSheet(_props: GitCommitSheetProps) {
className="bg-sheet ios:flex-1 android:flex-col-reverse"
style={android ? { maxHeight: windowHeight * 0.92 } : undefined}
>
- {android ? (
- <NativeStackScreenOptions
- options={{ sheetCornerRadius: 28, sheetAllowedDetents: "fitToContents" }}
- />
- ) : null}
{android ? null : header}
<ScreenContent fitToContents>
<ScrollView
diff --git a/apps/mobile/src/features/threads/git/GitConfirmSheet.tsx b/apps/mobile/src/features/threads/git/GitConfirmSheet.tsx
index edb8a46eb7a..fe7df8aa2b3 100644
--- a/apps/mobile/src/features/threads/git/GitConfirmSheet.tsx
+++ b/apps/mobile/src/features/threads/git/GitConfirmSheet.tsx
@@ -11,7 +11,6 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AppBar } from "../../../components/ui/AppBar";
import { ScreenContent } from "../../../components/ui/ScreenContent";
-import { NativeStackScreenOptions } from "../../../native/StackHeader";
import { AppText as Text } from "../../../components/ui/AppText";
import { useSelectedThreadGitActions } from "../../../state/use-selected-thread-git-actions";
import { useSelectedThreadGitState } from "../../../state/use-selected-thread-git-state";
@@ -121,14 +120,6 @@ export function GitConfirmSheet(props: GitConfirmSheetProps) {
className="bg-sheet ios:flex-1"
style={Platform.OS === "android" ? { maxHeight: windowHeight * 0.92 } : undefined}
>
- {Platform.OS === "android" ? (
- <NativeStackScreenOptions
- options={{
- sheetCornerRadius: 28,
- sheetAllowedDetents: "fitToContents",
- }}
- />
- ) : null}
{Platform.OS === "android" ? (
<AppBar sheet title="Confirm action" onBack={() => navigation.goBack()} hideBottomBorder />
) : (
diff --git a/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx b/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
index 1c246e694ec..98e63c96b33 100644
--- a/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
+++ b/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
@@ -27,7 +27,6 @@ import { ScreenContent } from "../../../components/ui/ScreenContent";
import { useAdaptiveWorkspaceLayout } from "../../layout/AdaptiveWorkspaceLayout";
import { InspectorSheetContext } from "../../layout/workspace-inspector-sheet";
import { AppText as Text } from "../../../components/ui/AppText";
-import { NativeStackScreenOptions } from "../../../native/StackHeader";
import { useEnvironmentQuery } from "../../../state/query";
import { useThreadSelection } from "../../../state/use-thread-selection";
import { useSelectedThreadGitActions } from "../../../state/use-selected-thread-git-actions";
@@ -376,9 +375,6 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
collapsable={false}
className={Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 bg-sheet"}
>
- <NativeStackScreenOptions
- options={{ sheetCornerRadius: Platform.OS === "android" ? 28 : undefined }}
- />
<AppBar
sheet
title={currentBranchLabel}
diff --git a/apps/mobile/src/native/createV5StackNavigator.ios.tsx b/apps/mobile/src/native/createV5StackNavigator.ios.tsx
index 7788400ec61..31490b85283 100644
--- a/apps/mobile/src/native/createV5StackNavigator.ios.tsx
+++ b/apps/mobile/src/native/createV5StackNavigator.ios.tsx
@@ -29,6 +29,7 @@ import { V5StackHeader } from "./V5StackHeader.ios";
import type { AppNativeStackNavigationOptions } from "./StackHeader";
import { NativeColumnContent } from "./NativeColumnContent.ios";
import {
+ isPresentedRoute,
nativeStackPopAction,
partitionStackPresentations,
reconcileStackScreens,
@@ -264,8 +265,7 @@ export function V5CardStackView(
export function V5StackView(props: V5StackViewProps) {
const groups = partitionStackPresentations(props.state.routes, (route) => {
- const presentation = props.descriptors[route.key]?.options.presentation;
- return presentation !== undefined && presentation !== "card";
+ return isPresentedRoute(props.descriptors[route.key]?.options);
});
const routes = groups.map((group) => group[0]!);
const descriptors = Object.fromEntries(
diff --git a/apps/mobile/src/native/sheet-surface.ts b/apps/mobile/src/native/sheet-surface.ts
index 9de5943a008..3d7eeaefd57 100644
--- a/apps/mobile/src/native/sheet-surface.ts
+++ b/apps/mobile/src/native/sheet-surface.ts
@@ -1,10 +1,5 @@
import { Platform } from "react-native";
-export const HORIZONTAL_FORM_SHEET_OPTIONS = {
- presentation: "formSheet" as const,
- sheetPrefersHorizontalBars: true,
-};
-
export function formSheetDetents(initialDetent: number, androidExpandedDetent = 0.92) {
// Duo moves the status bar above the sheet only at the maximum native detent.
return [initialDetent, Platform.OS === "ios" ? 1 : androidExpandedDetent];
diff --git a/apps/mobile/src/native/workspace-stack-projection.ts b/apps/mobile/src/native/workspace-stack-projection.ts
index 7d12cc89a31..281887a3910 100644
--- a/apps/mobile/src/native/workspace-stack-projection.ts
+++ b/apps/mobile/src/native/workspace-stack-projection.ts
@@ -161,3 +161,9 @@ export function reconcileStackScreens<T extends { readonly key: string }>(
});
return screens;
}
+
+/** Whether a route is presented over the stack (a sheet or modal) rather than pushed. */
+export function isPresentedRoute(options: { readonly presentation?: string } | undefined) {
+ const presentation = options?.presentation;
+ return presentation !== undefined && presentation !== "card";
+}