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

auto merge #1

Merged
merged 3 commits into from
Jan 12, 2016
Merged
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
8 changes: 4 additions & 4 deletions ExRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export class ExRouteAdapter {
:
React.cloneElement(React.Children.only(this.route.children), {...this.route.props, data:this.props, route:this.route});

const Header = this.route.props.header;
const Header = this.route.header;
const header = Header ? <Header {...this.route.props} {...this.props}/> : null;

const Footer = this.route.props.footer;
const Footer = this.route.footer;
const footer = Footer ? <Footer {...this.route.props} {...this.props}/> : null;

return (
Expand Down Expand Up @@ -152,7 +152,7 @@ class ExNavigationBar extends Navigator.NavigationBar {
if (route.props.hideNavBar === false){
return super.render();
}
if (this.props.router.props.hideNavBar){
if (this.props.router.props.hideNavBar || route.props.hideNavBar){
return null;
}
return super.render();
Expand Down Expand Up @@ -263,7 +263,7 @@ export default class ExRouter extends React.Component {
<ExNavigator ref="nav" initialRouteStack={router.stack.map(route => new ExRouteAdapter(router.routes[route]))}
style={styles.transparent}
sceneStyle={{ paddingTop: 0 }}
renderNavigationBar={props=><ExNavigationBar {...props} router={router} navigationStyles={Navigator.NavigationBar.StylesIOS}/>}
renderNavigationBar={props=><ExNavigationBar {...props} router={router}/>}
{...this.props}
/>
{footer}
Expand Down
14 changes: 10 additions & 4 deletions Example/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class TabIcon extends React.Component {
}
}

class Header extends React.Component {
render(){
return <Text>Header</Text>
}
}

export default class Example extends React.Component {
render() {
return (
Expand All @@ -31,16 +37,16 @@ export default class Example extends React.Component {
<Route name="register" component={Register} title="Register"/>
<Route name="home" component={Home} title="Replace" type="replace"/>
<Route name="login" schema="modal">
<Router>
<Router name="loginRouter">
<Route name="loginModal" component={Login} title="Login" schema="modal"/>
<Route name="loginModal2" component={Login2} title="Login2"/>
<Route name="loginModal2" hideNavBar={true} component={Login2} title="Login2"/>
</Router>
</Route>
<Route name="register2" component={Register} title="Register2" schema="withoutAnimation"/>
<Route name="tabbar">
<Router footer={TabBar} showNavigationBar={false}>
<Route name="tab1" schema="tab" title="Tab #1" >
<Router>
<Router onPop={()=>{console.log("onPop is called!"); return true} }>
<Route name="tab1_1" component={TabView} title="Tab #1_1" />
<Route name="tab1_2" component={TabView} title="Tab #1_2" />
</Router>
Expand All @@ -51,7 +57,7 @@ export default class Example extends React.Component {
<Route name="tab5" schema="tab" title="Tab #5" component={TabView} />
</Router>
</Route>
<Route name="launch" component={Launch} wrapRouter={true} title="Launch" hideNavBar={true} initial={true}/>
<Route name="launch" header={Header} component={Launch} wrapRouter={true} title="Launch" hideNavBar={true} initial={true}/>
</Router>
);
}
Expand Down
2 changes: 1 addition & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"dependencies": {
"react-native": "^0.17",
"react-native-button": "^1.2.1",
"react-native-router-flux": "^2.0.5"
"react-native-router-flux": "^2.0.6"
}
}
8 changes: 7 additions & 1 deletion Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import Route from './Route';
import Actions from './Actions';
import debug from './debug';

export class RouterDelegate {
onPush(name:string, props:{ [key: string]: any}):boolean {
Expand All @@ -34,6 +35,7 @@ export default class Router {
schemas: {[key: string]: {[key:string]:any } };
props: { [key: string]: any};
parentRoute: ?Route;
nextRoute: ?Route;
_stack: Array<string>;
delegate:RouterDelegate;

Expand Down Expand Up @@ -65,6 +67,8 @@ export default class Router {
stack:Array<string> = null, props:{ [key: string]: any} = {}){
this.schemas = {};
this.routes = {};
this.pop = this.pop.bind(this);
this.route = this.route.bind(this);
this.delegate = new RouterDelegate();
if (!routes || !routes.length){
throw new Error("routes is not defined");
Expand Down Expand Up @@ -147,10 +151,11 @@ export default class Router {
if (!this["_"+action]){
throw new Error("No type="+action+" is supported");
}
this.nextRoute = this.routes[name];

const handler = "on"+capitalizeFirstLetter(action);
if (this.delegate[handler]) {
console.log("Run handler "+handler);
debug("Run handler "+handler);
const res:boolean = this.delegate[handler](this.routes[name], props);
if (!res) {
console.log("Ignore push, handler returns false");
Expand Down Expand Up @@ -193,6 +198,7 @@ export default class Router {
if (this._stack.length <= num){
throw new Error("Cannot pop(), stack=["+this._stack+"]");
}
this.nextRoute = null;
if (this.delegate.onPop && this.delegate.onPop(num)){
const routes = this._stack.splice(-num, num);
return true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-router-flux",
"version": "2.0.5",
"version": "2.0.6",
"description": "React Native Router using Flux architecture",
"main": "index.js",
"scripts": {
Expand Down