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

问题描述 投票:0回答:1

我的抽屉当前没有显示任何内容。如果我摆脱了自定义组件,它将在抽屉上显示Home选项。所以我知道我设置自定义组件的方式有问题,但是我不太确定是什么,因为我没有收到任何错误,我尝试过使用组件的样式。

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>
); 
react-native react-navigation
1个回答
1
投票

你忘了从'native-base'导入Body,从'react-native'导入Image。

要修复您的导入:

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,因为它们没有在您的文件中使用。

© www.soinside.com 2019 - 2024. All rights reserved.