嵌套抽屉堆栈导航器,触发"DrawerOpen"在 React-Native 上不起作用



我正在与使用React Native与React-Navigation一起制作应用程序。

[我的应用程序的层次结构]

*抽屉(app)

ㄴstacknavigator

ㄴstacknavigator

我想要的是fire 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://reaectnavigation.org/docs/en/drawer-nate-navigation.html

我解决了!

const Nav = StackNavigator({
    mainnav_list:{
        screen: (props) => <TodoList {...props} dbCollectionName={props.screenProps.dbCollectionName}/>,
        navigationOptions:(props) => ({
            headerLeft:(
                <TouchableOpacity onPress={() => {props.screenProps.drawerNavigation.navigate('DrawerOpen');}}>
                    <Text style={{color:'white', marginLeft:15, fontWeight:'bold'}}>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:({navigation}) => <Nav screenProps={{dbCollectionName:'todos', drawerNavigation:navigation}}/> },
    drawer2:{screen:({navigation}) => <Nav screenProps={{dbCollectionName:'todos2', drawerNavigation:navigation}}/> }
})
AppRegistry.registerComponent('TodosFS', () => AppDrawer);

相关内容

  • 没有找到相关文章

最新更新