我很反应原生。我想打开抽屉按钮点击但得到错误导航.navigate找不到变量导航。 我试过这个.props.navigation也没用。
以下是我的代码:
import React from 'react';
import Icon from 'react-native-vector-icons/FontAwesome';
import {
StackNavigator,
} from 'react-navigation';
import HomeContainer from './HomeContainer';
const Manager = StackNavigator({
HomeScreen: {
screen: HomeContainer,
navigationOptions: {
// header: null,
headerTitle: 'Home',
headerLeft: <Icon name="menu" size={35} onPress={ () =>{ navigation.navigate('DrawerOpen')}} />
},
},
});
export default Manager;
答案 0 :(得分:1)
您可以尝试如下,
import React from 'react';
import Icon from 'react-native-vector-icons/FontAwesome';
import {
StackNavigator,
} from 'react-navigation';
import HomeContainer from './HomeContainer';
const Manager = StackNavigator({
HomeScreen: {
screen: HomeContainer,
navigationOptions: ({navigation}) => ({
// header: null,
headerTitle: 'Home',
headerLeft: <Icon name="menu" size={35} onPress={ () =>{ navigation.navigate('DrawerOpen')}} />
})
}
});
export default Manager;
navigationOptions
现在返回函数而不是object,navigation
将作为参数传递给此函数。
希望这会有所帮助!