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