From fdbf5bfa15b0301c1571bd2eb45dcef23b370c65 Mon Sep 17 00:00:00 2001 From: Ashoat Tevosyan Date: Fri, 12 Apr 2019 12:31:44 -0400 Subject: [PATCH] [flow] Update for Flow 0.92 (#5806) Changes: 1. We can now type React components with static members as `React.ComponentType` (instead of requiring the `StatelessFunctionalComponent`) hack. 2. We can now type-parameterize React components on all of their props, instead of just the ones we care about. Not sure why this wasn't previously. Note: this is a breaking change, in the sense that people's parameterization of `NavigationScreenComponent`, `NavigationNavigator`, and `NavigationContainer` may need to change. 3. The order of object-type-spread in the `getParam` definition has been switched. It was giving errors with the old order. 4. Avoid recursive type inference `NavigationScreenProp`. This was yielding an "*** Recursion limit exceeded ***" error, which was rather difficult to debug. We can just use a `NavigationState` and let the user cast. 5. Fix `onTransitionStart`/`onTransitionEnd` types in `NavigationStackViewConfig`. 6. Add `navigationConfig` property to `NavigationView`. --- .../react-navigation/flow/react-navigation.js | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/packages/react-navigation/flow/react-navigation.js b/packages/react-navigation/flow/react-navigation.js index 08f46ea8..b4e81522 100644 --- a/packages/react-navigation/flow/react-navigation.js +++ b/packages/react-navigation/flow/react-navigation.js @@ -353,12 +353,8 @@ declare module 'react-navigation' { declare export type NavigationScreenComponent< Route: NavigationRoute, Options: {}, - Props: {} - > = React$ComponentType<{ - ...Props, - ...NavigationNavigatorProps, - }> & - withOptionalNavigationOptions; + Props: NavigationNavigatorProps + > = React$ComponentType & withOptionalNavigationOptions; declare interface withRouter { router: NavigationRouter; @@ -367,11 +363,8 @@ declare module 'react-navigation' { declare export type NavigationNavigator< State: NavigationState, Options: {}, - Props: {} - > = React$StatelessFunctionalComponent<{ - ...Props, - ...NavigationNavigatorProps, - }> & + Props: NavigationNavigatorProps + > = React$ComponentType & withRouter & withOptionalNavigationOptions; @@ -463,8 +456,14 @@ declare module 'react-navigation' { prevTransitionProps: ?NavigationTransitionProps, isModal: boolean ) => TransitionConfig, - onTransitionStart?: () => void, - onTransitionEnd?: () => void, + onTransitionStart?: ( + transitionProps: NavigationTransitionProps, + prevTransitionProps: ?NavigationTransitionProps + ) => void, + onTransitionEnd?: ( + transitionProps: NavigationTransitionProps, + prevTransitionProps: ?NavigationTransitionProps + ) => void, transparentCard?: boolean, disableKeyboardHandling?: boolean, |}; @@ -589,8 +588,8 @@ declare module 'react-navigation' { fallback?: $ElementType< $PropertyType< {| - ...{| params: {| [ParamName]: void |} |}, ...$Exact, + ...{| params: {| [ParamName]: void |} |}, |}, 'params' >, @@ -599,14 +598,14 @@ declare module 'react-navigation' { ) => $ElementType< $PropertyType< {| - ...{| params: {| [ParamName]: void |} |}, ...$Exact, + ...{| params: {| [ParamName]: void |} |}, |}, 'params' >, ParamName >, - dangerouslyGetParent: () => NavigationScreenProp<*>, + dangerouslyGetParent: () => ?NavigationScreenProp, isFocused: () => boolean, // Shared action creators that exist for all routers goBack: (routeKey?: ?string) => boolean, @@ -672,11 +671,8 @@ declare module 'react-navigation' { declare export type NavigationContainer< State: NavigationState, Options: {}, - Props: {} - > = React$ComponentType<{ - ...Props, - ...NavigationContainerProps, - }> & + Props: NavigationContainerProps + > = React$ComponentType & withRouter & withOptionalNavigationOptions; @@ -936,6 +932,7 @@ declare module 'react-navigation' { declare type NavigationView = React$ComponentType<{ descriptors: { [key: string]: NavigationDescriptor }, navigation: NavigationScreenProp, + navigationConfig: *, }>; declare export function createNavigator(