React native 如何在react native中的抽屉标题中放置图像?

React native 如何在react native中的抽屉标题中放置图像?,react-native,React Native,我使用的是React导航版本:5.x。这是我的App.js: import { createDrawerNavigator } from '@react-navigation/drawer'; import ImageInDrawer from './common/ImageInDrawer'; const DrawerAccountant = createDrawerNavigator(); function AccountantDrawer() { return ( <

我使用的是React导航版本:5.x。这是我的App.js:

import { createDrawerNavigator } from '@react-navigation/drawer';
import ImageInDrawer from './common/ImageInDrawer';

const DrawerAccountant = createDrawerNavigator();

function AccountantDrawer() {
  return (
    <DrawerAccountant.Navigator initialRouteName="Home" contentComponent={ImageInDrawer}>
      <DrawerAccountant.Screen name="Home" component={AccountantScreen} />
      <DrawerAccountant.Screen name="My Account" component={MyAccountScreen} />
      <DrawerAccountant.Screen name="Tasks" component={TasksScreen} />
      <DrawerAccountant.Screen name="Task Price" component={TaskPriceScreen} />
    </DrawerAccountant.Navigator>
  );
}
从'@react navigation/drawer'导入{createDrawerNavigator};
从“./common/ImageInDrawer”导入ImageInDrawer;
const DrawerAccountant=createDrawerNavigator();
函数AccountantDrawer(){
返回(
);
}
这是ImageInDrawer.js的代码:

import React, { Component } from 'react';
import { View, Image } from 'react-native';

export default class ImageInDrawer extends Component {
    render () {
        return (
            <View>
                <Image source={require('../assets/images/man.jpg')}/>
            </View>
        )
    }
}
import React,{Component}来自'React';
从“react native”导入{View,Image};
导出默认类ImageInDrawer扩展组件{
渲染(){
返回(
)
}
}

我尝试了这段代码,但无法在抽屉中显示任何图像。正确的方法是什么?

这里是链接,请尝试此示例


标题部分
您可以在此处显示徽标或个人资料图像

添加图像路径并尝试。

我是通过使用drawerContent而不是contentComponent来完成的。

您是否尝试过为图像提供宽度和高度是的,我累了。但他们没有单独的文件来放置抽屉的代码。而我已经将代码放在App.js中。他们使用的是react navigation抽屉,而我使用的是@react navigation/drawer。我不能像你说的那样做。
<ImageBackground source={require('../../assets/drawer-cover.png')} style={{flex: 1, width: 280, justifyContent: 'center'}} >
                    <Text style={styles.headerText}>Header Portion</Text>
                    <Text style={styles.headerText}>You can display here logo or profile image</Text>
                </ImageBackground>