The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useNavigation, useRoute } from "@react-navigation/native"; |
| 2 | import { Platform } from "react-native"; |
| 3 | |
| 4 | import { resetAndroidWorkspace } from "../../lib/android-workspace-navigation"; |
| 5 | import { useHardwareBack } from "../../lib/backHandler"; |
| 6 | import { useAdaptiveWorkspaceLayout } from "../layout/adaptive-workspace-context"; |
| 7 | |
| 8 | /** |
| 9 | * The page's Back action, or undefined for the first page beside the Settings list on wide |
| 10 | * Android: that page roots the detail column, so Back leaves Settings rather than emptying it. |
| 11 | */ |
| 12 | export function useSettingsPageBack() { |
| 13 | const navigation = useNavigation(); |
| 14 | const route = useRoute(); |
| 15 | const { layout } = useAdaptiveWorkspaceLayout(); |
| 16 | const routes = navigation.getState()?.routes ?? []; |
| 17 | const below = routes[routes.findIndex((candidate) => candidate.key === route.key) - 1]; |
| 18 | const columnRoot = |
| 19 | Platform.OS === "android" && layout.usesSplitView && below?.name === "Settings"; |
| 20 | useHardwareBack(columnRoot, () => { |
| 21 | resetAndroidWorkspace(navigation); |
| 22 | return true; |
| 23 | }); |
| 24 | return columnRoot ? undefined : () => navigation.goBack(); |
| 25 | } |