|
1 | 1 | // @flow |
2 | 2 |
|
3 | | -declare module '@react-navigation/core' { |
| 3 | +declare module 'react-navigation' { |
4 | 4 |
|
5 | 5 | //--------------------------------------------------------------------------- |
6 | 6 | // SECTION 1: IDENTICAL TYPE DEFINITIONS |
@@ -212,9 +212,11 @@ declare module '@react-navigation/core' { |
212 | 212 | * Router |
213 | 213 | */ |
214 | 214 |
|
| 215 | + declare export type NavigationScreenProps = { [key: string]: mixed, ... }; |
| 216 | + |
215 | 217 | declare export type NavigationScreenOptionsGetter<Options: {...}> = ( |
216 | 218 | navigation: NavigationScreenProp<NavigationRoute>, |
217 | | - screenProps: ?{...}, |
| 219 | + ncreenProps: ?NavigationScreenProps, |
218 | 220 | theme: SupportedThemes, |
219 | 221 | ) => Options; |
220 | 222 |
|
@@ -260,7 +262,7 @@ declare module '@react-navigation/core' { |
260 | 262 |
|
261 | 263 | declare export type NavigationScreenConfigProps = $Shape<{| |
262 | 264 | navigation: NavigationScreenProp<NavigationRoute>, |
263 | | - screenProps: {...}, |
| 265 | + screenProps: NavigationScreenProps, |
264 | 266 | theme: SupportedThemes, |
265 | 267 | |}>; |
266 | 268 |
|
@@ -298,17 +300,15 @@ declare module '@react-navigation/core' { |
298 | 300 | withRouter<State, Options> & |
299 | 301 | withOptionalNavigationOptions<Options>; |
300 | 302 |
|
| 303 | + declare type _NavigationRouteConfigCore = {| |
| 304 | + navigationOptions?: NavigationScreenConfig<*>, |
| 305 | + params?: NavigationParams, |
| 306 | + path?: string, |
| 307 | + |}; |
301 | 308 | declare export type NavigationRouteConfig = |
302 | 309 | | NavigationComponent |
303 | | - | ({ |
304 | | - navigationOptions?: NavigationScreenConfig<*>, |
305 | | - path?: string, |
306 | | - ... |
307 | | - } & NavigationScreenRouteConfig); |
308 | | - |
309 | | - declare export type NavigationScreenRouteConfig = |
310 | | - | { screen: NavigationComponent, ... } |
311 | | - | { getScreen: () => NavigationComponent, ... }; |
| 310 | + | {| ..._NavigationRouteConfigCore, screen: NavigationComponent |} |
| 311 | + | {| ..._NavigationRouteConfigCore, getScreen: () => NavigationComponent |}; |
312 | 312 |
|
313 | 313 | declare export type NavigationRouteConfigMap = { [routeName: string]: NavigationRouteConfig, ... }; |
314 | 314 |
|
@@ -392,7 +392,7 @@ declare module '@react-navigation/core' { |
392 | 392 |
|
393 | 393 | declare export type NavigationNavigatorProps<O: {...}, S: {...}> = $Shape<{ |
394 | 394 | navigation: NavigationScreenProp<S>, |
395 | | - screenProps?: {...}, |
| 395 | + screenProps?: NavigationScreenProps, |
396 | 396 | navigationOptions?: O, |
397 | 397 | theme?: SupportedThemes | 'no-preference', |
398 | 398 | detached?: boolean, |
@@ -421,7 +421,7 @@ declare module '@react-navigation/core' { |
421 | 421 | navigation?: NavigationScreenProp<S>, |
422 | 422 | persistenceKey?: ?string, |
423 | 423 | renderLoadingExperimental?: React$ComponentType<{...}>, |
424 | | - screenProps?: *, |
| 424 | + screenProps?: NavigationScreenProps, |
425 | 425 | navigationOptions?: O, |
426 | 426 | ... |
427 | 427 | }>; |
@@ -556,8 +556,9 @@ declare module '@react-navigation/core' { |
556 | 556 | cardOverlayEnabled?: boolean, |
557 | 557 | |}>; |
558 | 558 |
|
| 559 | + declare type _InterpolationResult = { [key: string]: mixed, ... }; |
559 | 560 | declare export type NavigationStackInterpolator = |
560 | | - (props: NavigationStackInterpolatorProps) => {...}; |
| 561 | + (props: NavigationStackInterpolatorProps) => _InterpolationResult; |
561 | 562 |
|
562 | 563 | /** |
563 | 564 | * Header |
@@ -764,14 +765,14 @@ declare module '@react-navigation/core' { |
764 | 765 | getCurrentNavigation: () => ?NavigationScreenProp<State> |
765 | 766 | ): NavigationScreenProp<State>; |
766 | 767 |
|
767 | | - declare type _NavigationView<O, S> = React$ComponentType<{ |
| 768 | + declare type _NavigationView<O, S, N: NavigationScreenProp<S>> = React$ComponentType<{ |
768 | 769 | descriptors: NavigationDescriptorMap, |
769 | | - navigation: NavigationScreenProp<S>, |
| 770 | + navigation: N, |
770 | 771 | navigationConfig: *, |
771 | 772 | ... |
772 | 773 | }>; |
773 | | - declare export function createNavigator<O: *, S: *, NavigatorConfig: *>( |
774 | | - view: _NavigationView<O, S>, |
| 774 | + declare export function createNavigator<O: *, S: *, NavigatorConfig: *, N: NavigationScreenProp<S>>( |
| 775 | + view: _NavigationView<O, S, N>, |
775 | 776 | router: NavigationRouter<S, O>, |
776 | 777 | navigatorConfig?: NavigatorConfig |
777 | 778 | ): NavigationNavigator<S, O, *>; |
@@ -877,17 +878,17 @@ declare module '@react-navigation/core' { |
877 | 878 | Options: {...} |
878 | 879 | >( |
879 | 880 | navigation: NavigationScreenProp<State>, |
880 | | - screenProps?: {...}, |
| 881 | + screenProps?: NavigationScreenProps, |
881 | 882 | theme?: SupportedThemes, |
882 | 883 | ): Options; |
883 | 884 |
|
884 | 885 | declare type _SceneViewProps = { |
885 | 886 | component: React$ComponentType<{ |
886 | | - screenProps: ?{...}, |
| 887 | + screenProps: ?NavigationScreenProps, |
887 | 888 | navigation: NavigationScreenProp<NavigationRoute>, |
888 | 889 | ... |
889 | 890 | }>, |
890 | | - screenProps: ?{...}, |
| 891 | + screenProps: ?NavigationScreenProps, |
891 | 892 | navigation: NavigationScreenProp<NavigationRoute>, |
892 | 893 | ... |
893 | 894 | }; |
@@ -917,4 +918,37 @@ declare module '@react-navigation/core' { |
917 | 918 | Component: ComponentType |
918 | 919 | ): React$ComponentType<$Diff<React$ElementConfig<ComponentType>, {| isFocused: ?boolean |}>>; |
919 | 920 |
|
| 921 | + declare export function createAppContainer<S: NavigationState, O: {...}>( |
| 922 | + Component: NavigationNavigator<S, O, *> |
| 923 | + ): NavigationContainer<S, O, *>; |
| 924 | + |
| 925 | + declare export function createKeyboardAwareNavigator<Props: {...}>( |
| 926 | + Comp: React$ComponentType<Props>, |
| 927 | + stackConfig: {...} |
| 928 | + ): React$ComponentType<Props>; |
| 929 | + |
| 930 | + declare export function withOrientation<Props: {...}, ComponentType: React$ComponentType<Props>>( |
| 931 | + Component: ComponentType |
| 932 | + ): React$ComponentType<$Diff<React$ElementConfig<ComponentType>, {| isLandscape: boolean |}>>; |
| 933 | + |
| 934 | + declare type _SafeAreaViewProps = { |
| 935 | + forceInset?: _SafeAreaViewInsets, |
| 936 | + children?: React$Node, |
| 937 | + style?: AnimatedViewStyleProp, |
| 938 | + ... |
| 939 | + }; |
| 940 | + declare export var SafeAreaView: React$ComponentType<_SafeAreaViewProps>; |
| 941 | + |
| 942 | + // These components take the same props that their React Native primitives do |
| 943 | + // Typing them correctly would be extremely brittle |
| 944 | + // We await the day we can import types from libraries in flow-typed libdefs |
| 945 | + declare export var ScrollView: React$ComponentType<{...}>; |
| 946 | + declare export var FlatList: React$ComponentType<{...}>; |
| 947 | + declare export var SectionList: React$ComponentType<{...}>; |
| 948 | + declare export var Themed: {| |
| 949 | + StatusBar: React$ComponentType<{...}>, |
| 950 | + Text: React$ComponentType<{...}>, |
| 951 | + TextInput: React$ComponentType<{...}>, |
| 952 | + |}; |
| 953 | + |
920 | 954 | } |
0 commit comments