@react-navigation/core 7.8.5 → 7.9.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/module/BaseNavigationContainer.js +3 -3
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/EnsureSingleNavigator.js +1 -1
- package/lib/module/EnsureSingleNavigator.js.map +1 -1
- package/lib/module/SceneView.js +1 -1
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js +1 -0
- 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/useLazyValue.js +1 -1
- package/lib/module/useLazyValue.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +19 -7
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +4 -4
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/deepFreeze.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 +10 -18
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +16 -5
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +18 -3
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationCache.d.ts +6 -1
- package/lib/typescript/src/useNavigationCache.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +6 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts.map +1 -1
- package/lib/typescript/src/useOnPreventRemove.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/BaseNavigationContainer.tsx +3 -3
- package/src/EnsureSingleNavigator.tsx +1 -1
- package/src/SceneView.tsx +1 -1
- package/src/StaticNavigation.tsx +4 -4
- package/src/index.tsx +2 -0
- package/src/types.tsx +32 -18
- package/src/useDescriptors.tsx +5 -3
- package/src/useFocusEvents.tsx +1 -1
- package/src/useLazyValue.tsx +1 -1
- package/src/useNavigationBuilder.tsx +44 -13
|
@@ -57,7 +57,27 @@ type NavigatorRoute = {
|
|
|
57
57
|
params?: NavigatorScreenParams<ParamListBase>;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const
|
|
60
|
+
const isScreen = (
|
|
61
|
+
child: React.ReactElement<unknown>
|
|
62
|
+
): child is React.ReactElement<{
|
|
63
|
+
name?: unknown;
|
|
64
|
+
navigationKey?: unknown;
|
|
65
|
+
}> => {
|
|
66
|
+
return child.type === Screen;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const isGroup = (
|
|
70
|
+
child: React.ReactElement<unknown>
|
|
71
|
+
): child is React.ReactElement<{
|
|
72
|
+
navigationKey?: unknown;
|
|
73
|
+
screenOptions?: unknown;
|
|
74
|
+
screenLayout?: unknown;
|
|
75
|
+
children?: unknown;
|
|
76
|
+
}> => {
|
|
77
|
+
return child.type === React.Fragment || child.type === Group;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const isValidKey = (key: unknown): key is string | undefined =>
|
|
61
81
|
key === undefined || (typeof key === 'string' && key !== '');
|
|
62
82
|
|
|
63
83
|
/**
|
|
@@ -83,11 +103,27 @@ const getRouteConfigsFromChildren = <
|
|
|
83
103
|
ScreenConfigWithParent<State, ScreenOptions, EventMap>[]
|
|
84
104
|
>((acc, child) => {
|
|
85
105
|
if (React.isValidElement(child)) {
|
|
86
|
-
if (child
|
|
106
|
+
if (isScreen(child)) {
|
|
87
107
|
// We can only extract the config from `Screen` elements
|
|
88
108
|
// If something else was rendered, it's probably a bug
|
|
89
109
|
|
|
90
|
-
if (
|
|
110
|
+
if (typeof child.props !== 'object' || child.props === null) {
|
|
111
|
+
throw new Error(`Got an invalid element for screen.`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (typeof child.props.name !== 'string' || child.props.name === '') {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`Got an invalid name (${JSON.stringify(
|
|
117
|
+
child.props.name
|
|
118
|
+
)}) for the screen. It must be a non-empty string.`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (
|
|
123
|
+
child.props.navigationKey !== undefined &&
|
|
124
|
+
(typeof child.props.navigationKey !== 'string' ||
|
|
125
|
+
child.props.navigationKey === '')
|
|
126
|
+
) {
|
|
91
127
|
throw new Error(
|
|
92
128
|
`Got an invalid 'navigationKey' prop (${JSON.stringify(
|
|
93
129
|
child.props.navigationKey
|
|
@@ -114,7 +150,7 @@ const getRouteConfigsFromChildren = <
|
|
|
114
150
|
return acc;
|
|
115
151
|
}
|
|
116
152
|
|
|
117
|
-
if (child
|
|
153
|
+
if (isGroup(child)) {
|
|
118
154
|
if (!isValidKey(child.props.navigationKey)) {
|
|
119
155
|
throw new Error(
|
|
120
156
|
`Got an invalid 'navigationKey' prop (${JSON.stringify(
|
|
@@ -127,8 +163,10 @@ const getRouteConfigsFromChildren = <
|
|
|
127
163
|
// This is handy to conditionally define a group of screens
|
|
128
164
|
acc.push(
|
|
129
165
|
...getRouteConfigsFromChildren<State, ScreenOptions, EventMap>(
|
|
130
|
-
child.props.children,
|
|
166
|
+
child.props.children as React.ReactNode,
|
|
131
167
|
child.props.navigationKey,
|
|
168
|
+
// FIXME
|
|
169
|
+
// @ts-expect-error: add validation
|
|
132
170
|
child.type !== Group
|
|
133
171
|
? groupOptions
|
|
134
172
|
: groupOptions != null
|
|
@@ -139,6 +177,7 @@ const getRouteConfigsFromChildren = <
|
|
|
139
177
|
: groupLayout
|
|
140
178
|
)
|
|
141
179
|
);
|
|
180
|
+
|
|
142
181
|
return acc;
|
|
143
182
|
}
|
|
144
183
|
}
|
|
@@ -167,14 +206,6 @@ const getRouteConfigsFromChildren = <
|
|
|
167
206
|
configs.forEach((config) => {
|
|
168
207
|
const { name, children, component, getComponent } = config.props;
|
|
169
208
|
|
|
170
|
-
if (typeof name !== 'string' || !name) {
|
|
171
|
-
throw new Error(
|
|
172
|
-
`Got an invalid name (${JSON.stringify(
|
|
173
|
-
name
|
|
174
|
-
)}) for the screen. It must be a non-empty string.`
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
209
|
if (
|
|
179
210
|
children != null ||
|
|
180
211
|
component !== undefined ||
|