react-native - 嵌套的 Drawer-StackNavigator,触发 "DrawerOpen"不适用于 React-Native

标签 react-native react-navigation

我正在使用 React Native 和 react-navigation 制作应用。

[我的应用的层次结构]

*抽屉(应用程序)

ㄴ堆栈导航器

ㄴ堆栈导航器

我想要的是触发 navigation.navigate('DrawerOpen');

我可以通过从左边缘拖动来显示我的抽屉,但它不会通过按下导航标题左侧的“菜单按钮”来触发。我花了很多时间来存档这个。请帮助我。

const Nav = StackNavigator({
    mainnav_list:{
        screen: (props) => <TodoList {...props} dbCollectionName={props.screenProps.dbCollectionName}/>,
        navigationOptions:({navigation}) => ({
            headerLeft:(
                <TouchableOpacity onPress={() => {console.log(navigation); navigation.navigate('DrawerOpen');}}>
                    <Text style={{color:'white', marginLeft:15}}>Menu</Text>
                </TouchableOpacity>
            )
        })
    },
    mainnav_detail:{screen: TodoDetail}
}
,
{
    navigationOptions:(props) => ({
        title:props.screenProps.dbCollectionName,
        headerBackTitle:null,
        headerStyle:{backgroundColor:'#000'},
        headerTitleStyle:{color:'#fff'},
        headerTintColor:'#fff',
    })
})

const AppDrawer = DrawerNavigator(
{
    drawer1:{screen:() => <Nav screenProps={{dbCollectionName:'todos'}}/> },
    drawer2:{screen:() => <Nav screenProps={{dbCollectionName:'todos2'}}/> }
})

AppRegistry.registerComponent('TodosFS', () => AppDrawer);

最佳答案

在新版本的 reactnavigation 中打开、关闭或切换你的 DrawerNavigator 只需使用以下内容

this.props.navigation.openDrawer();
this.props.navigation.closeDrawer();
this.props.navigation.toggleDrawer();

https://reactnavigation.org/docs/en/drawer-based-navigation.html

关于react-native - 嵌套的 Drawer-StackNavigator,触发 "DrawerOpen"不适用于 React-Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47794833/

相关文章:

react-native - React Native 的定位、百分比和计算优于 flex 的最佳实践?

react-native - React Native,支持 Windows Phone 和 BlackBerry

react-native - react 导航: Transparent header has no height

react-native - 如何在 Material 顶部选项卡导航器上方呈现单个标题组件?

javascript - 传递 react 导航 goBack 作为引用

android - 找不到类 'android.view.autofill.AutofillManager

javascript - 不了解 Navigator IOS React Native

javascript - 如何使用 Tab Navigator NOT stack navigator 将参数传递给路由

javascript - React 导航 - 如何导航到数据源中的特定索引

ios - 从 ListView 中保存数据的正确方法是什么?