Skip to content

Instantly share code, notes, and snippets.

@tomauty
Created December 11, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomauty/0d49aa4abbd67b91e9fc to your computer and use it in GitHub Desktop.
Save tomauty/0d49aa4abbd67b91e9fc to your computer and use it in GitHub Desktop.
binding to 'this'
export default class Router extends Component {
constructor(props) {
super(props);
this.renderScene = this.renderScene.bind(this);
}
componentWillReceiveProps(nextProps) {
if (this.props.router.currentRoute === nextProps.router.currentRoute) { return; }
const {closeSideMenu} = this.props;
switch (nextProps.router.type) {
case 'ROUTER_REPLACE': this.refs.navigator.replace(nextProps.router.currentRoute); break;
case 'ROUTER_PUSH': this.refs.navigator.push(nextProps.router.currentRoute); break;
case 'ROUTER_POP': this.refs.navigator.pop(); break;
default: break;
}
closeSideMenu();
}
renderScene(route, _nav) {
const Element = route.component();
return (
<Element {...route.passProps } {...this.props} />
);
}
render() {
return (
<Navigator
ref="navigator"
style={{backgroundColor: C.colors.primary}}
initialRoute={this.props.currentRoute}
renderScene={this.renderScene}
configureScene={(route) => {
return (route.sceneConfig) ? route.sceneConfig : Navigator.SceneConfigs.PushFromRight;
}}
/>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment