Skip to content

Commit 361a000

Browse files
authored
Merge pull request #43658 from software-mansion-labs/fix-for-android-hybrid-back
[HybridApp] Fix android back button behaviour - NewDot part
2 parents 595967d + 12e777f commit 361a000

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/libs/Navigation/setupCustomAndroidBackHandler/index.android.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {findFocusedRoute, StackActions} from '@react-navigation/native';
22
import type {StackScreenProps} from '@react-navigation/stack';
3-
import {BackHandler} from 'react-native';
3+
import {BackHandler, NativeModules} from 'react-native';
44
import getTopmostCentralPaneRoute from '@navigation/getTopmostCentralPaneRoute';
55
import navigationRef from '@navigation/navigationRef';
66
import type {BottomTabNavigatorParamList, RootStackParamList, State} from '@navigation/types';
@@ -23,6 +23,12 @@ function setupCustomAndroidBackHandler() {
2323
return false;
2424
}
2525

26+
const isLastScreenOnStack = bottomTabRoutes.length === 1 && rootState.routes.length === 1;
27+
28+
if (NativeModules.HybridAppModule && isLastScreenOnStack) {
29+
NativeModules.HybridAppModule.exitApp();
30+
}
31+
2632
// Handle back press on the search page.
2733
// We need to pop two screens, from the central pane and from the bottom tab.
2834
if (bottomTabRoutes[bottomTabRoutes.length - 1].name === SCREENS.SEARCH.BOTTOM_TAB && focusedRoute?.name === SCREENS.SEARCH.CENTRAL_PANE) {

src/types/modules/react-native.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type StartupTimer from '@libs/StartupTimer/types';
1212

1313
type HybridAppModule = {
1414
closeReactNativeApp: () => void;
15+
exitApp: () => void;
1516
};
1617

1718
type RNTextInputResetModule = {

0 commit comments

Comments
 (0)