Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide React Native NavigationBar

Tags:

I have NavigatorIOS under Navigator and would like to hide Navigator's NavigationBar to use NavigatorIOS's bar. Is there any way to do this?

This is screenshot that I've seen. I need backend of NavigatorIOS..

The structure that I want to build is the following:

├── NavigatorRoute1 │   ├── NavigatorIOSRoute1 │   ├── NavigatorIOSRoute2 │   └── NavigatorIOSRoute3 └── NavigatorRoute2 

The code that I have is the below. (Basically obtained from UIExplore examples.

Navigator

render: function(){ return (   <Navigator     initialRoute={ROUTE_STACK[this.getInitialRouteIndex()]}     initialRouteStack={ROUTE_STACK}     style={styles.container}     renderScene={this.renderScene}     navigationBar={       <Navigator.NavigationBar         routeMapper={NavigationBarRouteMapper}         style={styles.navBar}       />     }   /> ); } 

NavigatorIOS

render: function(){ var nav = this.props.navigator;  return (   <NavigatorIOS     style={styles.container}     ref="nav"     initialRoute={{       component: UserSetting,       rightButtonTitle: 'Done',       title: 'My View Title',       passProps: {nav: nav},     }}     tintColor="#FFFFFF"     barTintColor="#183E63"     titleTextColor="#FFFFFF"   /> ); 

}

UPDATE with my solution

I added a function to change state that handle rendering of Navigator and pass the prop to the component to change the state.

hideNavBar: function(){   this.setState({hideNavBar: true}); }, render: function(){  if ( this.state.hideNavBar === true ) {   return (     <Navigator       initialRoute={ROUTE_STACK[0]}       initialRouteStack={ROUTE_STACK}       renderScene={this.renderScene}     />   );  }else{   return (     <Navigator       initialRoute={ROUTE_STACK[this.getInitialRouteIndex()]}       initialRouteStack={ROUTE_STACK}       style={styles.container}       renderScene={this.renderScene}       navigationBar={         <Navigator.NavigationBar           routeMapper={NavigationBarRouteMapper}           style={styles.navBar}         />       }     />   ); } 

}

and

render: function(){  var hideNavBar = this.props.hideNavBar;  return (   <NavigatorIOS     style={styles.container}     initialRoute={{       component: UserSetting,       rightButtonTitle: 'Done',       title: 'My View Title',       passProps: {hideNavBar: hideNavBar},     }}     tintColor="#FFFFFF"     barTintColor="#183E63"     titleTextColor="#FFFFFF"   />  ); 

}

like image 406
shohey1226 Avatar asked May 12 '15 22:05

shohey1226


People also ask

How do I hide the top bar in React Native?

The hidden property can be used to hide the status bar. In our example it is set to false. This is default value. The barStyle can have three values – dark-content, light-content and default.

How do I hide the header in React Native?

To hide the navigation header on Press of a ButtonsetOptions({headerShown: false}); In this example, We will create a stack navigator with a single screen which will have a header and has a button to click.

How do I disable the bottom tab in React Native?

You can try with tabBarComponent props available in the second parameter for createBottomTabNavigator. You can enable or disable button as you like but please look at the note below.


2 Answers

Because some old methods are deprecated i used stacknavigator. It works for me, if you are using StackNavigator.

//******For Older Versions. But Will be Deprecated in future******* //static navigationOptions = { title: 'Welcome', header: null };  //For Latest Version Use: static navigationOptions = { title: 'Welcome', headerShown: false}; 

Feel free to contact, if any issue.

like image 149
Naeem Ibrahim Avatar answered Oct 26 '22 02:10

Naeem Ibrahim


I solved this by defining a custom NavigationBar which can inspect the current route. Would look something like this:

class NavigationBar extends Navigator.NavigationBar {   render() {     var routes = this.props.navState.routeStack;      if (routes.length) {       var route = routes[routes.length - 1];        if (route.display === false) {         return null;       }     }      return super.render();   } } 

Using your example:

render: function(){   return (     <Navigator       initialRoute={{         component: UserSetting,         rightButtonTitle: 'Done',         title: 'My View Title',         display: false,       }}       style={styles.container}       renderScene={this.renderScene}       navigationBar={         <NavigationBar           routeMapper={NavigationBarRouteMapper}           style={styles.navBar}         />       }     />   ); } 
like image 40
Jeff Trudeau Avatar answered Oct 26 '22 02:10

Jeff Trudeau