I am using React Navigation in React Native app and i want to change the backgroundColor for the header to be gradient and i found out there is a node module : react-native-linear-gradient to achieve gradient in react native
i have Root StackNavigator like that :
const Router = StackNavigator({
Login: {
screen: Login,
navigationOptions: ({navigation}) => ({
headerTitle: <Text>SomeTitle</Text>
headerLeft: <SearchAndAgent />,
headerRight: <TouchableOpacity
onPress={() => { null }
</TouchableOpacity>,
headerStyle: { backgroundColor: '#005D97' },
}),
},
});
i can wrap Text or View to be gradient like that :
<LinearGradient colors={['#3076A7', '#19398A']}><Text style={styles.title}>{title}</Text></LinearGradient>,
how can i wrap the header background in the navigationOptions to use the the LinearGradient module?
i know that i can create a custom header component and use it but when i doing it all the native navigation animations from React Navigation not working like the Title Animation between two Routes so its not helping me.
thanks for helping !
Just for your information, now with
headerBackground
props it's a way easier.You can have a gradient header just doing this :
This solution works good even with SafeArea for IosX
You can use
LinearGradient
component from the expo. It is a useful component and you can't install another library like react-native-linear-gradient. https://docs.expo.io/versions/latest/sdk/linear-gradient/. By the way, you can change the back button. It is easy.You can implement it on inside screen with navigationOptions like that
Similar to this issue: React Navigation; use image in header?
For a Linear Gradient you would simply do >
//imports
//header
Create the Header component which is wrapped in the Linear Gradient. by making the header
backgroundColor: 'transparent'
you will then show the Linear Gradient wrapping it.Return the screen with the header being your
GradientHeader
component.Should look something like this with the above code.
Gradient Header
The solution of Mark P was right but now you need to define headerStyle and do the absolute positioning there:
and the GradientHeader: