@react-navigation/core 8.0.0-alpha.6 → 8.0.0-alpha.8
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 +1 -1
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/ConsumedParamsContext.js +5 -0
- package/lib/module/ConsumedParamsContext.js.map +1 -0
- package/lib/module/NavigationProvider.js +2 -2
- package/lib/module/NavigationProvider.js.map +1 -1
- package/lib/module/PreventRemoveProvider.js +3 -3
- package/lib/module/PreventRemoveProvider.js.map +1 -1
- package/lib/module/SceneView.js +26 -17
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +14 -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/theming/useTheme.js +1 -1
- package/lib/module/theming/useTheme.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useCurrentRender.js +1 -1
- package/lib/module/useCurrentRender.js.map +1 -1
- package/lib/module/useDescriptors.js +2 -2
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useFocusEvents.js +1 -1
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +11 -12
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +2 -2
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +1 -1
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useNavigationIndependentTree.js +1 -1
- package/lib/module/useNavigationIndependentTree.js.map +1 -1
- package/lib/module/useOnAction.js +1 -1
- package/lib/module/useOnAction.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 +1 -1
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +2 -2
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/usePreventRemoveContext.js +1 -1
- package/lib/module/usePreventRemoveContext.js.map +1 -1
- package/lib/module/useRegisterNavigator.js +1 -1
- package/lib/module/useRegisterNavigator.js.map +1 -1
- package/lib/module/useScheduleUpdate.js +1 -1
- package/lib/module/useScheduleUpdate.js.map +1 -1
- package/lib/module/useStateForPath.js +1 -1
- package/lib/module/useStateForPath.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/StaticNavigation.d.ts +21 -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/lib/typescript/src/useScheduleUpdate.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/BaseNavigationContainer.tsx +1 -1
- package/src/ConsumedParamsContext.tsx +10 -0
- package/src/NavigationProvider.tsx +2 -2
- package/src/PreventRemoveProvider.tsx +3 -3
- package/src/SceneView.tsx +29 -20
- package/src/StaticNavigation.tsx +45 -23
- package/src/createNavigatorFactory.tsx +35 -4
- package/src/index.tsx +0 -1
- package/src/theming/useTheme.tsx +1 -1
- package/src/types.tsx +46 -18
- package/src/useCurrentRender.tsx +1 -1
- package/src/useDescriptors.tsx +2 -2
- package/src/useFocusEvents.tsx +1 -1
- package/src/useFocusedListenersChildrenAdapter.tsx +1 -1
- package/src/useNavigationBuilder.tsx +13 -15
- package/src/useNavigationCache.tsx +2 -2
- package/src/useNavigationHelpers.tsx +1 -1
- package/src/useNavigationIndependentTree.tsx +1 -1
- package/src/useOnAction.tsx +1 -1
- package/src/useOnGetState.tsx +2 -2
- package/src/useOnPreventRemove.tsx +2 -2
- package/src/useOnRouteFocus.tsx +1 -1
- package/src/useOptionsGetters.tsx +2 -2
- package/src/usePreventRemoveContext.tsx +1 -1
- package/src/useRegisterNavigator.tsx +1 -1
- package/src/useScheduleUpdate.tsx +1 -3
- package/src/useStateForPath.tsx +1 -1
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<
|
package/src/useCurrentRender.tsx
CHANGED
|
@@ -23,7 +23,7 @@ type Options = {
|
|
|
23
23
|
* Mutating values like this is not safe in async mode, but it doesn't apply to SSR
|
|
24
24
|
*/
|
|
25
25
|
export function useCurrentRender({ state, navigation, descriptors }: Options) {
|
|
26
|
-
const current = React.
|
|
26
|
+
const current = React.use(CurrentRenderContext);
|
|
27
27
|
|
|
28
28
|
if (current && navigation.isFocused()) {
|
|
29
29
|
current.options = descriptors[state.routes[state.index].key].options;
|
package/src/useDescriptors.tsx
CHANGED
|
@@ -113,7 +113,7 @@ export function useDescriptors<
|
|
|
113
113
|
router,
|
|
114
114
|
emitter,
|
|
115
115
|
}: Options<State, ScreenOptions, EventMap>) {
|
|
116
|
-
const theme = React.
|
|
116
|
+
const theme = React.use(ThemeContext);
|
|
117
117
|
const [options, setOptions] = React.useState<Record<string, ScreenOptions>>(
|
|
118
118
|
{}
|
|
119
119
|
);
|
|
@@ -124,7 +124,7 @@ export function useDescriptors<
|
|
|
124
124
|
scheduleUpdate,
|
|
125
125
|
flushUpdates,
|
|
126
126
|
stackRef,
|
|
127
|
-
} = React.
|
|
127
|
+
} = React.use(NavigationBuilderContext);
|
|
128
128
|
|
|
129
129
|
const context = React.useMemo(
|
|
130
130
|
() => ({
|
package/src/useFocusEvents.tsx
CHANGED
|
@@ -17,7 +17,7 @@ export function useFocusEvents<State extends NavigationState>({
|
|
|
17
17
|
state,
|
|
18
18
|
emitter,
|
|
19
19
|
}: Options<State>) {
|
|
20
|
-
const navigation = React.
|
|
20
|
+
const navigation = React.use(NavigationContext);
|
|
21
21
|
const lastFocusedKeyRef = React.useRef<string | undefined>(undefined);
|
|
22
22
|
|
|
23
23
|
const currentFocusedKey = state.routes[state.index].key;
|
|
@@ -20,7 +20,7 @@ export function useFocusedListenersChildrenAdapter({
|
|
|
20
20
|
navigation,
|
|
21
21
|
focusedListeners,
|
|
22
22
|
}: Options) {
|
|
23
|
-
const { addListener } = React.
|
|
23
|
+
const { addListener } = React.use(NavigationBuilderContext);
|
|
24
24
|
|
|
25
25
|
const listener = React.useCallback(
|
|
26
26
|
(callback: FocusedNavigationCallback<any>) => {
|
|
@@ -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<{
|
|
@@ -323,14 +322,13 @@ export function useNavigationBuilder<
|
|
|
323
322
|
) {
|
|
324
323
|
const navigatorKey = useRegisterNavigator();
|
|
325
324
|
|
|
326
|
-
const route = React.
|
|
327
|
-
|
|
328
|
-
|
|
325
|
+
const route = React.use(NavigationRouteContext) as NavigatorRoute | undefined;
|
|
326
|
+
|
|
327
|
+
const consumedParams = React.use(ConsumedParamsContext);
|
|
329
328
|
|
|
330
329
|
const isNestedParamsConsumed =
|
|
331
330
|
typeof route?.params === 'object' && route.params != null
|
|
332
|
-
?
|
|
333
|
-
route.params[CONSUMED_PARAMS] === route.params
|
|
331
|
+
? consumedParams?.ref?.deref() === route.params
|
|
334
332
|
: false;
|
|
335
333
|
|
|
336
334
|
const {
|
|
@@ -447,7 +445,7 @@ export function useNavigationBuilder<
|
|
|
447
445
|
setKey,
|
|
448
446
|
getKey,
|
|
449
447
|
getIsInitial,
|
|
450
|
-
} = React.
|
|
448
|
+
} = React.use(NavigationStateContext);
|
|
451
449
|
|
|
452
450
|
const stateCleanupRef = React.useRef<boolean>(false);
|
|
453
451
|
const lastStateRef = React.useRef<State | PartialState<State> | undefined>(
|
|
@@ -724,20 +722,20 @@ export function useNavigationBuilder<
|
|
|
724
722
|
: nextState;
|
|
725
723
|
}
|
|
726
724
|
|
|
725
|
+
const setConsumedParamsRef = consumedParams?.setRef;
|
|
726
|
+
|
|
727
727
|
React.useEffect(() => {
|
|
728
728
|
if (
|
|
729
|
+
setConsumedParamsRef &&
|
|
729
730
|
didConsumeNestedParams &&
|
|
730
731
|
typeof route?.params === 'object' &&
|
|
731
732
|
route.params != null
|
|
732
733
|
) {
|
|
733
734
|
// Track whether the params have been already consumed
|
|
734
735
|
// Set it to the same object, so merged params can be handled again
|
|
735
|
-
|
|
736
|
-
value: route.params,
|
|
737
|
-
enumerable: false,
|
|
738
|
-
});
|
|
736
|
+
setConsumedParamsRef(new WeakRef(route.params));
|
|
739
737
|
}
|
|
740
|
-
}, [didConsumeNestedParams, route?.params]);
|
|
738
|
+
}, [didConsumeNestedParams, route?.params, setConsumedParamsRef]);
|
|
741
739
|
|
|
742
740
|
const shouldUpdate = state !== nextState;
|
|
743
741
|
|
|
@@ -814,7 +812,7 @@ export function useNavigationBuilder<
|
|
|
814
812
|
);
|
|
815
813
|
});
|
|
816
814
|
|
|
817
|
-
const { onEmitEvent } = React.
|
|
815
|
+
const { onEmitEvent } = React.use(NavigationBuilderContext);
|
|
818
816
|
|
|
819
817
|
const emitter = useEventEmitter<EventMapCore<State>>((e) => {
|
|
820
818
|
const routeNames = [];
|
|
@@ -908,7 +906,7 @@ export function useNavigationBuilder<
|
|
|
908
906
|
setState,
|
|
909
907
|
});
|
|
910
908
|
|
|
911
|
-
const onUnhandledActionParent = React.
|
|
909
|
+
const onUnhandledActionParent = React.use(UnhandledActionContext);
|
|
912
910
|
|
|
913
911
|
const onUnhandledAction = useLatestCallback((action: NavigationAction) => {
|
|
914
912
|
if (
|
|
@@ -72,8 +72,8 @@ export function useNavigationCache<
|
|
|
72
72
|
router,
|
|
73
73
|
emitter,
|
|
74
74
|
}: Options<State, ScreenOptions, EventMap>) {
|
|
75
|
-
const parentNavigationHelpers = React.
|
|
76
|
-
const { stackRef } = React.
|
|
75
|
+
const parentNavigationHelpers = React.use(NavigationContext);
|
|
76
|
+
const { stackRef } = React.use(NavigationBuilderContext);
|
|
77
77
|
|
|
78
78
|
// Cache object which holds navigation objects for each screen
|
|
79
79
|
// We use `React.useMemo` instead of `React.useRef` coz we want to invalidate it when deps change
|
|
@@ -41,7 +41,7 @@ export function useNavigationHelpers<
|
|
|
41
41
|
router,
|
|
42
42
|
stateRef,
|
|
43
43
|
}: Options<State, Action>) {
|
|
44
|
-
const parentNavigationHelpers = React.
|
|
44
|
+
const parentNavigationHelpers = React.use(NavigationContext);
|
|
45
45
|
|
|
46
46
|
return React.useMemo(() => {
|
|
47
47
|
const dispatch = (op: Action | ((state: State) => Action)) => {
|
|
@@ -3,5 +3,5 @@ import * as React from 'react';
|
|
|
3
3
|
import { NavigationIndependentTreeContext } from './NavigationIndependentTreeContext';
|
|
4
4
|
|
|
5
5
|
export function useNavigationIndependentTree() {
|
|
6
|
-
return React.
|
|
6
|
+
return React.use(NavigationIndependentTreeContext);
|
|
7
7
|
}
|
package/src/useOnAction.tsx
CHANGED
|
@@ -51,7 +51,7 @@ export function useOnAction<State extends NavigationState>({
|
|
|
51
51
|
onRouteFocus: onRouteFocusParent,
|
|
52
52
|
addListener: addListenerParent,
|
|
53
53
|
onDispatchAction,
|
|
54
|
-
} = React.
|
|
54
|
+
} = React.use(NavigationBuilderContext);
|
|
55
55
|
|
|
56
56
|
const routerConfigOptionsRef =
|
|
57
57
|
React.useRef<RouterConfigOptions>(routerConfigOptions);
|
package/src/useOnGetState.tsx
CHANGED
|
@@ -14,8 +14,8 @@ type Options = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export function useOnGetState({ getState, getStateListeners }: Options) {
|
|
17
|
-
const { addKeyedListener } = React.
|
|
18
|
-
const route = React.
|
|
17
|
+
const { addKeyedListener } = React.use(NavigationBuilderContext);
|
|
18
|
+
const route = React.use(NavigationRouteContext);
|
|
19
19
|
const key = route ? route.key : 'root';
|
|
20
20
|
|
|
21
21
|
const getRehydratedState = React.useCallback(() => {
|
|
@@ -78,8 +78,8 @@ export function useOnPreventRemove({
|
|
|
78
78
|
emitter,
|
|
79
79
|
beforeRemoveListeners,
|
|
80
80
|
}: Options) {
|
|
81
|
-
const { addKeyedListener } = React.
|
|
82
|
-
const route = React.
|
|
81
|
+
const { addKeyedListener } = React.use(NavigationBuilderContext);
|
|
82
|
+
const route = React.use(NavigationRouteContext);
|
|
83
83
|
const routeKey = route?.key;
|
|
84
84
|
|
|
85
85
|
React.useEffect(() => {
|
package/src/useOnRouteFocus.tsx
CHANGED
|
@@ -23,7 +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 } = React.
|
|
26
|
+
const { onRouteFocus: onRouteFocusParent } = React.use(
|
|
27
27
|
NavigationBuilderContext
|
|
28
28
|
);
|
|
29
29
|
|
|
@@ -17,8 +17,8 @@ export function useOptionsGetters({ key, options, navigation }: Options) {
|
|
|
17
17
|
Record<string, () => object | undefined | null>
|
|
18
18
|
>({});
|
|
19
19
|
|
|
20
|
-
const { onOptionsChange } = React.
|
|
21
|
-
const { addOptionsGetter: parentAddOptionsGetter } = React.
|
|
20
|
+
const { onOptionsChange } = React.use(NavigationBuilderContext);
|
|
21
|
+
const { addOptionsGetter: parentAddOptionsGetter } = React.use(
|
|
22
22
|
NavigationStateContext
|
|
23
23
|
);
|
|
24
24
|
|
|
@@ -3,7 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { PreventRemoveContext } from './PreventRemoveContext';
|
|
4
4
|
|
|
5
5
|
export function usePreventRemoveContext() {
|
|
6
|
-
const value = React.
|
|
6
|
+
const value = React.use(PreventRemoveContext);
|
|
7
7
|
|
|
8
8
|
if (value == null) {
|
|
9
9
|
throw new Error(
|
|
@@ -9,7 +9,7 @@ import { SingleNavigatorContext } from './EnsureSingleNavigator';
|
|
|
9
9
|
*/
|
|
10
10
|
export function useRegisterNavigator() {
|
|
11
11
|
const [key] = React.useState(() => nanoid());
|
|
12
|
-
const container = React.
|
|
12
|
+
const container = React.use(SingleNavigatorContext);
|
|
13
13
|
|
|
14
14
|
if (container === undefined) {
|
|
15
15
|
throw new Error(
|
|
@@ -10,9 +10,7 @@ import { NavigationBuilderContext } from './NavigationBuilderContext';
|
|
|
10
10
|
* Then we call setState during after the component updates.
|
|
11
11
|
*/
|
|
12
12
|
export function useScheduleUpdate(callback: () => void) {
|
|
13
|
-
const { scheduleUpdate, flushUpdates } = React.
|
|
14
|
-
NavigationBuilderContext
|
|
15
|
-
);
|
|
13
|
+
const { scheduleUpdate, flushUpdates } = React.use(NavigationBuilderContext);
|
|
16
14
|
|
|
17
15
|
// FIXME: This is potentially unsafe
|
|
18
16
|
// However, since we are using sync store, it might be fine
|
package/src/useStateForPath.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { NavigationFocusedRouteStateContext } from './NavigationFocusedRouteStat
|
|
|
9
9
|
* @returns Minimal state to build a path for the current route.
|
|
10
10
|
*/
|
|
11
11
|
export function useStateForPath() {
|
|
12
|
-
const state = React.
|
|
12
|
+
const state = React.use(NavigationFocusedRouteStateContext);
|
|
13
13
|
|
|
14
14
|
return state;
|
|
15
15
|
}
|