From 32071c40b8e3494554aacf7181a563d4fb85977c Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Mon, 26 Feb 2018 13:54:38 +0800 Subject: [PATCH 1/6] Refactor react-navigation types based on 1.2.0 flow type --- types/react-navigation/index.d.ts | 244 +++++++++++++----- .../react-navigation-tests.tsx | 36 ++- 2 files changed, 201 insertions(+), 79 deletions(-) diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index edf5cbc915..53349d4be8 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -1,5 +1,5 @@ -// Type definitions for react-navigation 1.0 -// Project: https://github.com/react-community/react-navigation +// Type definitions for react-navigation 1.2 +// Project: https://github.com/react-navigation/react-navigation // Definitions by: Huhuanming // mhcgrq // fangpenlin @@ -10,16 +10,18 @@ // charlesfamu // Tim Wang // Qibang Sun +// Sergei Butko: +// Veit Lehmann: // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.6 /** * BEGIN FLOW TYPEDEFINITION.JS PORT - * Reference: https://github.com/react-community/react-navigation/tree/52a2846e77119148320bcea83b8982a8bc6acce3 + * Reference: https://github.com/react-navigation/react-navigation/tree/a37473c5e4833f48796ee6c7c9cb4a8ac49d9c06 * * NOTE: Please update the commit/link above when updating to a new Flow - * TypeDefinition.js reference, so we can conveniently just look at diffs on - * TypeDefinition.js between this latest reference point and the one you are + * react-navigation/flow/react-navigation.js reference, so we can conveniently just look at diffs on + * react-navigation/flow/react-navigation.js between this latest reference point and the one you are * using when making new updates. */ @@ -71,9 +73,9 @@ export interface NavigationState { routes: any[]; } -export type NavigationRoute = NavigationLeafRoute | NavigationStateRoute; +export type NavigationRoute = NavigationLeafRoute | NavigationStateRoute; -export interface NavigationLeafRoute { +export interface NavigationLeafRoute { /** * React's key used by some navigators. No need to specify these manually, * they will be defined by the router. @@ -92,16 +94,13 @@ export interface NavigationLeafRoute { * Params passed to this route when navigating to it, * e.g. `{ car_id: 123 }` in a route that displays a car. */ - params: Params; + params?: NavigationParams; } -export interface NavigationStateRoute extends NavigationLeafRoute { - index: number; - routes: Array>; -} +export type NavigationStateRoute = NavigationLeafRoute & NavigationState; -export type NavigationScreenOptionsGetter = ( - navigation: NavigationScreenProp, Action>, +export type NavigationScreenOptionsGetter = ( + navigation: NavigationScreenProp, screenProps?: { [key: string]: any } ) => Options; @@ -141,20 +140,20 @@ export interface NavigationRouter { * * {routeName: 'Foo', key: '123'} */ - getScreenOptions: NavigationScreenOptionsGetter; + getScreenOptions: NavigationScreenOptionsGetter; } export type NavigationScreenOption = T | (( - navigation: NavigationScreenProp, NavigationAction>, + navigation: NavigationScreenProp, config: T ) => T); export interface NavigationScreenDetails { options: T; - state: NavigationRoute; - navigation: NavigationScreenProp, NavigationAction>; + state: NavigationRoute; + navigation: NavigationScreenProp; } export interface NavigationScreenOptions { @@ -162,7 +161,7 @@ export interface NavigationScreenOptions { } export interface NavigationScreenConfigProps { - navigation: NavigationScreenProp, NavigationAction>; + navigation: NavigationScreenProp; screenProps: { [key: string]: any }; } @@ -170,10 +169,7 @@ export type NavigationScreenConfig = Options | (NavigationScreenConfigProps & ((navigationOptionsContainer: { - navigationOptions: NavigationScreenProp< - NavigationRoute, - NavigationAction - >, + navigationOptions: NavigationScreenProp, }) => Options)); export type NavigationComponent = @@ -262,6 +258,7 @@ export interface NavigationStackViewConfig { export type NavigationStackScreenOptions = NavigationScreenOptions & { header?: (React.ReactElement | ((headerProps: HeaderProps) => React.ReactElement)) | null; + headerTransparent?: boolean; headerTitle?: string | React.ReactElement; headerTitleStyle?: StyleProp; headerTintColor?: string; @@ -272,10 +269,13 @@ export type NavigationStackScreenOptions = NavigationScreenOptions & { headerPressColorAndroid?: string; headerRight?: React.ReactElement; headerStyle?: StyleProp; + headerBackground?: React.ReactNode | React.ComponentType; gesturesEnabled?: boolean; + gestureResponseDistance?: { vertical?: number; horizontal?: number }; }; export interface NavigationStackRouterConfig { + headerTransitionPreset?: 'fade-in-place' | 'uikit'; initialRouteName?: string; initialRouteParams?: NavigationParams; paths?: NavigationPathsConfig; @@ -299,18 +299,16 @@ export type NavigationAction = | NavigationStackAction | NavigationTabAction; -export type NavigationRouteConfig = T & { +export type NavigationRouteConfig = NavigationComponent | ({ navigationOptions?: NavigationScreenConfig, path?: string, -}; +} & NavigationScreenRouteConfig); -export type NavigationScreenRouteConfig = - { - screen: NavigationComponent, - } - | { - getScreen: () => NavigationComponent, - }; +export type NavigationScreenRouteConfig = NavigationComponent | { + screen: NavigationComponent, +} | { + getScreen: () => NavigationComponent, +}; export interface NavigationPathsConfig { [routeName: string]: string; @@ -325,7 +323,12 @@ export interface NavigationTabRouterConfig { // Does the back button cause the router to switch to the initial tab backBehavior?: 'none' | 'initialRoute'; // defaults `initialRoute` } - +export interface TabScene { + route: NavigationRoute; + focused: boolean; + index: number; + tintColor?: string; +} export interface NavigationTabScreenOptions extends NavigationScreenOptions { tabBarIcon?: React.ReactElement @@ -339,6 +342,11 @@ export interface NavigationTabScreenOptions extends NavigationScreenOptions { any > | string | null)); tabBarVisible?: boolean; + tabBarTestIDProps?: { testID?: string, accessibilityLabel?: string }; + tabBarOnPress?: (options: { + scene: TabScene, + jumpToIndex: (index: number) => void + }) => void; } export interface NavigationDrawerScreenOptions extends NavigationScreenOptions { @@ -348,26 +356,49 @@ export interface NavigationDrawerScreenOptions extends NavigationScreenOptions { any > | null)); drawerLabel?: - React.ReactElement + string + | React.ReactElement | ((options: { tintColor: (string | null), focused: boolean }) => (React.ReactElement< any > | null)); } export interface NavigationRouteConfigMap { - [routeName: string]: NavigationRouteConfig; + [routeName: string]: NavigationRouteConfig; } -export type NavigationDispatch = (action: A) => boolean; +export type NavigationDispatch = (action: NavigationAction) => boolean; -export interface NavigationProp { +export interface NavigationProp { state: S; - dispatch: NavigationDispatch; + dispatch: NavigationDispatch; } -export interface NavigationScreenProp { +export type EventType = +| 'willFocus' +| 'didFocus' +| 'willBlur' +| 'didBlur' +| 'action'; + +export interface NavigationEventPayload { + type: EventType; + action: NavigationAction; + state: NavigationState; + lastState: NavigationState; +} + +export type NavigationEventCallback = ( + payload: NavigationEventPayload +) => void; + +export interface NavigationEventSubscription { + remove: () => void; +} + +export interface NavigationScreenProp { state: S; - dispatch: NavigationDispatch; + dispatch: NavigationDispatch; goBack: (routeKey?: (string | null)) => boolean; navigate: ( routeName: string, @@ -375,10 +406,26 @@ export interface NavigationScreenProp { action?: NavigationAction ) => boolean; setParams: (newParams: NavigationParams) => boolean; + addListener: ( + eventName: string, + callback: NavigationEventCallback + ) => NavigationEventSubscription; + push: ( + routeName: string, + params?: NavigationParams, + action?: NavigationNavigateAction + ) => boolean; + replace: ( + routeName: string, + params?: NavigationParams, + action?: NavigationNavigateAction + ) => boolean; + pop: (n?: number, params?: { immediate?: boolean }) => boolean; + popToTop: (params?: { immediate?: boolean }) => boolean; } -export interface NavigationNavigatorProps { - navigation?: NavigationProp; +export interface NavigationNavigatorProps { + navigation?: NavigationProp; screenProps?: { [key: string]: any }; navigationOptions?: any; } @@ -402,7 +449,7 @@ export interface NavigationScene { isActive: boolean; isStale: boolean; key: string; - route: NavigationRoute; + route: NavigationRoute; } export interface NavigationTransitionProps { @@ -410,7 +457,7 @@ export interface NavigationTransitionProps { layout: NavigationLayout; // The destination navigation state of the transition - navigation: NavigationScreenProp; + navigation: NavigationScreenProp; // The progressive index of the transitioner's navigation state. position: AnimatedValue; @@ -498,7 +545,9 @@ export type NavigatorType = | 'react-navigation/DRAWER'; // From addNavigatorHelpers.js -export function addNavigationHelpers(navigation: NavigationProp): NavigationScreenProp; +export function addNavigationHelpers( + navigation: NavigationProp +): NavigationScreenProp; // From createNavigationContainer.js export interface NavigationContainerProps { @@ -531,15 +580,16 @@ export function StackNavigator( ): NavigationContainer; // DrawerItems -export const DrawerItems: React.ComponentClass; +export const DrawerItems: React.ComponentType; /** * Drawer Navigator */ export interface DrawerViewConfig { + drawerBackgroundColor?: string; drawerWidth?: number; drawerPosition?: 'left' | 'right'; - contentComponent?: (props: any) => React.ReactElement | React.ComponentClass; + contentComponent?: React.ComponentType; contentOptions?: any; style?: StyleProp; } @@ -566,10 +616,11 @@ export function DrawerNavigator( // From views/TabView/TabView.js export interface TabViewConfig { - tabBarComponent?: React.ComponentClass; + tabBarComponent?: React.ComponentType; tabBarPosition?: 'top' | 'bottom'; tabBarOptions?: { activeTintColor?: string, + allowFontScaling?: boolean, activeBackgroundColor?: string, inactiveTintColor?: string, inactiveBackgroundColor?: string, @@ -592,7 +643,11 @@ export interface TabViewConfig { } // From navigators/TabNavigator.js -export interface TabNavigatorConfig extends NavigationTabRouterConfig, TabViewConfig { } +export interface TabNavigatorConfig extends NavigationTabRouterConfig, TabViewConfig { + lazy?: boolean; + removeClippedSubviews?: boolean; + initialLayout?: { height: number, width: number }; +} // From navigators/TabNavigator.js export function TabNavigator( @@ -600,13 +655,74 @@ export function TabNavigator( drawConfig?: TabNavigatorConfig, ): NavigationContainer; -export const TabBarTop: React.ComponentClass; -export const TabBarBottom: React.ComponentClass; +export interface TabBarTopProps { + activeTintColor: string; + inactiveTintColor: string; + showIcon: boolean; + showLabel: boolean; + upperCaseLabel: boolean; + allowFontScaling: boolean; + position: AnimatedValue; + tabBarPosition: string; + navigation: NavigationScreenProp; + jumpToIndex: (index: number) => void; + getLabel: (scene: TabScene) => (React.ReactNode | string); + getOnPress: ( + previousScene: NavigationRoute, + scene: TabScene + ) => (args: { + previousScene: NavigationRoute, + scene: TabScene, + jumpToIndex: (index: number) => void, + }) => void; + renderIcon: (scene: TabScene) => React.ReactElement; + labelStyle?: TextStyle; + iconStyle?: ViewStyle; +} + +export interface TabBarBottomProps { + activeTintColor: string; + activeBackgroundColor: string; + adaptive?: boolean; + inactiveTintColor: string; + inactiveBackgroundColor: string; + showLabel?: boolean; + allowFontScaling: boolean; + position: AnimatedValue; + navigation: NavigationScreenProp; + jumpToIndex: (index: number) => void; + getLabel: (scene: TabScene) => (React.ReactNode | string); + getOnPress: ( + previousScene: NavigationRoute, + scene: TabScene + ) => (args: { + previousScene: NavigationRoute, + scene: TabScene, + jumpToIndex: (index: number) => void, + }) => void; + getTestIDProps: (scene: TabScene) => (scene: TabScene) => any; + renderIcon: (scene: TabScene) => React.ReactNode; + style?: ViewStyle; + animateStyle?: ViewStyle; + labelStyle?: TextStyle; + tabStyle?: ViewStyle; + showIcon?: boolean; +} + +export const TabBarTop: React.ComponentType; +export const TabBarBottom: React.ComponentType; /** * NavigationActions */ export namespace NavigationActions { + const BACK: 'Navigation/BACK'; + const INIT: 'Navigation/INIT'; + const NAVIGATE: 'Navigation/NAVIGATE'; + const RESET: 'Navigation/RESET'; + const SET_PARAMS: 'Navigation/SET_PARAMS'; + const URI: 'Navigation/URI'; + function init(options?: NavigationInitActionPayload): NavigationInitAction; function navigate(options: NavigationNavigateActionPayload): NavigationNavigateAction; function reset(options: NavigationResetActionPayload): NavigationResetAction; @@ -623,7 +739,7 @@ export interface TransitionerProps { transitionProps: NavigationTransitionProps, prevTransitionProps?: NavigationTransitionProps ) => NavigationTransitionSpec; - navigation: NavigationScreenProp; + navigation: NavigationScreenProp; onTransitionEnd?: () => void; onTransitionStart?: () => void; render: ( @@ -668,7 +784,7 @@ export function StackRouter( /** * Create Navigator * - * @see https://github.com/react-community/react-navigation/blob/master/src/navigators/createNavigator.js + * @see https://github.com/react-navigation/react-navigation/blob/master/src/navigators/createNavigator.js */ export function createNavigator( router: NavigationRouter, @@ -683,11 +799,11 @@ export function createNavigator( * This allows to use e.g. the StackNavigator and TabNavigator as root-level * components. * - * @see https://github.com/react-community/react-navigation/blob/master/src/createNavigationContainer.js + * @see https://github.com/react-navigation/react-navigation/blob/master/src/createNavigationContainer.js */ export function createNavigationContainer( Component: NavigationNavigator -): React.Component; +): NavigationContainer; /** * END MANUAL DEFINITIONS OUTSIDE OF TYPEDEFINITION.JS */ @@ -696,8 +812,8 @@ export function createNavigationContainer( * BEGIN CUSTOM CONVENIENCE INTERFACES */ -export interface NavigationScreenProps { - navigation: NavigationScreenProp, NavigationAction>; +export interface NavigationScreenProps { + navigation: NavigationScreenProp; screenProps?: { [key: string]: any }; navigationOptions?: NavigationScreenConfig; } @@ -727,3 +843,15 @@ export const HeaderBackButton: React.ComponentClass; * Header Component */ export const Header: React.ComponentClass; + +export interface NavigationInjectedProps { + navigation: NavigationScreenProp; +} + +export function withNavigation( + Component: React.ComponentType +): React.ComponentType; + +export function withNavigationFocus( + Component: React.ComponentType +): React.ComponentType; diff --git a/types/react-navigation/react-navigation-tests.tsx b/types/react-navigation/react-navigation-tests.tsx index e8573bac89..2ac8e1617c 100644 --- a/types/react-navigation/react-navigation-tests.tsx +++ b/types/react-navigation/react-navigation-tests.tsx @@ -29,6 +29,7 @@ import { addNavigationHelpers, HeaderBackButton, Header, + NavigationParams, } from 'react-navigation'; // Constants @@ -40,21 +41,17 @@ const viewStyle: ViewStyle = { }; const ROUTE_NAME_START_SCREEN = "StartScreen"; -interface StartScreenNavigationParams { - id: number; - s: string; -} /** * @desc Simple screen component class with typed component props that should * receive the navigation prop from the AppNavigator. */ -class StartScreen extends React.Component> { +class StartScreen extends React.Component { render() { // Implicit type checks. - const navigationStateParams: StartScreenNavigationParams = this.props.navigation.state.params; - const id = this.props.navigation.state.params.id; - const s = this.props.navigation.state.params.s; + const navigationStateParams = this.props.navigation.state.params; + const id = this.props.navigation.state.params && this.props.navigation.state.params.id; + const s = this.props.navigation.state.params && this.props.navigation.state.params.s; return ( @@ -63,25 +60,22 @@ class StartScreen extends React.Component { - const params: NextScreenNavigationParams = { - id: this.props.navigation.state.params.id, - name: this.props.navigation.state.params.s, + const params = { + id: this.props.navigation.state.params && this.props.navigation.state.params.id, + name: this.props.navigation.state.params && this.props.navigation.state.params.s, }; this.props.navigation.navigate(ROUTE_NAME_NEXT_SCREEN, params); } } const ROUTE_NAME_NEXT_SCREEN = "NextScreen"; -interface NextScreenNavigationParams { - id: number; - name: string; -} -class NextScreen extends React.Component> { + +class NextScreen extends React.Component { render() { // Implicit type checks. - const navigationStateParams: NextScreenNavigationParams = this.props.navigation.state.params; - const id = this.props.navigation.state.params.id; - const name = this.props.navigation.state.params.name; + const navigationStateParams = this.props.navigation.state.params; + const id = this.props.navigation.state.params && this.props.navigation.state.params.id; + const name = this.props.navigation.state.params && this.props.navigation.state.params.name; return ( @@ -92,7 +86,7 @@ class NextScreen extends React.Component; + navigation: NavigationScreenProp; } /** * @desc Custom transitioner component. Follows react-navigation/src/views/CardStackTransitioner.js. From f1e2710d7671bc2d9b2da5269780cc7881a5a518 Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Mon, 26 Feb 2018 14:18:31 +0800 Subject: [PATCH 2/6] Fix CI --- types/react-navigation/react-navigation-tests.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-navigation/react-navigation-tests.tsx b/types/react-navigation/react-navigation-tests.tsx index 112aa02964..a7eaad092b 100644 --- a/types/react-navigation/react-navigation-tests.tsx +++ b/types/react-navigation/react-navigation-tests.tsx @@ -61,7 +61,7 @@ class StartScreen extends React.Component { ); } - private navigateToNextScreen = (): void => { + private readonly navigateToNextScreen = (): void => { const params = { id: this.props.navigation.state.params && this.props.navigation.state.params.id, name: this.props.navigation.state.params && this.props.navigation.state.params.s, From 9ef92bafb5ad1b7d0096e9129c6f5a82a0c97ada Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Mon, 26 Feb 2018 14:29:37 +0800 Subject: [PATCH 3/6] Replace React.ComponentType to React.ReactType --- types/react-navigation/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index 53349d4be8..ba9eb44152 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -269,7 +269,7 @@ export type NavigationStackScreenOptions = NavigationScreenOptions & { headerPressColorAndroid?: string; headerRight?: React.ReactElement; headerStyle?: StyleProp; - headerBackground?: React.ReactNode | React.ComponentType; + headerBackground?: React.ReactNode | React.ReactType; gesturesEnabled?: boolean; gestureResponseDistance?: { vertical?: number; horizontal?: number }; }; @@ -580,7 +580,7 @@ export function StackNavigator( ): NavigationContainer; // DrawerItems -export const DrawerItems: React.ComponentType; +export const DrawerItems: React.ReactType; /** * Drawer Navigator @@ -589,7 +589,7 @@ export interface DrawerViewConfig { drawerBackgroundColor?: string; drawerWidth?: number; drawerPosition?: 'left' | 'right'; - contentComponent?: React.ComponentType; + contentComponent?: React.ReactType; contentOptions?: any; style?: StyleProp; } @@ -616,7 +616,7 @@ export function DrawerNavigator( // From views/TabView/TabView.js export interface TabViewConfig { - tabBarComponent?: React.ComponentType; + tabBarComponent?: React.ReactType; tabBarPosition?: 'top' | 'bottom'; tabBarOptions?: { activeTintColor?: string, From 07f5f260a9843c4cdf2cc27a1de9e5b15b999ab2 Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Mon, 26 Feb 2018 14:34:40 +0800 Subject: [PATCH 4/6] Fix format and outdated comment --- types/react-navigation/index.d.ts | 126 ++++++++++++++---------------- 1 file changed, 57 insertions(+), 69 deletions(-) diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index ba9eb44152..3a4b079000 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -16,7 +16,6 @@ // TypeScript Version: 2.6 /** - * BEGIN FLOW TYPEDEFINITION.JS PORT * Reference: https://github.com/react-navigation/react-navigation/tree/a37473c5e4833f48796ee6c7c9cb4a8ac49d9c06 * * NOTE: Please update the commit/link above when updating to a new Flow @@ -382,18 +381,18 @@ export type EventType = | 'action'; export interface NavigationEventPayload { - type: EventType; - action: NavigationAction; - state: NavigationState; - lastState: NavigationState; + type: EventType; + action: NavigationAction; + state: NavigationState; + lastState: NavigationState; } export type NavigationEventCallback = ( - payload: NavigationEventPayload + payload: NavigationEventPayload ) => void; export interface NavigationEventSubscription { - remove: () => void; + remove: () => void; } export interface NavigationScreenProp { @@ -530,26 +529,15 @@ export interface LayoutEvent { }; } -/** - * END FLOW TYPEDEFINITION.JS PORT - */ - -/** - * BEGIN MANUAL DEFINITIONS OUTSIDE OF TYPEDEFINITION.JS - */ - -// From navigators/NavigatorTypes.js export type NavigatorType = | 'react-navigation/STACK' | 'react-navigation/TABS' | 'react-navigation/DRAWER'; -// From addNavigatorHelpers.js export function addNavigationHelpers( navigation: NavigationProp ): NavigationScreenProp; -// From createNavigationContainer.js export interface NavigationContainerProps { uriPrefix?: string | RegExp; onNavigationStateChange?: ( @@ -656,57 +644,57 @@ export function TabNavigator( ): NavigationContainer; export interface TabBarTopProps { - activeTintColor: string; - inactiveTintColor: string; - showIcon: boolean; - showLabel: boolean; - upperCaseLabel: boolean; - allowFontScaling: boolean; - position: AnimatedValue; - tabBarPosition: string; - navigation: NavigationScreenProp; - jumpToIndex: (index: number) => void; - getLabel: (scene: TabScene) => (React.ReactNode | string); - getOnPress: ( - previousScene: NavigationRoute, - scene: TabScene - ) => (args: { - previousScene: NavigationRoute, - scene: TabScene, - jumpToIndex: (index: number) => void, - }) => void; - renderIcon: (scene: TabScene) => React.ReactElement; - labelStyle?: TextStyle; - iconStyle?: ViewStyle; + activeTintColor: string; + inactiveTintColor: string; + showIcon: boolean; + showLabel: boolean; + upperCaseLabel: boolean; + allowFontScaling: boolean; + position: AnimatedValue; + tabBarPosition: string; + navigation: NavigationScreenProp; + jumpToIndex: (index: number) => void; + getLabel: (scene: TabScene) => (React.ReactNode | string); + getOnPress: ( + previousScene: NavigationRoute, + scene: TabScene + ) => (args: { + previousScene: NavigationRoute, + scene: TabScene, + jumpToIndex: (index: number) => void, + }) => void; + renderIcon: (scene: TabScene) => React.ReactElement; + labelStyle?: TextStyle; + iconStyle?: ViewStyle; } export interface TabBarBottomProps { - activeTintColor: string; - activeBackgroundColor: string; - adaptive?: boolean; - inactiveTintColor: string; - inactiveBackgroundColor: string; - showLabel?: boolean; - allowFontScaling: boolean; - position: AnimatedValue; - navigation: NavigationScreenProp; - jumpToIndex: (index: number) => void; - getLabel: (scene: TabScene) => (React.ReactNode | string); - getOnPress: ( - previousScene: NavigationRoute, - scene: TabScene - ) => (args: { - previousScene: NavigationRoute, - scene: TabScene, - jumpToIndex: (index: number) => void, - }) => void; - getTestIDProps: (scene: TabScene) => (scene: TabScene) => any; - renderIcon: (scene: TabScene) => React.ReactNode; - style?: ViewStyle; - animateStyle?: ViewStyle; - labelStyle?: TextStyle; - tabStyle?: ViewStyle; - showIcon?: boolean; + activeTintColor: string; + activeBackgroundColor: string; + adaptive?: boolean; + inactiveTintColor: string; + inactiveBackgroundColor: string; + showLabel?: boolean; + allowFontScaling: boolean; + position: AnimatedValue; + navigation: NavigationScreenProp; + jumpToIndex: (index: number) => void; + getLabel: (scene: TabScene) => (React.ReactNode | string); + getOnPress: ( + previousScene: NavigationRoute, + scene: TabScene + ) => (args: { + previousScene: NavigationRoute, + scene: TabScene, + jumpToIndex: (index: number) => void, + }) => void; + getTestIDProps: (scene: TabScene) => (scene: TabScene) => any; + renderIcon: (scene: TabScene) => React.ReactNode; + style?: ViewStyle; + animateStyle?: ViewStyle; + labelStyle?: TextStyle; + tabStyle?: ViewStyle; + showIcon?: boolean; } export const TabBarTop: React.ComponentType; @@ -845,13 +833,13 @@ export const HeaderBackButton: React.ComponentClass; export const Header: React.ComponentClass; export interface NavigationInjectedProps { - navigation: NavigationScreenProp; + navigation: NavigationScreenProp; } export function withNavigation( - Component: React.ComponentType + Component: React.ComponentType ): React.ComponentType; export function withNavigationFocus( - Component: React.ComponentType + Component: React.ComponentType ): React.ComponentType; From 820f42b0ff9b8f6736ae3d764f51085727390826 Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Mon, 26 Feb 2018 15:49:42 +0800 Subject: [PATCH 5/6] Fix addNavigationHelpers type --- types/react-navigation/index.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index 3a4b079000..b9c3fd53f8 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -535,7 +535,14 @@ export type NavigatorType = | 'react-navigation/DRAWER'; export function addNavigationHelpers( - navigation: NavigationProp + navigation: { + state: S; + dispatch: (action: NavigationAction) => any; + addListener?: ( + eventName: string, + callback: NavigationEventCallback + ) => NavigationEventSubscription; + } ): NavigationScreenProp; export interface NavigationContainerProps { From 4739cf80e488687d8dc0d2f638f7b25602689b31 Mon Sep 17 00:00:00 2001 From: Tim Wang Date: Mon, 26 Feb 2018 16:53:56 +0800 Subject: [PATCH 6/6] Make getStateForAction lastState optional --- types/react-navigation/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index b9c3fd53f8..7cc0dc3d63 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -109,7 +109,7 @@ export interface NavigationRouter { * an optional previous state. When the action is considered handled but the * state is unchanged, the output state is null. */ - getStateForAction: (action: Action, lastState: (State | null)) => (State | null); + getStateForAction: (action: Action, lastState?: State) => (State | null); /** * Maps a URI-like string to an action. This can be mapped to a state