3

I'm using React Native to build an Android and iOS application. I'm using react-navigation to navigate between screens.

The problem is that the navigation on iOS is different from the one in Android (image below). I want both of them to be like on Android, so how can I hide the 'Search cars' from iOS?

enter image description here

I've set the navigation options as follows:

Screen.navigationOptions = () => {

    const title = 'Search location';

    return {
        headerTitleStyle: {
            fontSize: 18,
            color: styles.headerTitle.color,
            paddingTop: 5,
            height: 40
        },
        headerStyle: {
            backgroundColor: '#fdfdfd'
        },
        title
    };
};
Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
Nick Arnie
  • 160
  • 1
  • 3
  • 10

5 Answers5

4

As of version 5, it is the option headerBackTitleVisible in screenOptions

Example of usage:

1. In Navigator

<Stack.Navigator
  screenOptions={{
    headerBackTitleVisible: false
  }}
>
  <Stack.Screen name="route-name" component={ScreenComponent} />
</Stack.Navigator>

2. In Screen

if you want only to hide in the single screen you can do this by setting the screenOptions on the screen component see below for example:

<Stack.Screen options={{headerBackTitleVisible: false}} name="route-name" component={ScreenComponent} />

3. In Screen Navigation Options

Screen.navigationOptions = ({ navigation }) => {
 headerTitle: 'Title',
 headerLeft: () =>
    <View>
      /* custom View here - back icon/back button text */
    </View
}

4. Common in navigator for all the screens

import { HeaderBackButton } from '@react-navigation/elements';

 <Stack.Navigator
            screenOptions={({ navigation }) => ({
                headerLeft: () => (
                    <HeaderBackButton
                        labelVisible={false}
                        tintColor={'#FFF'}
                        onPress={() => navigation.goBack()}
                    />
                )
            })}>
Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34
2

You need to set the headerBackTitleVisible: false to hide the back button title. It can be on a Screen's options, on a Navigator's screenOptions, or like in your case inside Screen.navigationOptions.

Screen.navigationOptions = () => {

    const title = 'Search location';

    return {
        headerBackTitleVisible: false, // all you needed
        headerTitleStyle: {
            fontSize: 18,
            color: styles.headerTitle.color,
            paddingTop: 5,
            height: 40
        },
        headerStyle: {
            backgroundColor: '#fdfdfd'
        },
        title
    };
};
Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
1

headerBackVisible:false

add in navigation options

Nikhil Dangi
  • 289
  • 3
  • 4
0

I solved this problem as follows:

Import the useNavigation from '@react-navigation/native':

import { useNavigation } from '@react-navigation/native';

Import the Feather from '@expo/vector-icons':

import { Feather } from '@expo/vector-icons';

Create a variable receiving the useNavigation:

const navigation = useNavigation();

Inside the Stack.Screen, you add the option below, this way it replaces the default button for the 2 platforms (Android and iOS) with this new one that you are implementing:

  <Stack.Screen
    name="FinishOrder"
    component={FinishOrder}
    options={{
      title: 'Finishing',
      headerTitleStyle: {
        fontSize: 25,
        color: '#FFF'
      },
      headerTitleAlign: 'center',
      headerStyle: {
        backgroundColor: '#1D1D2E'
      },
      headerLeft: () => (
        <Feather
          name='arrow-left'
          size={35}
          onPress={() => navigation.goBack()}
          title="Voltar"
          color="#FF3F4B"
        />
      ),
    }} />

Result:

Final result

-2

headerBackTitle: false worked for me.

<Stack.Navigator
  screenOptions={{
    headerBackTitle: false,
  }}
>
rosnk
  • 1,068
  • 1
  • 14
  • 36