Skip to content Skip to sidebar Skip to footer

How To Pass Navigator Reference To React Native ?

Using react-native-drawer ( https://github.com/root-two/react-native-drawer ) in my index.ios.js, I have the following set up and trying to pass 'navigator' reference into content'

Solution 1:

This is how it should be done. You save the navigator reference form renderScene method define a getter method, pass the method to the component you want.

classpracticeextendsComponent {
    ...
    renderScene(route, navigator){
        this._navigator = navigator
    }

    configureScene(route, routeStack){
        ...
    }
     
    getNav = () => {
      returnthis._navigator
    }

    render() {
        return (
          <Drawercontent={<DrawerPanelgetNav={this.getNav}/>}
            ...
          >
            <NavigatorconfigureScene={this.configureScene}initialRoute={{name: 'Login', component:Login}}
              renderScene={(route,navigator) => this.renderScene(route, navigator)}
              style={styles.container}
              navigationBar={
                <Navigator.NavigationBarstyle={styles.navBar}routeMapper={NavigationBarRouteMapper(this.openDrawer)}
                />
              }
            />
         </Drawer>
    );
  }
}

Solution 2:

I think you are wrong. If you use , should not has the same parent node with .

constDrawer = <Drawercontent={<DrawerPanelnavigator={navigator}/>}
                  ...
               /><NavigatorinitialRoute={{name: 'Drawer', component:Drawer }}
  renderScene={(route,navigator) =>
  configureScene={(route) => {
    return Navigator.SceneConfigs.VerticalDownSwipeJump;
  }}
  renderScene={(route, navigator) => {
    let Component = route.component;
    return <Component {...route.params} navigator={navigator} />
   }} />
  }
/>

Solution 3:

In update 2, you have done: var navigator = pr.getNav. This only assigns getNav function to the navigator variable you just defined. So your navigator here is just a reference to the getNav function.

What you need to do is var navigator = pr.getNav() and then pass the navigator to MadeButton. Hope is clarify things.

Post a Comment for "How To Pass Navigator Reference To React Native ?"