Skip to content

Commit

Permalink
correction to aksonov#1057
Browse files Browse the repository at this point in the history
aksonov#1057 allows to push params to tab scenes, but it is breaking sceanes
tree.
Ex: 5 tabs
invoke :Actions.tab5(70)
all tab icons disappear, except tab5 itself.

Here is correction that updates only target scene(appending passed
params only to it)
May be it would repair aksonov#1081 too (not tested)
  • Loading branch information
alexicum committed Sep 30, 2016
1 parent e2fb556 commit f4ebb07
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,26 @@ function inject(state, action, props, scenes) {
};
case ActionConst.JUMP:
assert(state.tabs, `Parent=${state.key} is not tab bar, jump action is not valid`);
ind = -1;
children = getInitialState(props, scenes, ind, action);
children = Array.isArray(children) ? children : [children];
children.forEach((child, i) => {
if (child.sceneKey === action.key) ind = i;
});

/* TODO: recursive key search (for sub-tab scenes)*/
ind = state.children.findIndex(el => el.sceneKey === action.key);
// variant #1
// get target scene with data passed in Actions.SCENE_KEY(PARAMS)
const targetSceneWithData = getInitialState(props, scenes, ind, action);
// find same scene in state.children
const targetSceneInState = state.children[ind];
// update child with data
state.children[ind] = {...targetSceneInState, ...targetSceneWithData};

// variant #2 - NOT WORKING
// just update target scene in state tree with PARAMS
// state.children[ind] = { ...props, ...state.children[ind] };

assert(ind !== -1, `Cannot find route with key=${action.key} for parent=${state.key}`);

if (action.unmountScenes) {
resetHistoryStack(state.children[ind]);
}
return { ...state, index: ind, children };
return { ...state, index: ind };
case ActionConst.REPLACE:
if (state.children[state.index].sceneKey === action.key) {
return state;
Expand Down

0 comments on commit f4ebb07

Please sign in to comment.