Skip to content

Commit

Permalink
fixes for #1994, #1987
Browse files Browse the repository at this point in the history
  • Loading branch information
aksonov committed Jul 10, 2017
1 parent 1f3dfe5 commit 7df07b5
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 90 deletions.
8 changes: 4 additions & 4 deletions Example/components/Login3.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const styles = StyleSheet.create({
});

const popToRoot = () => {
Actions.popTo("root");
}
Actions.popTo("launch");
};

const popToLogin1 = () => {
Actions.popTo("loginModal");
}
};

const popToLogin2 = () => {
Actions.popTo("loginModal2");
}
};

export default class extends React.Component {
render(){
Expand Down
2 changes: 1 addition & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"mobx-react": "^4.2.1",
"react-native-button": "^2.0.0",
"react-navigation": "^1.0.0-beta.11",
"react-native-router-flux": "4.0.0-beta.3",
"react-native-router-flux": "^4.0.0-beta.7",
"react": "16.0.0-alpha.6",
"react-native": "0.44.0"
},
Expand Down
22 changes: 12 additions & 10 deletions dist/ActionConst.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Object.defineProperty(exports,"__esModule",{value:true});var _reactNavigation=require('react-navigation');

var JUMP=_reactNavigation.NavigationActions.NAVIGATE;
var PUSH=_reactNavigation.NavigationActions.NAVIGATE;
var REPLACE=_reactNavigation.NavigationActions.RESET;
var BACK=_reactNavigation.NavigationActions.BACK;
var REFRESH=_reactNavigation.NavigationActions.SET_PARAMS;
var RESET=_reactNavigation.NavigationActions.RESET;exports.default=

{JUMP:JUMP,PUSH:PUSH,REPLACE:REPLACE,BACK:BACK,REFRESH:REFRESH,RESET:RESET};
Object.defineProperty(exports,"__esModule",{value:true});var JUMP=exports.JUMP='REACT_NATIVE_ROUTER_FLUX_JUMP';
var PUSH=exports.PUSH='REACT_NATIVE_ROUTER_FLUX_PUSH';
var PUSH_OR_POP=exports.PUSH_OR_POP='REACT_NATIVE_ROUTER_FLUX_PUSH_OR_POP';
var REPLACE=exports.REPLACE='REACT_NATIVE_ROUTER_FLUX_REPLACE';
var BACK=exports.BACK='REACT_NATIVE_ROUTER_FLUX_BACK';
var BACK_ACTION=exports.BACK_ACTION='REACT_NATIVE_ROUTER_FLUX_BACK_ACTION';
var POP_AND_REPLACE=exports.POP_AND_REPLACE='REACT_NATIVE_ROUTER_FLUX_POP_AND_REPLACE';
var POP_TO=exports.POP_TO='REACT_NATIVE_ROUTER_FLUX_POP_TO';
var REFRESH=exports.REFRESH='REACT_NATIVE_ROUTER_FLUX_REFRESH';
var RESET=exports.RESET='REACT_NATIVE_ROUTER_FLUX_RESET';
var FOCUS=exports.FOCUS='REACT_NATIVE_ROUTER_FLUX_FOCUS';
var ANDROID_BACK=exports.ANDROID_BACK='REACT_NATIVE_ROUTER_FLUX_ANDROID_BACK';
33 changes: 14 additions & 19 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
Object.defineProperty(exports,"__esModule",{value:true});exports.Actions=exports.Scene=exports.Router=exports.Reducer=exports.navigationStore=exports.ActionConst=undefined;


var _ActionConst=require('./ActionConst');var ActionConst=_interopRequireWildcard(_ActionConst);
var _navigationStore=require('./navigationStore');var _navigationStore2=_interopRequireDefault(_navigationStore);
var _Reducer=require('./Reducer');var _Reducer2=_interopRequireDefault(_Reducer);
var _Router=require('./Router');var _Router2=_interopRequireDefault(_Router);
var _Scene=require('./Scene');var _Scene2=_interopRequireDefault(_Scene);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}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;}}exports.

module.exports={
get Actions(){
return require('./navigationStore').default;
},
get ActionConst(){
return require('./ActionConst').default;
},
get Reducer(){
return require('./Reducer').default;
},
get Router(){
return require('./Router').default;
},
get navigationStore(){
return require('./navigationStore').default;
},
get Scene(){
return require('./Scene').default;
}};


ActionConst=ActionConst;exports.
navigationStore=_navigationStore2.default;exports.
Reducer=_Reducer2.default;exports.
Router=_Router2.default;exports.
Scene=_Scene2.default;exports.
Actions=_navigationStore2.default;
99 changes: 80 additions & 19 deletions dist/navigationStore.js

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions src/ActionConst.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {NavigationActions} from 'react-navigation';

const JUMP = NavigationActions.NAVIGATE;
const PUSH = NavigationActions.NAVIGATE;
const REPLACE = NavigationActions.RESET;
const BACK = NavigationActions.BACK;
const REFRESH = NavigationActions.SET_PARAMS;
const RESET = NavigationActions.RESET;

export default {JUMP, PUSH, REPLACE, BACK, REFRESH, RESET};

export const JUMP = 'REACT_NATIVE_ROUTER_FLUX_JUMP';
export const PUSH = 'REACT_NATIVE_ROUTER_FLUX_PUSH';
export const PUSH_OR_POP = 'REACT_NATIVE_ROUTER_FLUX_PUSH_OR_POP';
export const REPLACE = 'REACT_NATIVE_ROUTER_FLUX_REPLACE';
export const BACK = 'REACT_NATIVE_ROUTER_FLUX_BACK';
export const BACK_ACTION = 'REACT_NATIVE_ROUTER_FLUX_BACK_ACTION';
export const POP_AND_REPLACE = 'REACT_NATIVE_ROUTER_FLUX_POP_AND_REPLACE';
export const POP_TO = 'REACT_NATIVE_ROUTER_FLUX_POP_TO';
export const REFRESH = 'REACT_NATIVE_ROUTER_FLUX_REFRESH';
export const RESET = 'REACT_NATIVE_ROUTER_FLUX_RESET';
export const FOCUS = 'REACT_NATIVE_ROUTER_FLUX_FOCUS';
export const ANDROID_BACK = 'REACT_NATIVE_ROUTER_FLUX_ANDROID_BACK';
35 changes: 15 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
/* @flow */
/* eslint-disable import/no-commonjs */

module.exports = {
get Actions() {
return require('./navigationStore').default;
},
get ActionConst() {
return require('./ActionConst').default;
},
get Reducer() {
return require('./Reducer').default;
},
get Router() {
return require('./Router').default;
},
get navigationStore() {
return require('./navigationStore').default;
},
get Scene() {
return require('./Scene').default;
},
};
import * as ActionConst from './ActionConst';
import navigationStore from './navigationStore';
import Reducer from './Reducer';
import Router from './Router';
import Scene from './Scene';
import Actions from './navigationStore';

export {
ActionConst,
navigationStore,
Reducer,
Router,
Scene,
Actions
}
73 changes: 67 additions & 6 deletions src/navigationStore.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
import {observable, autorun, autorunAsync, computed, toJS} from 'mobx';
import {observable, action, useStrict, autorun, autorunAsync, computed, toJS} from 'mobx';
import {NavigationActions} from 'react-navigation';
import ActionConst from './ActionConst';
import * as ActionConst from './ActionConst';
import {OnEnter, OnExit} from './Util';

export const ActionMap = {
jump: ActionConst.JUMP,
push: ActionConst.PUSH,
replace: ActionConst.REPLACE,
back: ActionConst.BACK,
BackAction: ActionConst.BACK_ACTION,
popAndReplace: ActionConst.POP_AND_REPLACE,
popTo: ActionConst.POP_TO,
refresh: ActionConst.REFRESH,
reset: ActionConst.RESET,
focus: ActionConst.FOCUS,
pushOrPop: ActionConst.PUSH_OR_POP,
androidBack: ActionConst.ANDROID_BACK,
[ActionConst.JUMP]: ActionConst.JUMP,
[ActionConst.PUSH]: ActionConst.PUSH,
[ActionConst.REPLACE]: ActionConst.REPLACE,
[ActionConst.BACK]: ActionConst.BACK,
[ActionConst.BACK_ACTION]: ActionConst.BACK_ACTION,
[ActionConst.POP_AND_REPLACE]: ActionConst.POP_AND_REPLACE,
[ActionConst.POP_TO]: ActionConst.POP_TO,
[ActionConst.REFRESH]: ActionConst.REFRESH,
[ActionConst.RESET]: ActionConst.RESET,
[ActionConst.FOCUS]: ActionConst.FOCUS,
[ActionConst.PUSH_OR_POP]: ActionConst.PUSH_OR_POP,
[ActionConst.ANDROID_BACK]: ActionConst.ANDROID_BACK,
};

export const supportedActions = {
[ActionConst.PUSH]: NavigationActions.NAVIGATE,
[ActionConst.JUMP]: NavigationActions.NAVIGATE,
[ActionConst.REPLACE]: NavigationActions.RESET,
[ActionConst.BACK]: NavigationActions.BACK,
[ActionConst.REFRESH]: NavigationActions.BACK,
[ActionConst.RESET]: NavigationActions.RESET,
};
function filterParam(data) {
if (data.toString() !== '[object Object]') {
return {data};
Expand Down Expand Up @@ -92,8 +127,15 @@ class NavigationStore {
});
}

nextState = (state, action) => {
return this.reducer ? this.reducer(state, action) : this._router.getStateForAction(action, state);
} ;

dispatch = (action) => {
const newState = this.reducer ? this.reducer(this.state, action) : this._router.getStateForAction(action, this.state);
this.setState(this.nextState(this.state, action));
};

@action setState = (newState) => {
// don't allow duplicated scenes or null state
if (!newState || this.currentState(newState).routeName === this.currentScene) {
return;
Expand All @@ -111,10 +153,25 @@ class NavigationStore {
}
}
res.routeName = routeName;
if (res.clone){
console.log("STATE:", JSON.stringify(this.state));
if (supportedActions[type]) {
this.dispatch(createAction(supportedActions[type])({routeName, index:0, actions, params: res}));
} else {
if (type === ActionConst.POP_TO) {
let nextScene = '', newState = this._state, currentState = this._state, currentScene = this.currentScene;
while (nextScene !== currentScene && newState && nextScene !== routeName) {
newState = this.nextState(currentState, NavigationActions.back());
if (newState) {
nextScene = this.currentState(newState).routeName;
if (nextScene !== routeName) {
currentState = newState;
}
}
}
if (nextScene === routeName) {
this.setState(newState);
}
}
}
this.dispatch(createAction(type)({routeName, index:0, actions, params: res}));
};

push = (routeName, ...params) => {
Expand Down Expand Up @@ -153,6 +210,10 @@ class NavigationStore {
this.replace(routeName, ...params);
};

popTo = (routeName, ...params) => {
this.run(ActionConst.POP_TO, routeName, ...params);
};

replace = (routeName, ...params) => {
let res = {};
for (const param of params) {
Expand Down

0 comments on commit 7df07b5

Please sign in to comment.