Skip to content

Commit

Permalink
Addresses #2152 (#2153)
Browse files Browse the repository at this point in the history
  • Loading branch information
aksonov authored Aug 1, 2017
1 parent 7c9c1e6 commit 84a807d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"react-native": "0.44.0",
"react-native-button": "^2.0.0",
"react-native-message-bar": "^1.6.0",
"react-native-router-flux": "github:aksonov/react-native-router-flux#tabicons",
"react-native-router-flux": "4.0.0-beta.15",
"react-navigation": "^1.0.0-beta.11"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions Example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3237,9 +3237,9 @@ react-native-message-bar@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/react-native-message-bar/-/react-native-message-bar-1.6.0.tgz#79623e89655475216927090771b0238616b6f1c7"

"react-native-router-flux@github:aksonov/react-native-router-flux#a3fd7ced2680c7870ed71d3e9163339e7d23773c":
version "4.0.0-beta.14"
resolved "https://codeload.github.com/aksonov/react-native-router-flux/tar.gz/a3fd7ced2680c7870ed71d3e9163339e7d23773c"
react-native-router-flux@4.0.0-beta.15:
version "4.0.0-beta.15"
resolved "https://registry.yarnpkg.com/react-native-router-flux/-/react-native-router-flux-4.0.0-beta.15.tgz#d4c340568677336a59f0cb704e308a449ce0245e"
dependencies:
mobx "^3.1.16"
mobx-react "^4.2.1"
Expand Down
3 changes: 2 additions & 1 deletion dist/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ reducer=reducer;exports.default=



createReducer;var _navigationStore=require('./navigationStore');var _navigationStore2=_interopRequireDefault(_navigationStore);var _ActionConst=require('./ActionConst');var ActionConst=_interopRequireWildcard(_ActionConst);var _reactNavigation=require('react-navigation');var _State=require('./State');function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj;}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key];}}newObj.default=obj;return newObj;}}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}var supportedActions=exports.supportedActions=(_supportedActions={},_defineProperty(_supportedActions,ActionConst.PUSH,_reactNavigation.NavigationActions.NAVIGATE),_defineProperty(_supportedActions,ActionConst.BACK,_reactNavigation.NavigationActions.BACK),_defineProperty(_supportedActions,ActionConst.REFRESH,_reactNavigation.NavigationActions.BACK),_defineProperty(_supportedActions,ActionConst.RESET,_reactNavigation.NavigationActions.RESET),_defineProperty(_supportedActions,ActionConst.REPLACE,_reactNavigation.NavigationActions.RESET),_supportedActions);var createAction=function createAction(type){return function(){var payload=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return _extends({type:type},payload);};};function reducer(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:_navigationStore2.default.state;var action=arguments[1];var type=action.type;var routeName=action.routeName;if(supportedActions[type]){var newState=_navigationStore2.default.router.getStateForAction(createAction(supportedActions[type])({routeName:routeName,params:action.params}),state);var newActiveState=(0,_State.getActiveState)(newState);var activeState=(0,_State.getActiveState)(state);if(type===ActionConst.JUMP&&newActiveState.routeName===activeState.routeName){return state;}return newState||state;}if(type===ActionConst.JUMP){var _newState=_navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.navigate({routeName:routeName,params:action.params}),state);var key=(0,_State.getActiveState)(_newState).key;return _navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.setParams({key:key,params:action.params}),_newState);}else if(type===ActionConst.POP_TO){var nextScene='';var _newState2=state;var currentState=state;var currentScene=(0,_State.getActiveState)(state).routeName;while(nextScene!==currentScene&&_newState2&&nextScene!==routeName){_newState2=_navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.back(),currentState);if(_newState2){nextScene=(0,_State.getActiveState)(_newState2).routeName;if(nextScene!==routeName){currentState=_newState2;}}}return nextScene===routeName?_newState2:state;}else if(type===ActionConst.POP_AND_PUSH){var _newState3=_navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.back(),state);return _navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.navigate({routeName:routeName,params:action.params}),_newState3);}return _navigationStore2.default.router.getStateForAction(action,state)||state;}function createReducer(){

createReducer;var _navigationStore=require('./navigationStore');var _navigationStore2=_interopRequireDefault(_navigationStore);var _ActionConst=require('./ActionConst');var ActionConst=_interopRequireWildcard(_ActionConst);var _reactNavigation=require('react-navigation');var _State=require('./State');function _interopRequireWildcard(obj){if(obj&&obj.__esModule){return obj;}else{var newObj={};if(obj!=null){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key))newObj[key]=obj[key];}}newObj.default=obj;return newObj;}}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}var supportedActions=exports.supportedActions=(_supportedActions={},_defineProperty(_supportedActions,ActionConst.PUSH,_reactNavigation.NavigationActions.NAVIGATE),_defineProperty(_supportedActions,ActionConst.BACK,_reactNavigation.NavigationActions.BACK),_defineProperty(_supportedActions,ActionConst.REFRESH,_reactNavigation.NavigationActions.BACK),_defineProperty(_supportedActions,ActionConst.RESET,_reactNavigation.NavigationActions.RESET),_defineProperty(_supportedActions,ActionConst.REPLACE,_reactNavigation.NavigationActions.RESET),_supportedActions);var createAction=function createAction(type){return function(){var payload=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};return _extends({type:type},payload);};};function reducer(){var state=arguments.length>0&&arguments[0]!==undefined?arguments[0]:_navigationStore2.default.state;var action=arguments[1];var type=action.type;var routeName=action.routeName;if(supportedActions[type]){var newState=_navigationStore2.default.router.getStateForAction(createAction(supportedActions[type])({routeName:routeName,params:action.params}),state);return newState||state;}if(type===ActionConst.JUMP){var _newState=_navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.navigate({routeName:routeName,params:action.params}),state);var newActiveState=(0,_State.getActiveState)(_newState);var activeState=(0,_State.getActiveState)(state);if(type===ActionConst.JUMP&&newActiveState.routeName===activeState.routeName){return state;}var key=(0,_State.getActiveState)(_newState).key;return _navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.setParams({key:key,params:action.params}),_newState);}else if(type===ActionConst.POP_TO){var nextScene='';var _newState2=state;var currentState=state;var currentScene=(0,_State.getActiveState)(state).routeName;while(nextScene!==currentScene&&_newState2&&nextScene!==routeName){_newState2=_navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.back(),currentState);if(_newState2){nextScene=(0,_State.getActiveState)(_newState2).routeName;if(nextScene!==routeName){currentState=_newState2;}}}return nextScene===routeName?_newState2:state;}else if(type===ActionConst.POP_AND_PUSH){var _newState3=_navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.back(),state);return _navigationStore2.default.router.getStateForAction(_reactNavigation.NavigationActions.navigate({routeName:routeName,params:action.params}),_newState3);}return _navigationStore2.default.router.getStateForAction(action,state)||state;}function createReducer(){
return reducer;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/aksonov/react-native-router-flux"
},
"license": "ISC",
"main": "dist/index.js",
"main": "src/index.js",
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"postinstall": "./node_modules/.bin/opencollective postinstall",
Expand Down
9 changes: 5 additions & 4 deletions src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ export function reducer(state = navigationStore.state, action) {
routeName,
params: action.params,
}), state);
return newState || state;
}
if (type === ActionConst.JUMP) {
const newState = navigationStore.router.getStateForAction(NavigationActions.navigate({ routeName, params: action.params }), state);
const newActiveState = getActiveState(newState);
const activeState = getActiveState(state);
// skip action if route name is the same (avoid pushing action)
if (type === ActionConst.JUMP && newActiveState.routeName === activeState.routeName) {
return state;
}
return newState || state;
}
if (type === ActionConst.JUMP) {
const newState = navigationStore.router.getStateForAction(NavigationActions.navigate({ routeName, params: action.params }), state);
const key = getActiveState(newState).key;
return navigationStore.router.getStateForAction(NavigationActions.setParams({
key,
Expand Down

0 comments on commit 84a807d

Please sign in to comment.