打开侧边抽屉

时间:2019-04-30 00:11:15

标签: react-native wix-react-native-navigation

我在SideDrawer中有一个Logout按钮。当用户点击它时,我要注销他/她,显示一个下拉警报并保持可见状态2000毫秒,然后关闭。我不想切换抽屉,这意味着如果用户关闭抽屉,我不想重新打开它。我怎样才能做到这一点。我知道有一个toggleDrawer函数,但这不是我想要的。

我已经在wix / react-native-navigation中搜索了问题,但没有发现任何有关此的问题。

这是我的代码:

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 );
        } );
    };

1 个答案:

答案 0 :(得分:0)

请尝试以下操作,

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 );
        } );
    };