-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathTabSelectorItem.tsx
63 lines (53 loc) · 2.45 KB
/
TabSelectorItem.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React from 'react';
import {Animated, StyleSheet} from 'react-native';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import type IconAsset from '@src/types/utils/IconAsset';
import TabIcon from './TabIcon';
import TabLabel from './TabLabel';
type TabSelectorItemProps = {
/** Function to call when onPress */
onPress?: () => void;
/** Icon to display on tab */
icon?: IconAsset;
/** Title of the tab */
title?: string;
/** Animated background color value for the tab button */
backgroundColor?: string | Animated.AnimatedInterpolation<string>;
/** Animated opacity value while the tab is in inactive state */
inactiveOpacity?: number | Animated.AnimatedInterpolation<number>;
/** Animated opacity value while the tab is in active state */
activeOpacity?: number | Animated.AnimatedInterpolation<number>;
/** Whether this tab is active */
isActive?: boolean;
};
function TabSelectorItem({icon, title = '', onPress = () => {}, backgroundColor = '', activeOpacity = 0, inactiveOpacity = 1, isActive = false}: TabSelectorItemProps) {
const styles = useThemeStyles();
return (
<PressableWithFeedback
accessibilityLabel={title}
style={[styles.tabSelectorButton]}
wrapperStyle={[styles.flex1]}
onPress={onPress}
role={CONST.ROLE.BUTTON}
>
{({hovered}) => (
<Animated.View style={[styles.tabSelectorButton, StyleSheet.absoluteFill, styles.tabBackground(hovered, isActive, backgroundColor)]}>
<TabIcon
icon={icon}
activeOpacity={styles.tabOpacity(hovered, isActive, activeOpacity, inactiveOpacity).opacity}
inactiveOpacity={styles.tabOpacity(hovered, isActive, inactiveOpacity, activeOpacity).opacity}
/>
<TabLabel
title={title}
activeOpacity={styles.tabOpacity(hovered, isActive, activeOpacity, inactiveOpacity).opacity}
inactiveOpacity={styles.tabOpacity(hovered, isActive, inactiveOpacity, activeOpacity).opacity}
/>
</Animated.View>
)}
</PressableWithFeedback>
);
}
TabSelectorItem.displayName = 'TabSelectorItem';
export default TabSelectorItem;