Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

Can you provide an example that uses <Navigator /> #60

Closed
logikaljay opened this issue Jun 24, 2015 · 2 comments
Closed

Can you provide an example that uses <Navigator /> #60

logikaljay opened this issue Jun 24, 2015 · 2 comments

Comments

@logikaljay
Copy link

I am having difficulty implementing the side menu with a navigator.

Here is what I have:

var Application = React.createClass({
  getInitialState: function() {
    return { applicationView: <SourceList /> };
  },
  handleChange: function(e) {
    this.setState({ applicationView: e });
  },
  render: function() {
    var nav = <Navigator ref="nav" initialRoute={{name: 'Sources', index: 0}} renderScene={(scene, navigator) => this.setState({ applicationView: e })} />;
    var menu = <Menu hiddenMenuOffset={10} close={true} navigator={nav} onChange={this.handleChange} />;
    return (
      <SideMenu menu={menu}>
        {this.state.applicationView}
      </SideMenu>
    );
  }
});

whenever I access this.props.navigator.push() in my

component, it is undefined - obviously I am doing this wrong (sorry react noob here) but I cannot find an example of how to do it properly.

Could you elaborate in your readme how to actually implement this properly with a <Navigator /> component?

@logikaljay
Copy link
Author

I managed to solve this by doing the following:

var Application = React.createClass({
  renderScene: function(route, navigator) {
    var Component = route.component;
    var menu = <Menu selected={Component.displayName} navigator={navigator} />;
    return (
      <SideMenu menu={menu}>
        <Component navigator={navigator} route={route} />
      </SideMenu>
    );
  },
  render: function() {
    return (
      <Navigator
        renderScene={this.renderScene}
        initialRoute={{
          component: SourceList
        }}/>
    );
  }
});

Not sure if it is the best way, but it works.

@Kureev
Copy link
Owner

Kureev commented Jun 25, 2015

IMO looks good

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants