@react-navigation/core 7.0.0-alpha.13 → 7.0.0-alpha.15
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/Group.js.map +1 -1
- package/lib/commonjs/Screen.js.map +1 -1
- package/lib/commonjs/StaticNavigation.js.map +1 -1
- package/lib/commonjs/createNavigatorFactory.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +4 -2
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +1 -1
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/module/Group.js.map +1 -1
- package/lib/module/Screen.js.map +1 -1
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +1 -0
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/getStateFromPath.js +4 -2
- package/lib/module/getStateFromPath.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.map +1 -1
- package/lib/module/useNavigationBuilder.js +1 -1
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/typescript/src/Group.d.ts +1 -1
- package/lib/typescript/src/Group.d.ts.map +1 -1
- package/lib/typescript/src/Screen.d.ts +1 -1
- package/lib/typescript/src/Screen.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +17 -15
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +1 -9
- 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 +60 -23
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +1 -1
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Group.tsx +2 -1
- package/src/Screen.tsx +11 -1
- package/src/StaticNavigation.tsx +107 -26
- package/src/createNavigatorFactory.tsx +1 -36
- package/src/getStateFromPath.tsx +3 -1
- package/src/index.tsx +1 -0
- package/src/types.tsx +129 -22
- package/src/useDescriptors.tsx +8 -1
- package/src/useNavigationBuilder.tsx +6 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/core",
|
|
3
3
|
"description": "Core utilities for building navigators",
|
|
4
|
-
"version": "7.0.0-alpha.
|
|
4
|
+
"version": "7.0.0-alpha.15",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"react-native",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
]
|
|
71
71
|
]
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "a601b72a5ae354900ab21f0e0293cb2c573ba8d0"
|
|
74
74
|
}
|
package/src/Group.tsx
CHANGED
|
@@ -8,7 +8,8 @@ import type { RouteGroupConfig } from './types';
|
|
|
8
8
|
export function Group<
|
|
9
9
|
ParamList extends ParamListBase,
|
|
10
10
|
ScreenOptions extends {},
|
|
11
|
-
|
|
11
|
+
Navigation,
|
|
12
|
+
>(_: RouteGroupConfig<ParamList, ScreenOptions, Navigation>) {
|
|
12
13
|
/* istanbul ignore next */
|
|
13
14
|
return null;
|
|
14
15
|
}
|
package/src/Screen.tsx
CHANGED
|
@@ -11,7 +11,17 @@ export function Screen<
|
|
|
11
11
|
State extends NavigationState,
|
|
12
12
|
ScreenOptions extends {},
|
|
13
13
|
EventMap extends EventMapBase,
|
|
14
|
-
|
|
14
|
+
NavigationProp,
|
|
15
|
+
>(
|
|
16
|
+
_: RouteConfig<
|
|
17
|
+
ParamList,
|
|
18
|
+
RouteName,
|
|
19
|
+
State,
|
|
20
|
+
ScreenOptions,
|
|
21
|
+
EventMap,
|
|
22
|
+
NavigationProp
|
|
23
|
+
>
|
|
24
|
+
) {
|
|
15
25
|
/* istanbul ignore next */
|
|
16
26
|
return null;
|
|
17
27
|
}
|
package/src/StaticNavigation.tsx
CHANGED
|
@@ -5,9 +5,12 @@ import { isValidElementType } from 'react-is';
|
|
|
5
5
|
import type {
|
|
6
6
|
DefaultNavigatorOptions,
|
|
7
7
|
EventMapBase,
|
|
8
|
+
NavigationListBase,
|
|
8
9
|
NavigatorScreenParams,
|
|
10
|
+
NavigatorTypeBagBase,
|
|
9
11
|
PathConfig,
|
|
10
|
-
|
|
12
|
+
RouteConfigComponent,
|
|
13
|
+
RouteConfigProps,
|
|
11
14
|
RouteGroupConfig,
|
|
12
15
|
} from './types';
|
|
13
16
|
import { useRoute } from './useRoute';
|
|
@@ -62,7 +65,8 @@ type ParamListForGroups<
|
|
|
62
65
|
ParamListBase,
|
|
63
66
|
NavigationState,
|
|
64
67
|
{},
|
|
65
|
-
EventMapBase
|
|
68
|
+
EventMapBase,
|
|
69
|
+
any
|
|
66
70
|
>;
|
|
67
71
|
};
|
|
68
72
|
}>
|
|
@@ -73,24 +77,53 @@ type ParamListForGroups<
|
|
|
73
77
|
ParamListBase,
|
|
74
78
|
NavigationState,
|
|
75
79
|
{},
|
|
76
|
-
EventMapBase
|
|
80
|
+
EventMapBase,
|
|
81
|
+
any
|
|
77
82
|
>;
|
|
78
83
|
};
|
|
79
84
|
}
|
|
80
85
|
? ParamListForScreens<UnionToIntersection<Groups[keyof Groups]['screens']>>
|
|
81
86
|
: {};
|
|
82
87
|
|
|
88
|
+
type StaticRouteConfig<
|
|
89
|
+
ParamList extends ParamListBase,
|
|
90
|
+
RouteName extends keyof ParamList,
|
|
91
|
+
State extends NavigationState,
|
|
92
|
+
ScreenOptions extends {},
|
|
93
|
+
EventMap extends EventMapBase,
|
|
94
|
+
Navigation,
|
|
95
|
+
> = RouteConfigProps<
|
|
96
|
+
// FIXME: the param list is inferred from the screen component
|
|
97
|
+
// So we can't use the type here
|
|
98
|
+
// Fallback to ParamListBase for now
|
|
99
|
+
ParamListBase,
|
|
100
|
+
string,
|
|
101
|
+
State,
|
|
102
|
+
ScreenOptions,
|
|
103
|
+
EventMap,
|
|
104
|
+
Navigation
|
|
105
|
+
> &
|
|
106
|
+
RouteConfigComponent<ParamList, RouteName>;
|
|
107
|
+
|
|
83
108
|
type StaticConfigScreens<
|
|
84
109
|
ParamList extends ParamListBase,
|
|
85
110
|
State extends NavigationState,
|
|
86
111
|
ScreenOptions extends {},
|
|
87
112
|
EventMap extends EventMapBase,
|
|
113
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
88
114
|
> = {
|
|
89
|
-
[
|
|
115
|
+
[RouteName in keyof ParamList]:
|
|
90
116
|
| React.ComponentType<any>
|
|
91
117
|
| StaticNavigation<any, any, any>
|
|
92
118
|
| (Omit<
|
|
93
|
-
|
|
119
|
+
StaticRouteConfig<
|
|
120
|
+
ParamList,
|
|
121
|
+
RouteName,
|
|
122
|
+
State,
|
|
123
|
+
ScreenOptions,
|
|
124
|
+
EventMap,
|
|
125
|
+
NavigationList[RouteName]
|
|
126
|
+
>,
|
|
94
127
|
'name' | 'component' | 'getComponent' | 'children'
|
|
95
128
|
> & {
|
|
96
129
|
/**
|
|
@@ -131,7 +164,11 @@ type GroupConfig<
|
|
|
131
164
|
State extends NavigationState,
|
|
132
165
|
ScreenOptions extends {},
|
|
133
166
|
EventMap extends EventMapBase,
|
|
134
|
-
|
|
167
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
168
|
+
> = Omit<
|
|
169
|
+
RouteGroupConfig<ParamList, ScreenOptions, NavigationList[keyof ParamList]>,
|
|
170
|
+
'screens' | 'children'
|
|
171
|
+
> & {
|
|
135
172
|
/**
|
|
136
173
|
* Callback to determine whether the screens in the group should be rendered or not.
|
|
137
174
|
* This can be useful for conditional rendering of group of screens.
|
|
@@ -140,26 +177,54 @@ type GroupConfig<
|
|
|
140
177
|
/**
|
|
141
178
|
* Static navigation config or Component to render for the screen.
|
|
142
179
|
*/
|
|
143
|
-
screens: StaticConfigScreens<
|
|
180
|
+
screens: StaticConfigScreens<
|
|
181
|
+
ParamList,
|
|
182
|
+
State,
|
|
183
|
+
ScreenOptions,
|
|
184
|
+
EventMap,
|
|
185
|
+
NavigationList
|
|
186
|
+
>;
|
|
144
187
|
};
|
|
145
188
|
|
|
146
|
-
export type StaticConfig<
|
|
189
|
+
export type StaticConfig<Bag extends NavigatorTypeBagBase> =
|
|
190
|
+
StaticConfigInternal<
|
|
191
|
+
Bag['ParamList'],
|
|
192
|
+
Bag['NavigatorID'],
|
|
193
|
+
Bag['State'],
|
|
194
|
+
Bag['ScreenOptions'],
|
|
195
|
+
Bag['EventMap'],
|
|
196
|
+
Bag['NavigationList'],
|
|
197
|
+
Bag['Navigator']
|
|
198
|
+
>;
|
|
199
|
+
|
|
200
|
+
type StaticConfigInternal<
|
|
147
201
|
ParamList extends ParamListBase,
|
|
202
|
+
NavigatorID extends string | undefined,
|
|
148
203
|
State extends NavigationState,
|
|
149
204
|
ScreenOptions extends {},
|
|
150
205
|
EventMap extends EventMapBase,
|
|
151
|
-
|
|
206
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
207
|
+
Navigator extends React.ComponentType<any>,
|
|
152
208
|
> = Omit<
|
|
153
209
|
Omit<
|
|
154
210
|
React.ComponentProps<Navigator>,
|
|
155
211
|
keyof DefaultNavigatorOptions<
|
|
156
212
|
ParamListBase,
|
|
213
|
+
string | undefined,
|
|
157
214
|
NavigationState,
|
|
158
215
|
{},
|
|
159
|
-
EventMapBase
|
|
216
|
+
EventMapBase,
|
|
217
|
+
NavigationList[keyof ParamList]
|
|
160
218
|
>
|
|
161
219
|
> &
|
|
162
|
-
DefaultNavigatorOptions<
|
|
220
|
+
DefaultNavigatorOptions<
|
|
221
|
+
ParamList,
|
|
222
|
+
NavigatorID,
|
|
223
|
+
State,
|
|
224
|
+
ScreenOptions,
|
|
225
|
+
EventMap,
|
|
226
|
+
NavigationList[keyof ParamList]
|
|
227
|
+
>,
|
|
163
228
|
'screens' | 'children'
|
|
164
229
|
> &
|
|
165
230
|
(
|
|
@@ -167,12 +232,24 @@ export type StaticConfig<
|
|
|
167
232
|
/**
|
|
168
233
|
* Screens to render in the navigator and their configuration.
|
|
169
234
|
*/
|
|
170
|
-
screens: StaticConfigScreens<
|
|
235
|
+
screens: StaticConfigScreens<
|
|
236
|
+
ParamList,
|
|
237
|
+
State,
|
|
238
|
+
ScreenOptions,
|
|
239
|
+
EventMap,
|
|
240
|
+
NavigationList
|
|
241
|
+
>;
|
|
171
242
|
/**
|
|
172
243
|
* Groups of screens to render in the navigator and their configuration.
|
|
173
244
|
*/
|
|
174
245
|
groups?: {
|
|
175
|
-
[key: string]: GroupConfig<
|
|
246
|
+
[key: string]: GroupConfig<
|
|
247
|
+
ParamList,
|
|
248
|
+
State,
|
|
249
|
+
ScreenOptions,
|
|
250
|
+
EventMap,
|
|
251
|
+
NavigationList
|
|
252
|
+
>;
|
|
176
253
|
};
|
|
177
254
|
}
|
|
178
255
|
| {
|
|
@@ -183,13 +260,20 @@ export type StaticConfig<
|
|
|
183
260
|
ParamList,
|
|
184
261
|
State,
|
|
185
262
|
ScreenOptions,
|
|
186
|
-
EventMap
|
|
263
|
+
EventMap,
|
|
264
|
+
NavigationList
|
|
187
265
|
>;
|
|
188
266
|
/**
|
|
189
267
|
* Groups of screens to render in the navigator and their configuration.
|
|
190
268
|
*/
|
|
191
269
|
groups: {
|
|
192
|
-
[key: string]: GroupConfig<
|
|
270
|
+
[key: string]: GroupConfig<
|
|
271
|
+
ParamList,
|
|
272
|
+
State,
|
|
273
|
+
ScreenOptions,
|
|
274
|
+
EventMap,
|
|
275
|
+
NavigationList
|
|
276
|
+
>;
|
|
193
277
|
};
|
|
194
278
|
}
|
|
195
279
|
);
|
|
@@ -227,13 +311,7 @@ export type StaticNavigation<NavigatorProps, GroupProps, ScreenProps> = {
|
|
|
227
311
|
Navigator: React.ComponentType<NavigatorProps>;
|
|
228
312
|
Group: React.ComponentType<GroupProps>;
|
|
229
313
|
Screen: React.ComponentType<ScreenProps>;
|
|
230
|
-
config: StaticConfig<
|
|
231
|
-
ParamListBase,
|
|
232
|
-
NavigationState,
|
|
233
|
-
{},
|
|
234
|
-
EventMapBase,
|
|
235
|
-
React.ComponentType<any>
|
|
236
|
-
>;
|
|
314
|
+
config: StaticConfig<NavigatorTypeBagBase>;
|
|
237
315
|
};
|
|
238
316
|
|
|
239
317
|
const MemoizedScreen = React.memo(
|
|
@@ -247,7 +325,7 @@ const MemoizedScreen = React.memo(
|
|
|
247
325
|
|
|
248
326
|
const getItemsFromScreens = (
|
|
249
327
|
Screen: React.ComponentType<any>,
|
|
250
|
-
screens: StaticConfigScreens<any, any, any, any>
|
|
328
|
+
screens: StaticConfigScreens<any, any, any, any, any>
|
|
251
329
|
) => {
|
|
252
330
|
return Object.entries(screens).map(([name, item]) => {
|
|
253
331
|
let component: React.ComponentType<any> | undefined;
|
|
@@ -387,7 +465,8 @@ export function createPathConfigForStaticNavigation(tree: {
|
|
|
387
465
|
ParamListBase,
|
|
388
466
|
NavigationState,
|
|
389
467
|
{},
|
|
390
|
-
EventMapBase
|
|
468
|
+
EventMapBase,
|
|
469
|
+
Record<string, unknown>
|
|
391
470
|
>;
|
|
392
471
|
groups?: {
|
|
393
472
|
[key: string]: {
|
|
@@ -395,7 +474,8 @@ export function createPathConfigForStaticNavigation(tree: {
|
|
|
395
474
|
ParamListBase,
|
|
396
475
|
NavigationState,
|
|
397
476
|
{},
|
|
398
|
-
EventMapBase
|
|
477
|
+
EventMapBase,
|
|
478
|
+
Record<string, unknown>
|
|
399
479
|
>;
|
|
400
480
|
};
|
|
401
481
|
};
|
|
@@ -406,7 +486,8 @@ export function createPathConfigForStaticNavigation(tree: {
|
|
|
406
486
|
ParamListBase,
|
|
407
487
|
NavigationState,
|
|
408
488
|
{},
|
|
409
|
-
EventMapBase
|
|
489
|
+
EventMapBase,
|
|
490
|
+
Record<string, unknown>
|
|
410
491
|
>
|
|
411
492
|
) {
|
|
412
493
|
return Object.fromEntries(
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { NavigationState, ParamListBase } from '@react-navigation/routers';
|
|
2
1
|
import type * as React from 'react';
|
|
3
2
|
|
|
4
3
|
import { Group } from './Group';
|
|
5
4
|
import { Screen } from './Screen';
|
|
6
|
-
import type { StaticConfig } from './StaticNavigation';
|
|
7
|
-
import type { EventMapBase, TypedNavigator } from './types';
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Higher order component to create a `Navigator` and `Screen` pair.
|
|
@@ -13,39 +10,7 @@ import type { EventMapBase, TypedNavigator } from './types';
|
|
|
13
10
|
* @param Navigator The navigator component to wrap.
|
|
14
11
|
* @returns Factory method to create a `Navigator` and `Screen` pair.
|
|
15
12
|
*/
|
|
16
|
-
export function createNavigatorFactory<
|
|
17
|
-
State extends NavigationState,
|
|
18
|
-
ScreenOptions extends {},
|
|
19
|
-
EventMap extends EventMapBase,
|
|
20
|
-
NavigatorComponent extends React.ComponentType<any>,
|
|
21
|
-
>(Navigator: NavigatorComponent) {
|
|
22
|
-
function createNavigator<ParamList extends ParamListBase>(): TypedNavigator<
|
|
23
|
-
ParamList,
|
|
24
|
-
State,
|
|
25
|
-
ScreenOptions,
|
|
26
|
-
EventMap,
|
|
27
|
-
typeof Navigator
|
|
28
|
-
>;
|
|
29
|
-
|
|
30
|
-
function createNavigator<
|
|
31
|
-
ParamList extends ParamListBase,
|
|
32
|
-
Config extends StaticConfig<
|
|
33
|
-
ParamList,
|
|
34
|
-
State,
|
|
35
|
-
ScreenOptions,
|
|
36
|
-
EventMap,
|
|
37
|
-
typeof Navigator
|
|
38
|
-
>,
|
|
39
|
-
>(
|
|
40
|
-
config: Config
|
|
41
|
-
): TypedNavigator<
|
|
42
|
-
ParamList,
|
|
43
|
-
State,
|
|
44
|
-
ScreenOptions,
|
|
45
|
-
EventMap,
|
|
46
|
-
typeof Navigator
|
|
47
|
-
> & { config: Config };
|
|
48
|
-
|
|
13
|
+
export function createNavigatorFactory(Navigator: React.ComponentType<any>) {
|
|
49
14
|
function createNavigator(config?: any): any {
|
|
50
15
|
if (config != null) {
|
|
51
16
|
return {
|
package/src/getStateFromPath.tsx
CHANGED
|
@@ -302,11 +302,13 @@ const matchAgainstConfigs = (remaining: string, configs: RouteConfig[]) => {
|
|
|
302
302
|
const decodedParamSegment = decodeURIComponent(
|
|
303
303
|
// The param segments appear every second item starting from 2 in the regex match result
|
|
304
304
|
match![(acc.pos + 1) * 2]
|
|
305
|
+
// Remove trailing slash
|
|
306
|
+
.replace(/\/$/, '')
|
|
305
307
|
);
|
|
306
308
|
|
|
307
309
|
Object.assign(acc.matchedParams, {
|
|
308
310
|
[p]: Object.assign(acc.matchedParams[p] || {}, {
|
|
309
|
-
[index]: decodedParamSegment
|
|
311
|
+
[index]: decodedParamSegment,
|
|
310
312
|
}),
|
|
311
313
|
});
|
|
312
314
|
|
package/src/index.tsx
CHANGED
package/src/types.tsx
CHANGED
|
@@ -24,15 +24,12 @@ type Keyof<T extends {}> = Extract<keyof T, string>;
|
|
|
24
24
|
|
|
25
25
|
export type DefaultNavigatorOptions<
|
|
26
26
|
ParamList extends ParamListBase,
|
|
27
|
+
NavigatorID extends string | undefined,
|
|
27
28
|
State extends NavigationState,
|
|
28
29
|
ScreenOptions extends {},
|
|
29
30
|
EventMap extends EventMapBase,
|
|
31
|
+
Navigation,
|
|
30
32
|
> = DefaultRouterOptions<Keyof<ParamList>> & {
|
|
31
|
-
/**
|
|
32
|
-
* Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.
|
|
33
|
-
*/
|
|
34
|
-
id?: string;
|
|
35
|
-
|
|
36
33
|
/**
|
|
37
34
|
* Children React Elements to extract the route configuration from.
|
|
38
35
|
* Only `Screen`, `Group` and `React.Fragment` are supported as children.
|
|
@@ -71,7 +68,7 @@ export type DefaultNavigatorOptions<
|
|
|
71
68
|
| ScreenListeners<State, EventMap>
|
|
72
69
|
| ((props: {
|
|
73
70
|
route: RouteProp<ParamList>;
|
|
74
|
-
navigation:
|
|
71
|
+
navigation: Navigation;
|
|
75
72
|
}) => ScreenListeners<State, EventMap>);
|
|
76
73
|
|
|
77
74
|
/**
|
|
@@ -81,7 +78,7 @@ export type DefaultNavigatorOptions<
|
|
|
81
78
|
| ScreenOptions
|
|
82
79
|
| ((props: {
|
|
83
80
|
route: RouteProp<ParamList>;
|
|
84
|
-
navigation:
|
|
81
|
+
navigation: Navigation;
|
|
85
82
|
theme: ReactNavigation.Theme;
|
|
86
83
|
}) => ScreenOptions);
|
|
87
84
|
|
|
@@ -90,7 +87,7 @@ export type DefaultNavigatorOptions<
|
|
|
90
87
|
*/
|
|
91
88
|
screenLayout?: (props: {
|
|
92
89
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
93
|
-
navigation:
|
|
90
|
+
navigation: Navigation;
|
|
94
91
|
theme: ReactNavigation.Theme;
|
|
95
92
|
children: React.ReactElement;
|
|
96
93
|
}) => React.ReactElement;
|
|
@@ -98,10 +95,19 @@ export type DefaultNavigatorOptions<
|
|
|
98
95
|
/**
|
|
99
96
|
A function returning a state, which may be set after modifying the routes name.
|
|
100
97
|
*/
|
|
101
|
-
|
|
98
|
+
UNSTABLE_getStateForRouteNamesChange?: (
|
|
102
99
|
state: NavigationState
|
|
103
100
|
) => PartialState<NavigationState> | undefined;
|
|
104
|
-
}
|
|
101
|
+
} & (NavigatorID extends string
|
|
102
|
+
? {
|
|
103
|
+
/**
|
|
104
|
+
* Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.
|
|
105
|
+
*/
|
|
106
|
+
id: NavigatorID;
|
|
107
|
+
}
|
|
108
|
+
: {
|
|
109
|
+
id?: undefined;
|
|
110
|
+
});
|
|
105
111
|
|
|
106
112
|
export type EventMapBase = Record<
|
|
107
113
|
string,
|
|
@@ -602,12 +608,13 @@ export type RouteConfigComponent<
|
|
|
602
608
|
getComponent?: never;
|
|
603
609
|
};
|
|
604
610
|
|
|
605
|
-
export type
|
|
611
|
+
export type RouteConfigProps<
|
|
606
612
|
ParamList extends ParamListBase,
|
|
607
613
|
RouteName extends keyof ParamList,
|
|
608
614
|
State extends NavigationState,
|
|
609
615
|
ScreenOptions extends {},
|
|
610
616
|
EventMap extends EventMapBase,
|
|
617
|
+
Navigation,
|
|
611
618
|
> = {
|
|
612
619
|
/**
|
|
613
620
|
* Optional key for this screen. This doesn't need to be unique.
|
|
@@ -628,7 +635,7 @@ export type RouteConfig<
|
|
|
628
635
|
| ScreenOptions
|
|
629
636
|
| ((props: {
|
|
630
637
|
route: RouteProp<ParamList, RouteName>;
|
|
631
|
-
navigation:
|
|
638
|
+
navigation: Navigation;
|
|
632
639
|
theme: ReactNavigation.Theme;
|
|
633
640
|
}) => ScreenOptions);
|
|
634
641
|
|
|
@@ -639,7 +646,7 @@ export type RouteConfig<
|
|
|
639
646
|
| ScreenListeners<State, EventMap>
|
|
640
647
|
| ((props: {
|
|
641
648
|
route: RouteProp<ParamList, RouteName>;
|
|
642
|
-
navigation:
|
|
649
|
+
navigation: Navigation;
|
|
643
650
|
}) => ScreenListeners<State, EventMap>);
|
|
644
651
|
|
|
645
652
|
/**
|
|
@@ -648,8 +655,8 @@ export type RouteConfig<
|
|
|
648
655
|
* e.g. for styling, error boundaries, suspense, etc.
|
|
649
656
|
*/
|
|
650
657
|
layout?: (props: {
|
|
651
|
-
route: RouteProp<ParamList,
|
|
652
|
-
navigation:
|
|
658
|
+
route: RouteProp<ParamList, RouteName>;
|
|
659
|
+
navigation: Navigation;
|
|
653
660
|
theme: ReactNavigation.Theme;
|
|
654
661
|
children: React.ReactElement;
|
|
655
662
|
}) => React.ReactElement;
|
|
@@ -670,11 +677,29 @@ export type RouteConfig<
|
|
|
670
677
|
* Initial params object for the route.
|
|
671
678
|
*/
|
|
672
679
|
initialParams?: Partial<ParamList[RouteName]>;
|
|
673
|
-
}
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
export type RouteConfig<
|
|
683
|
+
ParamList extends ParamListBase,
|
|
684
|
+
RouteName extends keyof ParamList,
|
|
685
|
+
State extends NavigationState,
|
|
686
|
+
ScreenOptions extends {},
|
|
687
|
+
EventMap extends EventMapBase,
|
|
688
|
+
Navigation,
|
|
689
|
+
> = RouteConfigProps<
|
|
690
|
+
ParamList,
|
|
691
|
+
RouteName,
|
|
692
|
+
State,
|
|
693
|
+
ScreenOptions,
|
|
694
|
+
EventMap,
|
|
695
|
+
Navigation
|
|
696
|
+
> &
|
|
697
|
+
RouteConfigComponent<ParamList, RouteName>;
|
|
674
698
|
|
|
675
699
|
export type RouteGroupConfig<
|
|
676
700
|
ParamList extends ParamListBase,
|
|
677
701
|
ScreenOptions extends {},
|
|
702
|
+
Navigation,
|
|
678
703
|
> = {
|
|
679
704
|
/**
|
|
680
705
|
* Optional key for the screens in this group.
|
|
@@ -689,7 +714,7 @@ export type RouteGroupConfig<
|
|
|
689
714
|
| ScreenOptions
|
|
690
715
|
| ((props: {
|
|
691
716
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
692
|
-
navigation:
|
|
717
|
+
navigation: Navigation;
|
|
693
718
|
theme: ReactNavigation.Theme;
|
|
694
719
|
}) => ScreenOptions);
|
|
695
720
|
|
|
@@ -699,7 +724,7 @@ export type RouteGroupConfig<
|
|
|
699
724
|
*/
|
|
700
725
|
screenLayout?: (props: {
|
|
701
726
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
702
|
-
navigation:
|
|
727
|
+
navigation: Navigation;
|
|
703
728
|
theme: ReactNavigation.Theme;
|
|
704
729
|
children: React.ReactElement;
|
|
705
730
|
}) => React.ReactElement;
|
|
@@ -790,11 +815,77 @@ export type NavigationContainerRefWithCurrent<ParamList extends {}> =
|
|
|
790
815
|
current: NavigationContainerRef<ParamList> | null;
|
|
791
816
|
};
|
|
792
817
|
|
|
818
|
+
export type NavigationListBase<ParamList extends ParamListBase> = {
|
|
819
|
+
[RouteName in keyof ParamList]: unknown;
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
export type TypeBag<
|
|
823
|
+
ParamList extends ParamListBase,
|
|
824
|
+
NavigatorID extends string | undefined,
|
|
825
|
+
State extends NavigationState,
|
|
826
|
+
ScreenOptions extends {},
|
|
827
|
+
EventMap extends EventMapBase,
|
|
828
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
829
|
+
Navigator extends React.ComponentType<any>,
|
|
830
|
+
> = {
|
|
831
|
+
ParamList: ParamList;
|
|
832
|
+
NavigatorID: NavigatorID;
|
|
833
|
+
State: State;
|
|
834
|
+
ScreenOptions: ScreenOptions;
|
|
835
|
+
EventMap: EventMap;
|
|
836
|
+
NavigationList: NavigationList;
|
|
837
|
+
Navigator: Navigator;
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
export type NavigatorTypeBagBase = {
|
|
841
|
+
ParamList: ParamListBase;
|
|
842
|
+
NavigatorID: string | undefined;
|
|
843
|
+
State: NavigationState;
|
|
844
|
+
ScreenOptions: {};
|
|
845
|
+
EventMap: EventMapBase;
|
|
846
|
+
NavigationList: NavigationListBase<ParamListBase>;
|
|
847
|
+
Navigator: React.ComponentType<any>;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
export type NavigatorTypeBag<
|
|
851
|
+
ParamList extends ParamListBase,
|
|
852
|
+
NavigatorID extends string | undefined,
|
|
853
|
+
State extends NavigationState,
|
|
854
|
+
ScreenOptions extends {},
|
|
855
|
+
EventMap extends EventMapBase,
|
|
856
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
857
|
+
Navigator extends React.ComponentType<any>,
|
|
858
|
+
> = {
|
|
859
|
+
ParamList: ParamList;
|
|
860
|
+
NavigatorID: NavigatorID;
|
|
861
|
+
State: State;
|
|
862
|
+
ScreenOptions: ScreenOptions;
|
|
863
|
+
EventMap: EventMap;
|
|
864
|
+
NavigationList: NavigationList;
|
|
865
|
+
Navigator: Navigator;
|
|
866
|
+
};
|
|
867
|
+
|
|
793
868
|
export type TypedNavigator<
|
|
869
|
+
Bag extends NavigatorTypeBagBase,
|
|
870
|
+
Config = unknown,
|
|
871
|
+
> = TypedNavigatorInternal<
|
|
872
|
+
Bag['ParamList'],
|
|
873
|
+
Bag['NavigatorID'],
|
|
874
|
+
Bag['State'],
|
|
875
|
+
Bag['ScreenOptions'],
|
|
876
|
+
Bag['EventMap'],
|
|
877
|
+
Bag['NavigationList'],
|
|
878
|
+
Bag['Navigator']
|
|
879
|
+
> &
|
|
880
|
+
(undefined extends Config ? {} : { config: Config });
|
|
881
|
+
|
|
882
|
+
type TypedNavigatorInternal<
|
|
794
883
|
ParamList extends ParamListBase,
|
|
884
|
+
NavigatorID extends string | undefined,
|
|
795
885
|
State extends NavigationState,
|
|
796
886
|
ScreenOptions extends {},
|
|
797
887
|
EventMap extends EventMapBase,
|
|
888
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
798
889
|
Navigator extends React.ComponentType<any>,
|
|
799
890
|
> = {
|
|
800
891
|
/**
|
|
@@ -803,19 +894,35 @@ export type TypedNavigator<
|
|
|
803
894
|
Navigator: React.ComponentType<
|
|
804
895
|
Omit<
|
|
805
896
|
React.ComponentProps<Navigator>,
|
|
806
|
-
keyof DefaultNavigatorOptions<any, any, any, any>
|
|
897
|
+
keyof DefaultNavigatorOptions<any, any, any, any, any, any>
|
|
807
898
|
> &
|
|
808
|
-
DefaultNavigatorOptions<
|
|
899
|
+
DefaultNavigatorOptions<
|
|
900
|
+
ParamList,
|
|
901
|
+
NavigatorID,
|
|
902
|
+
State,
|
|
903
|
+
ScreenOptions,
|
|
904
|
+
EventMap,
|
|
905
|
+
NavigationList[keyof ParamList]
|
|
906
|
+
>
|
|
809
907
|
>;
|
|
810
908
|
/**
|
|
811
909
|
* Component used for grouping multiple route configuration.
|
|
812
910
|
*/
|
|
813
|
-
Group: React.ComponentType<
|
|
911
|
+
Group: React.ComponentType<
|
|
912
|
+
RouteGroupConfig<ParamList, ScreenOptions, NavigationList[keyof ParamList]>
|
|
913
|
+
>;
|
|
814
914
|
/**
|
|
815
915
|
* Component used for specifying route configuration.
|
|
816
916
|
*/
|
|
817
917
|
Screen: <RouteName extends keyof ParamList>(
|
|
818
|
-
_: RouteConfig<
|
|
918
|
+
_: RouteConfig<
|
|
919
|
+
ParamList,
|
|
920
|
+
RouteName,
|
|
921
|
+
State,
|
|
922
|
+
ScreenOptions,
|
|
923
|
+
EventMap,
|
|
924
|
+
NavigationList[RouteName]
|
|
925
|
+
>
|
|
819
926
|
) => null;
|
|
820
927
|
};
|
|
821
928
|
|
package/src/useDescriptors.tsx
CHANGED
|
@@ -36,7 +36,14 @@ export type ScreenConfigWithParent<
|
|
|
36
36
|
keys: (string | undefined)[];
|
|
37
37
|
options: (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined;
|
|
38
38
|
layout: ScreenLayout | undefined;
|
|
39
|
-
props: RouteConfig<
|
|
39
|
+
props: RouteConfig<
|
|
40
|
+
ParamListBase,
|
|
41
|
+
string,
|
|
42
|
+
State,
|
|
43
|
+
ScreenOptions,
|
|
44
|
+
EventMap,
|
|
45
|
+
unknown
|
|
46
|
+
>;
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
type ScreenLayout = (props: {
|
|
@@ -103,7 +103,8 @@ const getRouteConfigsFromChildren = <
|
|
|
103
103
|
string,
|
|
104
104
|
State,
|
|
105
105
|
ScreenOptions,
|
|
106
|
-
EventMap
|
|
106
|
+
EventMap,
|
|
107
|
+
unknown
|
|
107
108
|
>,
|
|
108
109
|
});
|
|
109
110
|
|
|
@@ -252,9 +253,11 @@ export function useNavigationBuilder<
|
|
|
252
253
|
createRouter: RouterFactory<State, any, RouterOptions>,
|
|
253
254
|
options: DefaultNavigatorOptions<
|
|
254
255
|
ParamListBase,
|
|
256
|
+
string | undefined,
|
|
255
257
|
State,
|
|
256
258
|
ScreenOptions,
|
|
257
|
-
EventMap
|
|
259
|
+
EventMap,
|
|
260
|
+
any
|
|
258
261
|
> &
|
|
259
262
|
RouterOptions
|
|
260
263
|
) {
|
|
@@ -471,7 +474,7 @@ export function useNavigationBuilder<
|
|
|
471
474
|
!isRecordEqual(routeKeyList, previousRouteKeyList)
|
|
472
475
|
) {
|
|
473
476
|
const navigatorStateForNextRouteNamesChange =
|
|
474
|
-
options.
|
|
477
|
+
options.UNSTABLE_getStateForRouteNamesChange?.(state);
|
|
475
478
|
// When the list of route names change, the router should handle it to remove invalid routes
|
|
476
479
|
nextState = navigatorStateForNextRouteNamesChange
|
|
477
480
|
? // @ts-expect-error this is ok
|