How to pass navigator reference to React Native ?

前端 未结 3 1741
时光说笑
时光说笑 2021-01-28 07:38

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 con

相关标签:
3条回答
  • 2021-01-28 08:27

    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.

    class practice extends Component {
        ...
        renderScene(route, navigator){
            this._navigator = navigator
        }
    
        configureScene(route, routeStack){
            ...
        }
         
        getNav = () => {
          return this._navigator
        }
    
        render() {
            return (
              <Drawer
                content={<DrawerPanel getNav={this.getNav}/>}
                ...
              >
                <Navigator
                  configureScene={this.configureScene}
                  initialRoute={{name: 'Login', component: Login}}
                  renderScene={(route, navigator) => this.renderScene(route, navigator)}
                  style={styles.container}
                  navigationBar={
                    <Navigator.NavigationBar
                      style={styles.navBar}
                      routeMapper={NavigationBarRouteMapper(this.openDrawer)}
                    />
                  }
                />
             </Drawer>
        );
      }
    }

    0 讨论(0)
  • 2021-01-28 08:27

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

    const Drawer = <Drawer
                      content={<DrawerPanel navigator={navigator}/>}
                      ...
                   />
    <Navigator
      initialRoute={{ 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} />
       }} />
      }
    />
    
    0 讨论(0)
  • 2021-01-28 08:35

    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.

    0 讨论(0)
提交回复
热议问题