You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/libs/Navigation/CustomActions.js
+16-36Lines changed: 16 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -6,40 +6,28 @@ import lodashGet from 'lodash/get';
6
6
importlinkingConfigfrom'./linkingConfig';
7
7
importnavigationReffrom'./navigationRef';
8
8
9
+
/**
10
+
* @returns {Object}
11
+
*/
12
+
functiongetActiveState(){
13
+
// We use our RootState as the dispatch's state is relative to the active navigator and might not contain our active screen.
14
+
returnnavigationRef.current.getRootState();
15
+
}
16
+
9
17
/**
10
18
* Go back to the Main Drawer
11
19
* @param {Object} navigationRef
12
20
*/
13
21
functionnavigateBackToRootDrawer(){
14
-
letisLeavingNestedDrawerNavigator=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
-
returnStackActions.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
-
returnStackActions.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
-
returnStackActions.pop(0);
22
+
constactiveState=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,
33
30
});
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
-
}
43
31
}
44
32
45
33
/**
@@ -69,14 +57,6 @@ function getScreenNameFromState(state) {
69
57
returngetRouteFromState(state).name||'';
70
58
}
71
59
72
-
/**
73
-
* @returns {Object}
74
-
*/
75
-
functiongetActiveState(){
76
-
// We use our RootState as the dispatch's state is relative to the active navigator and might not contain our active screen.
77
-
returnnavigationRef.current.getRootState();
78
-
}
79
-
80
60
/**
81
61
* Special accomodation must be made for navigating to a screen inside a DrawerNavigator (e.g. our ReportScreen). The web/mWeb default behavior when
82
62
* 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