fix(dae): navigation back

This commit is contained in:
devthejo 2026-03-08 20:28:40 +01:00
parent cf00b5cea4
commit 59ccc13836
No known key found for this signature in database
GPG key ID: 00CCA7A92B1D5351
2 changed files with 20 additions and 2 deletions

View file

@ -85,6 +85,7 @@ export default React.memo(function DrawerNav() {
return ( return (
<Drawer.Navigator <Drawer.Navigator
backBehavior="history"
drawerContent={(props) => <DrawerContent {...props} />} drawerContent={(props) => <DrawerContent {...props} />}
drawerStyle={{ drawerStyle={{
width: getDefaultDrawerWidth(dimensions), width: getDefaultDrawerWidth(dimensions),

View file

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import { Image } from "react-native"; import { Image } from "react-native";
import { useNavigation } from "@react-navigation/native"; import { useNavigation, CommonActions } from "@react-navigation/native";
import { HeaderBackButton } from "@react-navigation/elements"; import { HeaderBackButton } from "@react-navigation/elements";
import { MaterialCommunityIcons } from "@expo/vector-icons"; import { MaterialCommunityIcons } from "@expo/vector-icons";
@ -28,7 +28,24 @@ export default function HeaderLeft(props) {
if (canGoBack) { if (canGoBack) {
navigation.goBack(); navigation.goBack();
} else { } else {
navigation.navigate(drawerState.topTabPrev || "SendAlert"); // HeaderLeft is rendered by the RootStack which has a single
// "Main" screen, so canGoBack is always false here.
// Dispatch GO_BACK targeted at the Drawer navigator so it
// uses its history-based back behaviour.
const rootState = navigation.getState();
const drawerNavState = rootState.routes[0]?.state;
if (
drawerNavState?.key &&
drawerNavState.history?.filter((h) => h.type === "route")
.length > 1
) {
navigation.dispatch({
...CommonActions.goBack(),
target: drawerNavState.key,
});
} else {
navigation.navigate(drawerState.topTabPrev || "SendAlert");
}
} }
}} }}
backImage={() => ( backImage={() => (