Skip to content

Commit

Permalink
correction to #1057 (#1236)
Browse files Browse the repository at this point in the history
* correction to #1057

#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 #1081 too (not tested)

* CRLF -> LF

CRLF -> LF

* fix eslint errors

* fontFamily update
  • Loading branch information
alexicum authored and aksonov committed Oct 2, 2016
1 parent e2fb556 commit b8ccb89
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
14 changes: 7 additions & 7 deletions Example/__tests__/__snapshots__/Example-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ exports[`Example renders correctly 1`] = `
Array [
Object {
"color": "#007aff",
"fontFamily": ".HelveticaNeueInterface-MediumP4",
"fontFamily": "HelveticaNeue-Medium",
"fontSize": 17,
"fontWeight": "bold",
"textAlign": "center"
Expand Down Expand Up @@ -234,7 +234,7 @@ exports[`Example renders correctly 1`] = `
Array [
Object {
"color": "#007aff",
"fontFamily": ".HelveticaNeueInterface-MediumP4",
"fontFamily": "HelveticaNeue-Medium",
"fontSize": 17,
"fontWeight": "bold",
"textAlign": "center"
Expand Down Expand Up @@ -271,7 +271,7 @@ exports[`Example renders correctly 1`] = `
Array [
Object {
"color": "#007aff",
"fontFamily": ".HelveticaNeueInterface-MediumP4",
"fontFamily": "HelveticaNeue-Medium",
"fontSize": 17,
"fontWeight": "bold",
"textAlign": "center"
Expand Down Expand Up @@ -308,7 +308,7 @@ exports[`Example renders correctly 1`] = `
Array [
Object {
"color": "#007aff",
"fontFamily": ".HelveticaNeueInterface-MediumP4",
"fontFamily": "HelveticaNeue-Medium",
"fontSize": 17,
"fontWeight": "bold",
"textAlign": "center"
Expand Down Expand Up @@ -345,7 +345,7 @@ exports[`Example renders correctly 1`] = `
Array [
Object {
"color": "#007aff",
"fontFamily": ".HelveticaNeueInterface-MediumP4",
"fontFamily": "HelveticaNeue-Medium",
"fontSize": 17,
"fontWeight": "bold",
"textAlign": "center"
Expand Down Expand Up @@ -382,7 +382,7 @@ exports[`Example renders correctly 1`] = `
Array [
Object {
"color": "#007aff",
"fontFamily": ".HelveticaNeueInterface-MediumP4",
"fontFamily": "HelveticaNeue-Medium",
"fontSize": 17,
"fontWeight": "bold",
"textAlign": "center"
Expand Down Expand Up @@ -419,7 +419,7 @@ exports[`Example renders correctly 1`] = `
Array [
Object {
"color": "#007aff",
"fontFamily": ".HelveticaNeueInterface-MediumP4",
"fontFamily": "HelveticaNeue-Medium",
"fontSize": 17,
"fontWeight": "bold",
"textAlign": "center"
Expand Down
25 changes: 16 additions & 9 deletions src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function inject(state, action, props, scenes) {
return state;
}
let ind;
let children;

switch (ActionMap[action.type]) {
case ActionConst.POP_TO: {
Expand Down Expand Up @@ -209,21 +208,29 @@ function inject(state, action, props, scenes) {
from: null,
children: [...state.children, getInitialState(props, scenes, state.index + 1, action)],
};
case ActionConst.JUMP:
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 scene from state.children with pased 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 b8ccb89

Please sign in to comment.