【问题标题】:Open SideDrawer打开 SideDrawer
【发布时间】:2019-04-30 00:11:14
【问题描述】:

我在 SideDrawer 中有一个注销按钮。当用户点击它时,我想将他/她注销,显示一个下拉警报,该警报保持可见 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 );
        } );
    };

【问题讨论】:

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


    【解决方案1】:

    请尝试以下方法,

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

    【讨论】:

    • 非常感谢,但我使用的是`react-native-navigation`而不是`react-navigation`
    • 已解决 .. `toggleDrawer` 函数接受一个 params 对象,该对象包含一个名为` to . if to ` 的属性,分配给` closed `,如果它是打开的,它只会关闭侧边抽屉。如果它是`关闭的`它什么也不做。 js this.props.navigator.toggleDrawer( { side: "left", to: "closed" } );
    猜你喜欢
    • 2016-09-01
    • 1970-01-01
    • 2018-03-21
    • 2017-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2019-06-19
    相关资源
    最近更新 更多