@react-navigation/core 7.14.0 → 8.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/BaseNavigationContainer.js +4 -9
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +12 -7
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +49 -0
- package/lib/module/NavigationProvider.js.map +1 -0
- package/lib/module/PreventRemoveProvider.js +1 -1
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +32 -21
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/getActionFromState.js +3 -2
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +1 -1
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +3 -3
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/index.js +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/theming/ThemeContext.js.map +1 -1
- package/lib/module/theming/ThemeProvider.js.map +1 -1
- package/lib/module/theming/useTheme.js +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js +41 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useChildListeners.js +2 -4
- package/lib/module/useChildListeners.js.map +1 -1
- package/lib/module/useDescriptors.js +5 -9
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +9 -20
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEvents.js +1 -1
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useNavigation.js +31 -8
- package/lib/module/useNavigation.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +10 -12
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +18 -11
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +2 -14
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationState.js +42 -9
- package/lib/module/useNavigationState.js.map +1 -1
- package/lib/module/useOnAction.js +2 -7
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +1 -1
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +1 -1
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useRoute.js +23 -5
- package/lib/module/useRoute.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +1 -2
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/module/useSyncState.js +25 -9
- package/lib/module/useSyncState.js.map +1 -1
- package/lib/module/utilities.js +2 -0
- package/lib/module/utilities.js.map +1 -0
- package/lib/typescript/src/BaseNavigationContainer.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
- package/lib/typescript/src/NavigationProvider.d.ts +44 -0
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -0
- package/lib/typescript/src/SceneView.d.ts +1 -1
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +231 -80
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/createNavigationContainerRef.d.ts +2 -2
- package/lib/typescript/src/createNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts +2 -1
- package/lib/typescript/src/theming/ThemeContext.d.ts.map +1 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts +2 -1
- package/lib/typescript/src/theming/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts +1 -1
- package/lib/typescript/src/theming/useTheme.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +188 -133
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useChildListeners.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +27 -109
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useEventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/useNavigation.d.ts +7 -5
- package/lib/typescript/src/useNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +25 -114
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +8 -22
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationContainerRef.d.ts +2 -2
- package/lib/typescript/src/useNavigationContainerRef.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +3 -11
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationState.d.ts +10 -3
- package/lib/typescript/src/useNavigationState.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useRoute.d.ts +8 -2
- package/lib/typescript/src/useRoute.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +12 -3
- package/lib/typescript/src/useRouteCache.d.ts.map +1 -1
- package/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
- package/lib/typescript/src/useSyncState.d.ts.map +1 -1
- package/lib/typescript/src/utilities.d.ts +99 -0
- package/lib/typescript/src/utilities.d.ts.map +1 -0
- package/package.json +7 -7
- package/src/BaseNavigationContainer.tsx +3 -9
- package/src/NavigationIndependentTree.tsx +17 -9
- package/src/NavigationProvider.tsx +64 -0
- package/src/PreventRemoveProvider.tsx +1 -1
- package/src/SceneView.tsx +1 -7
- package/src/StaticNavigation.tsx +372 -134
- package/src/createNavigationContainerRef.tsx +2 -1
- package/src/getActionFromState.tsx +4 -2
- package/src/getPathFromState.tsx +6 -5
- package/src/getStateFromPath.tsx +11 -11
- package/src/index.tsx +8 -4
- package/src/theming/ThemeContext.tsx +3 -3
- package/src/theming/ThemeProvider.tsx +2 -1
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +392 -243
- package/src/useChildListeners.tsx +3 -2
- package/src/useDescriptors.tsx +11 -17
- package/src/useEventEmitter.tsx +14 -31
- package/src/useFocusEvents.tsx +1 -1
- package/src/useNavigation.tsx +57 -14
- package/src/useNavigationBuilder.tsx +10 -13
- package/src/useNavigationCache.tsx +40 -18
- package/src/useNavigationContainerRef.tsx +2 -2
- package/src/useNavigationHelpers.tsx +2 -19
- package/src/useNavigationState.tsx +90 -19
- package/src/useOnAction.tsx +1 -12
- package/src/useOnGetState.tsx +1 -1
- package/src/useOnPreventRemove.tsx +1 -1
- package/src/useRoute.tsx +52 -7
- package/src/useScheduleUpdate.tsx +1 -2
- package/src/useSyncState.tsx +28 -13
- package/src/utilities.tsx +122 -0
- package/lib/module/DeprecatedNavigationInChildContext.js +0 -9
- package/lib/module/DeprecatedNavigationInChildContext.js.map +0 -1
- package/lib/module/NavigationContext.js +0 -8
- package/lib/module/NavigationContext.js.map +0 -1
- package/lib/module/NavigationRouteContext.js +0 -9
- package/lib/module/NavigationRouteContext.js.map +0 -1
- package/lib/module/useClientLayoutEffect.js +0 -9
- package/lib/module/useClientLayoutEffect.js.map +0 -1
- package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts +0 -6
- package/lib/typescript/src/DeprecatedNavigationInChildContext.d.ts.map +0 -1
- package/lib/typescript/src/NavigationContext.d.ts +0 -8
- package/lib/typescript/src/NavigationContext.d.ts.map +0 -1
- package/lib/typescript/src/NavigationRouteContext.d.ts +0 -7
- package/lib/typescript/src/NavigationRouteContext.d.ts.map +0 -1
- package/lib/typescript/src/useClientLayoutEffect.d.ts +0 -6
- package/lib/typescript/src/useClientLayoutEffect.d.ts.map +0 -1
- package/src/DeprecatedNavigationInChildContext.tsx +0 -6
- package/src/NavigationContext.tsx +0 -11
- package/src/NavigationRouteContext.tsx +0 -9
- package/src/useClientLayoutEffect.tsx +0 -10
|
@@ -167,9 +167,10 @@ export function getActionFromState(
|
|
|
167
167
|
const createNormalizedConfigItem = (config: PathConfig<object> | string) =>
|
|
168
168
|
typeof config === 'object' && config != null
|
|
169
169
|
? {
|
|
170
|
-
initialRouteName:
|
|
170
|
+
initialRouteName:
|
|
171
|
+
'initialRouteName' in config ? config.initialRouteName : undefined,
|
|
171
172
|
screens:
|
|
172
|
-
config.screens != null
|
|
173
|
+
'screens' in config && config.screens != null
|
|
173
174
|
? createNormalizedConfigs(config.screens)
|
|
174
175
|
: undefined,
|
|
175
176
|
}
|
|
@@ -177,6 +178,7 @@ const createNormalizedConfigItem = (config: PathConfig<object> | string) =>
|
|
|
177
178
|
|
|
178
179
|
const createNormalizedConfigs = (options: PathConfigMap<object>) =>
|
|
179
180
|
Object.entries(options).reduce<Record<string, ConfigItem>>((acc, [k, v]) => {
|
|
181
|
+
// @ts-expect-error -we can't properly type this
|
|
180
182
|
acc[k] = createNormalizedConfigItem(v);
|
|
181
183
|
return acc;
|
|
182
184
|
}, {});
|
package/src/getPathFromState.tsx
CHANGED
|
@@ -17,7 +17,7 @@ type Options<ParamList extends {}> = {
|
|
|
17
17
|
|
|
18
18
|
type State = NavigationState | Omit<PartialState<NavigationState>, 'stale'>;
|
|
19
19
|
|
|
20
|
-
type StringifyConfig = Record<string, (value: unknown) => string>;
|
|
20
|
+
type StringifyConfig = Record<string, ((value: unknown) => string) | undefined>;
|
|
21
21
|
|
|
22
22
|
type ConfigItem = {
|
|
23
23
|
parts?: PatternPart[];
|
|
@@ -288,7 +288,7 @@ export function getPathFromState<ParamList extends {}>(
|
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
const createConfigItem = (
|
|
291
|
-
config: PathConfig<
|
|
291
|
+
config: PathConfig<{}> | string,
|
|
292
292
|
parentParts?: PatternPart[]
|
|
293
293
|
): ConfigItem => {
|
|
294
294
|
if (typeof config === 'string') {
|
|
@@ -320,9 +320,10 @@ const createConfigItem = (
|
|
|
320
320
|
? getPatternParts(config.path)
|
|
321
321
|
: undefined;
|
|
322
322
|
|
|
323
|
-
const screens =
|
|
324
|
-
|
|
325
|
-
|
|
323
|
+
const screens =
|
|
324
|
+
'screens' in config && config.screens
|
|
325
|
+
? createNormalizedConfigs(config.screens, parts)
|
|
326
|
+
: undefined;
|
|
326
327
|
|
|
327
328
|
return {
|
|
328
329
|
parts,
|
package/src/getStateFromPath.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
InitialState,
|
|
3
3
|
NavigationState,
|
|
4
|
-
ParamListBase,
|
|
5
4
|
PartialState,
|
|
6
5
|
} from '@react-navigation/routers';
|
|
7
6
|
import escape from 'escape-string-regexp';
|
|
@@ -20,7 +19,7 @@ type Options<ParamList extends {}> = {
|
|
|
20
19
|
screens: PathConfigMap<ParamList>;
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
type ParseConfig = Record<string, (value: string) => unknown>;
|
|
22
|
+
type ParseConfig = Record<string, ((value: string) => unknown) | undefined>;
|
|
24
23
|
|
|
25
24
|
type RouteConfig = {
|
|
26
25
|
screen: string;
|
|
@@ -213,7 +212,7 @@ function getInitialRoutes(options?: Options<{}>) {
|
|
|
213
212
|
|
|
214
213
|
function getSortedNormalizedConfigs(
|
|
215
214
|
initialRoutes: InitialRouteConfig[],
|
|
216
|
-
screens: Record<string, string | PathConfig<
|
|
215
|
+
screens: Record<string, string | PathConfig<{}>> = {}
|
|
217
216
|
) {
|
|
218
217
|
// Create a normalized configs array which will be easier to use
|
|
219
218
|
return ([] as RouteConfig[])
|
|
@@ -418,7 +417,7 @@ const matchAgainstConfigs = (remaining: string, configs: RouteConfig[]) => {
|
|
|
418
417
|
|
|
419
418
|
const createNormalizedConfigs = (
|
|
420
419
|
screen: string,
|
|
421
|
-
routeConfig: Record<string, string | PathConfig<
|
|
420
|
+
routeConfig: Record<string, string | PathConfig<{}>>,
|
|
422
421
|
initials: InitialRouteConfig[],
|
|
423
422
|
paths: { screen: string; path: string }[],
|
|
424
423
|
parentScreens: string[],
|
|
@@ -500,9 +499,12 @@ const createNormalizedConfigs = (
|
|
|
500
499
|
);
|
|
501
500
|
}
|
|
502
501
|
|
|
503
|
-
if (config.screens) {
|
|
502
|
+
if ('screens' in config && config.screens) {
|
|
504
503
|
// property `initialRouteName` without `screens` has no purpose
|
|
505
|
-
if (
|
|
504
|
+
if (
|
|
505
|
+
'initialRouteName' in config &&
|
|
506
|
+
typeof config.initialRouteName === 'string'
|
|
507
|
+
) {
|
|
506
508
|
initials.push({
|
|
507
509
|
initialRouteName: config.initialRouteName,
|
|
508
510
|
parentScreens,
|
|
@@ -512,7 +514,7 @@ const createNormalizedConfigs = (
|
|
|
512
514
|
Object.keys(config.screens).forEach((nestedConfig) => {
|
|
513
515
|
const result = createNormalizedConfigs(
|
|
514
516
|
nestedConfig,
|
|
515
|
-
config.screens as Record<string, string | PathConfig<
|
|
517
|
+
config.screens as Record<string, string | PathConfig<{}>>,
|
|
516
518
|
initials,
|
|
517
519
|
[...paths],
|
|
518
520
|
[...parentScreens],
|
|
@@ -709,10 +711,7 @@ const createNestedStateObject = (
|
|
|
709
711
|
return state;
|
|
710
712
|
};
|
|
711
713
|
|
|
712
|
-
const parseQueryParams = (
|
|
713
|
-
path: string,
|
|
714
|
-
parseConfig?: Record<string, (value: string) => unknown>
|
|
715
|
-
) => {
|
|
714
|
+
const parseQueryParams = (path: string, parseConfig?: ParseConfig) => {
|
|
716
715
|
const query = path.split('?')[1];
|
|
717
716
|
const params: Record<string, unknown> = queryString.parse(query);
|
|
718
717
|
|
|
@@ -720,6 +719,7 @@ const parseQueryParams = (
|
|
|
720
719
|
Object.keys(params).forEach((name) => {
|
|
721
720
|
if (
|
|
722
721
|
Object.hasOwnProperty.call(parseConfig, name) &&
|
|
722
|
+
parseConfig[name] &&
|
|
723
723
|
typeof params[name] === 'string'
|
|
724
724
|
) {
|
|
725
725
|
params[name] = parseConfig[name](params[name]);
|
package/src/index.tsx
CHANGED
|
@@ -8,21 +8,25 @@ export { getFocusedRouteNameFromRoute } from './getFocusedRouteNameFromRoute';
|
|
|
8
8
|
export { getPathFromState } from './getPathFromState';
|
|
9
9
|
export { getStateFromPath } from './getStateFromPath';
|
|
10
10
|
export { NavigationContainerRefContext } from './NavigationContainerRefContext';
|
|
11
|
-
export { NavigationContext } from './NavigationContext';
|
|
12
11
|
export { NavigationHelpersContext } from './NavigationHelpersContext';
|
|
13
12
|
export { NavigationIndependentTree } from './NavigationIndependentTree';
|
|
14
13
|
export { NavigationMetaContext } from './NavigationMetaContext';
|
|
15
|
-
export {
|
|
14
|
+
export {
|
|
15
|
+
NavigationContext,
|
|
16
|
+
NavigationProvider,
|
|
17
|
+
NavigationRouteContext,
|
|
18
|
+
} from './NavigationProvider';
|
|
16
19
|
export { PreventRemoveContext } from './PreventRemoveContext';
|
|
17
20
|
export { PreventRemoveProvider } from './PreventRemoveProvider';
|
|
18
21
|
export {
|
|
19
22
|
createComponentForStaticNavigation,
|
|
20
23
|
createPathConfigForStaticNavigation,
|
|
21
24
|
type StaticConfig,
|
|
22
|
-
type StaticConfigGroup,
|
|
23
|
-
type StaticConfigScreens,
|
|
24
25
|
type StaticNavigation,
|
|
25
26
|
type StaticParamList,
|
|
27
|
+
type StaticScreenConfig,
|
|
28
|
+
type StaticScreenConfigLinking,
|
|
29
|
+
type StaticScreenConfigScreen,
|
|
26
30
|
type StaticScreenProps,
|
|
27
31
|
} from './StaticNavigation';
|
|
28
32
|
export { ThemeContext } from './theming/ThemeContext';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
>(undefined);
|
|
3
|
+
import type { Theme } from '../types';
|
|
4
|
+
|
|
5
|
+
export const ThemeContext = React.createContext<Theme | undefined>(undefined);
|
|
6
6
|
|
|
7
7
|
ThemeContext.displayName = 'ThemeContext';
|
package/src/theming/useTheme.tsx
CHANGED
|
@@ -7,7 +7,7 @@ export function useTheme() {
|
|
|
7
7
|
|
|
8
8
|
if (theme == null) {
|
|
9
9
|
throw new Error(
|
|
10
|
-
"Couldn't find a theme. Is your component inside NavigationContainer or
|
|
10
|
+
"Couldn't find a theme. Is your component inside NavigationContainer or a ThemeProvider?"
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|