77import {
88 DrawerActions ,
99 DrawerNavigationState ,
10+ DrawerStatus ,
1011 ParamListBase ,
1112 useTheme ,
1213} from '@react-navigation/native' ;
@@ -39,6 +40,7 @@ import { GestureHandlerRootView } from './GestureHandler';
3940import { MaybeScreen , MaybeScreenContainer } from './ScreenFallback' ;
4041
4142type Props = DrawerNavigationConfig & {
43+ defaultStatus : DrawerStatus ;
4244 state : DrawerNavigationState < ParamListBase > ;
4345 navigation : DrawerNavigationHelpers ;
4446 descriptors : DrawerDescriptorMap ;
@@ -71,6 +73,7 @@ function DrawerViewBase({
7173 state,
7274 navigation,
7375 descriptors,
76+ defaultStatus,
7477 drawerContent = ( props : DrawerContentComponentProps ) => (
7578 < DrawerContent { ...props } />
7679 ) ,
@@ -132,25 +135,29 @@ function DrawerViewBase({
132135 } , [ navigation , state . key ] ) ;
133136
134137 React . useEffect ( ( ) => {
135- if ( drawerStatus !== 'open' || drawerType === 'permanent' ) {
138+ if ( drawerStatus === defaultStatus || drawerType === 'permanent' ) {
136139 return ;
137140 }
138141
139- const handleClose = ( ) => {
142+ const handleHardwareBack = ( ) => {
140143 // We shouldn't handle the back button if the parent screen isn't focused
141144 // This will avoid the drawer overriding event listeners from a focused screen
142145 if ( ! navigation . isFocused ( ) ) {
143146 return false ;
144147 }
145148
146- handleDrawerClose ( ) ;
149+ if ( defaultStatus === 'open' ) {
150+ handleDrawerOpen ( ) ;
151+ } else {
152+ handleDrawerClose ( ) ;
153+ }
147154
148155 return true ;
149156 } ;
150157
151158 const handleEscape = ( e : KeyboardEvent ) => {
152159 if ( e . key === 'Escape' ) {
153- handleClose ( ) ;
160+ handleHardwareBack ( ) ;
154161 }
155162 } ;
156163
@@ -159,7 +166,7 @@ function DrawerViewBase({
159166 // This will make sure that our handler will run first when back button is pressed
160167 const subscription = BackHandler . addEventListener (
161168 'hardwareBackPress' ,
162- handleClose
169+ handleHardwareBack
163170 ) ;
164171
165172 if ( Platform . OS === 'web' ) {
@@ -173,7 +180,14 @@ function DrawerViewBase({
173180 document ?. body ?. removeEventListener ?.( 'keyup' , handleEscape ) ;
174181 }
175182 } ;
176- } , [ drawerStatus , drawerType , handleDrawerClose , navigation ] ) ;
183+ } , [
184+ defaultStatus ,
185+ drawerStatus ,
186+ drawerType ,
187+ handleDrawerClose ,
188+ handleDrawerOpen ,
189+ navigation ,
190+ ] ) ;
177191
178192 const renderDrawerContent = ( ) => {
179193 return (
0 commit comments