0

I have a Logout button in the SideDrawer. When the user hits it, I want to log him/her out, display a drop down alert that remains visible for 2000 ms and then close the drawer. I do not want to toggle the drawer meaning that if the user closes the drawer I do not want to reopen it. How can I do that. I know that there is a toggleDrawer function but that's not what I want.

I have searched the issues in wix/react-native-navigation but did not find any issue talking about this.

Here is my code:

signUserOut = () => {
      firebase.auth().signOut()
        .then( response => {
          this.dropDownAlert.alertWithType( "success", "Success", "Signed out successfully", null, 2000 );

          setTimeout( () => {
            // TODO: We need to close the drawer if it is open not toggle it
            this.props.navigator.toggleDrawer( {
              side: "left"
            } );
          }, 2500 );
        } )
        .catch( error => {
          console.log( "Error signing out:", error );
          this.dropDownAlert.alertWithType( "error", "Error", "Failed signing out. Please, try again.", null, 2000 );
        } );
    };
Hosam Abdelnaser
  • 127
  • 2
  • 11

1 Answers1

0

Please try the following,

import { DrawerActions } from "react-navigation"; //Import it on top

....other code

signUserOut = () => {
      firebase.auth().signOut()
        .then( response => {
          this.dropDownAlert.alertWithType( "success", "Success", "Signed out successfully", null, 2000 );

          setTimeout( () => {
            this.props.navigation.dispatch(DrawerActions.closeDrawer());
          }, 2500 );
        } )
        .catch( error => {
          console.log( "Error signing out:", error );
          this.dropDownAlert.alertWithType( "error", "Error", "Failed signing out. Please, try again.", null, 2000 );
        } );
    };
Jebin Benny
  • 933
  • 1
  • 5
  • 9
  • Thanks a lot but I'm using ` react-native-navigation ` not ` react-navigation ` – Hosam Abdelnaser Apr 30 '19 at 20:24
  • Solved .. the ` toggleDrawer ` function accepts a params object which includes a property named ` to `. if ` to ` is assigned ` closed ` it just closes the Side drawer if it is open. If it is ` closed ` it does nothing. ```js this.props.navigator.toggleDrawer( { side: "left", to: "closed" } ); ``` – Hosam Abdelnaser Apr 30 '19 at 21:22