1 | import type { DefaultRouterOptions, InitialState, NavigationAction, NavigationState, ParamListBase, PartialState, Route } from '@react-navigation/routers';
|
2 | import type * as React from 'react';
|
3 | declare global {
|
4 | namespace ReactNavigation {
|
5 | interface RootParamList {
|
6 | }
|
7 | }
|
8 | }
|
9 | type Keyof<T extends {}> = Extract<keyof T, string>;
|
10 | export type DefaultNavigatorOptions<ParamList extends ParamListBase, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase> = DefaultRouterOptions<Keyof<ParamList>> & {
|
11 | |
12 |
|
13 |
|
14 | id?: string;
|
15 | |
16 |
|
17 |
|
18 |
|
19 | children: React.ReactNode;
|
20 | |
21 |
|
22 |
|
23 | screenListeners?: ScreenListeners<State, EventMap> | ((props: {
|
24 | route: RouteProp<ParamList>;
|
25 | navigation: any;
|
26 | }) => ScreenListeners<State, EventMap>);
|
27 | |
28 |
|
29 |
|
30 | screenOptions?: ScreenOptions | ((props: {
|
31 | route: RouteProp<ParamList>;
|
32 | navigation: any;
|
33 | }) => ScreenOptions);
|
34 | };
|
35 | export type EventMapBase = Record<string, {
|
36 | data?: any;
|
37 | canPreventDefault?: boolean;
|
38 | }>;
|
39 | export type EventMapCore<State extends NavigationState> = {
|
40 | focus: {
|
41 | data: undefined;
|
42 | };
|
43 | blur: {
|
44 | data: undefined;
|
45 | };
|
46 | state: {
|
47 | data: {
|
48 | state: State;
|
49 | };
|
50 | };
|
51 | beforeRemove: {
|
52 | data: {
|
53 | action: NavigationAction;
|
54 | };
|
55 | canPreventDefault: true;
|
56 | };
|
57 | };
|
58 | export type EventArg<EventName extends string, CanPreventDefault extends boolean | undefined = false, Data = undefined> = {
|
59 | |
60 |
|
61 |
|
62 | readonly type: EventName;
|
63 | readonly target?: string;
|
64 | } & (CanPreventDefault extends true ? {
|
65 | |
66 |
|
67 |
|
68 | readonly defaultPrevented: boolean;
|
69 | |
70 |
|
71 |
|
72 | preventDefault(): void;
|
73 | } : {}) & (undefined extends Data ? {
|
74 | readonly data?: Readonly<Data>;
|
75 | } : {
|
76 | readonly data: Readonly<Data>;
|
77 | });
|
78 | export type EventListenerCallback<EventMap extends EventMapBase, EventName extends keyof EventMap> = (e: EventArg<Extract<EventName, string>, EventMap[EventName]['canPreventDefault'], EventMap[EventName]['data']>) => void;
|
79 | export type EventConsumer<EventMap extends EventMapBase> = {
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | addListener<EventName extends Keyof<EventMap>>(type: EventName, callback: EventListenerCallback<EventMap, EventName>): () => void;
|
87 | removeListener<EventName extends Keyof<EventMap>>(type: EventName, callback: EventListenerCallback<EventMap, EventName>): void;
|
88 | };
|
89 | export type EventEmitter<EventMap extends EventMapBase> = {
|
90 | |
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | emit<EventName extends Keyof<EventMap>>(options: {
|
99 | type: EventName;
|
100 | target?: string;
|
101 | } & (EventMap[EventName]['canPreventDefault'] extends true ? {
|
102 | canPreventDefault: true;
|
103 | } : {}) & (undefined extends EventMap[EventName]['data'] ? {
|
104 | data?: EventMap[EventName]['data'];
|
105 | } : {
|
106 | data: EventMap[EventName]['data'];
|
107 | })): EventArg<EventName, EventMap[EventName]['canPreventDefault'], EventMap[EventName]['data']>;
|
108 | };
|
109 | export declare class PrivateValueStore<T extends [any, any, any]> {
|
110 | |
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | protected ''?: T;
|
121 | }
|
122 | type NavigationHelpersCommon<ParamList extends ParamListBase, State extends NavigationState = NavigationState> = {
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | dispatch(action: NavigationAction | ((state: State) => NavigationAction)): void;
|
130 | /**
|
131 | * Navigate to a route in current navigation tree.
|
132 | *
|
133 | * @param name Name of the route to navigate to.
|
134 | * @param [params] Params object for the route.
|
135 | */
|
136 | navigate<RouteName extends keyof ParamList>(...args: RouteName extends unknown ? undefined extends ParamList[RouteName] ? [screen: RouteName] | [screen: RouteName, params: ParamList[RouteName]] : [screen: RouteName, params: ParamList[RouteName]] : never): void;
|
137 | /**
|
138 | * Navigate to a route in current navigation tree.
|
139 | *
|
140 | * @param route Object with `key` or `name` for the route to navigate to, and a `params` object.
|
141 | */
|
142 | navigate<RouteName extends keyof ParamList>(options: RouteName extends unknown ? {
|
143 | key: string;
|
144 | params?: ParamList[RouteName];
|
145 | merge?: boolean;
|
146 | } | {
|
147 | name: RouteName;
|
148 | key?: string;
|
149 | params: ParamList[RouteName];
|
150 | merge?: boolean;
|
151 | } : never): void;
|
152 | /**
|
153 | * Reset the navigation state to the provided state.
|
154 | *
|
155 | * @param state Navigation state object.
|
156 | */
|
157 | reset(state: PartialState<State> | State): void;
|
158 | /**
|
159 | * Go back to the previous route in history.
|
160 | */
|
161 | goBack(): void;
|
162 | /**
|
163 | * Check if the screen is focused. The method returns `true` if focused, `false` otherwise.
|
164 | * Note that this method doesn't re-render screen when the focus changes. So don't use it in `render`.
|
165 | * To get notified of focus changes, use `addListener('focus', cb)` and `addListener('blur', cb)`.
|
166 | * To conditionally render content based on focus state, use the `useIsFocused` hook.
|
167 | */
|
168 | isFocused(): boolean;
|
169 | /**
|
170 | * Check if dispatching back action will be handled by navigation.
|
171 | * Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.
|
172 | */
|
173 | canGoBack(): boolean;
|
174 | /**
|
175 | * Returns the name of the navigator specified in the `name` prop.
|
176 | * If no name is specified, returns `undefined`.
|
177 | */
|
178 | getId(): string | undefined;
|
179 | /**
|
180 | * Returns the navigation helpers from a parent navigator based on the ID.
|
181 | * If an ID is provided, the navigation helper from the parent navigator with matching ID (including current) will be returned.
|
182 | * If no ID is provided, the navigation helper from the immediate parent navigator will be returned.
|
183 | *
|
184 | * @param id Optional ID of a parent navigator.
|
185 | */
|
186 | getParent<T = NavigationHelpers<ParamListBase> | undefined>(id?: string): T;
|
187 | /**
|
188 | * Returns the navigator's state.
|
189 | * Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.
|
190 | */
|
191 | getState(): State;
|
192 | } & PrivateValueStore<[ParamList, unknown, unknown]>;
|
193 | export type NavigationHelpers<ParamList extends ParamListBase, EventMap extends EventMapBase = {}> = NavigationHelpersCommon<ParamList> & EventEmitter<EventMap> & {
|
194 | /**
|
195 | * Update the param object for the route.
|
196 | * The new params will be shallow merged with the old one.
|
197 | *
|
198 | * @param params Params object for the current route.
|
199 | */
|
200 | setParams<RouteName extends keyof ParamList>(params: Partial<ParamList[RouteName]>): void;
|
201 | };
|
202 | export type NavigationContainerProps = {
|
203 | /**
|
204 | * Initial navigation state for the child navigators.
|
205 | */
|
206 | initialState?: InitialState;
|
207 | /**
|
208 | * Callback which is called with the latest navigation state when it changes.
|
209 | */
|
210 | onStateChange?: (state: NavigationState | undefined) => void;
|
211 | |
212 |
|
213 |
|
214 | onUnhandledAction?: (action: NavigationAction) => void;
|
215 | |
216 |
|
217 |
|
218 |
|
219 |
|
220 | independent?: boolean;
|
221 | |
222 |
|
223 |
|
224 | children: React.ReactNode;
|
225 | };
|
226 | export type NavigationProp<ParamList extends {}, RouteName extends keyof ParamList = Keyof<ParamList>, NavigatorID extends string | undefined = undefined, State extends NavigationState = NavigationState<ParamList>, ScreenOptions extends {} = {}, EventMap extends EventMapBase = {}> = Omit<NavigationHelpersCommon<ParamList, State>, 'getParent'> & {
|
227 | |
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 | getParent<T = NavigationProp<ParamListBase> | undefined>(id?: NavigatorID): T;
|
235 | |
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 | setParams(params: ParamList[RouteName] extends undefined ? undefined : Partial<ParamList[RouteName]>): void;
|
242 | |
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | setOptions(options: Partial<ScreenOptions>): void;
|
249 | } & EventConsumer<EventMap & EventMapCore<State>> & PrivateValueStore<[ParamList, RouteName, EventMap]>;
|
250 | export type RouteProp<ParamList extends ParamListBase, RouteName extends keyof ParamList = Keyof<ParamList>> = Route<Extract<RouteName, string>, ParamList[RouteName]>;
|
251 | export type CompositeNavigationProp<A extends NavigationProp<ParamListBase, string, any, any, any>, B extends NavigationHelpersCommon<ParamListBase, any>> = Omit<A & B, keyof NavigationProp<any>> & NavigationProp<
|
252 |
|
253 |
|
254 |
|
255 |
|
256 | (A extends NavigationHelpersCommon<infer T> ? T : never) & (B extends NavigationHelpersCommon<infer U> ? U : never),
|
257 |
|
258 |
|
259 |
|
260 |
|
261 | A extends NavigationProp<any, infer R> ? R : string,
|
262 |
|
263 |
|
264 |
|
265 | (A extends NavigationProp<any, any, infer I> ? I : never) | (B extends NavigationProp<any, any, infer J> ? J : never),
|
266 |
|
267 |
|
268 |
|
269 | A extends NavigationProp<any, any, any, infer S> ? S : NavigationState,
|
270 |
|
271 |
|
272 |
|
273 |
|
274 | (A extends NavigationProp<any, any, any, any, infer O> ? O : {}) & (B extends NavigationProp<any, any, any, any, infer P> ? P : {}),
|
275 |
|
276 |
|
277 |
|
278 |
|
279 | A extends NavigationProp<any, any, any, any, any, infer E> ? E : {}>;
|
280 | export type CompositeScreenProps<A extends {
|
281 | navigation: NavigationProp<ParamListBase, string, string | undefined, any, any, any>;
|
282 | route: RouteProp<ParamListBase>;
|
283 | }, B extends {
|
284 | navigation: NavigationHelpersCommon<any, any>;
|
285 | }> = {
|
286 | navigation: CompositeNavigationProp<A['navigation'], B['navigation']>;
|
287 | route: A['route'];
|
288 | };
|
289 | export type Descriptor<ScreenOptions extends {}, Navigation extends NavigationProp<any, any, any, any, any, any>, Route extends RouteProp<any, any>> = {
|
290 | |
291 |
|
292 |
|
293 | render(): JSX.Element;
|
294 | |
295 |
|
296 |
|
297 | options: ScreenOptions;
|
298 | |
299 |
|
300 |
|
301 | route: Route;
|
302 | |
303 |
|
304 |
|
305 | navigation: Navigation;
|
306 | };
|
307 | export type ScreenListeners<State extends NavigationState, EventMap extends EventMapBase> = Partial<{
|
308 | [EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<EventMap, EventName>;
|
309 | }>;
|
310 | type ScreenComponentType<ParamList extends ParamListBase, RouteName extends keyof ParamList> = React.ComponentType<{
|
311 | route: RouteProp<ParamList, RouteName>;
|
312 | navigation: any;
|
313 | }> | React.ComponentType<{}>;
|
314 | export type RouteConfigComponent<ParamList extends ParamListBase, RouteName extends keyof ParamList> = {
|
315 | |
316 |
|
317 |
|
318 | component: ScreenComponentType<ParamList, RouteName>;
|
319 | getComponent?: never;
|
320 | children?: never;
|
321 | } | {
|
322 | |
323 |
|
324 |
|
325 | getComponent: () => ScreenComponentType<ParamList, RouteName>;
|
326 | component?: never;
|
327 | children?: never;
|
328 | } | {
|
329 | |
330 |
|
331 |
|
332 | children: (props: {
|
333 | route: RouteProp<ParamList, RouteName>;
|
334 | navigation: any;
|
335 | }) => React.ReactNode;
|
336 | component?: never;
|
337 | getComponent?: never;
|
338 | };
|
339 | export type RouteConfig<ParamList extends ParamListBase, RouteName extends keyof ParamList, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase> = {
|
340 | |
341 |
|
342 |
|
343 |
|
344 |
|
345 | navigationKey?: string;
|
346 | |
347 |
|
348 |
|
349 | name: RouteName;
|
350 | |
351 |
|
352 |
|
353 | options?: ScreenOptions | ((props: {
|
354 | route: RouteProp<ParamList, RouteName>;
|
355 | navigation: any;
|
356 | }) => ScreenOptions);
|
357 | |
358 |
|
359 |
|
360 | listeners?: ScreenListeners<State, EventMap> | ((props: {
|
361 | route: RouteProp<ParamList, RouteName>;
|
362 | navigation: any;
|
363 | }) => ScreenListeners<State, EventMap>);
|
364 | |
365 |
|
366 |
|
367 |
|
368 |
|
369 |
|
370 | getId?: ({ params }: {
|
371 | params: ParamList[RouteName];
|
372 | }) => string | undefined;
|
373 | |
374 |
|
375 |
|
376 | initialParams?: Partial<ParamList[RouteName]>;
|
377 | } & RouteConfigComponent<ParamList, RouteName>;
|
378 | export type RouteGroupConfig<ParamList extends ParamListBase, ScreenOptions extends {}> = {
|
379 | |
380 |
|
381 |
|
382 |
|
383 | navigationKey?: string;
|
384 | |
385 |
|
386 |
|
387 | screenOptions?: ScreenOptions | ((props: {
|
388 | route: RouteProp<ParamList, keyof ParamList>;
|
389 | navigation: any;
|
390 | }) => ScreenOptions);
|
391 | |
392 |
|
393 |
|
394 |
|
395 | children: React.ReactNode;
|
396 | };
|
397 | export type NavigationContainerEventMap = {
|
398 | |
399 |
|
400 |
|
401 | state: {
|
402 | data: {
|
403 | |
404 |
|
405 |
|
406 | state: NavigationState | PartialState<NavigationState> | undefined;
|
407 | };
|
408 | };
|
409 | |
410 |
|
411 |
|
412 | options: {
|
413 | data: {
|
414 | options: object;
|
415 | };
|
416 | };
|
417 | |
418 |
|
419 |
|
420 |
|
421 |
|
422 | __unsafe_action__: {
|
423 | data: {
|
424 | |
425 |
|
426 |
|
427 | action: NavigationAction;
|
428 | |
429 |
|
430 |
|
431 | noop: boolean;
|
432 | |
433 |
|
434 |
|
435 | stack: string | undefined;
|
436 | };
|
437 | };
|
438 | };
|
439 | export type NavigationContainerRef<ParamList extends {}> = NavigationHelpers<ParamList> & EventConsumer<NavigationContainerEventMap> & {
|
440 | |
441 |
|
442 |
|
443 |
|
444 |
|
445 | resetRoot(state?: PartialState<NavigationState> | NavigationState): void;
|
446 | |
447 |
|
448 |
|
449 | getRootState(): NavigationState;
|
450 | |
451 |
|
452 |
|
453 | getCurrentRoute(): Route<string> | undefined;
|
454 | |
455 |
|
456 |
|
457 | getCurrentOptions(): object | undefined;
|
458 | |
459 |
|
460 |
|
461 | isReady(): boolean;
|
462 | };
|
463 | export type NavigationContainerRefWithCurrent<ParamList extends {}> = NavigationContainerRef<ParamList> & {
|
464 | current: NavigationContainerRef<ParamList> | null;
|
465 | };
|
466 | export type TypedNavigator<ParamList extends ParamListBase, State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase, Navigator extends React.ComponentType<any>> = {
|
467 | |
468 |
|
469 |
|
470 | Navigator: React.ComponentType<Omit<React.ComponentProps<Navigator>, keyof DefaultNavigatorOptions<any, any, any, any>> & DefaultNavigatorOptions<ParamList, State, ScreenOptions, EventMap>>;
|
471 | |
472 |
|
473 |
|
474 | Group: React.ComponentType<RouteGroupConfig<ParamList, ScreenOptions>>;
|
475 | |
476 |
|
477 |
|
478 | Screen: <RouteName extends keyof ParamList>(_: RouteConfig<ParamList, RouteName, State, ScreenOptions, EventMap>) => null;
|
479 | };
|
480 | export type NavigatorScreenParams<ParamList, State extends NavigationState = NavigationState> = {
|
481 | screen?: never;
|
482 | params?: never;
|
483 | initial?: never;
|
484 | path?: string;
|
485 | state: PartialState<State> | State | undefined;
|
486 | } | {
|
487 | [RouteName in keyof ParamList]: undefined extends ParamList[RouteName] ? {
|
488 | screen: RouteName;
|
489 | params?: ParamList[RouteName];
|
490 | initial?: boolean;
|
491 | path?: string;
|
492 | state?: never;
|
493 | } : {
|
494 | screen: RouteName;
|
495 | params: ParamList[RouteName];
|
496 | initial?: boolean;
|
497 | path?: string;
|
498 | state?: never;
|
499 | };
|
500 | }[keyof ParamList];
|
501 | export type PathConfig<ParamList extends {}> = {
|
502 | path?: string;
|
503 | exact?: boolean;
|
504 | parse?: Record<string, (value: string) => any>;
|
505 | stringify?: Record<string, (value: any) => string>;
|
506 | screens?: PathConfigMap<ParamList>;
|
507 | initialRouteName?: keyof ParamList;
|
508 | };
|
509 | export type PathConfigMap<ParamList extends {}> = {
|
510 | [RouteName in keyof ParamList]?: NonNullable<ParamList[RouteName]> extends NavigatorScreenParams<infer T extends {}> ? string | PathConfig<T> : string | Omit<PathConfig<{}>, 'screens' | 'initialRouteName'>;
|
511 | };
|
512 | export {};
|
513 |
|
\ | No newline at end of file |