Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pushOrPop action - it will pop if scene exists in the stack, push… #947

Merged
merged 1 commit into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ActionConst.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
Expand Down
2 changes: 2 additions & 0 deletions src/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const ActionMap = {
refresh: ActionConst.REFRESH,
reset: ActionConst.RESET,
focus: ActionConst.FOCUS,
pushOrPop: ActionConst.PUSH_OR_POP,
[ActionConst.JUMP]: ActionConst.JUMP,
[ActionConst.PUSH]: ActionConst.PUSH,
[ActionConst.REPLACE]: ActionConst.REPLACE,
Expand All @@ -29,6 +30,7 @@ export const ActionMap = {
[ActionConst.REFRESH]: ActionConst.REFRESH,
[ActionConst.RESET]: ActionConst.RESET,
[ActionConst.FOCUS]: ActionConst.FOCUS,
[ActionConst.PUSH_OR_POP]: ActionConst.PUSH_OR_POP,
};

function filterParam(data) {
Expand Down
17 changes: 17 additions & 0 deletions src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ function inject(state, action, props, scenes) {
key: state.key,
from: null,
};
case ActionConst.PUSH_OR_POP:
ind = state.children.findIndex(el => el.sceneKey === action.key);
if (ind !== -1) {
return {
...state,
index: ind,
from: state.children[state.index],
children: state.children.slice(0, ind + 1),
};
}
return {
...state,
index: state.index + 1,
from: null,
children: [...state.children, getInitialState(props, scenes, state.index + 1, action)],
};
case ActionConst.PUSH:
if (state.children[state.index].sceneKey === action.key && !props.clone
&& checkPropertiesEqual(action, state.children[state.index])) {
Expand Down Expand Up @@ -275,6 +291,7 @@ function reducer({ initialState, scenes }) {
case ActionConst.POP_TO:
case ActionConst.REFRESH:
case ActionConst.PUSH:
case ActionConst.PUSH_OR_POP:
case ActionConst.JUMP:
case ActionConst.REPLACE:
case ActionConst.RESET:
Expand Down