控制台中没有错误,也没有指出错误的地方。所有示例似乎都已过时,也许我使用的是错误的版本?我使用this作为参考。
依赖项:
"react-native-scripts": "1.14.0",
"expo": "^27.0.1",
"native-base": "^2.7.2",
"react": "16.3.1",
"react-native": "~0.55.2",
"react-navigation": "^2.12.1"
代码:
import React from "react";
import { createDrawerNavigator } from "react-navigation";
import { Text, Root, Container, Content, Header, Left, Button, Icon, Body, Title } from "native-base";
import StyleProvider from "theme/StyleProvider";
class HomeScreen extends React.Component {
render() {
return (
<Container>
<Header>
<Left>
<Button
transparent
onPress={() => this.props.navigation.navigate("DrawerOpen")}
>
<Icon name="menu" />
</Button>
</Left>
<Body>
<Title>HomeScreen</Title>
</Body>
</Header>
<Content padder />
</Container>
);
}
}
const SideBar = () => (
<Container>
<Content>
<Text>Text</Text>
</Content>
</Container>
);
const HomeScreenRouter = createDrawerNavigator({
Home: { screen: HomeScreen }
}, {
contentComponent: props => <SideBar {...props} />
});
export default class App extends React.Component {
render() {
return (
<StyleProvider>
<Root>
<HomeScreenRouter />
</Root>
</StyleProvider>
);
}
}
我不知道我还能提供什么。不知道这是一个错误还是我做错了。
答案 0 :(得分:2)
您只需使用
this.props.navigation.openDrawer();
装有
this.props.navigation.navigate("DrawerOpen")