@react-navigation/core 6.1.0 → 6.2.1
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/BaseNavigationContainer.js +13 -9
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
- package/lib/commonjs/CurrentRenderContext.js.map +1 -1
- package/lib/commonjs/EnsureSingleNavigator.js +5 -4
- package/lib/commonjs/EnsureSingleNavigator.js.map +1 -1
- package/lib/commonjs/NavigationContainerRefContext.js.map +1 -1
- package/lib/commonjs/NavigationContext.js.map +1 -1
- package/lib/commonjs/NavigationHelpersContext.js.map +1 -1
- package/lib/commonjs/NavigationRouteContext.js.map +1 -1
- package/lib/commonjs/SceneView.js +11 -10
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/UnhandledActionContext.js.map +1 -1
- package/lib/commonjs/createNavigationContainerRef.js +11 -6
- package/lib/commonjs/createNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/fromEntries.js +3 -1
- package/lib/commonjs/fromEntries.js.map +1 -1
- package/lib/commonjs/getActionFromState.js +2 -1
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/getPathFromState.js +13 -3
- package/lib/commonjs/getPathFromState.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +12 -2
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/commonjs/index.js +24 -24
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useChildListeners.js.map +1 -1
- package/lib/commonjs/useCurrentRender.js +6 -5
- package/lib/commonjs/useCurrentRender.js.map +1 -1
- package/lib/commonjs/useDescriptors.js +16 -15
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useEventEmitter.js +7 -6
- package/lib/commonjs/useEventEmitter.js.map +1 -1
- package/lib/commonjs/useFocusEvents.js +5 -4
- package/lib/commonjs/useFocusEvents.js.map +1 -1
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js +5 -4
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +10 -5
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +26 -10
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationHelpers.js +28 -10
- package/lib/commonjs/useNavigationHelpers.js.map +1 -1
- package/lib/commonjs/useOnAction.js +13 -11
- package/lib/commonjs/useOnAction.js.map +1 -1
- package/lib/commonjs/useOnGetState.js +5 -4
- package/lib/commonjs/useOnGetState.js.map +1 -1
- package/lib/commonjs/useOnPreventRemove.js +6 -5
- package/lib/commonjs/useOnPreventRemove.js.map +1 -1
- package/lib/commonjs/useOnRouteFocus.js +7 -6
- package/lib/commonjs/useOnRouteFocus.js.map +1 -1
- package/lib/commonjs/useOptionsGetters.js +6 -5
- package/lib/commonjs/useOptionsGetters.js.map +1 -1
- package/lib/commonjs/useRouteCache.js +1 -1
- package/lib/commonjs/useScheduleUpdate.js +1 -1
- package/lib/commonjs/validatePathConfig.js +5 -2
- package/lib/commonjs/validatePathConfig.js.map +1 -1
- package/lib/module/BaseNavigationContainer.js +13 -9
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/CurrentRenderContext.js.map +1 -1
- package/lib/module/EnsureSingleNavigator.js +4 -3
- package/lib/module/EnsureSingleNavigator.js.map +1 -1
- package/lib/module/NavigationContainerRefContext.js.map +1 -1
- package/lib/module/NavigationContext.js.map +1 -1
- package/lib/module/NavigationHelpersContext.js.map +1 -1
- package/lib/module/NavigationRouteContext.js.map +1 -1
- package/lib/module/SceneView.js +11 -10
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/UnhandledActionContext.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js +10 -5
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/fromEntries.js +3 -1
- package/lib/module/fromEntries.js.map +1 -1
- package/lib/module/getActionFromState.js +2 -1
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +13 -3
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +12 -2
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useChildListeners.js.map +1 -1
- package/lib/module/useCurrentRender.js +6 -5
- package/lib/module/useCurrentRender.js.map +1 -1
- package/lib/module/useDescriptors.js +16 -15
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +7 -6
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEvents.js +5 -4
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +5 -4
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +10 -5
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +26 -10
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +28 -10
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useOnAction.js +13 -11
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +5 -4
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +6 -5
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +7 -6
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +6 -5
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/validatePathConfig.js +5 -2
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/NavigationContext.d.ts +1 -1
- package/lib/typescript/src/SceneView.d.ts +1 -1
- package/lib/typescript/src/types.d.ts +39 -18
- package/lib/typescript/src/useDescriptors.d.ts +8 -6
- package/lib/typescript/src/useNavigationBuilder.d.ts +12 -73
- package/lib/typescript/src/useNavigationCache.d.ts +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +7 -69
- package/package.json +4 -4
- package/src/CurrentRenderContext.tsx +3 -2
- package/src/EnsureSingleNavigator.tsx +7 -8
- package/src/NavigationContainerRefContext.tsx +3 -4
- package/src/NavigationContext.tsx +3 -2
- package/src/NavigationHelpersContext.tsx +3 -2
- package/src/NavigationRouteContext.tsx +3 -2
- package/src/SceneView.tsx +7 -1
- package/src/UnhandledActionContext.tsx +3 -4
- package/src/createNavigationContainerRef.tsx +3 -1
- package/src/types.tsx +57 -21
- package/src/useChildListeners.tsx +3 -5
- package/src/useDescriptors.tsx +8 -1
- package/src/useKeyedChildListeners.tsx +6 -8
- package/src/useNavigationBuilder.tsx +19 -9
- package/src/useNavigationCache.tsx +17 -1
- package/src/useNavigationHelpers.tsx +33 -15
|
@@ -199,13 +199,19 @@ const getRouteConfigsFromChildren = <
|
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
if (typeof component === 'function'
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
if (typeof component === 'function') {
|
|
203
|
+
if (component.name === 'component') {
|
|
204
|
+
// Inline anonymous functions passed in the `component` prop will have the name of the prop
|
|
205
|
+
// It's relatively safe to assume that it's not a component since it should also have PascalCase name
|
|
206
|
+
// We won't catch all scenarios here, but this should catch a good chunk of incorrect use.
|
|
207
|
+
console.warn(
|
|
208
|
+
`Looks like you're passing an inline function for 'component' prop for the screen '${name}' (e.g. component={() => <SomeComponent />}). Passing an inline function will cause the component state to be lost on re-render and cause perf issues since it's re-created every render. You can pass the function as children to 'Screen' instead to achieve the desired behaviour.`
|
|
209
|
+
);
|
|
210
|
+
} else if (/^[a-z]/.test(component.name)) {
|
|
211
|
+
console.warn(
|
|
212
|
+
`Got a component with the name '${component.name}' for the screen '${name}'. React Components must start with an uppercase letter. If you're passing a regular function and not a component, pass it as children to 'Screen' instead. Otherwise capitalize your component's name.`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
209
215
|
}
|
|
210
216
|
} else {
|
|
211
217
|
throw new Error(
|
|
@@ -260,8 +266,11 @@ export default function useNavigationBuilder<
|
|
|
260
266
|
})
|
|
261
267
|
);
|
|
262
268
|
|
|
263
|
-
const routeConfigs =
|
|
264
|
-
|
|
269
|
+
const routeConfigs = getRouteConfigsFromChildren<
|
|
270
|
+
State,
|
|
271
|
+
ScreenOptions,
|
|
272
|
+
EventMap
|
|
273
|
+
>(children);
|
|
265
274
|
|
|
266
275
|
const screens = routeConfigs.reduce<
|
|
267
276
|
Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>
|
|
@@ -636,6 +645,7 @@ export default function useNavigationBuilder<
|
|
|
636
645
|
NavigationAction,
|
|
637
646
|
EventMap
|
|
638
647
|
>({
|
|
648
|
+
id: options.id,
|
|
639
649
|
onAction,
|
|
640
650
|
getState,
|
|
641
651
|
emitter,
|
|
@@ -32,7 +32,14 @@ type NavigationCache<
|
|
|
32
32
|
EventMap extends Record<string, any>
|
|
33
33
|
> = Record<
|
|
34
34
|
string,
|
|
35
|
-
NavigationProp<
|
|
35
|
+
NavigationProp<
|
|
36
|
+
ParamListBase,
|
|
37
|
+
string,
|
|
38
|
+
string | undefined,
|
|
39
|
+
State,
|
|
40
|
+
ScreenOptions,
|
|
41
|
+
EventMap
|
|
42
|
+
>
|
|
36
43
|
>;
|
|
37
44
|
|
|
38
45
|
/**
|
|
@@ -133,6 +140,15 @@ export default function useNavigationCache<
|
|
|
133
140
|
// FIXME: too much work to fix the types for now
|
|
134
141
|
...(emitter.create(route.key) as any),
|
|
135
142
|
dispatch: (thunk: Thunk) => withStack(() => dispatch(thunk)),
|
|
143
|
+
getParent: (id?: string) => {
|
|
144
|
+
if (id !== undefined && id === rest.getId()) {
|
|
145
|
+
// If the passed id is the same as the current navigation id,
|
|
146
|
+
// we return the cached navigation object for the relevant route
|
|
147
|
+
return acc[route.key];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return rest.getParent(id);
|
|
151
|
+
},
|
|
136
152
|
setOptions: (options: object) =>
|
|
137
153
|
setOptions((o) => ({
|
|
138
154
|
...o,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
|
|
10
10
|
import NavigationContext from './NavigationContext';
|
|
11
|
-
import { NavigationHelpers,
|
|
11
|
+
import { NavigationHelpers, PrivateValueStore } from './types';
|
|
12
12
|
import UnhandledActionContext from './UnhandledActionContext';
|
|
13
13
|
import type { NavigationEventEmitter } from './useEventEmitter';
|
|
14
14
|
|
|
@@ -17,6 +17,7 @@ import type { NavigationEventEmitter } from './useEventEmitter';
|
|
|
17
17
|
PrivateValueStore;
|
|
18
18
|
|
|
19
19
|
type Options<State extends NavigationState, Action extends NavigationAction> = {
|
|
20
|
+
id: string | undefined;
|
|
20
21
|
onAction: (action: NavigationAction) => boolean;
|
|
21
22
|
getState: () => State;
|
|
22
23
|
emitter: NavigationEventEmitter<any>;
|
|
@@ -32,7 +33,13 @@ export default function useNavigationHelpers<
|
|
|
32
33
|
ActionHelpers extends Record<string, () => void>,
|
|
33
34
|
Action extends NavigationAction,
|
|
34
35
|
EventMap extends Record<string, any>
|
|
35
|
-
>({
|
|
36
|
+
>({
|
|
37
|
+
id: navigatorId,
|
|
38
|
+
onAction,
|
|
39
|
+
getState,
|
|
40
|
+
emitter,
|
|
41
|
+
router,
|
|
42
|
+
}: Options<State, Action>) {
|
|
36
43
|
const onUnhandledAction = React.useContext(UnhandledActionContext);
|
|
37
44
|
const parentNavigationHelpers = React.useContext(NavigationContext);
|
|
38
45
|
|
|
@@ -52,16 +59,13 @@ export default function useNavigationHelpers<
|
|
|
52
59
|
...CommonActions,
|
|
53
60
|
};
|
|
54
61
|
|
|
55
|
-
const helpers = Object.keys(actions).reduce
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
{}
|
|
62
|
-
);
|
|
62
|
+
const helpers = Object.keys(actions).reduce((acc, name) => {
|
|
63
|
+
// @ts-expect-error: name is a valid key, but TypeScript is dumb
|
|
64
|
+
acc[name] = (...args: any) => dispatch(actions[name](...args));
|
|
65
|
+
return acc;
|
|
66
|
+
}, {} as ActionHelpers);
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
const navigationHelpers = {
|
|
65
69
|
...parentNavigationHelpers,
|
|
66
70
|
...helpers,
|
|
67
71
|
dispatch,
|
|
@@ -82,12 +86,26 @@ export default function useNavigationHelpers<
|
|
|
82
86
|
false
|
|
83
87
|
);
|
|
84
88
|
},
|
|
85
|
-
|
|
89
|
+
getId: () => navigatorId,
|
|
90
|
+
getParent: (id?: string) => {
|
|
91
|
+
if (id !== undefined) {
|
|
92
|
+
let current = navigationHelpers;
|
|
93
|
+
|
|
94
|
+
while (current && id !== current.getId()) {
|
|
95
|
+
current = current.getParent();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return current;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return parentNavigationHelpers;
|
|
102
|
+
},
|
|
86
103
|
getState,
|
|
87
|
-
} as NavigationHelpers<ParamListBase, EventMap> &
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
} as NavigationHelpers<ParamListBase, EventMap> & ActionHelpers;
|
|
105
|
+
|
|
106
|
+
return navigationHelpers;
|
|
90
107
|
}, [
|
|
108
|
+
navigatorId,
|
|
91
109
|
emitter.emit,
|
|
92
110
|
getState,
|
|
93
111
|
onAction,
|