Skip to content
the poor coder

How To Hide React Navigation Header in React Native

Poor Man
Published
Reading time
1 min read
On this page

How To Hide React Navigation Header in React Native#

If you are building a React Native app with React Navigation, you might want to hide the header of a specific screen to have more control over the design of your app. There are different ways to do this depending on your specific use case.

Option 1: using navigationOptions#

The easiest way to hide the header of a screen is to use the navigationOptions object and set headerShown to false. This will disable the header and make it disappear from the screen.

Text

import React from 'react';
import { View, Text } from 'react-native';

const MyScreen = () => (
  <View>
    <Text>My Screen</Text>
  </View>
);

MyScreen.navigationOptions = {
  headerShown: false,
};

export default MyScreen;

Option 2: using StackNavigator options#

If you are using a StackNavigator to manage your screens, you can also hide the header by setting headerMode to 'none' in the StackNavigator options. This will remove the header from all screens in the stack.

Text

import { createStackNavigator } from 'react-navigation';
import MyScreen from './MyScreen';

const AppNavigator = createStackNavigator({
  Home: {
    screen: MyScreen,
    navigationOptions: {
      title: 'Home',
    },
  },
}, {
  headerMode: 'none',
});

export default AppNavigator;

Option 3: using navigationOptions headerStyle#

If you want to hide the header on a specific screen but keep it visible on other screens, you can use the headerStyle option in the navigationOptions object and set its height to 0.

Text

import React from 'react';
import { View, Text } from 'react-native';

const MyScreen = () => (
  <View>
    <Text>My Screen</Text>
  </View>
);

MyScreen.navigationOptions = {
  headerStyle: {
    height: 0,
  },
};

export default MyScreen;

These are some of the ways you can hide the header in React Navigation. Choose the option that best fits your specific use case and customize it to achieve the desired result.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC