-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTab.jsx
More file actions
76 lines (68 loc) · 1.69 KB
/
Tab.jsx
File metadata and controls
76 lines (68 loc) · 1.69 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
import React, { forwardRef, useCallback } from "react";
import { View, StyleSheet } from "react-native";
import PropTypes from "prop-types";
import { moderateScale } from "react-native-size-matters";
import { Touchable } from "../Touchable";
import { Typography } from "../Typography";
export const Tab = forwardRef(
({ label, value, navigation, flex, count }, ref) => {
const handleOnPress = useCallback(
() => navigation.navigate(value),
[navigation, value]
);
return (
<View
ref={ref}
style={[
styles.container,
{
flex,
minWidth: count !== undefined ? moderateScale(56) : undefined,
},
]}
>
<Touchable
alignItems="center"
flex={1}
justifyContent="center"
onPress={handleOnPress}
>
<Typography
fontFamily="sf600"
fontSize="xs"
numberOfLines={1}
textAlign="center"
>
{label}
</Typography>
{count !== undefined && (
<Typography
fontFamily="sf500"
fontSize="xs"
numberOfLines={1}
textAlign="center"
>
({count})
</Typography>
)}
</Touchable>
</View>
);
}
);
const styles = StyleSheet.create({
container: {
height: "100%",
},
});
Tab.displayName = "Tab";
Tab.propTypes = {
flex: PropTypes.number,
label: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
navigation: PropTypes.object,
count: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};
Tab.defaultProps = {
flex: 1,
};