C.P.
C.P.

Reputation: 1222

How to access child navigator and its properties in react-native?

I am using 'Navigator' component to manage different scenes in my react-native app.

Like we can access parent navigators properties from child navigator (say, MyChildNavigator) using 'parentNavigator' property as following :

MyChildNavigator.parentNavigator.getCurrentRoutes();

How we can access child navigator and its properties or methods like getCurrentRoutes from parent navigator?

Upvotes: 0

Views: 484

Answers (1)

Pierre Charpentier
Pierre Charpentier

Reputation: 270

This is an example. I hope it will help you.

In my index.android.js file :

class App extends Component {
render() {
 var myVar='aVar';
 return (
  <Navigator
    initialRoute={{id: 'page_splash_screen', name: 'Index', myVar:myVar}}
    renderScene={(route, navigator) => {return this.renderScene(route, navigator)}}
    configureScene={(route) => {
      if (route.sceneConfig) {
        return route.sceneConfig;
      }
      return Navigator.SceneConfigs.FloatFromRight;
    }}  />
  );
}
renderScene(route, navigator) {
 switch (route.id) {
  case "page_splash_screen":
    return (
      <SplashPage
        navigator={navigator} />
    );
  ...  

and in my SplashPage :

class SplachPage extends Component {
 render() {
   var myVar=this.props.myVar;
  ...
 }
}

You can pass your function like myVar in my example

Upvotes: 0

Related Questions