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 from prop to navigation state for better pop animations #505

Merged
merged 2 commits into from
Apr 12, 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
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
presets: ["react-native"]
}
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Example/
.idea

.babelrc
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
},
"main": "index.js",
"scripts": {
"test": "jest"
"test": "mocha --compilers js:babel-core/register --require react-native-mock/mock",
"test:watch": "npm run test -- --watch"
},
"keywords": [
"react-native",
Expand Down Expand Up @@ -43,6 +44,7 @@
"babel-core": "^6.7.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react-native": "^1.5.6",
"babel-preset-stage-0": "^6.5.0",
"chai": "^3.5.0",
"chai-as-promised": "^5.2.0",
Expand Down
20 changes: 17 additions & 3 deletions src/Reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,28 @@ function inject(state, action, props, scenes) {
case POP_ACTION2:
case POP_ACTION:
assert(!state.tabs, "pop() operation cannot be run on tab bar (tabs=true)")
return {...state, index:state.index-1, children:state.children.slice(0, -1) };
return {
...state,
index:state.index-1,
from: state.children[state.children.length - 1],
children:state.children.slice(0, -1),
};
case REFRESH_ACTION:
return {...state, ...props};
return {
...state,
...props,
from: null
};
case PUSH_ACTION:
if (state.children[state.index].sceneKey == action.key && !props.clone && checkPropertiesEqual(action, state.children[state.index])){
return state;
}
return {...state, index:state.index+1, children:[...state.children, getInitialState(props, scenes, state.index + 1, action)]};
return {
...state,
index:state.index+1,
from: null,
children:[...state.children, getInitialState(props, scenes, state.index + 1, action)]
};
case JUMP_ACTION:
assert(state.tabs, "Parent="+state.key+" is not tab bar, jump action is not valid");
let ind = -1;
Expand Down
15 changes: 9 additions & 6 deletions test/Actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ describe('Actions', () => {
Actions.callback = scene=>state = reducer(state, scene);
expect(state).equal(undefined);
Actions.init();
expect(state.key).equal("modal");
expect(state.key).equal("0_modal");

Actions.messaging();
expect(state.scenes.current).equal("messaging");
//Actions.pop();
expect(currentScene.key).equal("messaging");

Actions.login();
expect(state.children[1].key).equal("login");
expect(state.children[1].key).equal("1_login");
expect(state.children[1].children.length).equal(1);
expect(state.children[1].children[0].key).equal("loginModal1");
expect(state.children[1].children[0].key).equal("0_loginModal1");

Actions.pop();
expect(state.from.key).equal("1_login");

});

});
});