Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set headerMode on some routes but not others. (React Navigation)

With React Navigation Is it possible to define certain routes with a headerMode and others without?

The majority of my pages don't use the header and I found how to turn it off globally.

export const App = StackNavigator({
  PhotoView: {
    screen: Photos
  },
  ListView: {
    screen: List
  }
}, {
  headerMode: 'none'
});

But if I wanted to show the header on ListView for example, how would I do that?

I've tried several approaches from the docs but no luck.

like image 867
Colton45 Avatar asked May 02 '17 04:05

Colton45


People also ask

How do I hide stack Navigator headers?

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

Which of the following method is used to create stack navigation for navigation?

Provides a way for your app to transition between screens where each new screen is placed on top of a stack. By default the stack navigator is configured to have the familiar iOS and Android look & feel: new screens slide in from the right on iOS, fade in from the bottom on Android.


2 Answers

You can wrap your app navigator in a root navigator, set navigationOptions.header to null to hide all wrapped navigators header, then set navigationOptions.headerTitle on screen that you want to display header.

This answer is based from react-navigation version v1.0.0-beta.9

const App = StackNavigator({
  PhotoView: {
    screen: Photos,
  },
  ListView: {
    screen: List,
    navigationOptions: {
      headerTitle: 'ListView',
    },
  }
});

export const Root = StackNavigator({
  Root: { 
    screen: App,
    navigationOptions: {
      header: null,
    },
  },
});
like image 62
alpha Avatar answered Sep 27 '22 20:09

alpha


You can hide the navigator header in the component of the screen attribute with:

static navigationOptions = {
    header: null
};
like image 28
Stephan Kirchhoff Avatar answered Sep 27 '22 21:09

Stephan Kirchhoff