Header backgroud color is gray/white intead of specified in screenOptions
See original GitHub issueDescription
I am using a native stack and setting a background color for the header using the screenOptions prop. However, once I add a header right, left element or even I replace the headerTitle with a component, the background color sometimes change color to gray/white.
It is happening on my project and header bg is turning gray, but on a repro it is turning white.
I noticed this happened once I add a header left/right component or replace headerTitle with component
Screenshots
personal project:
repro:
Steps To Reproduce
- initialize a new expo project using expo init projectName
- create a simple native stack navigator. Set a background color for the header and add a some kind of component to the header preferrably a <View /> component in header right.
- refresh the app multiple times to reproduce
Expected behavior
The header bg to be as specified in the prop
Actual behavior
Sometimes header bg turns white/gray
Reproduction
https://github.com/ramiel1999/navigation-header-bg
import { StyleSheet, Text, View } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator, NativeStackScreenProps } from "@react-navigation/native-stack";
import { useEffect } from "react";
type StackType = { Home: undefined };
type HomeScreenProps = NativeStackScreenProps<StackType, "Home">;
const { Navigator, Screen } = createNativeStackNavigator<StackType>();
const Home = ({ navigation }: HomeScreenProps) => {
useEffect(() => {
navigation.setOptions({ headerRight: () => <View style={{ height: 25, aspectRatio: 1, backgroundColor: "green" }} /> });
}, []);
return (
<View style={styles.screen}>
<Text>🏚️</Text>
</View>
);
};
export default function App() {
return (
<NavigationContainer>
<Navigator
screenOptions={{
headerStyle: {
backgroundColor: "hsla(356, 83%, 41%, 1)",
},
headerTitleAlign: "center",
headerTintColor: "#FFF",
headerTitleStyle: {
fontSize: 18,
},
}}
>
<Screen name="Home" component={Home} />
</Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
Platform
- iOS
- Android
- Web
- Windows
- tvOS
Workflow
- Managed workflow
- Bare workflow
Package versions
package | version |
---|---|
react-native | 0.68.2 |
@react-navigation/native | 6.0.10 |
@react-navigation/native-stack | 6.6.2 |
react-native-screens | 3.11.1 |
react-native-safe-area-context | 4.2.4 |
expo | 45.0.5 |
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top Results From Across the Web
React Navigation switching background colors and styling ...
After implementing React Navigation, my background color switched from white to grey, and what was grey to white. This is a strange and...
Read more >Configuring the header bar - React Navigation
headerTintColor : the back button and title both use this property as their color. In the example below, we set the tint color...
Read more >header background grey instead of white - WordPress.com
I created one with a (definetly!) white background! :D But when I upload the picture as a header the white colour of it...
Read more >createStackNavigator - React Navigation - Netlify
Style object for the card in stack. You can provide a custom background color to use instead of the default background here. You...
Read more >Keeping the screen in navigation drawer but hide its name ...
... headerStyle: { backgroundColor: '#f4511e', //Set Header color }, headerTintColor: '#fff', //Set Header text color headerTitleStyle: { fontWeight: 'bold' ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, seem like this issue still happens in 3.15.0 and ios 14 (can not reproduce in ios 15).
Not only background color. All the config of header like,
background color, title color, largeHeader will not be affected. And header display same as the default style.
Thanks for some direction. I checked the change logs of version 3.11.0 and the following:
update header in vc below modal (https://github.com/software-mansion/react-native-screens/pull/1228) by @WoLewicki
seems to be the one causing it.I added a patch to undo those changes
built a new dev client after that, refreshed 10 times and seems to be good.
I will keep it open until addressed by library authors