[react-navigation] Fix navigationOptions differences between createTabNavigator and createBottomTabNavigator.

This commit is contained in:
DenisFrezzato
2018-08-24 09:22:51 +02:00
committed by frezzatod
parent 37926fac89
commit e8a0c4402e
2 changed files with 40 additions and 4 deletions
+33 -4
View File
@@ -22,6 +22,7 @@
// Yosuke Seki <https://github.com/jshosomichi>
// Jake <https://github.com/jakebooyah>
// Gustavo Brunoro <https://github.com/brunoro>
// Denis Frezzato <https://github.com/DenisFrezzato>
// 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<NavigationScreenOptions>;
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<NavigationScreenOptions>;
}
export interface NavigationBottomTabRouterConfig extends NavigationTabRouterConfigBase {
navigationOptions?: NavigationScreenConfig<NavigationBottomTabScreenOptions>;
}
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<any>
@@ -511,13 +519,27 @@ export interface NavigationTabScreenOptions {
) => React.ReactElement<any> | 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<NavigationRoute>;
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(
@@ -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({