[ReactNative] Navigator initialRoute default change
Summary: The default initialRoute was the first route, but it makes more sense for the default initialRoute to be the last route in the initialRouteStack. Updated the docs to reflect that. @public Test Plan: Updated call sites and checked that they work. Not many places use initialRouteStack yet.
This commit is contained in:
parent
790cee6e26
commit
40e3f6ea8c
|
@ -227,15 +227,17 @@ var Navigator = React.createClass({
|
||||||
renderScene: PropTypes.func.isRequired,
|
renderScene: PropTypes.func.isRequired,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a single "route" to start on. A route is an arbitrary object
|
* Specify a route to start on. A route is an object that the navigator
|
||||||
* that the navigator will use to identify each scene before rendering.
|
* will use to identify each scene to render. `initialRoute` must be
|
||||||
* Either initialRoute or initialRouteStack is required.
|
* a route in the `initialRouteStack` if both props are provided. The
|
||||||
|
* `initialRoute` will default to the last item in the `initialRouteStack`.
|
||||||
*/
|
*/
|
||||||
initialRoute: PropTypes.object,
|
initialRoute: PropTypes.object,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a set of routes to initially mount the scenes for. Required if no
|
* Provide a set of routes to initially mount. Required if no initialRoute
|
||||||
* initialRoute is provided
|
* is provided. Otherwise, it will default to an array containing only the
|
||||||
|
* `initialRoute`
|
||||||
*/
|
*/
|
||||||
initialRouteStack: PropTypes.arrayOf(PropTypes.object),
|
initialRouteStack: PropTypes.arrayOf(PropTypes.object),
|
||||||
|
|
||||||
|
@ -295,21 +297,18 @@ var Navigator = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
var routeStack = this.props.initialRouteStack || [];
|
var routeStack = this.props.initialRouteStack || [this.props.initialRoute];
|
||||||
var initialRouteIndex = 0;
|
invariant(
|
||||||
if (this.props.initialRoute && routeStack.length) {
|
routeStack.length >= 1,
|
||||||
|
'Navigator requires props.initialRoute or props.initialRouteStack.'
|
||||||
|
);
|
||||||
|
var initialRouteIndex = routeStack.length - 1;
|
||||||
|
if (this.props.initialRoute) {
|
||||||
initialRouteIndex = routeStack.indexOf(this.props.initialRoute);
|
initialRouteIndex = routeStack.indexOf(this.props.initialRoute);
|
||||||
invariant(
|
invariant(
|
||||||
initialRouteIndex !== -1,
|
initialRouteIndex !== -1,
|
||||||
'initialRoute is not in initialRouteStack.'
|
'initialRoute is not in initialRouteStack.'
|
||||||
);
|
);
|
||||||
} else if (this.props.initialRoute) {
|
|
||||||
routeStack = [this.props.initialRoute];
|
|
||||||
} else {
|
|
||||||
invariant(
|
|
||||||
routeStack.length >= 1,
|
|
||||||
'Navigator requires props.initialRoute or props.initialRouteStack.'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
sceneConfigStack: routeStack.map(
|
sceneConfigStack: routeStack.map(
|
||||||
|
|
Loading…
Reference in New Issue