mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
Add method popN() to Navigator.
Summary: Compareing API of `Navigator`(http://facebook.github.io/react-native/releases/next/docs/navigator.html) and `NavigatorIOS`(http://facebook.github.io/react-native/releases/next/docs/navigatorios.html), we found `Navigator` object lacks of the method `popN()` which is sometimes useful. This PR add it. Closes https://github.com/facebook/react-native/pull/8806 Differential Revision: D3648001 Pulled By: ericvicenti fbshipit-source-id: 661efba39e68049fd4a094304ec080092a14296d
This commit is contained in:
parent
55bc825092
commit
bbe95c2acf
@ -1072,14 +1072,17 @@ var Navigator = React.createClass({
|
||||
});
|
||||
},
|
||||
|
||||
_popN: function(n) {
|
||||
if (n === 0) {
|
||||
/**
|
||||
* Go back N scenes at once. When N=1, behavior matches `pop()`.
|
||||
* When N is invalid(negative or bigger than current routes count), do nothing.
|
||||
* @param {number} n The number of scenes to pop. Should be an integer.
|
||||
*/
|
||||
popN: function(n) {
|
||||
invariant(typeof n === 'number', 'Must supply a number to popN');
|
||||
n = parseInt(n, 10);
|
||||
if (n <= 0 || this.state.presentedIndex - n < 0) {
|
||||
return;
|
||||
}
|
||||
invariant(
|
||||
this.state.presentedIndex - n >= 0,
|
||||
'Cannot pop below zero'
|
||||
);
|
||||
var popIndex = this.state.presentedIndex - n;
|
||||
var presentedRoute = this.state.routeStack[this.state.presentedIndex];
|
||||
var popSceneConfig = this.props.configureScene(presentedRoute); // using the scene config of the currently presented view
|
||||
@ -1109,9 +1112,7 @@ var Navigator = React.createClass({
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.state.presentedIndex > 0) {
|
||||
this._popN(1);
|
||||
}
|
||||
this.popN(1);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1185,7 +1186,7 @@ var Navigator = React.createClass({
|
||||
'Calling popToRoute for a route that doesn\'t exist!'
|
||||
);
|
||||
var numToPop = this.state.presentedIndex - indexOfRoute;
|
||||
this._popN(numToPop);
|
||||
this.popN(numToPop);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1209,9 +1210,7 @@ var Navigator = React.createClass({
|
||||
this.replaceAtIndex(route, 0, () => {
|
||||
// Do not use popToRoute here, because race conditions could prevent the
|
||||
// route from existing at this time. Instead, just go to index 0
|
||||
if (this.state.presentedIndex > 0) {
|
||||
this._popN(this.state.presentedIndex);
|
||||
}
|
||||
this.popN(this.state.presentedIndex);
|
||||
});
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user