React Native Drawer导航

时间:2017-12-20 07:00:41

标签: react-native react-navigation

您好,我正在尝试在React Native中实现抽屉导航 提到this example

我差不多完成了编码,但是在抽屉类(contentComponent)中添加HomeScreenRouter属性时出现错误。删除它后,我能够成功运行它并且一切正常但是当我使用contentComponent添加侧边栏菜单时会抛出错误。我的抽屉需要定制设计。

error-image

这是抽屉的代码:

import React, { Component } from "react";
import HomeScreen from "./HomeScreen.js";
import MainScreenNavigator from "../DealScreen/mychat.js";
import Profiled from "../profilescreen/Profile.js";
import SideBar from "../SideBar/SideBar.js";


import { DrawerNavigator } from "react-navigation";
const HomeScreenRouter = DrawerNavigator(
  {
    Home: { screen: HomeScreen },
    Chat: { screen: MainScreenNavigator },
    Profile: { screen: Profiled },




  },

  {
    contentComponent: props => <SideBar {...props} />
  });  
export default HomeScreenRouter;

Sidemenu:

import React from "react";
import { AppRegistry, Image, StatusBar } from "react-native";
import { Container, Content, Text, List, ListItem } from "native-base";

export default class SideBar extends React.Component {
  render() {
    const routes = ["Home", "Chat", "Profile"];
    return (
      <Container>
        <Content>
          <Image
            source={{
              uri: "https://github.com/GeekyAnts/NativeBase-KitchenSink/raw/react-navigation/img/drawer-cover.png"
            }}
            style={{
              height: 120,
              alignSelf: "stretch",
              justifyContent: "center",
              alignItems: "center"
            }}>
            <Image
              square
              style={{ height: 80, width: 70 }}
              source={{
                uri: "https://github.com/GeekyAnts/NativeBase-KitchenSink/raw/react-navigation/img/logo.png"
              }}
            />
          </Image>
          <List
            dataArray={routes}
            renderRow={data => {
              return (
                <ListItem
                  button
                  onPress={() => this.props.navigation.navigate("Profile")}>
                  <Text>{data}</Text>
                </ListItem>
              );
            }}
          />
        </Content>
      </Container>
    );
  }
}

0 个答案:

没有答案