Compare commits

...

5 Commits

Author SHA1 Message Date
Satyajit Sahoo
5b7bbbdfd9 chore: publish
- @react-navigation/bottom-tabs@5.0.5
- @react-navigation/compat@5.0.5
- @react-navigation/core@5.1.4
- @react-navigation/drawer@5.0.5
- @react-navigation/material-bottom-tabs@5.0.5
- @react-navigation/material-top-tabs@5.0.5
- @react-navigation/native-stack@5.0.5
- @react-navigation/native@5.0.5
- @react-navigation/stack@5.0.5
2020-02-15 00:18:52 +01:00
Satyajit Sahoo
c5fefc6ee9 chore: tweak versions for peer dependencies 2020-02-15 00:15:01 +01:00
Satyajit Sahoo
aaf01e01e7 fix: return '/' for empty paths 2020-02-14 23:17:29 +01:00
Satyajit Sahoo
ac242fd281 refactor: discard all routes but last when getting action from state 2020-02-14 23:04:09 +01:00
Satyajit Sahoo
c5fcfbd427 fix: link to migration guide on invalid usage 2020-02-14 22:48:04 +01:00
25 changed files with 214 additions and 89 deletions

View File

@@ -124,7 +124,8 @@ export default function App() {
prefixes: LinkingPrefixes, prefixes: LinkingPrefixes,
config: { config: {
Root: { Root: {
path: 'root', path: '',
initialRouteName: 'Home',
screens: Object.keys(SCREENS).reduce<{ [key: string]: string }>( screens: Object.keys(SCREENS).reduce<{ [key: string]: string }>(
(acc, name) => { (acc, name) => {
// Convert screen names such as SimpleStack to kebab case (simple-stack) // Convert screen names such as SimpleStack to kebab case (simple-stack)
@@ -135,7 +136,7 @@ export default function App() {
return acc; return acc;
}, },
{} { Home: '' }
), ),
}, },
}, },

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.4...@react-navigation/bottom-tabs@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/bottom-tabs
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.3...@react-navigation/bottom-tabs@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/bottom-tabs/compare/@react-navigation/bottom-tabs@5.0.3...@react-navigation/bottom-tabs@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/bottom-tabs **Note:** Version bump only for package @react-navigation/bottom-tabs

View File

@@ -49,7 +49,7 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-safe-area-context": "^0.6.0" "react-native-safe-area-context": ">= 0.6.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.4...@react-navigation/compat@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/compat
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.3...@react-navigation/compat@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/compat/compare/@react-navigation/compat@5.0.3...@react-navigation/compat@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/compat **Note:** Version bump only for package @react-navigation/compat

View File

@@ -33,7 +33,7 @@
}, },
"peerDependencies": { "peerDependencies": {
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "~16.9.0" "react": "*"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.1.4](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.3...@react-navigation/core@5.1.4) (2020-02-14)
### Bug Fixes
* link to migration guide on invalid usage ([c5fcfbd](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/c5fcfbd4277541e131acbaa7602a5d7e636afebb))
* return '/' for empty paths ([aaf01e0](https://github.com/react-navigation/react-navigation/tree/master/packages/core/commit/aaf01e01e7b47b375f68aebe6d0effe82878d060))
## [5.1.3](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.2...@react-navigation/core@5.1.3) (2020-02-14) ## [5.1.3](https://github.com/react-navigation/react-navigation/tree/master/packages/core/compare/@react-navigation/core@5.1.2...@react-navigation/core@5.1.3) (2020-02-14)

View File

@@ -49,7 +49,7 @@
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },
"peerDependencies": { "peerDependencies": {
"react": "~16.9.0" "react": "*"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -41,10 +41,9 @@ it('gets navigate action from state', () => {
}, },
type: 'NAVIGATE', type: 'NAVIGATE',
}); });
});
it('gets reset action from state', () => { expect(
const state = { getActionFromState({
routes: [ routes: [
{ {
name: 'foo', name: 'foo',
@@ -66,10 +65,40 @@ it('gets reset action from state', () => {
}, },
}, },
], ],
})
).toEqual({
payload: {
name: 'foo',
params: {
screen: 'bar',
params: {
screen: 'quz',
},
},
},
type: 'NAVIGATE',
});
});
it('gets reset action from state', () => {
const state = {
routes: [
{
name: 'foo',
state: {
routes: [
{
name: 'bar',
state: {
routes: [],
},
},
],
},
},
],
}; };
expect(getActionFromState(state)).toEqual({ expect(getActionFromState(state)).toBe(undefined);
payload: state, expect(getActionFromState({ routes: [] })).toBe(undefined);
type: 'RESET_ROOT',
});
}); });

View File

@@ -489,3 +489,31 @@ it('handles empty path at the end', () => {
expect(getPathFromState(state, config)).toBe(path); expect(getPathFromState(state, config)).toBe(path);
expect(getPathFromState(getStateFromPath(path, config), config)).toBe(path); expect(getPathFromState(getStateFromPath(path, config), config)).toBe(path);
}); });
it('returns "/" for empty path', () => {
const config = {
Foo: {
path: '',
screens: {
Bar: '',
},
},
};
const state = {
routes: [
{
name: 'Foo',
state: {
routes: [
{
name: 'Bar',
},
],
},
},
],
};
expect(getPathFromState(state, config)).toBe('/');
});

View File

@@ -21,7 +21,7 @@ export default function createNavigatorFactory<
> { > {
if (arguments[0] !== undefined) { if (arguments[0] !== undefined) {
throw new Error( throw new Error(
"Creating a navigator doesn't take an argument. Maybe you are trying to use React Navigation 4 API with React Navigation 5? See https://reactnavigation.org/docs/en/hello-react-navigation.html for usage guide." "Creating a navigator doesn't take an argument. Maybe you are trying to use React Navigation 4 API with React Navigation 5? See https://reactnavigation.org/docs/en/upgrading-from-4.x.html for migration guide."
); );
} }

View File

@@ -5,37 +5,36 @@ type NavigateParams = {
params?: NavigateParams; params?: NavigateParams;
}; };
type Action = type NavigateAction = {
| {
type: 'NAVIGATE'; type: 'NAVIGATE';
payload: { name: string; params: NavigateParams }; payload: { name: string; params: NavigateParams };
}
| {
type: 'RESET_ROOT';
payload: PartialState<NavigationState>;
}; };
export default function getActionFromState( export default function getActionFromState(
state: PartialState<NavigationState> state: PartialState<NavigationState>
): Action { ): NavigateAction | undefined {
let payload: { name: string; params: NavigateParams } | undefined; if (state.routes.length === 0) {
return undefined;
}
if (state.routes.length === 1) {
// Try to construct payload for a `NAVIGATE` action from the state // Try to construct payload for a `NAVIGATE` action from the state
// This lets us preserve the navigation state and not lose it // This lets us preserve the navigation state and not lose it
let route = state.routes[0]; let route = state.routes[state.routes.length - 1];
payload = { let payload: { name: string; params: NavigateParams } = {
name: route.name, name: route.name,
params: { ...route.params }, params: { ...route.params },
}; };
let current = state.routes[0].state; let current = route.state;
let params = payload.params; let params = payload.params;
while (current) { while (current) {
if (current.routes.length === 1) { if (current.routes.length === 0) {
route = current.routes[0]; return undefined;
}
route = current.routes[current.routes.length - 1];
params.screen = route.name; params.screen = route.name;
if (route.state) { if (route.state) {
@@ -46,22 +45,10 @@ export default function getActionFromState(
} }
current = route.state; current = route.state;
} else {
payload = undefined;
break;
}
}
} }
if (payload) {
return { return {
type: 'NAVIGATE', type: 'NAVIGATE',
payload, payload,
}; };
} }
return {
type: 'RESET_ROOT',
payload: state,
};
}

View File

@@ -158,6 +158,10 @@ export default function getPathFromState(
current = route.state; current = route.state;
} }
path = path.slice(path.length - 1) === '/' ? path.slice(0, -1) : path; path =
path !== '/' && path.slice(path.length - 1) === '/'
? path.slice(0, -1)
: path;
return path; return path;
} }

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.4...@react-navigation/drawer@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/drawer
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.3...@react-navigation/drawer@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/drawer/compare/@react-navigation/drawer@5.0.3...@react-navigation/drawer@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/drawer **Note:** Version bump only for package @react-navigation/drawer

View File

@@ -56,10 +56,10 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-gesture-handler": "^1.0.0", "react-native-gesture-handler": ">= 1.0.0",
"react-native-reanimated": "^1.0.0", "react-native-reanimated": ">= 1.0.0",
"react-native-safe-area-context": "^0.6.0", "react-native-safe-area-context": ">= 0.6.0",
"react-native-screens": "^2.0.0-alpha.33" "react-native-screens": ">= 2.0.0-alpha.0 || >= 2.0.0-beta.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.4...@react-navigation/material-bottom-tabs@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.3...@react-navigation/material-bottom-tabs@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/material-bottom-tabs/compare/@react-navigation/material-bottom-tabs@5.0.3...@react-navigation/material-bottom-tabs@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs **Note:** Version bump only for package @react-navigation/material-bottom-tabs

View File

@@ -51,8 +51,8 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-paper": "^3.5.0", "react-native-paper": ">= 3.0.0",
"react-native-vector-icons": "^6.0.0" "react-native-vector-icons": ">= 6.0.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.4...@react-navigation/material-top-tabs@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-top-tabs
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.3...@react-navigation/material-top-tabs@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/material-top-tabs/compare/@react-navigation/material-top-tabs@5.0.3...@react-navigation/material-top-tabs@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/material-top-tabs **Note:** Version bump only for package @react-navigation/material-top-tabs

View File

@@ -54,9 +54,9 @@
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-gesture-handler": "^1.0.0", "react-native-gesture-handler": ">= 1.0.0",
"react-native-reanimated": "^1.0.0", "react-native-reanimated": ">= 1.0.0",
"react-native-tab-view": "^2.13.0" "react-native-tab-view": ">= 2.0.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.4...@react-navigation/native-stack@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native-stack
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.3...@react-navigation/native-stack@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/native-stack/compare/@react-navigation/native-stack@5.0.3...@react-navigation/native-stack@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native-stack **Note:** Version bump only for package @react-navigation/native-stack

View File

@@ -37,10 +37,10 @@
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },
"peerDependencies": { "peerDependencies": {
"@react-navigation/native": "^5.0.0", "@react-navigation/native": ">= 5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-screens": "^2.0.0-alpha.33" "react-native-screens": ">= 2.0.0-alpha.0 || >= 2.0.0-beta.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.4...@react-navigation/native@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.3...@react-navigation/native@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/native/compare/@react-navigation/native@5.0.3...@react-navigation/native@5.0.4) (2020-02-14)
**Note:** Version bump only for package @react-navigation/native **Note:** Version bump only for package @react-navigation/native

View File

@@ -76,10 +76,10 @@ export default function useLinking(
if (state) { if (state) {
const action = getActionFromState(state); const action = getActionFromState(state);
if (action.type === 'RESET_ROOT') { if (action !== undefined) {
navigation.resetRoot(action.payload);
} else {
navigation.dispatch(action); navigation.dispatch(action);
} else {
navigation.resetRoot(state);
} }
} }
} }

View File

@@ -162,10 +162,10 @@ export default function useLinking(
pendingStateUpdateRef.current = true; pendingStateUpdateRef.current = true;
if (action.type === 'RESET_ROOT') { if (action !== undefined) {
navigation.resetRoot(action.payload);
} else {
navigation.dispatch(action); navigation.dispatch(action);
} else {
navigation.resetRoot(state);
} }
} }
} }

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [5.0.5](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.4...@react-navigation/stack@5.0.5) (2020-02-14)
**Note:** Version bump only for package @react-navigation/stack
## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.3...@react-navigation/stack@5.0.4) (2020-02-14) ## [5.0.4](https://github.com/react-navigation/react-navigation/tree/master/packages/stack/compare/@react-navigation/stack@5.0.3...@react-navigation/stack@5.0.4) (2020-02-14)

View File

@@ -53,13 +53,13 @@
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },
"peerDependencies": { "peerDependencies": {
"@react-native-community/masked-view": "^0.1.1", "@react-native-community/masked-view": ">= 0.1.0",
"@react-navigation/native": "^5.0.0", "@react-navigation/native": "^5.0.0",
"react": "*", "react": "*",
"react-native": "*", "react-native": "*",
"react-native-gesture-handler": "^1.0.0", "react-native-gesture-handler": ">= 1.0.0",
"react-native-safe-area-context": "^0.6.0", "react-native-safe-area-context": ">= 0.6.0",
"react-native-screens": "^2.0.0-alpha.33" "react-native-screens": ">= 2.0.0-alpha.0 || >= 2.0.0-beta.0"
}, },
"@react-native-community/bob": { "@react-native-community/bob": {
"source": "src", "source": "src",