23

I want to hide header because I already have styled Toolbar in code:

import {createStackNavigator}
from 'react-navigation'
const AppStackNavigator = createStackNavigator ({
  Home: HomePage,
  Friend: AddFriend,
  Bill: AddBill,
})
class App extends Component {
render() {
  return (
  <AppStackNavigator initialRouteName='Home'/>`<br>
  );
  }
}
export default App;

What should I add to my code?

CKE
  • 1,533
  • 19
  • 18
  • 29
Just Ahead
  • 2,377
  • 6
  • 16
  • 25

10 Answers10

59

update your code like this code

const AppStackNavigator = createStackNavigator ({
    Home: {
        screen: HomePage, 
        navigationOptions: {
            header: null,
        },
    },
})

and if you dont want the header for all screens, then

const AppStackNavigator = createStackNavigator ({
    Home: {
        screen: HomePage,
    },
},
{
    navigationOptions: {
        header: null,
    },
})

Note: This solution is for an old version of React Navigation.

Aravind S
  • 2,347
  • 2
  • 12
  • 21
34

To disable headers for all views in a createStackNavigator, you can use headerMode option.

const AppStackNavigator = createStackNavigator({
  Home: HomePage,
  Friend: AddFriend,
  Bill: AddBill,
},
{
  headerMode: 'none',
})

Reference: StackNavigatorConfig - createStackNavigator - React Navigation

asukiaaa
  • 1,594
  • 17
  • 19
4

Can you try:

static navigationOptions = {
    header: null
}

Inside your screen component.

Stiven Castillo
  • 370
  • 1
  • 7
  • 20
2

For hiding headers for specific screens or globally, you can do

const StackNavigator = createStackNavigator({
    Home: {
        screen: HomePage,
        navigationOptions: {
            header: null // Will hide header for HomePage
        }
    }
}, {
    navigationOptions: {
        header: null // Will hide header for all screens of current stack navigator,
        headerLeft: <HeaderLeft /> // Component to be displayed in left side of header (Generally it can be Hamburger)
        headerRight: <HeaderRight /> // Component to be displayed in right side of header
    }
})

Also note that, screen specific settings will override global settings. Hope, this helps.

Mahesh Bhuva
  • 744
  • 5
  • 17
2

try this
options ={{ header: () => {}}}
since you are explicitly not providing any argument to header function, it won't show any header.
For more information refer this: react native docs

chris
  • 194
  • 2
  • 10
1

I used following code to hide the header.

   {
    navigationOptions: {
        header: null // Will hide header for all screens of current stack 

    }
Kishan Oza
  • 1,707
  • 1
  • 16
  • 38
1

2020 UPDATE - REACT NAVIGATION 5+

Using header : null will not work anymore. In the options you need to set both headerMode to none along with headerShown to false as below:

<AuthStack.Navigator>
   <AuthStack.Screen name="AUTH" component={AuthScreen} options={{headerMode: 'none', headerShown : false}}/>
</AuthStack.Navigator>
METALHEAD
  • 2,734
  • 3
  • 22
  • 37
0

All the answers I could find were from React navigation v4 for some reason, which doesn't work in v5. After spending some time on it I figured out a way to hide toolbar in v5. Here it is:

import { createStackNavigator } from "@react-navigation/stack";
import { NavigationContainer } from "@react-navigation/native";

...

const Stack = createStackNavigator();

....
//and inside render
render(){
    return (
          <NavigationContainer>
            <Stack.Navigator>
              <Stack.Screen
                name="Home"
                component={HomeScreen}
                options={{
                  title: "Home",
                  headerShown: false,
                }}
              />
}

headerShown: false, this will do the trick

If you need help with migrating from v4 to v5 -> https://reactnavigation.org/docs/upgrading-from-4.x/

hushed_voice
  • 3,161
  • 3
  • 34
  • 66
0
navigationOptions: { 
    header: null
}

is deprecated. The new is

navigationOptions: { 
    headerShown: false
}

Reference: https://stackoverflow.com/a/62732551/8724367

sareno
  • 576
  • 8
  • 10
0

React Navigation 6 (from October'21)

The solution below is not working anymore:

navigationOptions: {
  header: null,
},

Instead of navigationOptions, you want to use just options, and with headerShown set to true, which replaces the header set to null. The working solution:

options={{
  headerShown: true,
}}
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94