Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add props "hideTabBar" to "Route" #177

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Route from './Route';
import Router from './Router';
import debug from './debug';

var _eventListener = {};

function isNumeric(n){
return !isNaN(parseFloat(n)) && isFinite(n);
}
Expand Down Expand Up @@ -31,7 +33,25 @@ class Actions {
this.route = this.route.bind(this);
this.dismiss = this.dismiss.bind(this);
}

addEventListener(type: string, handler: Function) {
if(_eventListener[type] === undefined) {
_eventListener[type] = []
}
_eventListener[type].push(handler);
}
removeEventListener(type: string, handler: Function) {
var i = _eventListener[type].indexOf(handler);
if(i != -1) {
_eventListener[type].splice(i, 1);
}
}
dispatchEvent(type :string, router: any) {
currentStack = router._stack[router._stack.length-1];
route = router.routes[currentStack];
_eventListener[type] && _eventListener[type].forEach(function(val, key){
val(route);
});
}
route(name: string, props: { [key: string]: any} = {}){
if (!this.currentRouter){
throw new Error("No current router is set");
Expand Down Expand Up @@ -59,14 +79,15 @@ class Actions {
debug("Switching to router="+router.name);
}
if (router.route(name, props)){

// deep into child router
while (router.currentRoute.childRouter){
router = router.currentRoute.childRouter;
debug("Switching to child router="+router.name);
}

this.currentRouter = router;
this.dispatchEvent('route', router);
return true;
}
return false;
Expand Down Expand Up @@ -108,6 +129,7 @@ class Actions {
}
if (router.pop()){
this.currentRouter = router;
this.dispatchEvent('route', router);
return true;
} else {
return false;
Expand Down
18 changes: 18 additions & 0 deletions TabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ import Actions from './Actions';
export default class TabBar extends React.Component {
constructor(props){
super(props);
this.onRoute = this.onRoute.bind(this);
Actions.addEventListener('route', this.onRoute);
}
isChild(route) {
router = route.parent;
while(router.parentRoute) {
if(this.props.router == router) {
return true;
}
router = router.parentRoute.parent;
}
return false;
}
onRoute(route) {
hideTabBar = route.props.hideTabBar ? true : false;
if(this.isChild(route) && hideTabBar != this.state.hideTabBar) {
this.setState({hideTabBar});
}
}
onSelect(el){
if (!Actions[el.props.name]){
Expand Down