React Navigation drawer 的状态?(打开或关闭) [英] Status of React Navigation drawer? (open or closed)

查看:42
本文介绍了React Navigation drawer 的状态?(打开或关闭)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 React Navigation 构建一个抽屉,并希望在用户关闭抽屉时执行一些逻辑.我在文档中没有看到任何明显的内容可以让我这样做.有人知道这样做的方法吗?

I'm building a drawer with React Navigation and want to perform some logic if the user closes the drawer. I don't see anything obvious in the documentation that will allow me to do this. Is anyone aware of a way to do this?

推荐答案

您需要自定义导航操作来捕获 DrawerClose 事件:

You need to custom navigation actions to capture the DrawerClose event:

const MyDrawerNavigator = DrawerNavigator({
    //...
});

const defaultGetStateForAction = MyDrawerNavigator.router.getStateForAction;

MyDrawerNavigator.router.getStateForAction = (action, state) => {

    //use 'DrawerOpen' to capture drawer open event
    if (state && action.type === 'Navigation/NAVIGATE' && action.routeName === 'DrawerClose') {
        console.log('DrawerClose');
        //write the code you want to deal with 'DrawerClose' event
    }
    return defaultGetStateForAction(action, state);
};

这篇关于React Navigation drawer 的状态?(打开或关闭)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆