简体   繁体   中英

Drawer navigator button is not working in react-navigation

I can't get why Button in the HomeScreen is not opening a Drawer. Button shows but nothing happens when you click on it. Here is a code, I did all needed imports while its still not working. Are there any examples of this approach which will work?

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>
    );
  }
}

How to make that button open a drawer?

try this

<Button transparent onPress={()=>this.props.navigation.openDrawer()}>

Refer to the examples that react-navigation have in their git repo, it is stated there under

react-navigation/examples/NavigationPlayground/js/MultipleDrawer.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM