我想在我的 react-native 应用程序中有一个抽屉菜单 . 所以就像你看到我在我的代码中使用react-navigation of react-native来确定路由以及 DrawerNavigator
连接到堆栈屏幕字段中的应用程序!:
const Application = StackNavigator({
Home: {
screen: Login,
}
,
Profile: {
screen: Profile,
}
});
const easyRNRoute = DrawerNavigator({
Stack: {
screen: Application
}
}, {
contentComponent: DrawerMenu,//<XXXDraw
contentOptions: {
activeTintColor: '#e91e63',
style: {
flex: 1,
paddingTop: 15,
} });
我在 app.js
中使用像 </Application>
这样的应用程序 . 我的DrawerMenu指向“//
export default class DrawerMenu extends Component {
render() {
return (
<View>
<Text>Menu</Text>
</View>
);
}
}
和我的页面 - 我想在其中显示菜单并遇到问题 - 包含以下代码:
export default class Profile extends React.Component {
static navigationOptions = { header: null };
constructor(props) {
super(props);
this.state = {
active: 'Today',
};
}
navigate() {
this.navigate.navigation.navigate('DrawerOpen'); // open drawer
}
render() {
return (
<View style={styles.countainer}>
<Text style={styles.header}>Profile</Text>
<Button onPress={this.navigate} title="Menu"></Button>
</View>
);
}
}
问题是这样的:当我点击菜单按钮 . 我有这个错误:
undefined不是对象(评估'this.props.navigation.navigate')
我尝试了一些代码,如: this.props.navigation.navigate('Home');
在组件中,他们正在努力,但我不知道为什么它不起作用,当我在 this.navigate.navigation.navigate 中采取"DrawerOpen"参数 .
我做了一些搜索 . 有人告诉我删除代码中的 this.prop
,但只是错误更改为导航未定义 . 因为这个错误,我遇到了麻烦 . 关于 DrawerMenu
在网上的真正湖泊
3 回答
你能用这段代码:
请阅读以下内容:
https://reactjs.org/docs/handling-events.html
来自网站的简短报价:
在app.js中使用easyRNRoute应用程序,可能会有效