The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { NavigationState } from "@react-navigation/native"; |
| 2 | import { androidWorkspaceNavigationState } from "../../../lib/android-workspace-navigation"; |
| 3 | import { |
| 4 | isSettingsRoute, |
| 5 | settingsNavigationState, |
| 6 | settingsOpenIn, |
| 7 | } from "../../settings/settings-navigation"; |
| 8 | import type { WorkspaceTab } from "./workspace-tabs-state"; |
| 9 | import { rememberedSettingsPage, workspaceSelectionsIn } from "./workspace-tab-navigation"; |
| 10 | |
| 11 | /** Settings joins the two list tabs as a top-level Android destination. */ |
| 12 | export type AndroidWorkspaceNavigationTab = WorkspaceTab | "settings"; |
| 13 | |
| 14 | const WORKSPACE_ROUTES = new Set(["Home", "Thread", "PullRequest", "Issue"]); |
| 15 | |
| 16 | /** The Settings tab resets over Home alone so stale chat and PR history is dropped. */ |
| 17 | export function androidWorkspaceTabNavigationState( |
| 18 | state: NavigationState, |
| 19 | tab: AndroidWorkspaceNavigationTab, |
| 20 | columns = false, |
| 21 | ) { |
| 22 | const home = androidWorkspaceNavigationState(state); |
| 23 | if (tab !== "settings") return home; |
| 24 | const page = columns |
| 25 | ? rememberedSettingsPage(workspaceSelectionsIn(state.routes, {})) |
| 26 | : undefined; |
| 27 | const current = state.routes.find((route) => route.name === page); |
| 28 | return settingsNavigationState(state, page, current?.params); |
| 29 | } |
| 30 | |
| 31 | /** Settings stays selected while one of its pages is the topmost workspace route. */ |
| 32 | export function androidWorkspaceSettingsOpen(state: NavigationState): boolean { |
| 33 | return settingsOpenIn( |
| 34 | state.routes |
| 35 | .slice(0, state.index + 1) |
| 36 | .filter((route) => WORKSPACE_ROUTES.has(route.name) || isSettingsRoute(route.name)), |
| 37 | ); |
| 38 | } |