25

Is there a way of removing the top navigation bar for specific screens only? I am using react-navigation.

I already tried the following:

header: { visible: false }

but it only hides the navbar. The space of the navbar is still cannot be used.

Thanks in advance!

Jed
  • 1,054
  • 1
  • 15
  • 34

8 Answers8

48

I use the headerShown flag like this:

 import React from 'react';
 import { NavigationContainer } from '@react-navigation/native';
 import { createStackNavigator } from '@react-navigation/stack';
 import 'react-native-gesture-handler';

 import Welcome from "./compenents/Welcome";
 import Home from "./compenents/Home";

 const Stack = createStackNavigator();

export default function App() {
   return (
      <NavigationContainer>
        <Stack.Navigator>
           <Stack.Screen name="Welcome" component={Welcome} options={{ headerShown: false }} />
           <Stack.Screen name="Home" component={Home} />
        </Stack.Navigator>
      </NavigationContainer>
   );
}
Dustin Spengler
  • 5,478
  • 4
  • 28
  • 36
45

This is an example of how I did mine using StackNavigator:

const stackN = StackNavigator({
    Screen1 : {
      screen: Screen1,
      navigationOptions: {
        header: null,
      }
    },
    Home : {
      screen: HomeScreen,
      navigationOptions: ({navigation}) => ({
        title: 'Home',
        headerStyle: styles.headerStyle,
        headerTitle: <Text>Home</Text>,
        headerLeft : null,
        headerRight: null,
      })
    }, 
}, {headerMode: 'screen'})

So every screen have their own navigationOptions instead. There may be a way to share navigationOptions, but I haven't looked into it at the moment.

rabbit87
  • 3,165
  • 2
  • 20
  • 29
  • Would be better if there's a way for the navigationOptions to be shared. I only want the navigation removed on the login and splash screen, the others it will be displayed. – Jed Sep 06 '17 at 03:21
  • After testing, your answer also satisfies the need of removing the navigation on certain views. What you do is just specify a navigation option on those certain views and put the `header: null` property. – Jed Sep 12 '17 at 09:05
  • what if I need to show Status Bar? If I add StatusBar component. its not showing – Nabeel K Sep 12 '18 at 12:49
11
options={{ headerShown: false }}

you are done .. have a nice day

import { createStackNavigator } from "@react-navigation/stack";
import HomeScreen from "./screens/HomeScreen";
import NewsDetailScreen from "./screens/NewsDetailScreen";
import React from "react";
    
const HomeStack = createStackNavigator();

const HomeScreenStack = () => {
  return (
<HomeStack.Navigator >
  <HomeStack.Screen
    name="homeScreen"
    component={HomeScreen}
    options={{ title: "Home" }}
  />
  <HomeStack.Screen
    name="newsDetailScreen"
    component={NewsDetailScreen}
    options={{
      title: "News Detail",
      headerShown:false
    }}
  />
</HomeStack.Navigator>
  );
};

export default HomeScreenStack;
Aravind Siruvuru
  • 1,019
  • 12
  • 7
4

When using createStackNavigator then top navigation bar can be removed as below.

const AppStack = createStackNavigator({ Home: MainTabNavigator }, { headerMode: 'none' });
Waseem Sarwar
  • 2,645
  • 1
  • 21
  • 18
4

Use navigationOptions: { header: null } to remove the top navigation bar.

Sample Code:

import { createStackNavigator, createAppContainer } from 'react-navigation';

import {Login} from './app/components/login/Login';
import {Register} from './app/components/register/Register';
import {Home} from './app/components/home/Home';

const AppNavigator = createStackNavigator(
    {
        Login: { 
                  screen: Login,
                  navigationOptions: {
                    header: null,
                  }
               },
        Register: { 
                    screen: Register, 
                    navigationOptions: {
                      header: null,
                    }  
                  },
        Home: { 
                screen: Home, 
                navigationOptions: {
                  header: null,
                }
              },
    },
    {
        initialRouteName: "Login"
    }
);

export default createAppContainer(AppNavigator);
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
4

Use navigationOptions: { headerShown: false } instead of navigationOptions: { header: null } to remove the top navigation bar.

Saurav Kumar
  • 256
  • 3
  • 6
3

"headerShown : false " in the latest React Native version

Kunal
  • 64
  • 3
1

2020 => v5 :

to delete title in all screens

Stack.Navigator.defaultProps = {
    headerMode: 'none',
};
M_Badrah
  • 437
  • 5
  • 6