导航('DrawerOpen')不起作用

时间:2018-08-24 11:10:57

标签: reactjs react-native react-navigation

我正在按照本教程制作一个应用程序:

我完全做到了相同。它可以编译,但是“抽屉菜单”的按钮不起作用。这是按钮所在的代码:

    import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import {createBottomTabNavigator} from 'react-navigation';
import ScreenOne from './TabNavigator/ScreenOne';
import ScreenTwo from './TabNavigator/ScreenTwo';
import { Container, Header,Left,Right,Icon } from 'native-base';

export default class AppTabNavigator extends React.Component{

    static navigationOptions = ({navigation}) =>{
        return{
            headerLeft:(
                <View style={{padding:10}}>
                    <Icon name ="menu" style={{fontSize: 24, color : 'black'}} onPress={()=>navigation.navigate('DrawerOpen')} />
                </View>
            )
        }
    }
    render(){
        return(
            <HomeScreenTabNavigator screenProps={{navigation: this.props.navigation}}/>
        )
    }
}

const HomeScreenTabNavigator = new createBottomTabNavigator({
    ScreenOne:{
        screen: ScreenOne,
        navigationOptions:{
            tabBarLabel: 'Feed'
        }
    },
    ScreenTwo:{
        screen: ScreenTwo,
        navigationOptions:{
            tabBarLabel: 'Feed'     }
    }
})

1 个答案:

答案 0 :(得分:0)

自版本2.X的react-navigation以来,您不能使用以下代码:

navigation.navigate('DrawerOpen')

但是您需要使用:

navigation.openDrawer()

另请参阅Drawer documentation