Skip to content

Commit

Permalink
[Fix #3194] Adjust reset to work with nested routes
Browse files Browse the repository at this point in the history
  • Loading branch information
daviscabral committed Sep 2, 2018
1 parent bb2e5bb commit 7d5eac0
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 5,908 deletions.
5 changes: 3 additions & 2 deletions Example/Example.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Example = () => (
<Lightbox key="lightbox">
<Stack hideNavBar key="root" titleStyle={{ alignSelf: 'center' }}>
<Scene key="echo" back clone component={EchoView} getTitle={({ navigation }) => navigation.state.key} />
<Scene key="launch" component={Launch} title="Launch" initial />
<Scene key="launch" component={Launch} title="Launch" initial type={ActionConst.RESET} />

<Stack key="customNavBar" hideTabBar titleStyle={{ alignSelf: 'center' }}>
<Scene key="customNavBar1" title="CustomNavBar 1" navBar={CustomNavBar} component={CustomNavBarView} back />
Expand All @@ -86,6 +86,7 @@ const Example = () => (
<Scene hideNavBar panHandlers={null}>
<Tabs
key="tabbar"
routeName="tabbar"
backToInitial
swipeEnabled
showLabel={false}
Expand Down Expand Up @@ -114,7 +115,7 @@ const Example = () => (
</Stack>

<Stack key="tab_3" icon={TabIcon} title="Tab #3">
<Scene key="tab_3_1" component={TabView} rightTitle="Right3" onRight={() => {}} />
<Scene key="tab_3_1" component={TabView} rightTitle="Reset to 'tabbar'" onRight={() => Actions.reset('tabbar')} />
</Stack>
<Scene key="tab_4_1" component={TabView} title="Tab #4" hideNavBar icon={TabIcon} />
<Stack key="tab_5" icon={TabIcon} title="Tab #5">
Expand Down
1 change: 1 addition & 0 deletions Example/components/drawer/DrawerContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DrawerContent extends React.Component {
Switch to tab5 with data
</Button>
<Button onPress={Actions.echo}>Push Clone Scene (EchoView)</Button>
<Button onPress={Actions.launch}>Reset back to launch</Button>
</View>
);
}
Expand Down
4 changes: 3 additions & 1 deletion Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"*/@babel/cli": "7.0.0-beta.47",
"*/@babel/core": "7.0.0-beta.47",
"*/@babel/code-frame": "7.0.0-beta.47",
"*/@babel/generator": "7.0.0-beta.47",
"*/@babel/highlight": "7.0.0-beta.47",
"*/babel-core": "7.0.0-bridge.0"
},
Expand All @@ -24,12 +25,13 @@
"react-navigation": "^2.12.1"
},
"devDependencies": {
"@babel/code-frame": "7.0.0-beta.47",
"@babel/core": "7.0.0-beta.47",
"@babel/plugin-proposal-decorators": "7.0.0-beta.47",
"autobind-decorator": "^2.1.0",
"babel-core": "^7.0.0-0",
"babel-jest": "^23.4.2",
"babel-preset-react-native": "^5.0.2",
"babel-preset-react-native": "5.0.2",
"jest": "^23.5.0",
"react-test-renderer": "^16.4.2"
},
Expand Down
5,679 changes: 0 additions & 5,679 deletions Example/yarn.lock

This file was deleted.

55 changes: 31 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,55 @@
},
"resolutions": {
"*/@babel/cli": "7.0.0-beta.47",
"*/@babel/core": "7.0.0-beta.47",
"*/@babel/code-frame": "7.0.0-beta.47",
"*/@babel/core": "7.0.0-beta.47",
"*/@babel/highlight": "7.0.0-beta.47",
"*/babel-core": "7.0.0-bridge.0"
},
"dependencies": {
"lodash.isequal": "^4.5.0",
"lodash.isequal": "4.5.0",
"opencollective": "^1.0.3",
"path-to-regexp": "^2.4.0",
"prop-types": "^15.6.2",
"react-navigation": "^2.12.1"
"react-navigation": "2.12.1"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.47",
"@babel/code-frame": "7.0.0-beta.47",
"@babel/core": "7.0.0-beta.47",
"@babel/generator": "7.0.0-beta.47",
"@babel/helper-split-export-declaration": "7.0.0-beta.47",
"@babel/highlight": "7.0.0-beta.47",
"@babel/plugin-proposal-decorators": "7.0.0-beta.47",
"@babel/plugin-proposal-optional-chaining": "7.0.0-beta.47",
"@types/react": "^16.4.12",
"@types/react-native": "^0.56.14",
"babel-core": "^7.0.0-0",
"babel-jest": "^23.4.0",
"babel-preset-react-native": "^5.0.2",
"eslint": "^5.4.0",
"@babel/template": "7.0.0-beta.47",
"@babel/traverse": "7.0.0-beta.47",
"@types/react-native": "0.56.14",
"@types/react": "16.4.12",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "9.0.0-beta.1",
"babel-jest": "23.4.0",
"babel-preset-react-native": "5.0.2",
"eslint": "5.4.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-eslint-comments": "^3.0.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^21.22.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.0",
"estraverse-fb": "^1.3.2",
"jest": "^23.4.1",
"prettier-eslint": "^8.8.2",
"prettier-eslint-cli": "^5.0.0-beta.0",
"react": "^16.4.1",
"react-native": "^0.56.0",
"react-test-renderer": "^16.4.1"
"eslint-config-prettier": "3.0.1",
"eslint-plugin-eslint-comments": "3.0.1",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jest": "21.22.0",
"eslint-plugin-jsx-a11y": "6.1.1",
"eslint-plugin-react": "7.11.0",
"estraverse-fb": "1.3.2",
"jest": "23.5.0",
"prettier-eslint": "8.8.2",
"prettier-eslint-cli": "5.0.0-beta.0",
"react": "16.4.1",
"react-native": "0.56.0",
"react-test-renderer": "16.4.1"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
"react-native": ">=0.55.*",
"react-navigation": "2.12.1",
"react": ">=16.3.*"
},
"jest": {
"preset": "react-native",
Expand Down
3 changes: 2 additions & 1 deletion src/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function getParent(state, routeName, parent) {
}
return null;
}

export function inject(state, key, index, routes) {
if (!state.routes) {
return state;
Expand All @@ -60,7 +61,7 @@ export function inject(state, key, index, routes) {

export function popPrevious(state, routeName) {
const parent = getParent(state, routeName);
console.log('FOUND PARENT:', JSON.stringify(parent));
// console.log('FOUND PARENT:', JSON.stringify(parent));
const { key, index } = parent;
if (index) {
const routes = [...parent.routes.slice(0, index - 1), ...parent.routes.slice(index)];
Expand Down
11 changes: 6 additions & 5 deletions src/navigationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { LeftButton, RightButton, BackButton } from './NavBar';
import LightboxRenderer from './LightboxRenderer';
import _drawerImage from '../images/menu_burger.png';
import Scene from './Scene';
import { getActiveState } from './State';
import { getActiveState, getParent } from './State';
import Modal from './Modal';
import Lightbox from './Lightbox';
import Drawer from './Drawer';
Expand Down Expand Up @@ -657,7 +657,7 @@ class NavigationStore {
success instanceof Function
? success
: args => {
console.log(`Transition to state=${success}`);
// console.log(`Transition to state=${success}`);
this[success](args);
};
}
Expand All @@ -666,7 +666,7 @@ class NavigationStore {
failure instanceof Function
? failure
: args => {
console.log(`Transition to state=${failure}`);
// console.log(`Transition to state=${failure}`);
this[failure](args);
};
}
Expand Down Expand Up @@ -907,17 +907,18 @@ class NavigationStore {

reset = (routeName, data) => {
const params = filterParam(data);
const { key } = getParent(this.state, routeName);
this.dispatch(
StackActions.reset({
key: null,
index: 0,
key,
actions: [
NavigationActions.navigate({
routeName,
params,
}),
],
}),
})
);
};
}
Expand Down
Loading

0 comments on commit 7d5eac0

Please sign in to comment.