8
8
} from '@react-navigation/native' ;
9
9
import PropTypes from 'prop-types' ;
10
10
import Onyx from 'react-native-onyx' ;
11
+ import Log from '../Log' ;
11
12
import linkTo from './linkTo' ;
12
13
import ROUTES from '../../ROUTES' ;
13
14
import SCREENS from '../../SCREENS' ;
@@ -39,7 +40,7 @@ function setDidTapNotification() {
39
40
*/
40
41
function openDrawer ( ) {
41
42
if ( ! navigationRef . isReady ( ) ) {
42
- console . debug ( '[Navigation] openDrawer failed because navigation ref was not yet ready' ) ;
43
+ Log . hmmm ( '[Navigation] openDrawer failed because navigation ref was not yet ready' ) ;
43
44
return ;
44
45
}
45
46
navigationRef . current . dispatch ( DrawerActions . openDrawer ( ) ) ;
@@ -51,7 +52,7 @@ function openDrawer() {
51
52
*/
52
53
function closeDrawer ( ) {
53
54
if ( ! navigationRef . isReady ( ) ) {
54
- console . debug ( '[Navigation] closeDrawer failed because navigation ref was not yet ready' ) ;
55
+ Log . hmmm ( '[Navigation] closeDrawer failed because navigation ref was not yet ready' ) ;
55
56
return ;
56
57
}
57
58
navigationRef . current . dispatch ( DrawerActions . closeDrawer ( ) ) ;
@@ -74,12 +75,12 @@ function getDefaultDrawerState(isSmallScreenWidth) {
74
75
*/
75
76
function goBack ( shouldOpenDrawer = true ) {
76
77
if ( ! navigationRef . isReady ( ) ) {
77
- console . debug ( '[Navigation] goBack failed because navigation ref was not yet ready' ) ;
78
+ Log . hmmm ( '[Navigation] goBack failed because navigation ref was not yet ready' ) ;
78
79
return ;
79
80
}
80
81
81
82
if ( ! navigationRef . current . canGoBack ( ) ) {
82
- console . debug ( ' Unable to go back') ;
83
+ Log . hmmm ( '[Navigation] Unable to go back') ;
83
84
if ( shouldOpenDrawer ) {
84
85
openDrawer ( ) ;
85
86
}
@@ -95,7 +96,7 @@ function goBack(shouldOpenDrawer = true) {
95
96
*/
96
97
function navigate ( route = ROUTES . HOME ) {
97
98
if ( ! navigationRef . isReady ( ) ) {
98
- console . debug ( '[Navigation] navigate failed because navigation ref was not yet ready' ) ;
99
+ Log . hmmm ( '[Navigation] navigate failed because navigation ref was not yet ready' , { route } ) ;
99
100
return ;
100
101
}
101
102
@@ -129,47 +130,18 @@ function navigate(route = ROUTES.HOME) {
129
130
*/
130
131
function dismissModal ( shouldOpenDrawer = false ) {
131
132
if ( ! navigationRef . isReady ( ) ) {
132
- console . debug ( '[Navigation] dismissModal failed because navigation ref was not yet ready' ) ;
133
+ Log . hmmm ( '[Navigation] dismissModal failed because navigation ref was not yet ready' ) ;
133
134
return ;
134
135
}
135
136
136
137
const normalizedShouldOpenDrawer = _ . isBoolean ( shouldOpenDrawer )
137
138
? shouldOpenDrawer
138
139
: false ;
139
140
140
- let isLeavingDrawerNavigator ;
141
-
142
- // This should take us to the first view of the modal's stack navigator
143
- navigationRef . current . dispatch ( ( state ) => {
144
- // If this is a nested drawer navigator then we pop the screen and
145
- // prevent calling goBack() as it's default behavior is to toggle open the active drawer
146
- if ( state . type === 'drawer' ) {
147
- isLeavingDrawerNavigator = true ;
148
- return StackActions . pop ( ) ;
149
- }
150
-
151
- // If there are multiple routes then we can pop back to the first route
152
- if ( state . routes . length > 1 ) {
153
- return StackActions . popToTop ( ) ;
154
- }
155
-
156
- // Otherwise, we are already on the last page of a modal so just do nothing here as goBack() will navigate us
157
- // back to the screen we were on before we opened the modal.
158
- return StackActions . pop ( 0 ) ;
159
- } ) ;
160
-
161
- if ( isLeavingDrawerNavigator ) {
162
- return ;
163
- }
164
-
165
- // Navigate back to where we were before we launched the modal
166
- goBack ( shouldOpenDrawer ) ;
167
-
168
- if ( ! normalizedShouldOpenDrawer ) {
169
- return ;
141
+ CustomActions . navigateBackToDrawer ( navigationRef ) ;
142
+ if ( normalizedShouldOpenDrawer ) {
143
+ openDrawer ( ) ;
170
144
}
171
-
172
- openDrawer ( ) ;
173
145
}
174
146
175
147
/**
0 commit comments