Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native Navigator.NavigationBar - where are the docs?

Tags:

react-native

I've seen a few examples online using Navigator.NavigationBar. It looks handy but I don't know how to use it. Are there docs anywhere?

like image 339
Jake Avatar asked Nov 12 '15 20:11

Jake


1 Answers

Officially there is no guide Navigator.Navigation Bar. But looking on the internet you can find examples of how it works. Below is an example that I used for one of my projects.

var PageOne = require('./pageone'),
    PageTwo = require('./pagetwo');


var NavigationBarRouteMapper = { 
  LeftButton: function( route, navigator, index, navState ){
    return(
      <Text>{ route.leftButton }</Text>
    )
  },
  Title: function( route, navigator, index, navState ){
    return(
      <Text>{ route.title }</Text>
    )
  },
  RightButton: function( route, navigator, index, navState ){
    return(
      <Text>{ route.rightButton }</Text>
    )
  }
}

var App = React.createClass({

  renderScene: function( route, nav ) {
    switch (route.id) {
      case 'PageOne':
        return <PageOne navigator={ nav } title={ "PageOne" } />
      case 'PageTwo':
        return <PageTwo navigator={ nav } leftButton={ "Back" } title={ "PageTwo" } />;
    }
  },

  render: function() {
    return (
      <Navigator
        initialRoute={{ id: 'PageOne', title: 'PageOne' }}
        renderScene={ this.renderScene }
        configureScene={( route ) => {
          if ( route.sceneConfig ) {
            return route.sceneConfig;
          }
          return Navigator.SceneConfigs.FloatFromRight;
        }}
        navigationBar={
          <Navigator.NavigationBar 
            routeMapper={ NavigationBarRouteMapper } 
          />
        } 
      />
    );
  },
});
like image 65
Leonardo Antongiovanni Avatar answered Oct 29 '22 01:10

Leonardo Antongiovanni