mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-25 01:28:16 +00:00
* remove ineffective invariant usages * fix flow err * fix tests * fix tests * use throw
This commit is contained in:
parent
c08be7fb43
commit
e4a7b7e073
@ -1,7 +1,6 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import invariant from './utils/invariant';
|
|
||||||
import { BackHandler, Linking } from './PlatformHelpers';
|
import { BackHandler, Linking } from './PlatformHelpers';
|
||||||
import NavigationActions from './NavigationActions';
|
import NavigationActions from './NavigationActions';
|
||||||
import addNavigationHelpers from './addNavigationHelpers';
|
import addNavigationHelpers from './addNavigationHelpers';
|
||||||
@ -74,8 +73,8 @@ export default function createNavigationContainer<S: *, O>(
|
|||||||
|
|
||||||
const keys = Object.keys(containerProps);
|
const keys = Object.keys(containerProps);
|
||||||
|
|
||||||
invariant(
|
if (keys.length !== 0) {
|
||||||
keys.length === 0,
|
throw new Error(
|
||||||
'This navigator has both navigation and container props, so it is ' +
|
'This navigator has both navigation and container props, so it is ' +
|
||||||
`unclear if it should own its own state. Remove props: "${keys.join(
|
`unclear if it should own its own state. Remove props: "${keys.join(
|
||||||
', '
|
', '
|
||||||
@ -84,6 +83,7 @@ export default function createNavigationContainer<S: *, O>(
|
|||||||
'navigator should maintain its own state, do not pass a navigation prop.'
|
'navigator should maintain its own state, do not pass a navigation prop.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_urlToPathAndParams(url: string) {
|
_urlToPathAndParams(url: string) {
|
||||||
const params = {};
|
const params = {};
|
||||||
|
@ -45,11 +45,12 @@ export default (
|
|||||||
tabRouters[routeName] = routeConfig.screen.router;
|
tabRouters[routeName] = routeConfig.screen.router;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
invariant(
|
if (initialRouteIndex === -1) {
|
||||||
initialRouteIndex !== -1,
|
throw new Error(
|
||||||
`Invalid initialRouteName '${initialRouteName}' for TabRouter. ` +
|
`Invalid initialRouteName '${initialRouteName}' for TabRouter. ` +
|
||||||
`Should be one of ${order.map((n: *) => `"${n}"`).join(', ')}`
|
`Should be one of ${order.map((n: *) => `"${n}"`).join(', ')}`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
getStateForAction(
|
getStateForAction(
|
||||||
action: NavigationAction | { action: NavigationAction },
|
action: NavigationAction | { action: NavigationAction },
|
||||||
|
@ -63,10 +63,11 @@ export default (
|
|||||||
let outputConfig = {};
|
let outputConfig = {};
|
||||||
|
|
||||||
if (Component.router) {
|
if (Component.router) {
|
||||||
invariant(
|
if (!route || !routes || index == null) {
|
||||||
route && routes && index != null,
|
throw new Error(
|
||||||
`Expect nav state to have routes and index, ${JSON.stringify(route)}`
|
`Expect nav state to have routes and index, ${JSON.stringify(route)}`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
const childRoute = routes[index];
|
const childRoute = routes[index];
|
||||||
const childNavigation = addNavigationHelpers({
|
const childNavigation = addNavigationHelpers({
|
||||||
state: childRoute,
|
state: childRoute,
|
||||||
|
@ -17,13 +17,14 @@ export default function getScreenForRouteName( // eslint-disable-line consistent
|
|||||||
): NavigationComponent {
|
): NavigationComponent {
|
||||||
const routeConfig = routeConfigs[routeName];
|
const routeConfig = routeConfigs[routeName];
|
||||||
|
|
||||||
invariant(
|
if (!routeConfig) {
|
||||||
routeConfig,
|
throw new Error(
|
||||||
`There is no route defined for key ${routeName}.\n` +
|
`There is no route defined for key ${routeName}.\n` +
|
||||||
`Must be one of: ${Object.keys(routeConfigs)
|
`Must be one of: ${Object.keys(routeConfigs)
|
||||||
.map((a: string) => `'${a}'`)
|
.map((a: string) => `'${a}'`)
|
||||||
.join(',')}`
|
.join(',')}`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (routeConfig.screen) {
|
if (routeConfig.screen) {
|
||||||
return routeConfig.screen;
|
return routeConfig.screen;
|
||||||
@ -41,5 +42,5 @@ export default function getScreenForRouteName( // eslint-disable-line consistent
|
|||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
invariant(false, `Route ${routeName} must define a screen or a getScreen.`);
|
throw new Error(`Route ${routeName} must define a screen or a getScreen.`);
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ function validateRouteConfigMap(routeConfigs: NavigationRouteConfigMap) {
|
|||||||
routeNames.forEach((routeName: string) => {
|
routeNames.forEach((routeName: string) => {
|
||||||
const routeConfig = routeConfigs[routeName];
|
const routeConfig = routeConfigs[routeName];
|
||||||
|
|
||||||
invariant(
|
if (!routeConfig.screen && !routeConfig.getScreen) {
|
||||||
routeConfig.screen || routeConfig.getScreen,
|
throw new Error(
|
||||||
`Route '${routeName}' should declare a screen. ` +
|
`Route '${routeName}' should declare a screen. ` +
|
||||||
'For example:\n\n' +
|
'For example:\n\n' +
|
||||||
"import MyScreen from './MyScreen';\n" +
|
"import MyScreen from './MyScreen';\n" +
|
||||||
@ -28,18 +28,15 @@ function validateRouteConfigMap(routeConfigs: NavigationRouteConfigMap) {
|
|||||||
' screen: MyScreen,\n' +
|
' screen: MyScreen,\n' +
|
||||||
'}'
|
'}'
|
||||||
);
|
);
|
||||||
|
} else if (routeConfig.screen && routeConfig.getScreen) {
|
||||||
if (routeConfig.screen && routeConfig.getScreen) {
|
throw new Error(
|
||||||
invariant(
|
|
||||||
false,
|
|
||||||
`Route '${routeName}' should declare a screen or ` +
|
`Route '${routeName}' should declare a screen or ` +
|
||||||
'a getScreen, not both.'
|
'a getScreen, not both.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (routeConfig.screen) {
|
if (routeConfig.screen && typeof routeConfig.screen !== 'function') {
|
||||||
invariant(
|
throw new Error(
|
||||||
typeof routeConfig.screen === 'function',
|
|
||||||
`The component for route '${routeName}' must be a ` +
|
`The component for route '${routeName}' must be a ` +
|
||||||
'React component. For example:\n\n' +
|
'React component. For example:\n\n' +
|
||||||
"import MyScreen from './MyScreen';\n" +
|
"import MyScreen from './MyScreen';\n" +
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
import invariant from '../utils/invariant';
|
|
||||||
|
|
||||||
import type { NavigationRoute } from '../TypeDefinition';
|
import type { NavigationRoute } from '../TypeDefinition';
|
||||||
|
|
||||||
@ -15,8 +14,7 @@ export default (screenOptions: *, route: NavigationRoute) => {
|
|||||||
const deprecatedKey = keys.find((key: *) => deprecatedKeys.includes(key));
|
const deprecatedKey = keys.find((key: *) => deprecatedKeys.includes(key));
|
||||||
|
|
||||||
if (typeof screenOptions.title === 'function') {
|
if (typeof screenOptions.title === 'function') {
|
||||||
invariant(
|
throw new Error(
|
||||||
false,
|
|
||||||
[
|
[
|
||||||
`\`title\` cannot be defined as a function in navigation options for \`${route.routeName}\` screen. \n`,
|
`\`title\` cannot be defined as a function in navigation options for \`${route.routeName}\` screen. \n`,
|
||||||
'Try replacing the following:',
|
'Try replacing the following:',
|
||||||
@ -33,8 +31,7 @@ export default (screenOptions: *, route: NavigationRoute) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (deprecatedKey && typeof screenOptions[deprecatedKey] === 'function') {
|
if (deprecatedKey && typeof screenOptions[deprecatedKey] === 'function') {
|
||||||
invariant(
|
throw new Error(
|
||||||
false,
|
|
||||||
[
|
[
|
||||||
`\`${deprecatedKey}\` cannot be defined as a function in navigation options for \`${route.routeName}\` screen. \n`,
|
`\`${deprecatedKey}\` cannot be defined as a function in navigation options for \`${route.routeName}\` screen. \n`,
|
||||||
'Try replacing the following:',
|
'Try replacing the following:',
|
||||||
@ -53,8 +50,7 @@ export default (screenOptions: *, route: NavigationRoute) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (deprecatedKey && typeof screenOptions[deprecatedKey] === 'object') {
|
if (deprecatedKey && typeof screenOptions[deprecatedKey] === 'object') {
|
||||||
invariant(
|
throw new Error(
|
||||||
false,
|
|
||||||
[
|
[
|
||||||
`Invalid key \`${deprecatedKey}\` defined in navigation options for \`${route.routeName}\` screen.`,
|
`Invalid key \`${deprecatedKey}\` defined in navigation options for \`${route.routeName}\` screen.`,
|
||||||
'\n',
|
'\n',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user