Skip to content

Instantly share code, notes, and snippets.

@mbrochh
Created April 30, 2015 04:02
Show Gist options
  • Select an option

  • Save mbrochh/010d052abaa81b4bfde0 to your computer and use it in GitHub Desktop.

Select an option

Save mbrochh/010d052abaa81b4bfde0 to your computer and use it in GitHub Desktop.
Reapp.io router sets active BarItem
import { Bar, React, Reapp, View } from 'reapp-kit';
export default Reapp(React.createClass({
contextTypes: {
router: React.PropTypes.func
},
getActiveBar() {
let currentPath = this.context.router.getCurrentPath();
if (currentPath.indexOf(this.context.router.makePath('shop')) === 0) {
return 0;
}
if (currentPath.indexOf(this.context.router.makePath('sell')) === 0) {
return 1;
}
if (currentPath.indexOf(this.context.router.makePath('profile')) === 0) {
return 2;
}
},
toggleDrawer(requestedBar) {
// do some action here to transition to another view
},
render() {
return (
<View
after={
<Bar display='text' position='bottom' activeIndex={this.getActiveBar()}>
<Bar.Item onTap={this.toggleDrawer.bind(this, 0)}>Shop</Bar.Item>
<Bar.Item onTap={this.toggleDrawer.bind(this, 1)}>Sell</Bar.Item>
<Bar.Item onTap={this.toggleDrawer.bind(this, 2)}>Profile</Bar.Item>
</Bar>}
fullscreen>
{this.props.child()}
</View>
);
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment