React Native Navigator:自定义组件不可见

时间:2018-09-16 03:20:45

标签: react-native react-navigation

我的抽屉当前没有任何显示。如果我放弃了自定义组件,它将在抽屉上显示“主页”选项。所以我知道我设置自定义组件的方式有问题,但是我不确定是什么原因,因为我没有收到任何错误,并且我尝试使用该组件的样式。

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createDrawerNavigator } from 'react-navigation';
import HomeScreen from './component/HomeScreen';
import Settings from './component/Settings';
import {Icon, Button, Container, Header, Content, Left} from 'native-base';


export default class App extends React.Component {
  render() {

  return (
    <MyApp/> 
  );
 }
}

const MyApp = createDrawerNavigator({
  Home: {
   screen: HomeScreen
  }
}, {
  initialRouteName: 'Home',
  drawerPosition: 'right',
  contentComponent: CustomDrawerContentComponent,
  drawerOpenRoute: 'DrawerOpen',
  drawerCloseRoute: 'DrawerClose',
  drawerToggleRoute: 'DrawerToggle'
})

const CustomDrawerContentComponent = (props) => (

  <Container>
    <Header style={{height: 200, backgroundColor: 'white', paddingTop: 50}}>
      <Body>
        <Image style={{width: 30, height: 30}} source={require("./img/close.png")}/>
      </Body>
   </Header>

 </Container>
); 

1 个答案:

答案 0 :(得分:1)

您忘记从“本机”导入“身体”,而从“反应本机”导入图像。

要修复您的进口商品,请执行以下操作:

import {Icon, Body, Button, Container, Header, Content, Left} from 'native-base'; import {Image} from 'react-native';

注意,我从import { StyleSheet, Text, View } from 'react-native';中删除了StyleSheet,Text和View模块,因为它们没有在您的文件中使用。