Skip to content

Commit

Permalink
Merge pull request #73 from liuyaodong/initial-route-stack
Browse files Browse the repository at this point in the history
Use `initialRouteStack` instead of `initialRoute`
  • Loading branch information
Pavlo Aksonov committed Dec 15, 2015
2 parents 19c6123 + 9fea6b8 commit a938eec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Example/Example.js
Expand Up @@ -22,13 +22,13 @@ class TabIcon extends React.Component {
export default class Example extends React.Component {
render() {
return (
<Router hideNavBar={true}>
<Router hideNavBar={true} initialRoutes={['launch', 'login']}>
<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="launch" component={Launch} initial={true} wrapRouter={true} title="Launch" hideNavBar={true}/>
<Route name="launch" component={Launch} wrapRouter={true} title="Launch" hideNavBar={true}/>
<Route name="register" component={Register} title="Register"/>
<Route name="home" component={Home} title="Replace" type="replace"/>
<Route name="login" schema="modal">
Expand Down
2 changes: 1 addition & 1 deletion Example/iOS/AppDelegate.m
Expand Up @@ -47,7 +47,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"Example"
initialProperties:nil
initialProperties:@{@"initialRoutes": @[@"launch", @"login"]}
launchOptions:launchOptions];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
Expand Down
16 changes: 8 additions & 8 deletions index.js
Expand Up @@ -479,7 +479,7 @@ class Router extends React.Component {
super(props);
this.routes = {};
this.schemas = {...props.schemas};
this.initial = props.initial;
this.initial = this.props.initialRoutes || []; // Initial names array

const self = this;
React.Children.forEach(this.props.children, function (child, index) {
Expand All @@ -491,8 +491,8 @@ class Router extends React.Component {
React.Children.forEach(this.props.children, function (child, index) {
const name = child.props.name;
if (child.type.prototype.className() === "Route") {
if (child.props.initial || !self.initial) {
self.initial = name;
if (child.props.initial) {
self.initial.push(name);
}
// declare function with null navigator to avoid undefined Actions
Actions.addAction(name, child.props, self.schemas, self)
Expand All @@ -519,12 +519,12 @@ class Router extends React.Component {
}

render(){
if (!this.state.initial){
if (!this.state.initial.length){
console.error("No initial attribute!");
}
const initialRoute = this.routes[this.state.initial];
if (!initialRoute) {
console.error("No initial route!"+JSON.stringify(this.routes));
const initialRoutes = this.state.initial.map((name) => this.routes[name]);
if (!initialRoutes.length) {
console.error("No initial routes!"+JSON.stringify(this.routes));
}

const Header = this.props.header;
Expand All @@ -537,7 +537,7 @@ class Router extends React.Component {
<View style={styles.transparent}>
{header}
<ExNavigator ref="nav"
initialRoute={new ExRoute(initialRoute, this.schemas)}
initialRouteStack={initialRoutes.map((route) => new ExRoute(route, this.schemas))}
style={styles.transparent}
sceneStyle={{ paddingTop: 0 }}
showNavigationBar={!this.props.hideNavBar}
Expand Down

0 comments on commit a938eec

Please sign in to comment.