Skip to content

Commit fb7da05

Browse files
Ashoatbrentvatne
authored andcommitted
[flow] Update for Flow 0.92 (react-navigation#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`.
1 parent 5d097b9 commit fb7da05

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

flow/react-navigation.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,8 @@ declare module 'react-navigation' {
353353
declare export type NavigationScreenComponent<
354354
Route: NavigationRoute,
355355
Options: {},
356-
Props: {}
357-
> = React$ComponentType<{
358-
...Props,
359-
...NavigationNavigatorProps<Options, Route>,
360-
}> &
361-
withOptionalNavigationOptions<Options>;
356+
Props: NavigationNavigatorProps<Options, Route>
357+
> = React$ComponentType<Props> & withOptionalNavigationOptions<Options>;
362358

363359
declare interface withRouter<State, Options> {
364360
router: NavigationRouter<State, Options>;
@@ -367,11 +363,8 @@ declare module 'react-navigation' {
367363
declare export type NavigationNavigator<
368364
State: NavigationState,
369365
Options: {},
370-
Props: {}
371-
> = React$StatelessFunctionalComponent<{
372-
...Props,
373-
...NavigationNavigatorProps<Options, State>,
374-
}> &
366+
Props: NavigationNavigatorProps<Options, State>
367+
> = React$ComponentType<Props> &
375368
withRouter<State, Options> &
376369
withOptionalNavigationOptions<Options>;
377370

@@ -463,8 +456,14 @@ declare module 'react-navigation' {
463456
prevTransitionProps: ?NavigationTransitionProps,
464457
isModal: boolean
465458
) => TransitionConfig,
466-
onTransitionStart?: () => void,
467-
onTransitionEnd?: () => void,
459+
onTransitionStart?: (
460+
transitionProps: NavigationTransitionProps,
461+
prevTransitionProps: ?NavigationTransitionProps
462+
) => void,
463+
onTransitionEnd?: (
464+
transitionProps: NavigationTransitionProps,
465+
prevTransitionProps: ?NavigationTransitionProps
466+
) => void,
468467
transparentCard?: boolean,
469468
disableKeyboardHandling?: boolean,
470469
|};
@@ -589,8 +588,8 @@ declare module 'react-navigation' {
589588
fallback?: $ElementType<
590589
$PropertyType<
591590
{|
592-
...{| params: {| [ParamName]: void |} |},
593591
...$Exact<S>,
592+
...{| params: {| [ParamName]: void |} |},
594593
|},
595594
'params'
596595
>,
@@ -599,14 +598,14 @@ declare module 'react-navigation' {
599598
) => $ElementType<
600599
$PropertyType<
601600
{|
602-
...{| params: {| [ParamName]: void |} |},
603601
...$Exact<S>,
602+
...{| params: {| [ParamName]: void |} |},
604603
|},
605604
'params'
606605
>,
607606
ParamName
608607
>,
609-
dangerouslyGetParent: () => NavigationScreenProp<*>,
608+
dangerouslyGetParent: () => ?NavigationScreenProp<NavigationState>,
610609
isFocused: () => boolean,
611610
// Shared action creators that exist for all routers
612611
goBack: (routeKey?: ?string) => boolean,
@@ -672,11 +671,8 @@ declare module 'react-navigation' {
672671
declare export type NavigationContainer<
673672
State: NavigationState,
674673
Options: {},
675-
Props: {}
676-
> = React$ComponentType<{
677-
...Props,
678-
...NavigationContainerProps<State, Options>,
679-
}> &
674+
Props: NavigationContainerProps<Options, State>
675+
> = React$ComponentType<Props> &
680676
withRouter<State, Options> &
681677
withOptionalNavigationOptions<Options>;
682678

@@ -936,6 +932,7 @@ declare module 'react-navigation' {
936932
declare type NavigationView<O, S> = React$ComponentType<{
937933
descriptors: { [key: string]: NavigationDescriptor },
938934
navigation: NavigationScreenProp<S>,
935+
navigationConfig: *,
939936
}>;
940937

941938
declare export function createNavigator<O: *, S: *, NavigatorConfig: *>(

0 commit comments

Comments
 (0)