Skip to content

Commit a2eb56c

Browse files
author
aksonov
committed
restore prevScene (fixes #2526), addresses #2413
1 parent 65ecba7 commit a2eb56c

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

dist/Router.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ App=(0,_native.observer)(_class=(_temp2=_class2=function(_React$Component){_inhe
2828

2929

3030

31-
onBackPress=function(){
32-
_navigationStore2.default.pop();
33-
return _navigationStore2.default.currentScene!==_navigationStore2.default.prevScene;
34-
},_this.
31+
onBackPress=function(){return!_navigationStore2.default.pop();},_this.
3532

3633
handleDeepURL=function(e){return _this.parseDeepURL(e.url);},_this.
3734

@@ -67,7 +64,7 @@ _navigationStore2.default[actionKey](params);
6764
{
6865
var AppNavigator=this.props.navigator;
6966
return(
70-
_react2.default.createElement(AppNavigator,{navigation:(0,_reactNavigation.addNavigationHelpers)({dispatch:_navigationStore2.default.dispatch,state:_navigationStore2.default.state}),__source:{fileName:_jsxFileName,lineNumber:70}}));
67+
_react2.default.createElement(AppNavigator,{navigation:(0,_reactNavigation.addNavigationHelpers)({dispatch:_navigationStore2.default.dispatch,state:_navigationStore2.default.state}),__source:{fileName:_jsxFileName,lineNumber:67}}));
7168

7269
}}]);return App;}(_react2.default.Component),_class2.propTypes={navigator:_propTypes2.default.func,backAndroidHandler:_propTypes2.default.func,uriPrefix:_propTypes2.default.string},_temp2))||_class;
7370

@@ -86,9 +83,9 @@ if(dispatch&&state){
8683

8784
_navigationStore2.default.setState(state);
8885
_navigationStore2.default.dispatch=dispatch;
89-
return _react2.default.createElement(AppNavigator,{navigation:(0,_reactNavigation.addNavigationHelpers)({dispatch:dispatch,state:state}),uriPrefix:uriPrefix,__source:{fileName:_jsxFileName,lineNumber:89}});
86+
return _react2.default.createElement(AppNavigator,{navigation:(0,_reactNavigation.addNavigationHelpers)({dispatch:dispatch,state:state}),uriPrefix:uriPrefix,__source:{fileName:_jsxFileName,lineNumber:86}});
9087
}
91-
return _react2.default.createElement(App,_extends({},props,{navigator:AppNavigator,uriPrefix:uriPrefix,__source:{fileName:_jsxFileName,lineNumber:91}}));
88+
return _react2.default.createElement(App,_extends({},props,{navigator:AppNavigator,uriPrefix:uriPrefix,__source:{fileName:_jsxFileName,lineNumber:88}}));
9289
};
9390
Router.propTypes={
9491
createReducer:_propTypes2.default.func,

dist/navigationStore.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Object.defineProperty(exports,"__esModule",{value:true});exports.actionMap=undefined;var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _actionMap,_jsxFileName='src/navigationStore.js',_desc,_value,_class2,_descriptor,_descriptor2,_descriptor3;var _react=require('react');var _react2=_interopRequireDefault(_react);
1+
Object.defineProperty(exports,"__esModule",{value:true});exports.actionMap=undefined;var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _actionMap,_jsxFileName='src/navigationStore.js',_desc,_value,_class2,_descriptor,_descriptor2,_descriptor3,_descriptor4;var _react=require('react');var _react2=_interopRequireDefault(_react);
22
var _mobx=require('mobx');
33
var _ActionConst=require('./ActionConst');var ActionConst=_interopRequireWildcard(_ActionConst);
44
var _Util=require('./Util');
@@ -355,7 +355,8 @@ var defaultFailure=function defaultFailure(){};var
355355
NavigationStore=(_class2=function(){function NavigationStore(){var _this2=this;_classCallCheck(this,NavigationStore);this.
356356
refs={};this.
357357
states={};this.
358-
reducer=null;_initDefineProp(this,'currentScene',_descriptor,this);_initDefineProp(this,'currentParams',_descriptor2,this);this.
358+
reducer=null;_initDefineProp(this,'currentScene',_descriptor,this);_initDefineProp(this,'prevScene',_descriptor2,this);_initDefineProp(this,'currentParams',_descriptor3,this);this.
359+
359360

360361

361362

@@ -515,8 +516,8 @@ if(lightbox){
515516
return(0,_LightboxNavigator2.default)(res,_extends({mode:mode,initialRouteParams:initialRouteParams,initialRouteName:initialRouteName},commonProps,{navigationOptions:createNavigationOptions(commonProps)}));
516517
}else if(tabs){
517518
if(!tabBarComponent){
518-
tabBarComponent=tabBarPosition==='top'?function(props){return _react2.default.createElement(_reactNavigation.TabBarTop,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:518}}));}:
519-
function(props){return _react2.default.createElement(_reactNavigation.TabBarBottom,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:519}}));};
519+
tabBarComponent=tabBarPosition==='top'?function(props){return _react2.default.createElement(_reactNavigation.TabBarTop,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:519}}));}:
520+
function(props){return _react2.default.createElement(_reactNavigation.TabBarBottom,_extends({},props,commonProps,{__source:{fileName:_jsxFileName,lineNumber:520}}));};
520521
}
521522
if(!tabBarPosition){
522523
tabBarPosition=_reactNative.Platform.OS==='android'?'top':'bottom';
@@ -543,7 +544,9 @@ nextState=function(state,cmd){return _this2.reducer?_this2.reducer(state,cmd):(0
543544

544545
dispatch=function(cmd){
545546
_this2.setState(_this2.nextState(_this2.state,cmd));
546-
};_initDefineProp(this,'setState',_descriptor3,this);this.
547+
};_initDefineProp(this,'setState',_descriptor4,this);this.
548+
549+
547550

548551

549552

@@ -637,6 +640,7 @@ _this2.dispatch(_reactNavigation.NavigationActions.setParams({key:key,params:par
637640
};this.
638641

639642
pop=function(){var _ref11=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{},timeout=_ref11.timeout,params=_objectWithoutProperties(_ref11,['timeout']);
643+
var previous=(0,_State.getActiveState)(_this2.state);
640644
var res=filterParam(params);
641645
if(timeout){
642646
setTimeout(function(){return _this2.pop(params);},timeout);
@@ -646,6 +650,7 @@ if(res.refresh){
646650
_this2.refresh(res.refresh);
647651
}
648652
}
653+
return!(0,_lodash2.default)(previous,(0,_State.getActiveState)(_this2.state));
649654
};this.
650655

651656
popTo=function(routeName,data){
@@ -669,7 +674,7 @@ _this2.dispatch(_reactNavigation.NavigationActions.reset({key:null,index:0,actio
669674
routeName:routeName,
670675
params:params})]}));
671676

672-
};}_createClass(NavigationStore,[{key:'state',get:function get(){var scene=this.currentScene;var params=this.currentParams;return this._state;}}]);return NavigationStore;}(),(_descriptor=_applyDecoratedDescriptor(_class2.prototype,'currentScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor2=_applyDecoratedDescriptor(_class2.prototype,'currentParams',[_mobx.observable],{enumerable:true,initializer:null}),_descriptor3=_applyDecoratedDescriptor(_class2.prototype,'setState',[_mobx.action],{enumerable:true,initializer:function initializer(){var _this3=this;return function _callee(newState){var state,currentScene,exitHandler,res,handler,_success,_failure,params,_res;return regeneratorRuntime.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(newState){_context.next=2;break;}return _context.abrupt('return');case 2:state=(0,_State.getActiveState)(newState);if(!((0,_lodash2.default)(state.params,_this3._currentParams)&&state.routeName===_this3.currentScene)){_context.next=5;break;}return _context.abrupt('return');case 5:currentScene=_this3.currentScene;_this3._state=newState;_this3.currentScene=state.routeName;_this3.currentParams=state.params;_this3._currentParams=state.params;if(!(currentScene!==_this3.currentScene&&_this3.currentScene!=='DrawerOpen'&&_this3.currentScene!=='DrawerClose')){_context.next=31;break;}_this3.dispatch({type:ActionConst.BLUR,routeName:currentScene});exitHandler=_this3[currentScene+_Util.OnExit];if(exitHandler){try{res=exitHandler();if(res instanceof Promise){res.then(defaultSuccess,defaultFailure);}}catch(e){console.error('Error during onExit handler:',e);}}_this3.dispatch({type:ActionConst.FOCUS,routeName:_this3.currentScene,params:_this3._currentParams});if(!_this3.states[_this3.currentScene]){_context.next=31;break;}handler=_this3[_this3.currentScene+_Util.OnEnter];_success=_this3.states[_this3.currentScene].success||defaultSuccess;_failure=_this3.states[_this3.currentScene].failure||defaultFailure;if(!handler){_context.next=31;break;}_context.prev=20;params=(0,_State.getActiveState)(_this3._state).params;_context.next=24;return regeneratorRuntime.awrap(handler(params));case 24:_res=_context.sent;if(_res){_success(_res);}else{_failure();}_context.next=31;break;case 28:_context.prev=28;_context.t0=_context['catch'](20);_failure({error:_context.t0.message});case 31:case'end':return _context.stop();}}},null,_this3,[[20,28]]);};}})),_class2);exports.default=
677+
};}_createClass(NavigationStore,[{key:'state',get:function get(){var scene=this.currentScene;var params=this.currentParams;return this._state;}}]);return NavigationStore;}(),(_descriptor=_applyDecoratedDescriptor(_class2.prototype,'currentScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor2=_applyDecoratedDescriptor(_class2.prototype,'prevScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor3=_applyDecoratedDescriptor(_class2.prototype,'currentParams',[_mobx.observable],{enumerable:true,initializer:null}),_descriptor4=_applyDecoratedDescriptor(_class2.prototype,'setState',[_mobx.action],{enumerable:true,initializer:function initializer(){var _this3=this;return function _callee(newState){var state,currentScene,exitHandler,res,handler,_success,_failure,params,_res;return regeneratorRuntime.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:if(newState){_context.next=2;break;}return _context.abrupt('return');case 2:state=(0,_State.getActiveState)(newState);if(!((0,_lodash2.default)(state.params,_this3._currentParams)&&state.routeName===_this3.currentScene)){_context.next=5;break;}return _context.abrupt('return');case 5:currentScene=_this3.currentScene;_this3._state=newState;_this3.currentScene=state.routeName;_this3.prevScene=currentScene;_this3.currentParams=state.params;_this3._currentParams=state.params;if(!(currentScene!==_this3.currentScene&&_this3.currentScene!=='DrawerOpen'&&_this3.currentScene!=='DrawerClose')){_context.next=32;break;}_this3.dispatch({type:ActionConst.BLUR,routeName:currentScene});exitHandler=_this3[currentScene+_Util.OnExit];if(exitHandler){try{res=exitHandler();if(res instanceof Promise){res.then(defaultSuccess,defaultFailure);}}catch(e){console.error('Error during onExit handler:',e);}}_this3.dispatch({type:ActionConst.FOCUS,routeName:_this3.currentScene,params:_this3._currentParams});if(!_this3.states[_this3.currentScene]){_context.next=32;break;}handler=_this3[_this3.currentScene+_Util.OnEnter];_success=_this3.states[_this3.currentScene].success||defaultSuccess;_failure=_this3.states[_this3.currentScene].failure||defaultFailure;if(!handler){_context.next=32;break;}_context.prev=21;params=(0,_State.getActiveState)(_this3._state).params;_context.next=25;return regeneratorRuntime.awrap(handler(params));case 25:_res=_context.sent;if(_res){_success(_res);}else{_failure();}_context.next=32;break;case 29:_context.prev=29;_context.t0=_context['catch'](21);_failure({error:_context.t0.message});case 32:case'end':return _context.stop();}}},null,_this3,[[21,29]]);};}})),_class2);exports.default=
673678

674679

675680

src/Router.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ class App extends React.Component {
2828
Linking.removeEventListener('url', this.handleDeepURL);
2929
}
3030

31-
onBackPress = () => {
32-
navigationStore.pop();
33-
return navigationStore.currentScene !== navigationStore.prevScene;
34-
};
31+
onBackPress = () => !navigationStore.pop();
3532

3633
handleDeepURL = (e) => this.parseDeepURL(e.url);
3734

src/navigationStore.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class NavigationStore {
360360
_state;
361361
_currentParams;
362362
@observable currentScene = '';
363+
@observable prevScene = '';
363364
@observable currentParams;
364365

365366
get state() {
@@ -558,6 +559,8 @@ class NavigationStore {
558559
const currentScene = this.currentScene;
559560
this._state = newState;
560561
this.currentScene = state.routeName;
562+
this.prevScene = currentScene;
563+
561564
this.currentParams = state.params;
562565
this._currentParams = state.params;
563566

@@ -637,6 +640,7 @@ class NavigationStore {
637640
};
638641

639642
pop = ({ timeout, ...params } = {}) => {
643+
const previous = getActiveState(this.state);
640644
const res = filterParam(params);
641645
if (timeout) {
642646
setTimeout(() => this.pop(params), timeout);
@@ -646,6 +650,7 @@ class NavigationStore {
646650
this.refresh(res.refresh);
647651
}
648652
}
653+
return !isEqual(previous, getActiveState(this.state));
649654
};
650655

651656
popTo = (routeName, data) => {

0 commit comments

Comments
 (0)