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

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
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)
**Note:** Version bump only for package @react-navigation/bottom-tabs

View File

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

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
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)
**Note:** Version bump only for package @react-navigation/compat

View File

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

View File

@@ -3,6 +3,18 @@
All notable changes to this project will be documented in this file.
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)

View File

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

View File

@@ -41,6 +41,43 @@ it('gets navigate action from state', () => {
},
type: 'NAVIGATE',
});
expect(
getActionFromState({
routes: [
{
name: 'foo',
state: {
routes: [
{
name: 'bar',
state: {
routes: [
{
name: 'qux',
params: { author: 'jane' },
},
{ name: 'quz' },
],
},
},
],
},
},
],
})
).toEqual({
payload: {
name: 'foo',
params: {
screen: 'bar',
params: {
screen: 'quz',
},
},
},
type: 'NAVIGATE',
});
});
it('gets reset action from state', () => {
@@ -53,13 +90,7 @@ it('gets reset action from state', () => {
{
name: 'bar',
state: {
routes: [
{
name: 'qux',
params: { author: 'jane' },
},
{ name: 'quz' },
],
routes: [],
},
},
],
@@ -68,8 +99,6 @@ it('gets reset action from state', () => {
],
};
expect(getActionFromState(state)).toEqual({
payload: state,
type: 'RESET_ROOT',
});
expect(getActionFromState(state)).toBe(undefined);
expect(getActionFromState({ routes: [] })).toBe(undefined);
});

View File

@@ -489,3 +489,31 @@ it('handles empty path at the end', () => {
expect(getPathFromState(state, 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) {
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,63 +5,50 @@ type NavigateParams = {
params?: NavigateParams;
};
type Action =
| {
type: 'NAVIGATE';
payload: { name: string; params: NavigateParams };
}
| {
type: 'RESET_ROOT';
payload: PartialState<NavigationState>;
};
type NavigateAction = {
type: 'NAVIGATE';
payload: { name: string; params: NavigateParams };
};
export default function getActionFromState(
state: PartialState<NavigationState>
): Action {
let payload: { name: string; params: NavigateParams } | undefined;
if (state.routes.length === 1) {
// Try to construct payload for a `NAVIGATE` action from the state
// This lets us preserve the navigation state and not lose it
let route = state.routes[0];
payload = {
name: route.name,
params: { ...route.params },
};
let current = state.routes[0].state;
let params = payload.params;
while (current) {
if (current.routes.length === 1) {
route = current.routes[0];
params.screen = route.name;
if (route.state) {
params.params = { ...route.params };
params = params.params;
} else {
params.params = route.params;
}
current = route.state;
} else {
payload = undefined;
break;
}
}
): NavigateAction | undefined {
if (state.routes.length === 0) {
return undefined;
}
if (payload) {
return {
type: 'NAVIGATE',
payload,
};
// Try to construct payload for a `NAVIGATE` action from the state
// This lets us preserve the navigation state and not lose it
let route = state.routes[state.routes.length - 1];
let payload: { name: string; params: NavigateParams } = {
name: route.name,
params: { ...route.params },
};
let current = route.state;
let params = payload.params;
while (current) {
if (current.routes.length === 0) {
return undefined;
}
route = current.routes[current.routes.length - 1];
params.screen = route.name;
if (route.state) {
params.params = { ...route.params };
params = params.params;
} else {
params.params = route.params;
}
current = route.state;
}
return {
type: 'RESET_ROOT',
payload: state,
type: 'NAVIGATE',
payload,
};
}

View File

@@ -158,6 +158,10 @@ export default function getPathFromState(
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;
}

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
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)
**Note:** Version bump only for package @react-navigation/drawer

View File

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

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
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)
**Note:** Version bump only for package @react-navigation/material-bottom-tabs

View File

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

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
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)
**Note:** Version bump only for package @react-navigation/material-top-tabs

View File

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

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
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)
**Note:** Version bump only for package @react-navigation/native-stack

View File

@@ -37,10 +37,10 @@
"typescript": "^3.7.5"
},
"peerDependencies": {
"@react-navigation/native": "^5.0.0",
"@react-navigation/native": ">= 5.0.0",
"react": "*",
"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": {
"source": "src",

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
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)
**Note:** Version bump only for package @react-navigation/native

View File

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

View File

@@ -162,10 +162,10 @@ export default function useLinking(
pendingStateUpdateRef.current = true;
if (action.type === 'RESET_ROOT') {
navigation.resetRoot(action.payload);
} else {
if (action !== undefined) {
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.
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)

View File

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