question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

headerStyle and headerLargeStyle backgroundColor are not applied after theme switching

See original GitHub issue

Description

Header styles are not applied after switching the theme within the application

Screenshots

image

image

Steps To Reproduce

  1. Add custom styles with two themes for react-native-screens header
  2. Toggle theme
    headerLargeTitleStyle: {
      color: EStyleSheet.value('$label01'),
    },
    headerLargeStyle: {
      backgroundColor: EStyleSheet.value('$ui02'),
    },
    headerTitleStyle: Platform.select({
      ios: {
        color: EStyleSheet.value('$label01'),
      },
      android: {
        fontWeight: '700',
        color: EStyleSheet.value('$label01'),
      },
    }),
    headerStyle: {
      backgroundColor: EStyleSheet.value('$ui02'),
    },

Expected behavior

headerStyle: { backgroundColor } and headerLargeStyle: { backgroundColor } equals `EStyleSheet.value(‘$ui02’) after theme switching

Actual behavior

headerStyle and headerLargeStyle backgroundColor have system colors (not defined in Stack)

Stack

        options={{
          headerLargeTitle: true,
          headerLargeTitleStyle: {
            color: EStyleSheet.value('$label01'),
          },
          headerLargeStyle: {
            backgroundColor: EStyleSheet.value('$ui02'),
          },
          headerTitleStyle: Platform.select({
            ios: {
              color: EStyleSheet.value('$label01'),
            },
            android: {
              fontWeight: '700',
              color: EStyleSheet.value('$label01'),
            },
          }),
          headerStyle: {
            backgroundColor: EStyleSheet.value('$ui02'),
          },
        }}
        component={HomeScreen}
      />

Package versions

  • React: 16.13.1
  • React Native: 0.63.4
  • React Native Screens: 2.18.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:23 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
evarousscommented, Apr 6, 2021

Here’s a scenario to reproduce the issue: In a nutshell, it’s a scenario where you have a native stack navigator inside of a tab navigator and custom screen options. The issue happens intermittently.

import React from "react";
import { View, Text } from "react-native";

import { createNativeStackNavigator } from "react-native-screens/native-stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { DefaultTheme, NavigationContainer } from "@react-navigation/native";

const FeedScreen = () => (
  <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
    <Text>Feed screen</Text>
  </View>
);

const ProfileScreen = () => (
  <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
    <Text>Profile screen</Text>
  </View>
);

const SettingsScreen = () => (
  <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
    <Text>Settings screen</Text>
  </View>
);

const FeedStack = createNativeStackNavigator();

function FeedStackScreen() {
  return (
    <FeedStack.Navigator>
      <FeedStack.Screen
        name="Feed"
        component={FeedScreen}
        options={{
          title: "Feed",
          headerLeft: () => (
            <View>
              <Text>Action Button</Text>
            </View>
          ),
        }}
      />
      {/* other screens */}
    </FeedStack.Navigator>
  );
}

const ProfileStack = createNativeStackNavigator();

function ProfileStackScreen() {
  return (
    <ProfileStack.Navigator>
      <ProfileStack.Screen name="Profile" component={ProfileScreen} />
    </ProfileStack.Navigator>
  );
}

const Tab = createBottomTabNavigator();

function HomeTabs() {
  return (
    <Tab.Navigator>
      <Tab.Screen name="Feed" component={FeedStackScreen} />
      <Tab.Screen name="Profile" component={ProfileStackScreen} />
    </Tab.Navigator>
  );
}

const RootStack = createNativeStackNavigator();

export default function App() {
  return (
    <NavigationContainer theme={DefaultTheme}>
      <RootStack.Navigator screenOptions={{ headerShown: false }}>
        <RootStack.Screen name="Home" component={HomeTabs} />
        <RootStack.Screen name="Settings" component={SettingsScreen} />
      </RootStack.Navigator>
    </NavigationContainer>
  );
}

Issue:

Notice how the header is getting a dark background / losing the Theme Styles

image

Versions:

{
    "@react-navigation/bottom-tabs": "^5.11.8",
    "@react-navigation/native": "^5.9.3",
    "@react-navigation/stack": "^5.14.3",
    "react-native": "0.63.4",
    "react-native-screens": "^3.0.0",
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactNavigationStack Header Style is not working only he ...
if anyone tries this so please help me, I am trying to change the border colour top and bottom in the header in...
Read more >
Change navigationOptions/headerStyle(backgroundColor) on ...
Hi guys, I am setting header style in navigationOptions Then on onScroll of View I am setting params bgColor to new value but...
Read more >
react-native-screens - Bountysource
headerStyle and headerLargeStyle backgroundColor are not applied after ... Header styles are not applied after switching the theme within the application ...
Read more >
Transparent Header – Submenu background color STILL ...
Hi,. I have read the changelog of the astra theme and I just want to tell you so much: the background colors of...
Read more >
Native Stack Navigator | React Navigation
This will have no effect on the first screen in the stack. ... and changes the background color to transparent unless specified in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found