I am trying to add a company logo to header of Drawer Navigator, but it displays only screen's title. Here is my code:
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"
}
Just replace const AppNavigator to
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>
)
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With