The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native"; |
| 2 | import { useCallback } from "react"; |
| 3 | import { BackHandler, Keyboard, Platform } from "react-native"; |
| 4 | import { returnToAndroidWorkspaceList } from "../../../lib/android-workspace-navigation"; |
| 5 | |
| 6 | export function useWorkspaceBackNavigation() { |
| 7 | const navigation = useNavigation(); |
| 8 | return () => { |
| 9 | if (Platform.OS === "android") returnToAndroidWorkspaceList(navigation); |
| 10 | else if (navigation.canGoBack()) navigation.goBack(); |
| 11 | else navigation.dispatch(StackActions.replace("Home")); |
| 12 | }; |
| 13 | } |
| 14 | |
| 15 | export function useAndroidWorkspaceBack() { |
| 16 | const goBack = useWorkspaceBackNavigation(); |
| 17 | useFocusEffect( |
| 18 | useCallback(() => { |
| 19 | if (Platform.OS !== "android") return; |
| 20 | const subscription = BackHandler.addEventListener("hardwareBackPress", () => { |
| 21 | if (Keyboard.isVisible()) Keyboard.dismiss(); |
| 22 | else goBack(); |
| 23 | return true; |
| 24 | }); |
| 25 | return () => subscription.remove(); |
| 26 | }, [goBack]), |
| 27 | ); |
| 28 | return goBack; |
| 29 | } |