343

I'm trying to switch screens using both stack and tab navigator.

const MainNavigation = StackNavigator({
      otp: { screen: OTPlogin },
      otpverify: { screen: OTPverification},
      userVerified: {
        screen: TabNavigator({
          List: { screen: List },
          Settings: { screen: Settings }
        }),
      },
    });

In this case stack navigator is used first and then tab navigator. I want to hide the headers from stack navigator. Which is not working properly when I use navigation options like::

navigationOptions: { header: { visible: false } }

i'm trying this code on first two components which are using in stacknavigator. if i use this line then getting some error like:

enter image description here

Ricardo Sanchez
  • 4,935
  • 11
  • 56
  • 86
Avijit Dutta
  • 3,651
  • 3
  • 13
  • 16

38 Answers38

830

UPDATE as of version 5

As of version 5 it is the option headerShown in screenOptions

Example of usage:

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

If you want only to hide the header on 1 screen you can do this by setting the screenOptions on the screen component see below for example:

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

See also the blog about version 5

UPDATE
As of version 2.0.0-alpha.36 (2019-11-07),
there is a new navigationOption: headershown

      navigationOptions: {
        headerShown: false,
      }

https://reactnavigation.org/docs/stack-navigator#headershown

https://github.com/react-navigation/react-navigation/commit/ba6b6ae025de2d586229fa8b09b9dd5732af94bd

Old answer

I use this to hide the stack bar (notice this is the value of the second param):

{
    headerMode: 'none',
    navigationOptions: {
        headerVisible: false,
    }
}

When you use the this method it will be hidden on all screens.

In your case it will look like this:

const MainNavigation = StackNavigator({
  otp: { screen: OTPlogin },
  otpverify: { screen: OTPverification },
  userVerified: {
    screen: TabNavigator({
    List: { screen: List },
    Settings: { screen: Settings }
   }),
 }
},
{
  headerMode: 'none',
  navigationOptions: {
    headerVisible: false,
  }
 }
);
Perry
  • 11,172
  • 2
  • 27
  • 37
  • 1
    Working perfectly! thanks for ur answer but i have one problem after adding this that is:: switching stacknavigator to tabnavigator its working fine. if i want to show header when i am switching screen from tabnavigator to stacknaviagtor what should i do? – Avijit Dutta Jun 22 '17 at 14:19
  • 2
    Hmm, that is a great Question. To be honest I don't know that. You can Try @Dpkstr answer on the screen you want to show it, instead of null it would be true. – Perry Jun 22 '17 at 14:30
  • Hmm, i already tried this but it was also not working... thanks for your first answer. I will make the second functionality using a button just for now. – Avijit Dutta Jun 22 '17 at 14:40
  • how to show and hide the header dynamically when click on button inside the component. If we give static navigationOptions = { header: null }. I will hide the header completely. I want to show or hide when click on some button – Venkatesh Somu Jul 06 '18 at 12:34
  • @BrodaNoel are you using version 2.x? – Perry Jul 24 '18 at 11:09
  • there is a section in here about 'Overiding Shared NavigationOptions' https://reactnavigation.org/docs/en/headers.html – Joey Gough Aug 20 '18 at 23:12
  • how to disable header for tabnavigator instead of full stack ? – Kartiikeya Jul 19 '19 at 05:31
  • @Kartiikeya So the simple way is to just create a new navigator with the options second param as in the answer. See this documentation page: https://reactnavigation.org/docs/en/common-mistakes.html#explicitly-rendering-more-than-one-navigator And than search for the example that show the correct way. That will show you how it works with multiple navigators. Let me know it that works or not – Perry Jul 19 '19 at 20:35
  • The new navigationOption is `headerShown`, note camelcasing (not headershown) – 46and2 Dec 31 '19 at 18:57
  • 1
    If he wants to hide header for a specific screen in v5+ should use `options` prop like this `` – Oliver D Mar 29 '20 at 21:55
  • To show a transparent header with just the 'back' carat try using. `options={{headerShown: true, headerTransparent: true, headerTitle: null, headerBackTitle: ' '}}` – Kelton Temby Jul 28 '20 at 03:11
  • you can just use `headerMode="none"` :) – Muh Ghazali Akbar Feb 16 '21 at 12:38
  • @MuhGhazaliAkbar In the upcoming version 6 headerMode will be deprecated, see https://github.com/react-navigation/react-navigation/issues/8981 – Perry Mar 08 '21 at 19:06
  • This only hides the header of the stack screens, but not the the parent's (tab navigator header) – 6rchid Nov 25 '21 at 00:49
136

On v4 simply use below code in the page you want to hide the header

export default class Login extends Component {
    static navigationOptions = {
        header: null
    }
}

refer to Stack Navigator

João Paulo Motta
  • 3,765
  • 1
  • 19
  • 18
Dpkstr
  • 1,649
  • 1
  • 10
  • 6
  • It is worikng fine, but one problem is that when screen switch into tabNavigator from stacknavigator ( as per mention on my question components like OTPverification screen to list screen on that time both headers are showing – Avijit Dutta Jun 22 '17 at 14:16
  • Can you tell me how exactly you are navigating to List – Dpkstr Jun 23 '17 at 08:43
29

In the given solution Header is hidden for HomeScreen by- options={{headerShown:false}}

<NavigationContainer>
  <Stack.Navigator>
    <Stack.Screen name="Home" component={HomeScreen} options={{headerShown:false}}/>
    <Stack.Screen name="Details" component={DetailsScreen}/>
  </Stack.Navigator>
</NavigationContainer>
Abhishek Kumar
  • 955
  • 11
  • 11
26

v6

headerMode prop has been removed from react navigation 6.x. Now we can use headerShown option to achieve the same result.

<Stack.Navigator screenOptions={{ headerShown: false }}>
   {/* Your screens */}
</Stack.Navigator>

v5

In react navigation 5.x you can hide the header for all screens by setting the headerMode prop of the Navigator to false.

<Stack.Navigator headerMode={false}>
   {/* Your screens */}
</Stack.Navigator>
Ajay Sivan
  • 2,807
  • 2
  • 32
  • 57
25

Just add this into your class/component code snippet and Header will be hidden

 static navigationOptions = { header: null }
Vaibhav KB
  • 1,695
  • 19
  • 17
20

{/*✌✌✌Login Screen✌✌✌ */}

 <Stack.Screen 
     options={{ headerShown:false }}
  name="Login" component={LoginScreen} />
Asim Khan
  • 309
  • 3
  • 2
17

If your screen is a class component

static navigationOptions = ({ navigation }) => {
    return {
       header: () => null
    } 
}

code this in your targeted screen as the first method (function).

17

React Native Navigation v6.x May 2022

put false in headerShown property in options prop of Screen

        <Stack.Navigator initialRouteName="Home">
          <Stack.Screen
            name="Home"
            component={Home}
            options={{ headerShown: false }}
          />
        </Stack.Navigator>
      

P.S
const Stack = createNativeStackNavigator().

Faramarz Qoshchi
  • 1,292
  • 1
  • 13
  • 24
Muneeb Ejaz
  • 696
  • 6
  • 11
15

If you use react-navigation Version: 6.x you can use like that. here, SignInScreen header will be hidden with the following snippet

options={{  
   headerShown: false,  
}} 

Complete script should be

import {createStackNavigator} from '@react-navigation/stack';  
import SignInScreen from '../screens/SignInscreen';  
import SignUpScreen from '../screens/SignUpScreen';  
const Stack = createStackNavigator();    
function MyStack() {  
 return (   
   <Stack.Navigator>   
     <Stack.Screen   
       name="Sing In"  
       component={SignInScreen}  
       options={{  
         headerShown: false,  
       }}   
     />  
     <Stack.Screen name="Sing Up" component={SignUpScreen} />   
   </Stack.Navigator>   
 );    
}  
export default function LoginFlowNavigator() {    
 return <MyStack />;   
}
Chilarai
  • 1,842
  • 2
  • 15
  • 33
11

If you want to hide on specific screen than do like this:

// create a component
export default class Login extends Component<{}> {
  static navigationOptions = { header: null };
}
Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
11

I am using header : null instead of header : { visible : true } i am using react-native cli. this is the example :

static navigationOptions = {
   header : null   
};
Cevin Ways
  • 984
  • 11
  • 13
10

Add new navigationOptions object in the stackNavigator.

Try this :

const MainNavigator = createStackNavigator({
  LoginPage: {screen : LoginPageContainer, navigationOptions: { header: null } },
  MiddlePage: {screen : MiddlePageContainer, navigationOptions: { header: null } },
  SMS: {screen: ShowSmsContainer, navigationOptions: { header: null } },
  Map: {screen: ShowMapContainer, navigationOptions: { header: null } }
});

Hope it helps.

Narayan Shrestha
  • 733
  • 8
  • 19
8

If someone searching how to toggle header so in componentDidMount write something like:

  this.props.navigation.setParams({
      hideHeader: true,
  });

When

static navigationOptions = ({ navigation }) => {
    const {params = {}} = navigation.state;

    if (params.hideHeader) {
      return {
        header: null,
      }
    }

    return {
        headerLeft: <Text>Hi</Text>,
        headerRight: <Text>Hi</Text>,
        headerTitle: <Text>Hi</Text>
    };
};

And somewhere when event finish job:

this.props.navigation.setParams({
  hideHeader: false,
});
Ernestyno
  • 797
  • 1
  • 10
  • 16
8

This worked for me:

const Routes = createStackNavigator({
Intro: {
    screen: Intro,
    navigationOptions: {
        header: null,
    }
}
},
    {
        initialRouteName: 'Intro',
    }
);
8

You can hide header like this:

<Stack.Screen name="Login" component={Login} options={{headerShown: false}}  />
Arun D
  • 2,369
  • 5
  • 27
  • 39
7

Try the best approach, below code works for me.

options={{
    headerShown: false,
}}

Put the above code in the <Stack.Screen tag.

<NavigationContainer>
    <Stack.Navigator>
        <Stack.Screen name="LogOut" component={LogOut} options={{ headerShown: false }} />
    </Stack.Navigator>
</NavigationContainer>
pistou
  • 2,799
  • 5
  • 33
  • 60
Abdul Basit Rishi
  • 2,268
  • 24
  • 30
5

All the answer are showing how to do it with class components, but for functional components you do:

const MyComponent = () => {
    return (
        <SafeAreaView>
            <Text>MyComponent</Text>
        </SafeAreaView>
    )
}

MyComponent.navigationOptions = ({ /*navigation*/ }) => {
    return {
        header: null
    }
}

If you remove the header your component may be on places where you can't see it (when the phone don't have square screen) so it's important to use it when removing the header.

Vencovsky
  • 28,550
  • 17
  • 109
  • 176
5

For me navigationOptions didn't work. The following worked for me.

<Stack.Screen name="Login" component={Login}
      options={{
               headerShown: false
              }}
     />
Sanan Ali
  • 2,349
  • 1
  • 24
  • 34
4

In your targeted screen you have to code this !

 static navigationOptions = ({ navigation }) => {
    return {
       header: null
    }
 }
Pheng Sengvuthy
  • 260
  • 2
  • 9
4
 <Stack.Screen
    name="SignInScreen"
    component={Screens.SignInScreen}
    options={{ headerShown: false }}
  />

options={{ headerShown: false }} works for me.

** "@react-navigation/native": "^5.0.7", "@react-navigation/stack": "^5.0.8",

mainak
  • 1,886
  • 2
  • 9
  • 19
4

This is working for stack navigation

<Stack.Screen
    name="Home"
    component={HomeComponent}
    options={{
        headerShown: false,
    }}
/>
3

If you only want to remove it from one screen in react-native-navigation then:

<Stack.Navigator>
    <Stack.Screen 
            name="Login" 
            component={Login} 
            options= {{headerShown: false}} />
</Stack.Navigator>
Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
Mehdi Raza
  • 313
  • 3
  • 15
3

You can hide StackNavigator header like this:

const Stack = createStackNavigator();
function StackScreen() {
    return (
        <Stack.Navigator
            screenOptions={{ headerShown: false }}>
            <Stack.Screen name="Login" component={Login} />
            <Stack.Screen name="Training" component={Training} />
            <Stack.Screen name="Course" component={Course} />
            <Stack.Screen name="Signup" component={Signup} />
        </Stack.Navigator>
    );
}
Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100
Paresh Chavda
  • 340
  • 1
  • 4
  • 11
2
const MyNavigator = createStackNavigator({
  FirstPage: {screen : FirstPageContainer, navigationOptions: { headerShown:false } },
  SecondPage: {screen : SecondPageContainer, navigationOptions: { headerShown: false } }
});

//header:null will be removed from upcoming versions
J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
2

if you want remove the header from all screen goto app.js and add this code to Stack.Navigator

screenOptions={ { headerShown: false } }
Mehrad Farahnak
  • 1,033
  • 1
  • 9
  • 18
2

This will remove the header from the component class.

export default class SampleClass extends Component {
    navigationOptions = {
       headerMode: 'none'
    }
...
}
2

With latest react-navigation-stack v4 you can hide the header with

import { createStackNavigator } from 'react-navigation-stack';

createStackNavigator({
 stackName: {
  screen:ComponentScreenName,
  navigationOptions: {
    headerShown:false
  }
 }
})
1
const CallStack = createStackNavigator({
  Calls: Calls,
  CallsScreen:CallsScreen,
}, {headerMode: 'none'});

CallStack.navigationOptions = {
  tabBarLabel: 'Calls',
  tabBarIcon: ({ focused }) => (
    <TabBarIcon
      focused={focused}
      name={Platform.OS === 'ios' ? 'ios-options' : 'md-options'}
    />
  ),

   header: null,

        headerVisible: false,

};
donald
  • 478
  • 8
  • 19
1

In the latest version of react-navigation this works to hide the header on every screen: headerMode={'none'}

<Stack.Navigator
headerMode={'none'}
>
    <Stack.Screen name="Home" component={HomeScreen}/>
    <Stack.Screen name="Details" component={DetailsScreen}/>
  </Stack.Navigator>
lamazing
  • 523
  • 3
  • 11
1

for 4.x, the header: null is deprecated, should use headerShown: false instead

ex:

const AppScreens = createStackNavigator({
  cover: {
    screen: Login,
    path: '/login',
    navigationOptions: () => ({
      headerShown: false,
    }),
  },
})
gasolin
  • 2,196
  • 1
  • 18
  • 20
1
  1. For the single screen, you can set header:null or headerShown: false in createStackNavigator like this

    const App = createStackNavigator({
     First: {
    screen: Home,
    navigationOptions: {
      header: null,
                       },
           },
    });
    
  2. Hide the header from all the screens in once using defaultNavigationOptions

    const App = createStackNavigator({
    
    First: {
      screen: HomeActivity,
    },
    },
    
    {
    defaultNavigationOptions: {
      header: null
    },
    
    });
    
Manan Gadhiya
  • 480
  • 4
  • 6
1
/*...*/
import { createNativeStackNavigator } from "@react-navigation/native-stack";
/*...*/

const {Navigator, Screen } =createNativeStackNavigator();

export function AuthRoutes(){
    return (
        <Navigator
            screenOptions={
                
                {
                    contentStyle:{
                        backgroundColor: 'transparent'
                    },
                    headerShown: false
                }
            }    
        >
            

        </Navigator>
    )

}
ilidiocn
  • 323
  • 2
  • 5
1

You can use headerShown:false in the new updated version only ( react-naviagion version 6 )

import { createStackNavigator } from '@react-navigation/stack';
    const Util = createStackNavigator();
    const UtilStack = () =>{
        return(
            <Util.Navigator>
                <Util.Screen name='Splash' component={Splash} options={{ headerShown: false }}/>
            )
            <Util.Navigator>
     }
Pruthvi mohan
  • 79
  • 1
  • 1
  • 11
0

It's important to match which version of react-navigation library you're using to the solution as they're all different. For those still using react-navigation v1.0.0 for some reason like me, both these worked:

For disabling/hiding header on individual screens:

const AppScreens = StackNavigator(
  {
    Main: { screen: Main, navigationOptions: { header: null } },
    Login: { screen: Login },
    Profile: { screen: Profile, navigationOptions: { header: null } },
  });

For disabling/hiding all screens at once, use this:

const AppScreens = StackNavigator(
  {
    Main: { screen: Main},
    Login: { screen: Login },
    Profile: { screen: Profile },
  },
  {
    headerMode: 'none',
  }
);
Edward Tan
  • 934
  • 9
  • 17
0

On V4 you have to use this:

headerLeft: () => { }

This is deprecated:

header: null
Filip Huhta
  • 2,043
  • 7
  • 25
0

One more way to hide the header from a particular screen is try to use useLayoutEffect from React. Like this:

import { View, Text, Button } from "react-native";
import React, { useLayoutEffect } from "react";
import { useNavigation } from "@react-navigation/native";
import useAuth from "../hooks/userAuth";
const HomeScreen = () => {
  const navigation = useNavigation();
  const { logout } = useAuth();
  useLayoutEffect(() => {
    navigation.setOptions({
      headerShown: false,
    });
  }, []);

  return (
    <View>
      <Text>I am the HomeScreen</Text>
      <Button
        title="Go to Chat Screen"
        onPress={() => navigation.navigate("Chat")}
      />

      <Button title="Logout" onPress={logout} />
    </View>
  );
};

export default HomeScreen;

This generally allows to hide component header and it will execute when the screen will render.

0
  <Stack.Navigator initialRouteName="splash">
        {
          screen_data?.map((item: any) => {
            return <Stack.Screen name={item?.name} component={item?.component} options={{ headerShown: false }}></Stack.Screen>
          })
        }

      </Stack.Navigator>
Awais Niaz
  • 41
  • 3
0

For Version 6.x.x

headerMode="none" is removed in favor of headerShown: false Previously, you could pass headerMode="none" prop to hide the header in a stack navigator. However, there is also a headerShown option which can be used to hide or show the header, and it supports configuration per screen.

So instead of having 2 ways to do very similar things, we have removed headerMode="none" in favor of headerShown: false. To get the old behavior, specify headerShown: false in screenOptions:

<Stack.Navigator screenOptions={{ headerShown: false }}>
  <Stack.Screen name="Home" component={Home} />
  <Stack.Screen name="Profile" component={Profile} />
</Stack.Navigator>
Lonare
  • 3,581
  • 1
  • 41
  • 45