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.

2.12.0 (Android) createNativeStackNavigator "headerTitle" / "title" not displaying when "headerLeft" is set

See original GitHub issue

Using v2.12.0, given the following example

import { Text } from "react-native";
import { createNativeStackNavigator } from "react-native-screens/native-stack";

const DashboardStack = createNativeStackNavigator();

function DashboardStackView() {
  return (
    <DashboardStack.Navigator screenOptions={{ headerStyle: { backgroundColor: "#DC5E5C" } }}>
      <DashboardStack.Screen
        name="DashboardScreen"
        component={DashboardScreen}
        options={({ route }) => ({
          headerTitle: "Dashboard",
          headerLeft: () => <LeftDrawerButton />, // "() => null" also doesn't work
        })}
      />
    </DashboardStack.Navigator>
  );
}

const LeftDrawerButton = () => <Text>Drawer</Text>

Setting headerTitle or title doesn’t seem to display at all when headerLeft is set.

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
darron1217commented, Jan 18, 2021

Oh, I found a solution navigation.addListener('beforeRemove', callback)

0reactions
thunderclap1030commented, Oct 1, 2021

Because it is the native behavior on Android since the title is on the left side of the header: https://github.com/software-mansion/react-native-screens/tree/master/native-stack#headerleft.

So you could use property headerCenter for show header title only for Android. That way will make sure consistent UI for both platform.

For instance :

headerCenter: () => Platform.OS === 'android' ? <Text> Home page </Text> : null

I already try it and everything seem to be work well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

After adding image to header title header left back button not ...
try: When I stopped showing header Title Image. I works properly fine. expectation: To start work with back button along with header Title....
Read more >
Configuring the header bar - React Navigation
The reason is that headerTitle is a property that is specific to stack navigators, the headerTitle defaults to a Text component that displays...
Read more >
createStackNavigator - React Navigation - Netlify
Function that given HeaderProps returns a React Element, to display as a header. Make sure to set headerMode to screen as well when...
Read more >
Keeping the screen in navigation drawer but hide its name ...
Screen name="FirstPage" component={FirstPage} options={{ title: 'First Page', //Set Header Title }} /> </Stack.Navigator> ); }; const secondScreenStack ...
Read more >
Problem with custom header in react navigation-React Native
... Header title not changing with bottom navigation React Native Navigation v5 · KeyboardAvoidingViev not working on iOS with react navigation header and ......
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