user3412625
user3412625

Reputation: 109

React Native Android Navigator

I'm trying to create an Android version of my React Native app but I'm having problems getting my head around the Android navigator. The code I use in my index.ios.js is:

render() {
return (
  <React.NavigatorIOS
    style={styles.container}
    initialRoute={{
      title: 'Product Searcher',
      component: ProductPage,
    }}/>
);}

How do I create an equivalent Navigator for Android in my index.android.js? I've looked at this piece of documentation (https://facebook.github.io/react-native/docs/navigator.html) but I can't seem to find a way to produce equivalent navigator logic using this tutorial even though my iOS navigator is very simple.

Upvotes: 1

Views: 440

Answers (1)

pinewood
pinewood

Reputation: 1839

A very simple use of the Navigator would be something like:

class MyApp extends Component {
   render() {
      return (
         <Navigator
            initialRoute={name: 'productpage'}
            renderScene={this.renderScene}
         />)
   }
   renderScene(route, navigator) {
      switch (route.name) {
         case 'productpage':
            return (<ProductPage navigator={navigator}/>)
   }};

In renderScene you will define all your scenes for the app. By passing the navigator as a property to the different scenes you can access the navigator.

Upvotes: 3

Related Questions