@react-navigation/core 8.0.0-alpha.7 → 8.0.0-alpha.9
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/ConsumedParamsContext.js +5 -0
- package/lib/module/ConsumedParamsContext.js.map +1 -0
- package/lib/module/SceneView.js +39 -16
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +17 -3
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +22 -1
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +7 -10
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/typescript/src/ConsumedParamsContext.d.ts +8 -0
- package/lib/typescript/src/ConsumedParamsContext.d.ts.map +1 -0
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/StaticContainer.d.ts +1 -1
- package/lib/typescript/src/StaticContainer.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +26 -14
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +13 -3
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/ConsumedParamsContext.tsx +10 -0
- package/src/SceneView.tsx +52 -18
- package/src/StaticNavigation.tsx +64 -25
- package/src/createNavigatorFactory.tsx +35 -4
- package/src/index.tsx +0 -1
- package/src/types.tsx +46 -18
- package/src/useNavigationBuilder.tsx +9 -11
package/src/types.tsx
CHANGED
|
@@ -55,15 +55,10 @@ export interface RootNavigator {}
|
|
|
55
55
|
export interface Theme {}
|
|
56
56
|
|
|
57
57
|
export type RootParamList =
|
|
58
|
-
RootNavigator extends
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
any,
|
|
63
|
-
any,
|
|
64
|
-
any
|
|
65
|
-
>
|
|
66
|
-
? ParamList
|
|
58
|
+
RootNavigator extends PrivateValueStore<[infer ParamList, any, any]>
|
|
59
|
+
? ParamList extends {}
|
|
60
|
+
? ParamList
|
|
61
|
+
: {}
|
|
67
62
|
: {};
|
|
68
63
|
|
|
69
64
|
export type DefaultNavigatorOptions<
|
|
@@ -1146,18 +1141,51 @@ export type NavigatorTypeBagBase = {
|
|
|
1146
1141
|
Navigator: React.ComponentType<any>;
|
|
1147
1142
|
};
|
|
1148
1143
|
|
|
1144
|
+
type TypedNavigatorComponent<Bag extends NavigatorTypeBagBase> =
|
|
1145
|
+
React.ComponentType<
|
|
1146
|
+
Omit<
|
|
1147
|
+
React.ComponentProps<
|
|
1148
|
+
TypedNavigatorInternal<
|
|
1149
|
+
Bag['ParamList'],
|
|
1150
|
+
Bag['State'],
|
|
1151
|
+
Bag['ScreenOptions'],
|
|
1152
|
+
Bag['EventMap'],
|
|
1153
|
+
Bag['NavigationList'],
|
|
1154
|
+
Bag['Navigator']
|
|
1155
|
+
>['Navigator']
|
|
1156
|
+
>,
|
|
1157
|
+
'children'
|
|
1158
|
+
>
|
|
1159
|
+
>;
|
|
1160
|
+
|
|
1161
|
+
type TypedNavigatorStaticDecorated<Bag extends NavigatorTypeBagBase, Config> = {
|
|
1162
|
+
getComponent: () => React.ComponentType<{}>;
|
|
1163
|
+
config: Config;
|
|
1164
|
+
} & PrivateValueStore<[Bag['ParamList'], Bag['NavigationList'], unknown]>;
|
|
1165
|
+
|
|
1166
|
+
type TypedNavigatorStatic<Bag extends NavigatorTypeBagBase, Config> = {
|
|
1167
|
+
config: Config;
|
|
1168
|
+
with: (
|
|
1169
|
+
Component: React.ComponentType<{
|
|
1170
|
+
Navigator: TypedNavigatorComponent<Bag>;
|
|
1171
|
+
}>
|
|
1172
|
+
) => TypedNavigatorStaticDecorated<Bag, Config>;
|
|
1173
|
+
getComponent: () => TypedNavigatorComponent<Bag>;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1149
1176
|
export type TypedNavigator<
|
|
1150
1177
|
Bag extends NavigatorTypeBagBase,
|
|
1151
1178
|
Config = unknown,
|
|
1152
|
-
> =
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1179
|
+
> = (undefined extends Config
|
|
1180
|
+
? TypedNavigatorInternal<
|
|
1181
|
+
Bag['ParamList'],
|
|
1182
|
+
Bag['State'],
|
|
1183
|
+
Bag['ScreenOptions'],
|
|
1184
|
+
Bag['EventMap'],
|
|
1185
|
+
Bag['NavigationList'],
|
|
1186
|
+
Bag['Navigator']
|
|
1187
|
+
>
|
|
1188
|
+
: TypedNavigatorStatic<Bag, Config>) &
|
|
1161
1189
|
PrivateValueStore<[Bag['ParamList'], Bag['NavigationList'], unknown]>;
|
|
1162
1190
|
|
|
1163
1191
|
type TypedNavigatorInternal<
|
|
@@ -15,6 +15,7 @@ import * as React from 'react';
|
|
|
15
15
|
import { isValidElementType } from 'react-is';
|
|
16
16
|
import useLatestCallback from 'use-latest-callback';
|
|
17
17
|
|
|
18
|
+
import { ConsumedParamsContext } from './ConsumedParamsContext';
|
|
18
19
|
import { deepFreeze } from './deepFreeze';
|
|
19
20
|
import { Group } from './Group';
|
|
20
21
|
import { isArrayEqual } from './isArrayEqual';
|
|
@@ -62,8 +63,6 @@ type NavigatorRoute = {
|
|
|
62
63
|
params?: NavigatorScreenParams<ParamListBase> | undefined;
|
|
63
64
|
};
|
|
64
65
|
|
|
65
|
-
const CONSUMED_PARAMS = Symbol('CONSUMED_PARAMS');
|
|
66
|
-
|
|
67
66
|
const isScreen = (
|
|
68
67
|
child: React.ReactElement<unknown>
|
|
69
68
|
): child is React.ReactElement<{
|
|
@@ -325,10 +324,11 @@ export function useNavigationBuilder<
|
|
|
325
324
|
|
|
326
325
|
const route = React.use(NavigationRouteContext) as NavigatorRoute | undefined;
|
|
327
326
|
|
|
327
|
+
const consumedParams = React.use(ConsumedParamsContext);
|
|
328
|
+
|
|
328
329
|
const isNestedParamsConsumed =
|
|
329
330
|
typeof route?.params === 'object' && route.params != null
|
|
330
|
-
?
|
|
331
|
-
route.params[CONSUMED_PARAMS] === route.params
|
|
331
|
+
? consumedParams?.isConsumed(route.params)
|
|
332
332
|
: false;
|
|
333
333
|
|
|
334
334
|
const {
|
|
@@ -722,20 +722,18 @@ export function useNavigationBuilder<
|
|
|
722
722
|
: nextState;
|
|
723
723
|
}
|
|
724
724
|
|
|
725
|
+
const setConsumedParams = consumedParams?.setConsumed;
|
|
726
|
+
|
|
725
727
|
React.useEffect(() => {
|
|
726
728
|
if (
|
|
729
|
+
setConsumedParams &&
|
|
727
730
|
didConsumeNestedParams &&
|
|
728
731
|
typeof route?.params === 'object' &&
|
|
729
732
|
route.params != null
|
|
730
733
|
) {
|
|
731
|
-
|
|
732
|
-
// Set it to the same object, so merged params can be handled again
|
|
733
|
-
Object.defineProperty(route.params, CONSUMED_PARAMS, {
|
|
734
|
-
value: route.params,
|
|
735
|
-
enumerable: false,
|
|
736
|
-
});
|
|
734
|
+
setConsumedParams(route.params);
|
|
737
735
|
}
|
|
738
|
-
}, [didConsumeNestedParams, route?.params]);
|
|
736
|
+
}, [didConsumeNestedParams, route?.params, setConsumedParams]);
|
|
739
737
|
|
|
740
738
|
const shouldUpdate = state !== nextState;
|
|
741
739
|
|