UNPKG

29.9 kBTypeScriptView Raw
1// Type definitions for react-navigation 3.0.0
2// Project: https://github.com/react-navigation/react-navigation
3// Definitions by: Huhuanming <https://github.com/huhuanming>
4// mhcgrq <https://github.com/mhcgrq>
5// fangpenlin <https://github.com/fangpenlin>
6// petejkim <https://github.com/petejkim>
7// Kyle Roach <https://github.com/iRoachie>
8// phanalpha <https://github.com/phanalpha>
9// charlesfamu <https://github.com/charlesfamu>
10// Tim Wang <https://github.com/timwangdev>
11// Qibang Sun <https://github.com/bang88>
12// Sergei Butko: <https://github.com/svbutko>
13// Veit Lehmann: <https://github.com/levito>
14// Steven Miller <https://github.com/YourGamesBeOver>
15// Armando Assuncao <https://github.com/ArmandoAssuncao>
16// Ciaran Liedeman <https://github.com/cliedeman>
17// Edward Sammut Alessi <https://github.com/Slessi>
18// Jérémy Magrin <https://github.com/magrinj>
19// Luca Campana <https://github.com/TizioFittizio>
20// Ullrich Schaefer <https://github.com/stigi>
21// Linus Unnebäck <https://github.com/LinusU>
22// Yosuke Seki <https://github.com/jshosomichi>
23// Jake <https://github.com/jakebooyah>
24// Gustavo Brunoro <https://github.com/brunoro>
25// Denis Frezzato <https://github.com/DenisFrezzato>
26// Mickael Wegerich <https://github.com/mickaelw>
27// Max Davidson <https://github.com/maxdavidson>
28// Lachlan Young <https://github.com/builtbyproxy>
29// Jason Killian <https://github.com/jkillian>
30// Jan Hesters <https://github.com/janhesters>
31// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
32// TypeScript Version: 2.8
33
34declare module 'react-navigation' {
35 import * as React from 'react';
36
37 import {
38 Animated,
39 Text,
40 TextInput,
41 StatusBar,
42 TextStyle,
43 ViewProps,
44 ViewStyle,
45 StyleProp,
46 } from 'react-native';
47
48 // re-export Scrollables
49 // @todo: should we re-export from RNGH? not currently exposed through it
50 export { FlatList, SectionList, ScrollView } from 'react-native';
51
52 // @todo - any..
53 export function getActiveChildNavigationOptions<S>(
54 navigation: NavigationProp<S>,
55 screenProps?: unknown,
56 theme?: SupportedThemes
57 ): NavigationParams;
58
59 // @todo when we split types into common, native and web,
60 // we can properly change Animated.Value to its real value
61 export type AnimatedValue = any;
62
63 /**
64 * NavigationState is a tree of routes for a single navigator, where each child
65 * route may either be a NavigationScreenRoute or a NavigationRouterRoute.
66 * NavigationScreenRoute represents a leaf screen, while the
67 * NavigationRouterRoute represents the state of a child navigator.
68 *
69 * NOTE: NavigationState is a state tree local to a single navigator and
70 * its child navigators (via the routes field).
71 * If we're in navigator nested deep inside the app, the state will only be the
72 * state for that navigator.
73 * The state for the root navigator of our app represents the whole navigation
74 * state for the whole app.
75 */
76 export interface NavigationState {
77 /**
78 * Index refers to the active child route in the routes array.
79 */
80 index: number;
81 routes: NavigationRoute[];
82 isTransitioning: boolean;
83 key: string;
84 params?: NavigationParams | undefined;
85 }
86
87 export interface DrawerNavigationState extends NavigationState {
88 isDrawerOpen: boolean;
89 isTransitioning: boolean;
90 }
91
92 export type NavigationRoute<Params = NavigationParams> =
93 | NavigationLeafRoute<Params>
94 | NavigationStateRoute<Params>;
95
96 export interface NavigationLeafRoute<Params = NavigationParams> {
97 /**
98 * React's key used by some navigators. No need to specify these manually,
99 * they will be defined by the router.
100 */
101 key: string;
102 /**
103 * Index that represents the depth of the stack
104 */
105 index: number;
106 /**
107 * For example 'Home'.
108 * This is used as a key in a route config when creating a navigator.
109 */
110 routeName: string;
111 /**
112 * Path is an advanced feature used for deep linking and on the web.
113 */
114 path?: string;
115 /**
116 * Params passed to this route when navigating to it,
117 * e.g. `{ car_id: 123 }` in a route that displays a car.
118 */
119 params?: Params;
120 /**
121 * Array containing the navigator's routes
122 */
123 routes: NavigationRoute[];
124 /**
125 * Flag that indicates the transition state of the route
126 */
127 isTransitioning: boolean;
128 }
129
130 export type NavigationStateRoute<
131 NavigationLeafRouteParams
132 > = NavigationLeafRoute<NavigationLeafRouteParams> & NavigationState;
133
134 export type NavigationScreenOptionsGetter<Options> = (
135 navigation: NavigationScreenProp<NavigationRoute<any>>,
136 screenProps: unknown | null,
137 theme: SupportedThemes
138 ) => Options;
139
140 export interface NavigationRouter<State = NavigationState, Options = {}> {
141 /**
142 * The reducer that outputs the new navigation state for a given action, with
143 * an optional previous state. When the action is considered handled but the
144 * state is unchanged, the output state is null.
145 */
146 getStateForAction: (
147 action: NavigationAction,
148 lastState?: State
149 ) => State | null;
150
151 /**
152 * Maps a URI-like string to an action. This can be mapped to a state
153 * using `getStateForAction`.
154 */
155 getActionForPathAndParams: (
156 path: string,
157 params?: NavigationParams
158 ) => NavigationAction | null;
159
160 getPathAndParamsForState: (
161 state: State
162 ) => {
163 path: string;
164 params?: NavigationParams;
165 };
166
167 getComponentForRouteName: (
168 routeName: string
169 ) => NavigationComponent<{}, NavigationScreenProp<NavigationRoute>>;
170
171 getComponentForState: (
172 state: State
173 ) => NavigationComponent<{}, NavigationScreenProp<NavigationRoute>>;
174
175 getActionCreators: (
176 route: NavigationRoute,
177 key: string
178 ) => {
179 [key: string]: () => NavigationAction;
180 };
181
182 /**
183 * Gets the screen navigation options for a given screen.
184 *
185 * For example, we could get the config for the 'Foo' screen when the
186 * `navigation.state` is:
187 *
188 * {routeName: 'Foo', key: '123'}
189 */
190 getScreenOptions: NavigationScreenOptionsGetter<Options>;
191 }
192
193 export type NavigationScreenComponent<
194 Options,
195 NavigationScreenPropType
196 > = React.ComponentType<any> & {
197 navigationOptions?: NavigationScreenConfig<
198 Options,
199 NavigationScreenPropType
200 >;
201 };
202
203 export interface NavigationScreenConfigProps<
204 NavigationScreenPropType,
205 ScreenProps = unknown
206 > {
207 navigation: NavigationScreenPropType;
208 screenProps: ScreenProps;
209 theme: SupportedThemes;
210 }
211
212 export type NavigationScreenConfig<
213 Options,
214 NavigationScreenPropType,
215 ScreenProps = unknown
216 > =
217 | Options
218 | ((
219 navigationOptionsContainer: NavigationScreenConfigProps<
220 NavigationScreenPropType,
221 ScreenProps
222 > & {
223 navigationOptions: Options;
224 }
225 ) => Options);
226
227 export type NavigationComponent<Options, NavigationPropType> =
228 | NavigationScreenComponent<Options, NavigationPropType>
229 | NavigationNavigator<Options, NavigationPropType>;
230
231 export type NavigationNavigator<
232 Options,
233 NavigationPropType
234 > = React.ComponentType<NavigationNavigatorProps<Options>> & {
235 router: NavigationRouter<Options>;
236 navigationOptions?: NavigationScreenConfig<Options, NavigationPropType>;
237 };
238
239 export interface NavigationParams {
240 [key: string]: any;
241 }
242
243 export interface NavigationNavigateActionPayload {
244 routeName: string;
245 params?: NavigationParams;
246
247 // The action to run inside the sub-router
248 action?: NavigationNavigateAction;
249
250 key?: string;
251 }
252
253 export interface NavigationNavigateAction
254 extends NavigationNavigateActionPayload {
255 type: 'Navigation/NAVIGATE';
256 }
257
258 export interface NavigationBackActionPayload {
259 key?: string | null;
260 immediate?: boolean;
261 }
262
263 export interface NavigationBackAction extends NavigationBackActionPayload {
264 type: 'Navigation/BACK';
265 }
266
267 export interface NavigationSetParamsActionPayload {
268 // The key of the route where the params should be set
269 key: string;
270
271 // The new params to merge into the existing route params
272 params?: NavigationParams;
273 }
274
275 export interface NavigationSetParamsAction
276 extends NavigationSetParamsActionPayload {
277 type: 'Navigation/SET_PARAMS';
278 }
279
280 export interface NavigationInitActionPayload {
281 params?: NavigationParams;
282 }
283
284 export interface NavigationInitAction extends NavigationInitActionPayload {
285 type: 'Navigation/INIT';
286 key?: string;
287 }
288
289 export interface NavigationReplaceActionPayload {
290 key?: string;
291 newKey?: string;
292 routeName: string;
293 params?: NavigationParams;
294 action?: NavigationNavigateAction;
295 }
296
297 export interface NavigationReplaceAction {
298 type: 'Navigation/REPLACE';
299 key: string;
300 routeName: string;
301 params?: NavigationParams;
302 action?: NavigationNavigateAction;
303 }
304
305 export interface NavigationCompleteTransitionActionPayload {
306 key?: string;
307 toChildKey?: string;
308 }
309
310 export interface NavigationCompleteTransitionAction {
311 type: 'Navigation/COMPLETE_TRANSITION';
312 key: string;
313 }
314
315 export interface NavigationResetActionPayload {
316 index: number;
317 key?: string | null;
318 actions: NavigationNavigateAction[];
319 }
320
321 export interface NavigationResetAction extends NavigationResetActionPayload {
322 type: 'Navigation/RESET';
323 }
324
325 export interface NavigationUriActionPayload {
326 uri: string;
327 }
328
329 export interface NavigationUriAction extends NavigationUriActionPayload {
330 type: 'Navigation/URI';
331 }
332
333 export interface NavigationPopActionPayload {
334 // n: the number of routes to pop of the stack
335 n?: number;
336 immediate?: boolean;
337 }
338
339 export interface NavigationPopAction extends NavigationPopActionPayload {
340 type: 'Navigation/POP';
341 key?: string;
342 }
343
344 export interface NavigationPopToTopActionPayload {
345 key?: string;
346 immediate?: boolean;
347 }
348
349 export interface NavigationPopToTopAction
350 extends NavigationPopToTopActionPayload {
351 type: 'Navigation/POP_TO_TOP';
352 }
353
354 export interface NavigationPushActionPayload {
355 routeName: string;
356 params?: NavigationParams;
357 action?: NavigationNavigateAction;
358 key?: string;
359 }
360
361 export interface NavigationPushAction {
362 type: 'Navigation/PUSH';
363 routeName: string;
364 params?: NavigationParams;
365 action?: NavigationNavigateAction;
366 key?: string;
367 }
368
369 export interface NavigationJumpToActionPayload {
370 routeName: string;
371 key?: string;
372 params?: NavigationParams;
373 }
374
375 export interface NavigationJumpToAction {
376 type: 'Navigation/JUMP_TO';
377 preserveFocus: boolean;
378 routeName: string;
379 key: string;
380 params?: NavigationParams;
381 }
382
383 export interface NavigationDrawerOpenedAction {
384 key?: string;
385 type: 'Navigation/DRAWER_OPENED';
386 }
387
388 export interface NavigationDrawerClosedAction {
389 key?: string;
390 type: 'Navigation/DRAWER_CLOSED';
391 }
392
393 export interface NavigationOpenDrawerAction {
394 key?: string;
395 type: 'Navigation/OPEN_DRAWER';
396 }
397
398 export interface NavigationCloseDrawerAction {
399 key?: string;
400 type: 'Navigation/CLOSE_DRAWER';
401 }
402
403 export interface NavigationToggleDrawerAction {
404 key?: string;
405 type: 'Navigation/TOGGLE_DRAWER';
406 }
407
408 /**
409 * Switch Navigator
410 */
411 export interface NavigationSwitchRouterConfig {
412 initialRouteName?: string;
413 initialRouteParams?: NavigationParams;
414 paths?: NavigationPathsConfig;
415 order?: string[];
416 backBehavior?: 'none' | 'initialRoute' | 'history' | 'order'; // defaults to 'none'
417 resetOnBlur?: boolean; // defaults to `true`
418 }
419
420 export function SwitchRouter(
421 routeConfigs: NavigationRouteConfigMap<any, any>,
422 config?: NavigationSwitchRouterConfig
423 ): NavigationRouter<any, any>;
424
425 export type NavigationSwitchProp<
426 State = NavigationRoute,
427 Params = NavigationParams
428 > = NavigationScreenProp<State, Params> & {
429 jumpTo(routeName: string, key?: string): void;
430 };
431
432 export type NavigationSwitchScreenProps<
433 Params = NavigationParams,
434 ScreenProps = unknown
435 > = {
436 theme: SupportedThemes;
437 navigation: NavigationSwitchProp<NavigationRoute, Params>;
438 screenProps: ScreenProps;
439 };
440
441 export type NavigationSwitchScreenComponent<
442 Params = NavigationParams,
443 ScreenProps = unknown
444 > = React.ComponentType<NavigationSwitchScreenProps<Params, ScreenProps>> & {
445 navigationOptions?: NavigationScreenConfig<
446 {},
447 NavigationSwitchProp<NavigationRoute, Params>,
448 ScreenProps
449 >;
450 };
451
452 export type NavigationStackAction =
453 | NavigationInitAction
454 | NavigationNavigateAction
455 | NavigationBackAction
456 | NavigationSetParamsAction
457 | NavigationResetAction
458 | NavigationReplaceAction
459 | NavigationPopAction
460 | NavigationPushAction
461 | NavigationPopToTopAction
462 | NavigationCompleteTransitionAction;
463
464 export type NavigationTabAction =
465 | NavigationInitAction
466 | NavigationNavigateAction
467 | NavigationBackAction;
468
469 export type NavigationDrawerAction =
470 | NavigationDrawerOpenedAction
471 | NavigationDrawerClosedAction
472 | NavigationOpenDrawerAction
473 | NavigationCloseDrawerAction
474 | NavigationToggleDrawerAction;
475
476 export type NavigationSwitchAction = NavigationJumpToAction;
477
478 export type NavigationAction =
479 | NavigationInitAction
480 | NavigationStackAction
481 | NavigationTabAction
482 | NavigationDrawerAction
483 | NavigationSwitchAction
484 | { type: 'CHILD_ACTION'; key?: string };
485
486 export type NavigationRouteConfig<Options, NavigationScreenPropType> =
487 | NavigationComponent<Options, NavigationScreenPropType>
488 | (
489 | { screen: NavigationComponent<Options, NavigationScreenPropType> }
490 | {
491 getScreen(): NavigationScreenComponent<
492 Options,
493 NavigationScreenPropType
494 >;
495 }) & {
496 navigationOptions?: NavigationScreenConfig<
497 Options,
498 NavigationScreenPropType
499 >;
500 params?: { [key: string]: any };
501 path?: string;
502 };
503
504 export interface NavigationPathsConfig {
505 [routeName: string]: string;
506 }
507
508 // tslint:disable-next-line:strict-export-declare-modifiers
509 export interface NavigationTabRouterConfig {
510 initialRouteName?: string;
511 initialRouteParams?: NavigationParams;
512 paths?: NavigationPathsConfig;
513 order?: string[]; // todo: type these as the real route names rather than 'string'
514 backBehavior?: 'none' | 'initialRoute' | 'history' | 'order'; // defaults to 'initialRoute'
515 resetOnBlur?: boolean;
516 }
517
518 export interface NavigationRouteConfigMap<Options, NavigationScreenPropType> {
519 [routeName: string]: NavigationRouteConfig<
520 Options,
521 NavigationScreenPropType
522 >;
523 }
524
525 export type NavigationDispatch = (action: NavigationAction) => boolean;
526
527 export interface NavigationProp<S> {
528 state: S;
529 dispatch: NavigationDispatch;
530 }
531
532 export type EventType =
533 | 'willFocus'
534 | 'didFocus'
535 | 'willBlur'
536 | 'didBlur'
537 | 'action';
538
539 export interface NavigationEventPayload {
540 type: EventType;
541 action: NavigationAction;
542 state: NavigationState;
543 lastState: NavigationState | null | undefined;
544 }
545
546 export type NavigationEventCallback = (
547 payload: NavigationEventPayload
548 ) => void;
549
550 export interface NavigationEventSubscription {
551 remove: () => void;
552 }
553
554 export interface NavigationEventsProps extends ViewProps {
555 onWillFocus?: NavigationEventCallback;
556 onDidFocus?: NavigationEventCallback;
557 onWillBlur?: NavigationEventCallback;
558 onDidBlur?: NavigationEventCallback;
559 }
560
561 export const NavigationEvents: React.ComponentType<NavigationEventsProps>;
562
563 export interface NavigationScreenProp<S, P = NavigationParams> {
564 state: S & { params?: P };
565 dispatch: NavigationDispatch;
566 goBack: (routeKey?: string | null) => boolean;
567 dismiss: () => boolean;
568 navigate(options: {
569 routeName:
570 | string
571 | {
572 routeName: string;
573 params?: NavigationParams;
574 action?: NavigationNavigateAction;
575 key?: string;
576 };
577 params?: NavigationParams;
578 action?: NavigationAction;
579 key?: string;
580 }): boolean;
581 navigate(
582 routeNameOrOptions: string,
583 params?: NavigationParams,
584 action?: NavigationAction
585 ): boolean;
586 openDrawer: () => any;
587 closeDrawer: () => any;
588 toggleDrawer: () => any;
589 getParam<T extends keyof P>(
590 param: T,
591 fallback: NonNullable<P[T]>
592 ): NonNullable<P[T]>;
593 getParam<T extends keyof P>(param: T): P[T];
594 setParams: (newParams: Partial<P>) => boolean;
595 emit: (eventName: 'refocus') => void;
596 addListener: (
597 eventName: string,
598 callback: NavigationEventCallback
599 ) => NavigationEventSubscription;
600 isFocused: () => boolean;
601 isFirstRouteInParent: () => boolean;
602 router?: NavigationRouter;
603 dangerouslyGetParent: () => NavigationScreenProp<S> | undefined;
604 }
605
606 export interface NavigationNavigatorProps<
607 Options = {},
608 State = {},
609 ScreenProps = unknown
610 > {
611 theme?: SupportedThemes | 'no-preference';
612 detached?: boolean;
613 navigation?: NavigationProp<State>;
614 screenProps?: ScreenProps;
615 navigationOptions?: Options;
616 }
617
618 export type NavigatorType =
619 | 'react-navigation/STACK'
620 | 'react-navigation/TABS'
621 | 'react-navigation/DRAWER';
622
623 export interface NavigationContainerProps<
624 State = {},
625 Options = {},
626 ScreenProps = unknown
627 > {
628 uriPrefix?: string | RegExp;
629 /**
630 * Controls whether the navigation container handles URLs opened via 'Linking'
631 * @see https://facebook.github.io/react-native/docs/linking
632 * @see https://reactnavigation.org/docs/en/deep-linking.html
633 */
634 enableURLHandling?: boolean; // defaults to true
635 onNavigationStateChange?: (
636 prevNavigationState: NavigationState,
637 nextNavigationState: NavigationState,
638 action: NavigationAction
639 ) => void | null | undefined;
640 navigation?: NavigationScreenProp<State>;
641 /*
642 * This prop is no longer supported. Use `loadNavigationState` and
643 * `persistNavigationState` instead.
644 */
645 persistenceKey?: string | null;
646
647 loadNavigationState?: () => Promise<any>;
648 persistNavigationState?: (state: NavigationState) => Promise<any>;
649
650 renderLoadingExperimental?: React.ComponentType;
651 screenProps?: ScreenProps;
652 navigationOptions?: Options;
653 style?: StyleProp<ViewStyle>;
654 }
655
656 export interface NavigationContainerComponent
657 extends React.Component<
658 NavigationContainerProps & NavigationNavigatorProps<any>
659 > {
660 dispatch: NavigationDispatch;
661 }
662
663 export interface NavigationContainer
664 extends React.ComponentClass<
665 NavigationContainerProps & NavigationNavigatorProps<any>
666 > {
667 new (
668 props: NavigationContainerProps & NavigationNavigatorProps<any>,
669 context?: any
670 ): NavigationContainerComponent;
671
672 router: NavigationRouter<any, any>;
673 screenProps: unknown;
674 navigationOptions: any;
675 state: { nav: NavigationState | null };
676 }
677
678 export function createSwitchNavigator(
679 routeConfigMap: NavigationRouteConfigMap<{}, NavigationSwitchProp>,
680 switchConfig?: CreateNavigatorConfig<
681 {},
682 NavigationSwitchRouterConfig,
683 {},
684 NavigationSwitchProp
685 >
686 ): NavigationNavigator<{}, NavigationProp<NavigationState>>;
687
688 /**
689 * NavigationActions
690 */
691 export namespace NavigationActions {
692 const BACK: 'Navigation/BACK';
693 const INIT: 'Navigation/INIT';
694 const NAVIGATE: 'Navigation/NAVIGATE';
695 const SET_PARAMS: 'Navigation/SET_PARAMS';
696
697 function init(options?: NavigationInitActionPayload): NavigationInitAction;
698 function navigate(
699 options: NavigationNavigateActionPayload
700 ): NavigationNavigateAction;
701 function back(options?: NavigationBackActionPayload): NavigationBackAction;
702 function setParams(
703 options: NavigationSetParamsActionPayload
704 ): NavigationSetParamsAction;
705 }
706
707 /**
708 * DrawerActions
709 */
710 export namespace DrawerActions {
711 const OPEN_DRAWER: 'Navigation/OPEN_DRAWER';
712 const CLOSE_DRAWER: 'Navigation/CLOSE_DRAWER';
713 const TOGGLE_DRAWER: 'Navigation/TOGGLE_DRAWER';
714
715 function openDrawer(): NavigationOpenDrawerAction;
716 function closeDrawer(): NavigationCloseDrawerAction;
717 function toggleDrawer(): NavigationToggleDrawerAction;
718 }
719
720 /**
721 * StackActions
722 */
723 export namespace StackActions {
724 const POP: 'Navigation/POP';
725 const POP_TO_TOP: 'Navigation/POP_TO_TOP';
726 const PUSH: 'Navigation/PUSH';
727 const RESET: 'Navigation/RESET';
728 const REPLACE: 'Navigation/REPLACE';
729 const COMPLETE_TRANSITION: 'Navigation/COMPLETE_TRANSITION';
730
731 function pop(options: NavigationPopActionPayload): NavigationPopAction;
732 function popToTop(
733 options?: NavigationPopToTopActionPayload
734 ): NavigationPopToTopAction;
735
736 function push(options: NavigationPushActionPayload): NavigationPushAction;
737 function reset(
738 options: NavigationResetActionPayload
739 ): NavigationResetAction;
740
741 function replace(
742 options: NavigationReplaceActionPayload
743 ): NavigationReplaceAction;
744
745 function completeTransition(
746 payload?: NavigationCompleteTransitionActionPayload
747 ): NavigationCompleteTransitionAction;
748 }
749
750 /**
751 * SwitchActions
752 */
753 export namespace SwitchActions {
754 const JUMP_TO: 'Navigation/JUMP_TO';
755
756 function jumpTo(
757 options: NavigationJumpToActionPayload
758 ): NavigationJumpToAction;
759 }
760
761 /**
762 * Tab Router
763 *
764 * @desc from react-navigation/src/routers/TabRouter.js
765 */
766 export function TabRouter(
767 routeConfigs: NavigationRouteConfigMap<any, any>,
768 config: NavigationTabRouterConfig
769 ): NavigationRouter<any, any>;
770
771 /**
772 * Stack Router
773 *
774 * @desc from react-navigation/src/routers/StackRouter.js
775 */
776 export function StackRouter(
777 routeConfigs: NavigationRouteConfigMap<any, any>,
778 config?: NavigationTabRouterConfig
779 ): NavigationRouter<any, any>;
780
781 export interface NavigationStackRouterConfig {
782 initialRouteName?: string;
783 initialRouteParams?: NavigationParams;
784 paths?: NavigationPathsConfig;
785 initialRouteKey?: string;
786 }
787
788 /**
789 * Create Navigator
790 *
791 * @see https://github.com/react-navigation/react-navigation/blob/master/src/navigators/createNavigator.js
792 */
793 export interface NavigationDescriptor<
794 Params = NavigationParams,
795 Options = {},
796 NavigationScreenPropType = NavigationScreenProp<NavigationRoute>
797 > {
798 key: string;
799 state: NavigationLeafRoute<Params> | NavigationStateRoute<Params>;
800 navigation: NavigationScreenPropType;
801 options: Options;
802 getComponent: () => React.ComponentType;
803 }
804
805 export type NavigationView<
806 Options,
807 State,
808 ScreenProps = unknown
809 > = React.ComponentType<
810 {
811 descriptors: { [key: string]: NavigationDescriptor };
812 navigationConfig: Options;
813 screenProps?: ScreenProps;
814 } & NavigationInjectedProps
815 >;
816
817 export type CreateNavigatorConfig<
818 NavigatorConfig,
819 RouterConfig,
820 Options,
821 NavigationScreenPropType
822 > = NavigatorConfig &
823 RouterConfig & {
824 defaultNavigationOptions?: NavigationScreenConfig<
825 Options,
826 NavigationScreenPropType
827 >;
828 navigationOptions?: NavigationScreenConfig<
829 { [key: string]: any },
830 NavigationScreenProp<NavigationRoute>
831 >;
832 };
833
834 export function createNavigator<S, Options>(
835 view: NavigationView<Options, S>,
836 router: NavigationRouter<S, Options>,
837 navigatorConfig?: {},
838 navigatorType?: NavigatorType
839 ): NavigationNavigator<Options, NavigationProp<NavigationState>>;
840
841 /**
842 * Create an HOC that injects the navigation and manages the navigation state
843 * in case it's not passed from above.
844 * This allows to use e.g. the StackNavigator and TabNavigator as root-level
845 * components.
846 *
847 * @see https://github.com/react-navigation/react-navigation/blob/master/src/createNavigationContainer.js
848 */
849 export function createNavigationContainer<Options, NavigationPropType>(
850 Component: NavigationNavigator<Options, NavigationPropType>
851 ): NavigationContainer;
852
853 /**
854 * Create an app container to wrap the root navigator
855 *
856 * @see https://github.com/react-navigation/react-navigation-native/blob/098e2e52b349d37357109d5aee545fa74699d3d4/src/createAppContainer.js#L64
857 */
858 export function createAppContainer<Options, NavigationPropType>(
859 Component: NavigationNavigator<Options, NavigationPropType>
860 ): NavigationContainer;
861
862 export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
863
864 export type InferProps<
865 T extends React.ComponentType<any>
866 > = T extends React.ComponentType<infer P> ? P : never;
867
868 export interface NavigationOrientationInjectedProps {
869 isLandscape: boolean;
870 }
871
872 export function createKeyboardAwareNavigator<Props>(
873 Comp: React.ComponentType<Props>,
874 stackConfig: object
875 ): React.ComponentType<Props>;
876
877 export function withOrientation<P extends NavigationOrientationInjectedProps>(
878 Component: React.ComponentType<P>
879 ): React.ComponentType<Omit<P, keyof NavigationOrientationInjectedProps>>;
880
881 export interface NavigationInjectedProps<P = NavigationParams> {
882 navigation: NavigationScreenProp<NavigationRoute<P>, P>;
883 }
884
885 // If the wrapped component is a class, we can get a ref to it
886 export function withNavigation<
887 P extends NavigationInjectedProps,
888 T extends React.ComponentClass<P>
889 >(
890 Component: T & React.ComponentClass<P>
891 ): React.ComponentType<
892 Omit<P, keyof NavigationInjectedProps> & {
893 onRef?: React.Ref<InstanceType<T>>;
894 }
895 >;
896
897 export function withNavigation<P extends NavigationInjectedProps>(
898 Component: React.ComponentType<P>
899 ): React.ComponentType<Omit<P, keyof NavigationInjectedProps>>;
900
901 // For backwards compatibility
902 export function withNavigation<T = {}, P = NavigationParams>(
903 Component: React.ComponentType<T & NavigationInjectedProps<P>>
904 ): React.ComponentType<
905 T & { onRef?: React.Ref<React.Component<T & NavigationInjectedProps<P>>> }
906 >;
907
908 export const NavigationProvider: React.ComponentType<{
909 value: NavigationProp<any>;
910 }>;
911
912 export interface NavigationFocusInjectedProps<P = NavigationParams>
913 extends NavigationInjectedProps<P> {
914 isFocused: boolean;
915 }
916
917 // If the wrapped component is a class, we can get a ref to it
918 export function withNavigationFocus<
919 P extends NavigationFocusInjectedProps,
920 T extends React.ComponentClass<P>
921 >(
922 Component: T & React.ComponentClass<P>
923 ): React.ComponentType<
924 Omit<P, keyof NavigationFocusInjectedProps> & {
925 onRef?: React.Ref<InstanceType<T>>;
926 }
927 >;
928
929 export function withNavigationFocus<P extends NavigationFocusInjectedProps>(
930 Component: React.ComponentType<P>
931 ): React.ComponentType<Omit<P, keyof NavigationFocusInjectedProps>>;
932
933 // For backwards compatibility
934 export function withNavigationFocus<T = {}, P = NavigationParams>(
935 Component: React.ComponentType<T & NavigationFocusInjectedProps<P>>
936 ): React.ComponentType<
937 T & {
938 onRef?: React.Ref<React.Component<T & NavigationFocusInjectedProps<P>>>;
939 }
940 >;
941
942 /**
943 * SafeAreaView Component
944 */
945 export type SafeAreaViewForceInsetValue = 'always' | 'never';
946 export interface SafeAreaViewProps extends ViewProps {
947 forceInset?: {
948 top?: SafeAreaViewForceInsetValue;
949 bottom?: SafeAreaViewForceInsetValue;
950 left?: SafeAreaViewForceInsetValue;
951 right?: SafeAreaViewForceInsetValue;
952 horizontal?: SafeAreaViewForceInsetValue;
953 vertical?: SafeAreaViewForceInsetValue;
954 };
955 children?: React.ReactNode;
956 }
957
958 export const SafeAreaView: React.ComponentClass<SafeAreaViewProps>;
959
960 export const NavigationContext: React.Context<
961 NavigationScreenProp<NavigationRoute>
962 >;
963
964 export function createKeyboardAwareNavigator<Props>(
965 Comp: React.ComponentType<Props>,
966 stackConfig: object
967 ): React.ComponentType<Props>;
968
969 /**
970 * SceneView
971 */
972
973 export interface SceneViewProps {
974 component: React.ComponentType;
975 screenProps: unknown;
976 navigation: NavigationProp<any>;
977 }
978
979 export const SceneView: React.ComponentType<SceneViewProps>;
980
981 /**
982 * Themes
983 */
984
985 // Context
986 export type SupportedThemes = 'light' | 'dark';
987 export const ThemeContext: React.Context<SupportedThemes>;
988
989 // Hooks
990 export function useTheme(): SupportedThemes;
991
992 // Colors
993 export interface Theme {
994 header: string;
995 headerBorder: string;
996 body: string;
997 bodyBorder: string;
998 bodyContent: string;
999 bodyContentBorder: string;
1000 label: string;
1001 }
1002 export const ThemeColors: { [k in SupportedThemes]: Theme };
1003
1004 // Themed components
1005 interface ThemedStatusBarProps
1006 extends React.ComponentProps<typeof StatusBar> {}
1007 interface ThemedTextProps extends React.ComponentProps<typeof Text> {}
1008 interface ThemedTextInputProps
1009 extends React.ComponentProps<typeof TextInput> {}
1010
1011 export namespace Themed {
1012 export const StatusBar: React.ComponentType<ThemedStatusBarProps>;
1013 export const Text: React.ComponentType<ThemedTextProps>;
1014 export const TextInput: React.ComponentType<ThemedTextInputProps>;
1015 }
1016}