I want to add a custom header with a background color and also an image which need to be fit to header. I am using React Navigation 5+ ( @react-navigation/native, @react-navigation/stack ) but image isn't fit to header. Is there a way to add a custom header (something like passing component to it)?
Here is how I was doing (Wanting to know if there is better way):
import * as React from 'react';
import { View,Image, Text, TouchableWithoutFeedback, Button, StyleSheet } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator, HeaderTitle } from '@react-navigation/stack';
import Icon from 'react-native-vector-icons/Ionicons';
const Stack = createStackNavigator();
class App extends React.Component {
constructor(props) {
super(props);
}
render () {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
headerBackground: props => <Header {...this.props}/>,
}}
/>
<Stack.Screen
name="FeedbackScreen"
component={FeedbackScreen}
/>
</Stack.Navigator>
</NavigationContainer>
)
}
}
function HomeScreen({navigation}) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
<Button
title="Feedback"
onPress={()=> navigation.navigate('FeedbackScreen')}/>
</View>
);
}
function FeedbackScreen() {
return (
<View>
</View>
)
}
function Header() {
return (
<View style={{backgroundColor: "#4f2170", flex:1, }}>
<Image style={StyleSheet.absoluteFill} source={require('./Images/Mon_logo.png')} />
</View>
);
}
export default App;
I tried other answers but couldn't succeed...