|
5 | 5 | View,
|
6 | 6 | Animated,
|
7 | 7 | TouchableWithoutFeedback,
|
| 8 | + TouchableWithoutFeedbackProps, |
8 | 9 | StyleSheet,
|
9 | 10 | StyleProp,
|
10 | 11 | Platform,
|
@@ -44,6 +45,14 @@ type TabPressEvent = {
|
44 | 45 | preventDefault(): void;
|
45 | 46 | };
|
46 | 47 |
|
| 48 | +type TouchableProps = TouchableWithoutFeedbackProps & { |
| 49 | + key: string; |
| 50 | + children: React.ReactNode; |
| 51 | + borderless?: boolean; |
| 52 | + centered?: boolean; |
| 53 | + rippleColor?: string; |
| 54 | +}; |
| 55 | + |
47 | 56 | type Props = {
|
48 | 57 | /**
|
49 | 58 | * Whether the shifting style is used, the active tab appears wider and the inactive tabs won't have a label.
|
@@ -147,6 +156,11 @@ type Props = {
|
147 | 156 | focused: boolean;
|
148 | 157 | color: string;
|
149 | 158 | }) => React.ReactNode;
|
| 159 | + /** |
| 160 | + * Callback which returns a React element to be used as the touchable for the tab item. |
| 161 | + * Renders a `TouchableRipple` on Android and `TouchableWithoutFeedback` with `View` on iOS. |
| 162 | + */ |
| 163 | + renderTouchable?: (props: TouchableProps) => React.ReactNode; |
150 | 164 | /**
|
151 | 165 | * Get label text for the tab, uses `route.title` by default. Use `renderLabel` to replace label component.
|
152 | 166 | */
|
@@ -263,11 +277,16 @@ const MAX_TAB_WIDTH = 168;
|
263 | 277 | const BAR_HEIGHT = 56;
|
264 | 278 | const FAR_FAR_AWAY = 9999;
|
265 | 279 |
|
266 |
| -// @ts-ignore |
267 | 280 | const Touchable = TouchableRipple.supported
|
268 | 281 | ? TouchableRipple
|
269 |
| - : // eslint-disable-next-line @typescript-eslint/no-unused-vars |
270 |
| - ({ style, children, borderless, centered, rippleColor, ...rest }: any) => ( |
| 282 | + : ({ |
| 283 | + style, |
| 284 | + children, |
| 285 | + borderless: _0, |
| 286 | + centered: _1, |
| 287 | + rippleColor: _2, |
| 288 | + ...rest |
| 289 | + }: TouchableProps) => ( |
271 | 290 | <TouchableWithoutFeedback {...rest}>
|
272 | 291 | <View style={style}>{children}</View>
|
273 | 292 | </TouchableWithoutFeedback>
|
@@ -594,6 +613,7 @@ class BottomNavigation extends React.Component<Props, State> {
|
594 | 613 | renderScene,
|
595 | 614 | renderIcon,
|
596 | 615 | renderLabel,
|
| 616 | + renderTouchable = (props: TouchableProps) => <Touchable {...props} />, |
597 | 617 | getLabelText = ({ route }: { route: Route }) => route.title,
|
598 | 618 | getBadge = ({ route }: { route: Route }) => route.badge,
|
599 | 619 | getColor = ({ route }: { route: Route }) => route.color,
|
@@ -820,23 +840,22 @@ class BottomNavigation extends React.Component<Props, State> {
|
820 | 840 |
|
821 | 841 | const badge = getBadge({ route });
|
822 | 842 |
|
823 |
| - return ( |
824 |
| - <Touchable |
825 |
| - key={route.key} |
826 |
| - borderless |
827 |
| - centered |
828 |
| - rippleColor={touchColor} |
829 |
| - onPress={() => this.handleTabPress(index)} |
830 |
| - testID={getTestID({ route })} |
831 |
| - accessibilityLabel={getAccessibilityLabel({ route })} |
832 |
| - accessibilityTraits={ |
833 |
| - focused ? ['button', 'selected'] : 'button' |
834 |
| - } |
835 |
| - accessibilityComponentType="button" |
836 |
| - accessibilityRole="button" |
837 |
| - accessibilityStates={['selected']} |
838 |
| - style={styles.item} |
839 |
| - > |
| 843 | + return renderTouchable({ |
| 844 | + key: route.key, |
| 845 | + borderless: true, |
| 846 | + centered: true, |
| 847 | + rippleColor: touchColor, |
| 848 | + onPress: () => this.handleTabPress(index), |
| 849 | + testID: getTestID({ route }), |
| 850 | + accessibilityLabel: getAccessibilityLabel({ route }), |
| 851 | + accessibilityTraits: focused |
| 852 | + ? ['button', 'selected'] |
| 853 | + : 'button', |
| 854 | + accessibilityComponentType: 'button', |
| 855 | + accessibilityRole: 'button', |
| 856 | + accessibilityStates: ['selected'], |
| 857 | + style: styles.item, |
| 858 | + children: ( |
840 | 859 | <View pointerEvents="none">
|
841 | 860 | <Animated.View
|
842 | 861 | style={[
|
@@ -964,8 +983,8 @@ class BottomNavigation extends React.Component<Props, State> {
|
964 | 983 | <View style={styles.labelContainer} />
|
965 | 984 | )}
|
966 | 985 | </View>
|
967 |
| - </Touchable> |
968 |
| - ); |
| 986 | + ), |
| 987 | + }); |
969 | 988 | })}
|
970 | 989 | </SafeAreaView>
|
971 | 990 | </Animated.View>
|
|
0 commit comments