forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabSelectorItem.tsx
More file actions
86 lines (73 loc) · 3.11 KB
/
TabSelectorItem.tsx
File metadata and controls
86 lines (73 loc) · 3.11 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, {useState} from 'react';
import {Animated} from 'react-native';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Tooltip from '@components/Tooltip';
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';
const AnimatedPressableWithFeedback = Animated.createAnimatedComponent(PressableWithFeedback);
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;
/** Whether to show the label when the tab is inactive */
shouldShowLabelWhenInactive?: boolean;
};
function TabSelectorItem({
icon,
title = '',
onPress = () => {},
backgroundColor = '',
activeOpacity = 0,
inactiveOpacity = 1,
isActive = false,
shouldShowLabelWhenInactive = true,
}: TabSelectorItemProps) {
const styles = useThemeStyles();
const [isHovered, setIsHovered] = useState(false);
return (
<Tooltip
shouldRender={!shouldShowLabelWhenInactive && !isActive}
text={title}
>
<AnimatedPressableWithFeedback
accessibilityLabel={title}
style={[styles.tabSelectorButton, styles.tabBackground(isHovered, isActive, backgroundColor), styles.userSelectNone]}
wrapperStyle={[styles.flexGrow1]}
onPress={onPress}
onHoverIn={() => setIsHovered(true)}
onHoverOut={() => setIsHovered(false)}
role={CONST.ROLE.BUTTON}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
>
<TabIcon
icon={icon}
activeOpacity={styles.tabOpacity(isHovered, isActive, activeOpacity, inactiveOpacity).opacity}
inactiveOpacity={styles.tabOpacity(isHovered, isActive, inactiveOpacity, activeOpacity).opacity}
/>
{(shouldShowLabelWhenInactive || isActive) && (
<TabLabel
title={title}
activeOpacity={styles.tabOpacity(isHovered, isActive, activeOpacity, inactiveOpacity).opacity}
inactiveOpacity={styles.tabOpacity(isHovered, isActive, inactiveOpacity, activeOpacity).opacity}
/>
)}
</AnimatedPressableWithFeedback>
</Tooltip>
);
}
TabSelectorItem.displayName = 'TabSelectorItem';
export default TabSelectorItem;