Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 8f26d12

Browse files
committed
fix: fix types for tab bar button component
1 parent 34fd957 commit 8f26d12

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/types.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ export type BottomTabBarOptions = {
5757
style?: StyleProp<ViewStyle>;
5858
};
5959

60+
export type ButtonComponentProps = {
61+
route: NavigationRoute;
62+
focused: boolean;
63+
onPress: () => void;
64+
onLongPress: () => void;
65+
testID?: string;
66+
accessibilityLabel?: string;
67+
accessibilityRole?: AccessibilityRole;
68+
accessibilityStates?: AccessibilityState[];
69+
style?: StyleProp<ViewStyle>;
70+
};
71+
6072
export type BottomTabBarProps = BottomTabBarOptions & {
6173
navigation: NavigationTabProp;
6274
onTabPress: (props: { route: NavigationRoute }) => void;
@@ -73,7 +85,7 @@ export type BottomTabBarProps = BottomTabBarOptions & {
7385
}) => AccessibilityState[];
7486
getButtonComponent: (props: {
7587
route: NavigationRoute;
76-
}) => React.ComponentType<any> | undefined;
88+
}) => React.ComponentType<ButtonComponentProps> | undefined;
7789
getLabelText: (props: {
7890
route: NavigationRoute;
7991
}) =>
@@ -172,7 +184,7 @@ export type NavigationCommonTabOptions = {
172184
};
173185

174186
export type NavigationBottomTabOptions = NavigationCommonTabOptions & {
175-
tabBarButtonComponent?: React.ComponentType<BottomTabBarProps>;
187+
tabBarButtonComponent?: React.ComponentType<ButtonComponentProps>;
176188
};
177189

178190
export type NavigationMaterialTabOptions = NavigationCommonTabOptions & {

src/views/BottomTabBar.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ThemeColors, ThemeContext, NavigationRoute } from 'react-navigation';
1313

1414
import CrossFadeIcon from './CrossFadeIcon';
1515
import withDimensions from '../utils/withDimensions';
16-
import { BottomTabBarProps } from '../types';
16+
import { BottomTabBarProps, ButtonComponentProps } from '../types';
1717

1818
type State = {
1919
layout: { height: number; width: number };
@@ -28,19 +28,21 @@ const isIOS11 = majorVersion >= 11 && isIos;
2828
const DEFAULT_MAX_TAB_ITEM_WIDTH = 125;
2929

3030
class TouchableWithoutFeedbackWrapper extends React.Component<
31-
React.ComponentProps<typeof TouchableWithoutFeedback> & {
32-
children: React.ReactNode;
33-
}
31+
ButtonComponentProps
3432
> {
3533
render() {
3634
const {
35+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
36+
route,
37+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
38+
focused,
3739
onPress,
3840
onLongPress,
3941
testID,
4042
accessibilityLabel,
4143
accessibilityRole,
4244
accessibilityStates,
43-
...props
45+
...rest
4446
} = this.props;
4547

4648
return (
@@ -53,7 +55,7 @@ class TouchableWithoutFeedbackWrapper extends React.Component<
5355
accessibilityRole={accessibilityRole}
5456
accessibilityStates={accessibilityStates}
5557
>
56-
<View {...props} />
58+
<View {...rest} />
5759
</TouchableWithoutFeedback>
5860
);
5961
}
@@ -407,6 +409,8 @@ class TabBarBottom extends React.Component<BottomTabBarProps, State> {
407409
return (
408410
<ButtonComponent
409411
key={route.key}
412+
route={route}
413+
focused={focused}
410414
onPress={() => onTabPress({ route })}
411415
onLongPress={() => onTabLongPress({ route })}
412416
testID={testID}

0 commit comments

Comments
 (0)