Skip to content

Commit 4b04f73

Browse files
authored
Merge pull request #7725 from hiteshagja/6720
Fix:: Account details stuck in RHN when switching chats
2 parents 18ff4f8 + aa5f9a4 commit 4b04f73

File tree

1 file changed

+16
-36
lines changed

1 file changed

+16
-36
lines changed

src/libs/Navigation/CustomActions.js

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,28 @@ import lodashGet from 'lodash/get';
66
import linkingConfig from './linkingConfig';
77
import navigationRef from './navigationRef';
88

9+
/**
10+
* @returns {Object}
11+
*/
12+
function getActiveState() {
13+
// We use our RootState as the dispatch's state is relative to the active navigator and might not contain our active screen.
14+
return navigationRef.current.getRootState();
15+
}
16+
917
/**
1018
* Go back to the Main Drawer
1119
* @param {Object} navigationRef
1220
*/
1321
function navigateBackToRootDrawer() {
14-
let isLeavingNestedDrawerNavigator = false;
15-
16-
// This should take us to the first view of the modal's stack navigator
17-
navigationRef.current.dispatch((state) => {
18-
// If this is a nested drawer navigator then we pop the screen and
19-
// prevent calling goBack() as it's default behavior is to toggle open the active drawer
20-
if (state.type === 'drawer') {
21-
isLeavingNestedDrawerNavigator = true;
22-
return StackActions.pop();
23-
}
24-
25-
// If there are multiple routes then we can pop back to the first route
26-
if (state.routes.length > 1) {
27-
return StackActions.popToTop();
28-
}
29-
30-
// Otherwise, we are already on the last page of a modal so just do nothing here as goBack() will navigate us
31-
// back to the screen we were on before we opened the modal.
32-
return StackActions.pop(0);
22+
const activeState = getActiveState();
23+
24+
// To navigate to the main drawer Route, pop to the first route on the Root Stack Navigator as the main drawer is always the first route that is activated.
25+
// It will pop all fullscreen and RHN modals that are over the main drawer.
26+
// It won't work when the main drawer is not the first route of the Root Stack Navigator which is not the case ATM.
27+
navigationRef.current.dispatch({
28+
...StackActions.popToTop(),
29+
target: activeState.key,
3330
});
34-
35-
if (isLeavingNestedDrawerNavigator) {
36-
return;
37-
}
38-
39-
// Navigate back to where we were before we launched the modal
40-
if (navigationRef.current.canGoBack()) {
41-
navigationRef.current.goBack();
42-
}
4331
}
4432

4533
/**
@@ -69,14 +57,6 @@ function getScreenNameFromState(state) {
6957
return getRouteFromState(state).name || '';
7058
}
7159

72-
/**
73-
* @returns {Object}
74-
*/
75-
function getActiveState() {
76-
// We use our RootState as the dispatch's state is relative to the active navigator and might not contain our active screen.
77-
return navigationRef.current.getRootState();
78-
}
79-
8060
/**
8161
* Special accomodation must be made for navigating to a screen inside a DrawerNavigator (e.g. our ReportScreen). The web/mWeb default behavior when
8262
* calling "navigate()" does not give us the browser history we would expect for a typical web paradigm (e.g. that navigating from one screen another

0 commit comments

Comments
 (0)