我正在尝试将公司徽标添加到 Drawer Navigator 的标题中,但它仅显示屏幕的标题。这是我的代码:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, ScrollView, Dimensions, Image} from 'react-native';
import { createDrawerNavigator, createAppContainer, DrawerItems, SafeAreaView } from 'react-navigation';
import HomeScreen from './screens/HomeScreen';
import SettingsScreen from './screens/SettingsScreen';
class App extends Component {
render() {
return (
<AppNavigator />
);
}
}
const AppNavigator = createDrawerNavigator({
Home: {screen: HomeScreen},
Settings: {screen: SettingsScreen},
},
{
CustomDrawerContentComponent: props => (
<SafeAreaView style={styles.container}>
<View style={{height: 150, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center'}}>
<Image source={require('./assets/typeme.png')} style={{height: 120, width:200}}></Image>
</View>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</SafeAreaView>
)
}
);
const DrawerContent = (props) => (
<View>
<View
style={{
backgroundColor: '#f50057',
height: 140,
alignItems: 'center',
justifyContent: 'center',
}}
>
<Text style={{ color: 'white', fontSize: 30 }}>
Header
</Text>
</View>
<DrawerItems {...props} />
</View>
)
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default createAppContainer(AppNavigator);
"dependencies": {
"native-base": "^2.10.0",
"react": "16.6.3",
"react-native": "0.55.2",
"react-native-gesture-handler": "^1.0.12",
"react-navigation": "^3.0.9"
}
最佳答案
只需将 const AppNavigator 替换为
const AppNavigator = createDrawerNavigator({
Home: {screen: HomeScreen},
Settings: {screen: SettingsScreen},
}, {
contentComponent: (props) => (
<SafeAreaView style={styles.container}>
<View style={{height: 100,alignItems: 'center', justifyContent: 'center'}}>
<Text style={{fontSize: 32}}>LOGO</Text>
</View>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</SafeAreaView>
)
});