Skip to content

Commit

Permalink
fix #132
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavlo Aksonov authored and Pavlo Aksonov committed Jan 25, 2016
1 parent adf4efa commit 3478716
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class Actions {
return true;
} else {
let router: Router = this.currentRouter;
debug("Pop, router="+router.name);
debug("Pop, router="+router.name+" stack length:"+router.stack.length);
debug("Current route="+router.currentRoute.name+" type="+router.currentRoute.type);
while (router.stack.length <= 1 || router.currentRoute.type === 'switch'){
router = router.parentRoute.parent;
debug("Switching to parent router="+router.name);
Expand Down
5 changes: 3 additions & 2 deletions ExRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ExRouteAdapter {
props: { [key: string]: any};

constructor(route: Route, props:{ [key: string]: any} = {}){
debug("ExRouter constructor"+props.schema);
if (!route){
throw new Error("route is not defined ");
}
Expand All @@ -40,11 +41,11 @@ export class ExRouteAdapter {
}

configureScene() {
return this.route.type === 'switch' ? Animations.None : this.route.props.sceneConfig || Animations.None;
return this.route.props.sceneConfig || Animations.None;
}

renderScene(navigator) {
debug("RENDER SCENE:"+ this.route.name + " TITLE:"+this.route.title);
debug("RENDER SCENE:"+ this.route.name + " TITLE:"+this.route.title+" NAVBAR"+this.route.props.hideNavBar+" IS COMPONENT:"+(this.route.component!=null)+" TYPE:"+this.route.type);
const Component = this.route.component;
const child = Component ?
!this.route.wrapRouter ? <Component key={this.route.name} name={this.route.name} {...this.route.props} {...this.props} route={this.route}/>:
Expand Down
21 changes: 16 additions & 5 deletions Example/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,42 @@ class Header extends React.Component {
export default class Example extends React.Component {
render() {
return (
<Router hideNavBar={true} >
<Router hideNavBar={true} name="root">
<Schema name="modal" sceneConfig={Navigator.SceneConfigs.FloatFromBottom}/>
<Schema name="default" sceneConfig={Navigator.SceneConfigs.FloatFromRight}/>
<Schema name="withoutAnimation"/>
<Schema name="tab" type="switch" icon={TabIcon} />

<Route name="tabbar" hideNavBar={true} >
<Route name="register" component={Register} title="Register"/>
<Route name="home" component={Home} title="Replace" type="replace"/>
<Route name="login" schema="modal">
<Router name="loginRouter">
<Route name="loginModal" component={Login} title="Login" schema="modal"/>
<Route name="loginModal2" hideNavBar={true} component={Login2} title="Login2"/>
</Router>
</Route>
<Route name="register2" component={Register} title="Register2" schema="withoutAnimation"/>
<Route name="error" type="modal" component={Error}/>
<Route name="tabbar">
<Router footer={TabBar} showNavigationBar={false}>
<Route name="tab1" schema="tab" title="Tab #1" >
<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>
</Route>
<Route name="tab2" schema="tab" title="Tab #2" >
<Route name="tab2" schema="tab" title="Tab #2" hideNavBar={true}>
<Router onPop={()=>{console.log("onPop is called!"); return true} }>
<Route name="tab2_1" component={TabView} title="Tab #2" />
<Route name="register" component={Register} title="Register"/>
<Route name="tab2_1" component={TabView} title="Tab #2_1" />
<Route name="tab2_2" component={TabView} title="Tab #2_2" />
</Router>
</Route>
<Route name="tab3" schema="tab" title="Tab #3" component={TabView} />
<Route name="tab4" schema="tab" title="Tab #4" component={TabView} />
<Route name="tab5" schema="tab" title="Tab #5" component={TabView} />
</Router>
</Route>
<Route name="launch" header={Header} component={Launch} wrapRouter={true} title="Launch" hideNavBar={true} initial={true}/>
</Router>
);
}
Expand Down
1 change: 0 additions & 1 deletion Example/components/TabView.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class TabView extends React.Component {
{this.props.name === "tab2_1" &&
<Button onPress={Actions.tab2_2}>next screen for tab2_1</Button>
}
<Button onPress={Actions.register}>Register</Button>
<Button onPress={Actions.pop}>Back</Button>
<Button onPress={Actions.tab1}>Switch to tab1</Button>
<Button onPress={Actions.tab2}>Switch to tab2</Button>
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.1.0"
"react-native-router-flux": "^2.1.2"
}
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ npm i react-native-router-flux --save
|-----------|--------|---------|--------------------------------------------|
| name | string | required | Will be used to call screen transition, for example, `Actions.name(params)`. Must be unique. |
| component | React.Component | semi-required | The `Component` to be displayed. Not required when defining a nested `Router` or child, see example |
| type | string | optional | Defines how the new screen is added to the navigator stack. One of `push`, `replace`, `switch`, `reset`. Default is 'push'. `replace` tells navigator to replace current route with new route. `switch` is used for tab screens. `reset` is similar to replace except it unmounts the componets in the navigator stack. |
| type | string | optional | Defines how the new screen is added to the navigator stack. One of `push`, `modal`,`replace`, `switch`, `reset`. Default is 'push'. `replace` tells navigator to replace current route with new route. `modal` type inserts its 'component' after navigator component. It could be used for popup alerts as well for various needed processes before any navigator transitions (like login auth process).``switch` is used for tab screens. `reset` is similar to replace except it unmounts the componets in the navigator stack. `modal` component could be dismissed by using Actions.dismiss() |
| initial | bool | false | Set to `true` if this is the initial screen |
| title | string | null | The title to be displayed in the navigation bar |
| schema | string | optional | Set this property to the name of a previously defined `Schema` to inherit its properties |
| wrapRouter | bool | false | If `true`, the route is automatically nested in its own `Router`. Useful for modal screens. |
| wrapRouter | bool | false | If `true`, the route is automatically nested in its own `Router`. Useful for modal screens. For type==switch wrapRouter will be true|
| sceneConfig | Navigator.SceneConfigs | optional | Defines the transition animation. |

##### Schema:
Expand Down Expand Up @@ -93,6 +93,7 @@ export default class Example extends React.Component {
<Route name="loginModal2" component={Login2} title="Login2"/>
</Router>
</Route>
<Route name="error" component={Error} title="Error" type="modal"/>
<Route name="register2" component={Register} title="Register2" schema="withoutAnimation"/>
<Route name="tabbar">
<Router footer={TabBar} showNavigationBar={false} tabBarStyle={{borderTopColor:'#00bb00',borderTopWidth:1,backgroundColor:'white'}}>
Expand Down Expand Up @@ -128,6 +129,7 @@ class Launch extends React.Component {
<Button onPress={()=>Actions.login({data:"Custom data", title:'Custom title' })}>Go to Login page</Button>
<Button onPress={Actions.register}>Go to Register page</Button>
<Button onPress={Actions.register2}>Go to Register page without animation</Button>
<Button onPress={Actions.error('error message')}>Show error popup</Button>
<Button onPress={Actions.tabbar}>Go to TabBar page</Button>
</View>
);
Expand Down Expand Up @@ -166,7 +168,6 @@ you might write:

## Limitations
### Nested Routers
* Showing and hiding navigation bars and tab bars is only possible on the root `Router`. For example, if you have a tab bar where each tab has its own `Router`, it would not be possible for to show the navigation bar on tab 1, and then push another screen onto the child navigator without the navigation bar shown. In order to get this behavior you will have to manage your own navigation bar component.
* Although you can pass data into a `Route` (e.g. `Actions.login({user_id: '3'})`), this is currently not working for `Route` inside of a nested `Router`.
* If you are using a tab bar where each tab has its own `Router`, modal screens will have to be presented from the root navigator in order to cover the tab bar. To do this, the modal screen should be defined in the root router, and should have the `wrapRouter={true}` property as in the example below.
```
Expand Down
4 changes: 2 additions & 2 deletions Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class Route {
navigator: any;
childRouter: ?Router;

constructor({name, type, component, children, header, footer, wrapRouter, ...props}: { [key: string]: any} = {}, parent: Router = null) {
constructor({name, type, component, schema, children, header, footer, wrapRouter, ...props}: { [key: string]: any} = {}, parent: Router = null) {
if (!name) {
throw new Error("no name is defined for Route=" + name);
}
Expand All @@ -43,7 +43,7 @@ export default class Route {
this.header = header;
this.footer = footer;
this.props = props;
this.wrapRouter = wrapRouter || this.type == 'switch';
this.wrapRouter = wrapRouter || type=='switch';

}

Expand Down
2 changes: 2 additions & 0 deletions Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export default class Router {
Actions[name] = function(data){
return Actions.route(name, data);
}
} else {
throw new Error("Action = "+name+" is not unique!");
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion TabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class TabBar extends React.Component {
if (!Actions[el.props.name]){
throw new Error("No action is defined for name="+el.props.name+" actions:"+JSON.stringify(Object.keys(Actions)));
}
Actions[el.props.name](el.props);
Actions[el.props.name]();
InteractionManager.runAfterInteractions(() =>
this.setState({hideTabBar: el.props.hideTabBar}));
return {selected: 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.1.1",
"version": "2.1.2",
"description": "React Native Router using Flux architecture",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 3478716

Please sign in to comment.