@react-navigation/core 8.0.0-alpha.32 → 8.0.0-alpha.34
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/NavigationBuilderContext.js +8 -13
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +42 -15
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/getPathFromState.js +41 -16
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getPatternParts.js +43 -12
- package/lib/module/getPatternParts.js.map +1 -1
- package/lib/module/getStateFromPath.js +176 -110
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/useDescriptors.js +2 -2
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +2 -2
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +2 -2
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +3 -3
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +2 -2
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useOnAction.js +6 -4
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetNavigation.js +2 -2
- package/lib/module/useOnGetNavigation.js.map +1 -1
- package/lib/module/useOnGetState.js +2 -2
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +2 -2
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +2 -2
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +2 -4
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +2 -2
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +8 -5
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPatternParts.d.ts +4 -2
- package/lib/typescript/src/getPatternParts.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +1 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnGetNavigation.d.ts.map +1 -1
- package/lib/typescript/src/useOnGetState.d.ts.map +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
- package/lib/typescript/src/useOptionsGetters.d.ts.map +1 -1
- package/lib/typescript/src/utilities.d.ts +3 -0
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/NavigationBuilderContext.tsx +21 -17
- package/src/NavigationIndependentTree.tsx +48 -22
- package/src/getPathFromState.tsx +63 -15
- package/src/getPatternParts.tsx +75 -14
- package/src/getStateFromPath.tsx +251 -114
- package/src/index.tsx +1 -0
- package/src/types.tsx +1 -1
- package/src/useDescriptors.tsx +2 -1
- package/src/useFocusedListenersChildrenAdapter.tsx +2 -2
- package/src/useNavigationBuilder.tsx +2 -4
- package/src/useNavigationCache.tsx +3 -3
- package/src/useNavigationHelpers.tsx +2 -2
- package/src/useOnAction.tsx +6 -5
- package/src/useOnGetNavigation.tsx +3 -2
- package/src/useOnGetState.tsx +4 -2
- package/src/useOnPreventRemove.tsx +4 -2
- package/src/useOnRouteFocus.tsx +2 -4
- package/src/useOptionsGetters.tsx +3 -2
- package/src/useScheduleUpdate.tsx +2 -2
- package/src/utilities.tsx +5 -2
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@react-navigation/routers';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { useNavigationBuilderContext } from './NavigationBuilderContext';
|
|
11
11
|
import { NavigationContext } from './NavigationProvider';
|
|
12
12
|
import { type NavigationHelpers, PrivateValueStore } from './types';
|
|
13
13
|
import type { NavigationEventEmitter } from './useEventEmitter';
|
|
@@ -41,7 +41,7 @@ export function useNavigationHelpers<
|
|
|
41
41
|
router,
|
|
42
42
|
}: Options<State, Action>) {
|
|
43
43
|
const parentNavigationHelpers = React.use(NavigationContext);
|
|
44
|
-
const { withStackTrace } =
|
|
44
|
+
const { withStackTrace } = useNavigationBuilderContext();
|
|
45
45
|
|
|
46
46
|
return React.useMemo(() => {
|
|
47
47
|
const dispatch = (op: Action | ((state: State) => Action)) => {
|
package/src/useOnAction.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { getLoaderForStateChange } from './DataLoading';
|
|
|
12
12
|
import {
|
|
13
13
|
type ChildActionListener,
|
|
14
14
|
type ChildBeforeRemoveListener,
|
|
15
|
-
|
|
15
|
+
useNavigationBuilderContext,
|
|
16
16
|
} from './NavigationBuilderContext';
|
|
17
17
|
import { StaticTreeContext } from './StaticTreeContext';
|
|
18
18
|
import type { EventMapCore } from './types';
|
|
@@ -55,7 +55,7 @@ export function useOnAction<State extends NavigationState>({
|
|
|
55
55
|
addListener: addListenerParent,
|
|
56
56
|
onDispatchAction,
|
|
57
57
|
flushUpdates,
|
|
58
|
-
} =
|
|
58
|
+
} = useNavigationBuilderContext();
|
|
59
59
|
|
|
60
60
|
const tree = React.use(StaticTreeContext);
|
|
61
61
|
const consumedParams = React.use(ConsumedParamsContext);
|
|
@@ -95,9 +95,10 @@ export function useOnAction<State extends NavigationState>({
|
|
|
95
95
|
);
|
|
96
96
|
|
|
97
97
|
// If a target is specified and set to current navigator, the action shouldn't bubble
|
|
98
|
-
// So
|
|
99
|
-
result
|
|
100
|
-
|
|
98
|
+
// So we immediately return `false` to mark it as unhandled
|
|
99
|
+
if (result === null && action.target === state.key) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
101
102
|
|
|
102
103
|
if (result !== null && result.stale !== false) {
|
|
103
104
|
// Some actions (e.g. `RESET`) may return a stale state from the router
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ParamListBase } from '@react-navigation/routers';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { useNavigationBuilderContext } from './NavigationBuilderContext';
|
|
5
5
|
import { NavigationRouteContext } from './NavigationProvider';
|
|
6
6
|
import type { NavigationHelpers } from './types';
|
|
7
7
|
|
|
@@ -14,7 +14,8 @@ type Options = {
|
|
|
14
14
|
* It's used for the navigation object returned by `useNavigation` outside a screen.
|
|
15
15
|
*/
|
|
16
16
|
export function useOnGetNavigation({ navigation }: Options) {
|
|
17
|
-
const { addKeyedListener } =
|
|
17
|
+
const { addKeyedListener } = useNavigationBuilderContext();
|
|
18
|
+
|
|
18
19
|
const route = React.use(NavigationRouteContext);
|
|
19
20
|
|
|
20
21
|
React.useInsertionEffect(() => {
|
package/src/useOnGetState.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import { isArrayEqual } from './isArrayEqual';
|
|
5
5
|
import {
|
|
6
6
|
type GetStateListener,
|
|
7
|
-
|
|
7
|
+
useNavigationBuilderContext,
|
|
8
8
|
} from './NavigationBuilderContext';
|
|
9
9
|
import { NavigationRouteContext } from './NavigationProvider';
|
|
10
10
|
|
|
@@ -14,8 +14,10 @@ type Options = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export function useOnGetState({ getState, getStateListeners }: Options) {
|
|
17
|
-
const { addKeyedListener } =
|
|
17
|
+
const { addKeyedListener } = useNavigationBuilderContext();
|
|
18
|
+
|
|
18
19
|
const route = React.use(NavigationRouteContext);
|
|
20
|
+
|
|
19
21
|
const key = route ? route.key : 'root';
|
|
20
22
|
|
|
21
23
|
const getRehydratedState = React.useCallback(() => {
|
|
@@ -9,7 +9,7 @@ import * as React from 'react';
|
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
11
|
type ChildBeforeRemoveListener,
|
|
12
|
-
|
|
12
|
+
useNavigationBuilderContext,
|
|
13
13
|
} from './NavigationBuilderContext';
|
|
14
14
|
import { NavigationRouteContext } from './NavigationProvider';
|
|
15
15
|
import type { EventMapCore } from './types';
|
|
@@ -107,8 +107,10 @@ export function useOnPreventRemove({
|
|
|
107
107
|
emitter,
|
|
108
108
|
beforeRemoveListeners,
|
|
109
109
|
}: Options) {
|
|
110
|
-
const { addKeyedListener } =
|
|
110
|
+
const { addKeyedListener } = useNavigationBuilderContext();
|
|
111
|
+
|
|
111
112
|
const route = React.use(NavigationRouteContext);
|
|
113
|
+
|
|
112
114
|
const routeKey = route?.key;
|
|
113
115
|
|
|
114
116
|
React.useInsertionEffect(() => {
|
package/src/useOnRouteFocus.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
} from '@react-navigation/routers';
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { useNavigationBuilderContext } from './NavigationBuilderContext';
|
|
9
9
|
|
|
10
10
|
type Options<State extends NavigationState, Action extends NavigationAction> = {
|
|
11
11
|
router: Router<State, Action>;
|
|
@@ -23,9 +23,7 @@ export function useOnRouteFocus<
|
|
|
23
23
|
State extends NavigationState,
|
|
24
24
|
Action extends NavigationAction,
|
|
25
25
|
>({ router, getState, key: sourceRouteKey, setState }: Options<State, Action>) {
|
|
26
|
-
const { onRouteFocus: onRouteFocusParent } =
|
|
27
|
-
NavigationBuilderContext
|
|
28
|
-
);
|
|
26
|
+
const { onRouteFocus: onRouteFocusParent } = useNavigationBuilderContext();
|
|
29
27
|
|
|
30
28
|
return React.useCallback(
|
|
31
29
|
(key: string) => {
|
|
@@ -17,7 +17,8 @@ export function useOptionsGetters({ key, options, navigation }: Options) {
|
|
|
17
17
|
Record<string, () => object | undefined | null>
|
|
18
18
|
>({});
|
|
19
19
|
|
|
20
|
-
const
|
|
20
|
+
const onOptionsChange = React.use(NavigationBuilderContext)?.onOptionsChange;
|
|
21
|
+
|
|
21
22
|
const { addOptionsGetter: parentAddOptionsGetter } = React.use(
|
|
22
23
|
NavigationStateContext
|
|
23
24
|
);
|
|
@@ -27,7 +28,7 @@ export function useOptionsGetters({ key, options, navigation }: Options) {
|
|
|
27
28
|
const hasChildren = Object.keys(optionsGettersFromChildRef.current).length;
|
|
28
29
|
|
|
29
30
|
if (isFocused && !hasChildren) {
|
|
30
|
-
onOptionsChange(optionsRef.current ?? {});
|
|
31
|
+
onOptionsChange?.(optionsRef.current ?? {});
|
|
31
32
|
}
|
|
32
33
|
}, [navigation, onOptionsChange]);
|
|
33
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useNavigationBuilderContext } from './NavigationBuilderContext';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* When screen config changes, we want to update the navigator in the same update phase.
|
|
@@ -11,7 +11,7 @@ import { NavigationBuilderContext } from './NavigationBuilderContext';
|
|
|
11
11
|
* This lets nested updates be applied from the root down without clobbering each other.
|
|
12
12
|
*/
|
|
13
13
|
export function useScheduleUpdate(callback: () => void) {
|
|
14
|
-
const { scheduleUpdate, flushUpdates } =
|
|
14
|
+
const { scheduleUpdate, flushUpdates } = useNavigationBuilderContext();
|
|
15
15
|
|
|
16
16
|
React.useInsertionEffect(() => {
|
|
17
17
|
scheduleUpdate(callback);
|
package/src/utilities.tsx
CHANGED
|
@@ -120,9 +120,11 @@ type StripRegex<Param extends string> = Param extends `${infer Name}(${string})`
|
|
|
120
120
|
type ExtractSegmentParam<Segment extends string> =
|
|
121
121
|
Segment extends `:${infer Param}?`
|
|
122
122
|
? { [K in StripRegex<Param>]?: string }
|
|
123
|
-
: Segment extends `:${infer Param}`
|
|
123
|
+
: Segment extends `:${infer Param}${'+' | '*'}`
|
|
124
124
|
? { [K in StripRegex<Param>]: string }
|
|
125
|
-
: {}
|
|
125
|
+
: Segment extends `:${infer Param}`
|
|
126
|
+
? { [K in StripRegex<Param>]: string }
|
|
127
|
+
: {};
|
|
126
128
|
|
|
127
129
|
export type StandardSchemaValidationResult<Output> =
|
|
128
130
|
| { value: Output; issues?: undefined }
|
|
@@ -146,6 +148,7 @@ export type QueryParamInput = string | string[] | null | undefined;
|
|
|
146
148
|
* Extract path params from a path string.
|
|
147
149
|
* e.g. `/foo/:userId/:postId` -> `{ userId: string; postId: string }`
|
|
148
150
|
* Supports optional params with `?` suffix.
|
|
151
|
+
* Supports repeated params with `+` and `*` suffixes as strings.
|
|
149
152
|
* Params must start with `:` at the beginning of a segment (after `/`).
|
|
150
153
|
*/
|
|
151
154
|
export type ExtractParamStrings<Path extends string> =
|