@react-navigation/core 7.3.0 → 7.4.0
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/commonjs/StaticNavigation.js +2 -2
- package/lib/commonjs/StaticNavigation.js.map +1 -1
- package/lib/commonjs/getActionFromState.js +25 -0
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +2 -1
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useScheduleUpdate.js +2 -1
- package/lib/commonjs/useScheduleUpdate.js.map +1 -1
- package/lib/module/StaticNavigation.js +2 -2
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/getActionFromState.js +25 -0
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +2 -1
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +3 -1
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/typescript/commonjs/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +9 -1
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useDescriptors.d.ts +2 -0
- package/lib/typescript/commonjs/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts +3 -0
- package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useNavigationCache.d.ts +1 -0
- package/lib/typescript/commonjs/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useNavigationHelpers.d.ts +1 -0
- package/lib/typescript/commonjs/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useScheduleUpdate.d.ts.map +1 -1
- package/lib/typescript/module/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/module/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +9 -1
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/useDescriptors.d.ts +2 -0
- package/lib/typescript/module/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/module/src/useNavigationBuilder.d.ts +3 -0
- package/lib/typescript/module/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/module/src/useNavigationCache.d.ts +1 -0
- package/lib/typescript/module/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/module/src/useNavigationHelpers.d.ts +1 -0
- package/lib/typescript/module/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/module/src/useScheduleUpdate.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/StaticNavigation.tsx +2 -4
- package/src/getActionFromState.tsx +35 -1
- package/src/types.tsx +9 -1
- package/src/useNavigationBuilder.tsx +1 -0
- package/src/useScheduleUpdate.tsx +3 -1
|
@@ -65,10 +65,35 @@ export function getActionFromState(
|
|
|
65
65
|
let config: ConfigItem | undefined = normalizedConfig?.screens?.[route?.name];
|
|
66
66
|
let params = { ...route.params } as NavigatorScreenParams<ParamListBase>;
|
|
67
67
|
|
|
68
|
-
const payload
|
|
68
|
+
const payload:
|
|
69
|
+
| {
|
|
70
|
+
name: string;
|
|
71
|
+
params: NavigatorScreenParams<ParamListBase>;
|
|
72
|
+
path?: string;
|
|
73
|
+
pop?: boolean;
|
|
74
|
+
}
|
|
75
|
+
| undefined = route
|
|
69
76
|
? { name: route.name, path: route.path, params }
|
|
70
77
|
: undefined;
|
|
71
78
|
|
|
79
|
+
// If the screen contains a navigator, pop other screens to navigate to it
|
|
80
|
+
// This avoid pushing multiple instances of navigators onto a stack
|
|
81
|
+
//
|
|
82
|
+
// For example:
|
|
83
|
+
// - RootStack
|
|
84
|
+
// - BottomTabs
|
|
85
|
+
// - SomeScreen
|
|
86
|
+
//
|
|
87
|
+
// In this case, if deep linking to `BottomTabs`, we should pop `SomeScreen`
|
|
88
|
+
// Otherwise, we'll end up with 2 instances of `BottomTabs` in the stack
|
|
89
|
+
//
|
|
90
|
+
// There are 2 ways we can detect if a screen contains a navigator:
|
|
91
|
+
// - The route contains nested state in `route.state`
|
|
92
|
+
// - Nested screens are defined in the config
|
|
93
|
+
if (payload && config?.screens && Object.keys(config.screens).length) {
|
|
94
|
+
payload.pop = true;
|
|
95
|
+
}
|
|
96
|
+
|
|
72
97
|
while (current) {
|
|
73
98
|
if (current.routes.length === 0) {
|
|
74
99
|
return undefined;
|
|
@@ -108,6 +133,7 @@ export function getActionFromState(
|
|
|
108
133
|
|
|
109
134
|
if (route.state) {
|
|
110
135
|
params.params = { ...route.params };
|
|
136
|
+
params.pop = true;
|
|
111
137
|
params = params.params as NavigatorScreenParams<ParamListBase>;
|
|
112
138
|
} else {
|
|
113
139
|
params.path = route.path;
|
|
@@ -116,6 +142,14 @@ export function getActionFromState(
|
|
|
116
142
|
|
|
117
143
|
current = route.state;
|
|
118
144
|
config = config?.screens?.[route.name];
|
|
145
|
+
|
|
146
|
+
if (config?.screens && Object.keys(config.screens).length) {
|
|
147
|
+
params.pop = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (payload?.params.screen || payload?.params.state) {
|
|
152
|
+
payload.pop = true;
|
|
119
153
|
}
|
|
120
154
|
|
|
121
155
|
if (!payload) {
|
package/src/types.tsx
CHANGED
|
@@ -271,7 +271,11 @@ type NavigationHelpersCommon<
|
|
|
271
271
|
/**
|
|
272
272
|
* Navigate to a route in current navigation tree.
|
|
273
273
|
*
|
|
274
|
-
* @param options
|
|
274
|
+
* @param options.name Name of the route to navigate to.
|
|
275
|
+
* @param [options.params] Params object for the route.
|
|
276
|
+
* @param [options.path] Path to associate the route with (e.g. for deep links).
|
|
277
|
+
* @param [options.merge] Whether to merge the params onto the route.
|
|
278
|
+
* @param [options.pop] Whether to pop routes in a stack to go back to the matching route.
|
|
275
279
|
*/
|
|
276
280
|
navigate<RouteName extends keyof ParamList>(
|
|
277
281
|
options: {
|
|
@@ -280,6 +284,7 @@ type NavigationHelpersCommon<
|
|
|
280
284
|
params: ParamList[Screen];
|
|
281
285
|
path?: string;
|
|
282
286
|
merge?: boolean;
|
|
287
|
+
pop?: boolean;
|
|
283
288
|
};
|
|
284
289
|
}[RouteName]
|
|
285
290
|
): void;
|
|
@@ -950,6 +955,7 @@ export type NavigatorScreenParams<ParamList extends {}> =
|
|
|
950
955
|
screen?: never;
|
|
951
956
|
params?: never;
|
|
952
957
|
initial?: never;
|
|
958
|
+
pop?: never;
|
|
953
959
|
path?: string;
|
|
954
960
|
state: PartialState<NavigationState> | NavigationState | undefined;
|
|
955
961
|
}
|
|
@@ -960,6 +966,7 @@ export type NavigatorScreenParams<ParamList extends {}> =
|
|
|
960
966
|
params?: ParamList[RouteName];
|
|
961
967
|
initial?: boolean;
|
|
962
968
|
path?: string;
|
|
969
|
+
pop?: boolean;
|
|
963
970
|
state?: never;
|
|
964
971
|
}
|
|
965
972
|
: {
|
|
@@ -967,6 +974,7 @@ export type NavigatorScreenParams<ParamList extends {}> =
|
|
|
967
974
|
params: ParamList[RouteName];
|
|
968
975
|
initial?: boolean;
|
|
969
976
|
path?: string;
|
|
977
|
+
pop?: boolean;
|
|
970
978
|
state?: never;
|
|
971
979
|
};
|
|
972
980
|
}[keyof ParamList];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
3
|
import { NavigationBuilderContext } from './NavigationBuilderContext';
|
|
4
|
+
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* When screen config changes, we want to update the navigator in the same update phase.
|
|
6
8
|
* However, navigation state is in the root component and React won't let us update it from a child.
|
|
@@ -17,5 +19,5 @@ export function useScheduleUpdate(callback: () => void) {
|
|
|
17
19
|
// However, since we are using sync store, it might be fine
|
|
18
20
|
scheduleUpdate(callback);
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
useIsomorphicLayoutEffect(flushUpdates);
|
|
21
23
|
}
|