我无法理解为什么HomeScreen中的Button没有打开抽屉。按钮显示,但单击它时没有任何反应。这是一个代码,我做了所有需要的导入,但它仍然无法正常工作。这种方法的例子是否有效?
HomeDrawer.js
import React from 'react';
import { DrawerNavigator } from 'react-navigation';
import HomeScreen from '../screens/HomeScreen';
import FoodScreen from '../screens/FoodScreen';
import RestaurantsScreen from '../screens/RestaurantsScreen';
import ProfileScreen from '../screens/ProfileScreen';
import FavoritesScreen from '../screens/FavoritesScreen';
import SettingsScreen from '../screens/SettingsScreen';
import SideBar from './SideBar';
const HomeDrawer = DrawerNavigator({
home: { screen: HomeScreen },
food: { screen: FoodScreen },
restaurants: { screen: RestaurantsScreen},
profile: { screen: ProfileScreen },
settings: { screen: SettingsScreen }
}, {
contentComponent: (props) => <SideBar {...props} />
});
export default HomeDrawer;
HomeScreen.js
import React from "react";
import { StatusBar } from "react-native";
import {
Button,
Text,
Container,
Card,
CardItem,
Body,
Content,
Header,
Title,
Left,
Icon,
Right
} from "native-base";
export default 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>
<Right />
</Header>
</Container>
);
}
}
如何让按钮打开抽屉?
答案 0 :(得分:0)
试试这个
<Button transparent onPress={()=>this.props.navigation.openDrawer()}>
请参阅反应导航在他们的git repo中的示例,在
下面说明反应的导航/示例/ NavigationPlayground / JS / MultipleDrawer.js