@react-navigation/core 7.3.1 → 7.5.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/deepFreeze.js +6 -3
- package/lib/commonjs/deepFreeze.js.map +1 -1
- package/lib/commonjs/getActionFromState.js +25 -0
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +13 -10
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/module/deepFreeze.js +6 -3
- package/lib/module/deepFreeze.js.map +1 -1
- package/lib/module/getActionFromState.js +25 -0
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +13 -10
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/typescript/commonjs/src/deepFreeze.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +16 -4
- 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 +4 -1
- 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/module/src/deepFreeze.d.ts.map +1 -1
- package/lib/typescript/module/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +16 -4
- 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 +4 -1
- 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/package.json +3 -3
- package/src/deepFreeze.tsx +6 -3
- package/src/getActionFromState.tsx +35 -1
- package/src/types.tsx +18 -5
- package/src/useNavigationBuilder.tsx +25 -21
package/src/types.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
ParamListBase,
|
|
7
7
|
PartialState,
|
|
8
8
|
Route,
|
|
9
|
+
Router,
|
|
9
10
|
} from '@react-navigation/routers';
|
|
10
11
|
import type * as React from 'react';
|
|
11
12
|
|
|
@@ -108,11 +109,15 @@ export type DefaultNavigatorOptions<
|
|
|
108
109
|
}) => React.ReactElement;
|
|
109
110
|
|
|
110
111
|
/**
|
|
111
|
-
A function returning
|
|
112
|
+
* A function returning overrides for the underlying router used by the navigator.
|
|
113
|
+
* The overrides will be shallow merged into the original router.
|
|
114
|
+
* It receives the original router as an argument to the function.
|
|
115
|
+
*
|
|
116
|
+
* This must be a pure function and cannot reference outside dynamic variables.
|
|
112
117
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
) =>
|
|
118
|
+
UNSTABLE_router?: <Action extends NavigationAction>(
|
|
119
|
+
original: Router<State, Action>
|
|
120
|
+
) => Partial<Router<State, Action>>;
|
|
116
121
|
} & (NavigatorID extends string
|
|
117
122
|
? {
|
|
118
123
|
/**
|
|
@@ -271,7 +276,11 @@ type NavigationHelpersCommon<
|
|
|
271
276
|
/**
|
|
272
277
|
* Navigate to a route in current navigation tree.
|
|
273
278
|
*
|
|
274
|
-
* @param options
|
|
279
|
+
* @param options.name Name of the route to navigate to.
|
|
280
|
+
* @param [options.params] Params object for the route.
|
|
281
|
+
* @param [options.path] Path to associate the route with (e.g. for deep links).
|
|
282
|
+
* @param [options.merge] Whether to merge the params onto the route.
|
|
283
|
+
* @param [options.pop] Whether to pop routes in a stack to go back to the matching route.
|
|
275
284
|
*/
|
|
276
285
|
navigate<RouteName extends keyof ParamList>(
|
|
277
286
|
options: {
|
|
@@ -280,6 +289,7 @@ type NavigationHelpersCommon<
|
|
|
280
289
|
params: ParamList[Screen];
|
|
281
290
|
path?: string;
|
|
282
291
|
merge?: boolean;
|
|
292
|
+
pop?: boolean;
|
|
283
293
|
};
|
|
284
294
|
}[RouteName]
|
|
285
295
|
): void;
|
|
@@ -950,6 +960,7 @@ export type NavigatorScreenParams<ParamList extends {}> =
|
|
|
950
960
|
screen?: never;
|
|
951
961
|
params?: never;
|
|
952
962
|
initial?: never;
|
|
963
|
+
pop?: never;
|
|
953
964
|
path?: string;
|
|
954
965
|
state: PartialState<NavigationState> | NavigationState | undefined;
|
|
955
966
|
}
|
|
@@ -960,6 +971,7 @@ export type NavigatorScreenParams<ParamList extends {}> =
|
|
|
960
971
|
params?: ParamList[RouteName];
|
|
961
972
|
initial?: boolean;
|
|
962
973
|
path?: string;
|
|
974
|
+
pop?: boolean;
|
|
963
975
|
state?: never;
|
|
964
976
|
}
|
|
965
977
|
: {
|
|
@@ -967,6 +979,7 @@ export type NavigatorScreenParams<ParamList extends {}> =
|
|
|
967
979
|
params: ParamList[RouteName];
|
|
968
980
|
initial?: boolean;
|
|
969
981
|
path?: string;
|
|
982
|
+
pop?: boolean;
|
|
970
983
|
state?: never;
|
|
971
984
|
};
|
|
972
985
|
}[keyof ParamList];
|
|
@@ -254,7 +254,7 @@ export function useNavigationBuilder<
|
|
|
254
254
|
ScreenOptions extends {},
|
|
255
255
|
EventMap extends Record<string, any>,
|
|
256
256
|
>(
|
|
257
|
-
createRouter: RouterFactory<State,
|
|
257
|
+
createRouter: RouterFactory<State, NavigationAction, RouterOptions>,
|
|
258
258
|
options: DefaultNavigatorOptions<
|
|
259
259
|
ParamListBase,
|
|
260
260
|
string | undefined,
|
|
@@ -277,6 +277,7 @@ export function useNavigationBuilder<
|
|
|
277
277
|
screenOptions,
|
|
278
278
|
screenLayout,
|
|
279
279
|
screenListeners,
|
|
280
|
+
UNSTABLE_router,
|
|
280
281
|
...rest
|
|
281
282
|
} = options;
|
|
282
283
|
|
|
@@ -298,7 +299,18 @@ export function useNavigationBuilder<
|
|
|
298
299
|
);
|
|
299
300
|
}
|
|
300
301
|
|
|
301
|
-
|
|
302
|
+
const original = createRouter(rest as unknown as RouterOptions);
|
|
303
|
+
|
|
304
|
+
if (UNSTABLE_router != null) {
|
|
305
|
+
const overrides = UNSTABLE_router(original);
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
...original,
|
|
309
|
+
...overrides,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return original;
|
|
302
314
|
});
|
|
303
315
|
|
|
304
316
|
const screens = routeConfigs.reduce<
|
|
@@ -488,26 +500,17 @@ export function useNavigationBuilder<
|
|
|
488
500
|
!isArrayEqual(state.routeNames, routeNames) ||
|
|
489
501
|
!isRecordEqual(routeKeyList, previousRouteKeyList)
|
|
490
502
|
) {
|
|
491
|
-
const navigatorStateForNextRouteNamesChange =
|
|
492
|
-
options.UNSTABLE_getStateForRouteNamesChange?.(state);
|
|
493
503
|
// When the list of route names change, the router should handle it to remove invalid routes
|
|
494
|
-
nextState =
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
routeGetIdList,
|
|
505
|
-
routeKeyChanges: Object.keys(routeKeyList).filter(
|
|
506
|
-
(name) =>
|
|
507
|
-
name in previousRouteKeyList &&
|
|
508
|
-
routeKeyList[name] !== previousRouteKeyList[name]
|
|
509
|
-
),
|
|
510
|
-
});
|
|
504
|
+
nextState = router.getStateForRouteNamesChange(state, {
|
|
505
|
+
routeNames,
|
|
506
|
+
routeParamList,
|
|
507
|
+
routeGetIdList,
|
|
508
|
+
routeKeyChanges: Object.keys(routeKeyList).filter(
|
|
509
|
+
(name) =>
|
|
510
|
+
name in previousRouteKeyList &&
|
|
511
|
+
routeKeyList[name] !== previousRouteKeyList[name]
|
|
512
|
+
),
|
|
513
|
+
});
|
|
511
514
|
}
|
|
512
515
|
|
|
513
516
|
const previousNestedParamsRef = React.useRef(route?.params);
|
|
@@ -538,6 +541,7 @@ export function useNavigationBuilder<
|
|
|
538
541
|
name: route.params.screen,
|
|
539
542
|
params: route.params.params,
|
|
540
543
|
path: route.params.path,
|
|
544
|
+
pop: route.params.pop,
|
|
541
545
|
});
|
|
542
546
|
}
|
|
543
547
|
|