diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index a1f60c0f81..61aab60a7c 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -22,6 +22,7 @@ // Yosuke Seki // Jake // Gustavo Brunoro +// Denis Frezzato // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -480,23 +481,30 @@ export interface NavigationPathsConfig { [routeName: string]: string; } -export interface NavigationTabRouterConfig { +// tslint:disable-next-line:strict-export-declare-modifiers +interface NavigationTabRouterConfigBase { initialRouteName?: string; initialRouteParams?: NavigationParams; paths?: NavigationPathsConfig; - navigationOptions?: NavigationScreenConfig; order?: string[]; // todo: type these as the real route names rather than 'string' // Does the back button cause the router to switch to the initial tab backBehavior?: 'none' | 'initialRoute'; // defaults `initialRoute` } +export interface NavigationTabRouterConfig extends NavigationTabRouterConfigBase { + navigationOptions?: NavigationScreenConfig; +} +export interface NavigationBottomTabRouterConfig extends NavigationTabRouterConfigBase { + navigationOptions?: NavigationScreenConfig; +} export interface TabScene { route: NavigationRoute; focused: boolean; index: number; tintColor?: string; } -export interface NavigationTabScreenOptions { +// tslint:disable-next-line:strict-export-declare-modifiers +interface NavigationTabScreenOptionsBase { title?: string; tabBarIcon?: | React.ReactElement @@ -511,13 +519,27 @@ export interface NavigationTabScreenOptions { ) => React.ReactElement | string | null); tabBarVisible?: boolean; tabBarTestIDProps?: { testID?: string; accessibilityLabel?: string }; +} +export interface NavigationTabScreenOptions + extends NavigationTabScreenOptionsBase { + swipeEnabled?: boolean; tabBarOnPress?: ( options: { + previousScene: TabScene; scene: TabScene; jumpToIndex: (index: number) => void; } ) => void; } +export interface NavigationBottomTabScreenOptions + extends NavigationTabScreenOptionsBase { + tabBarOnPress?: ( + options: { + navigation: NavigationScreenProp; + defaultHandler: () => void; + } + ) => void; +} export interface NavigationDrawerScreenOptions { title?: string; @@ -916,6 +938,13 @@ export interface TabNavigatorConfig removeClippedSubviews?: boolean; initialLayout?: { height: number; width: number }; } +export interface BottomTabNavigatorConfig + extends NavigationBottomTabRouterConfig, + TabViewConfig { + lazy?: boolean; + removeClippedSubviews?: boolean; + initialLayout?: { height: number; width: number }; +} // From navigators/TabNavigator.js export function TabNavigator( @@ -930,7 +959,7 @@ export function createTabNavigator( export function createBottomTabNavigator( routeConfigMap: NavigationRouteConfigMap, - drawConfig?: TabNavigatorConfig + drawConfig?: BottomTabNavigatorConfig ): NavigationContainer; export function createMaterialTopTabNavigator( diff --git a/types/react-navigation/react-navigation-tests.tsx b/types/react-navigation/react-navigation-tests.tsx index 30d984683e..dfb566984e 100644 --- a/types/react-navigation/react-navigation-tests.tsx +++ b/types/react-navigation/react-navigation-tests.tsx @@ -178,6 +178,9 @@ const tabNavigatorConfig: TabNavigatorConfig = { lazy: true, tabBarComponent: TabBarTop, tabBarOptions: { activeBackgroundColor: "blue" }, + navigationOptions: () => ({ + tabBarOnPress: ({ scene, jumpToIndex }) => jumpToIndex(scene.index) + }) }; const tabNavigatorConfigWithInitialLayout: TabNavigatorConfig = { @@ -457,6 +460,10 @@ const BottomStack = createBottomTabNavigator({ }; } } +}, { + navigationOptions: () => ({ + tabBarOnPress: ({ defaultHandler }) => defaultHandler() + }) }); const CustomHeaderStack = createStackNavigator({