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

Commit

Permalink
fix: fix types for tab bar button component
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Sep 19, 2019
1 parent 34fd957 commit 8f26d12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export type BottomTabBarOptions = {
style?: StyleProp<ViewStyle>;
};

export type ButtonComponentProps = {
route: NavigationRoute;
focused: boolean;
onPress: () => void;
onLongPress: () => void;
testID?: string;
accessibilityLabel?: string;
accessibilityRole?: AccessibilityRole;
accessibilityStates?: AccessibilityState[];
style?: StyleProp<ViewStyle>;
};

export type BottomTabBarProps = BottomTabBarOptions & {
navigation: NavigationTabProp;
onTabPress: (props: { route: NavigationRoute }) => void;
Expand All @@ -73,7 +85,7 @@ export type BottomTabBarProps = BottomTabBarOptions & {
}) => AccessibilityState[];
getButtonComponent: (props: {
route: NavigationRoute;
}) => React.ComponentType<any> | undefined;
}) => React.ComponentType<ButtonComponentProps> | undefined;
getLabelText: (props: {
route: NavigationRoute;
}) =>
Expand Down Expand Up @@ -172,7 +184,7 @@ export type NavigationCommonTabOptions = {
};

export type NavigationBottomTabOptions = NavigationCommonTabOptions & {
tabBarButtonComponent?: React.ComponentType<BottomTabBarProps>;
tabBarButtonComponent?: React.ComponentType<ButtonComponentProps>;
};

export type NavigationMaterialTabOptions = NavigationCommonTabOptions & {
Expand Down
16 changes: 10 additions & 6 deletions src/views/BottomTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ThemeColors, ThemeContext, NavigationRoute } from 'react-navigation';

import CrossFadeIcon from './CrossFadeIcon';
import withDimensions from '../utils/withDimensions';
import { BottomTabBarProps } from '../types';
import { BottomTabBarProps, ButtonComponentProps } from '../types';

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

class TouchableWithoutFeedbackWrapper extends React.Component<
React.ComponentProps<typeof TouchableWithoutFeedback> & {
children: React.ReactNode;
}
ButtonComponentProps
> {
render() {
const {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
route,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
focused,
onPress,
onLongPress,
testID,
accessibilityLabel,
accessibilityRole,
accessibilityStates,
...props
...rest
} = this.props;

return (
Expand All @@ -53,7 +55,7 @@ class TouchableWithoutFeedbackWrapper extends React.Component<
accessibilityRole={accessibilityRole}
accessibilityStates={accessibilityStates}
>
<View {...props} />
<View {...rest} />
</TouchableWithoutFeedback>
);
}
Expand Down Expand Up @@ -407,6 +409,8 @@ class TabBarBottom extends React.Component<BottomTabBarProps, State> {
return (
<ButtonComponent
key={route.key}
route={route}
focused={focused}
onPress={() => onTabPress({ route })}
onLongPress={() => onTabLongPress({ route })}
testID={testID}
Expand Down

0 comments on commit 8f26d12

Please sign in to comment.