-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationButton.tsx
90 lines (76 loc) · 2.4 KB
/
NavigationButton.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, { FunctionComponent } from 'react'
// Hooks
// Styles
import { Metrics, Colors, Fonts, ApplicationStyles } from '../Theme';
// Utils
// Redux
// Components
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import IconMaterialCommunity from 'react-native-vector-icons/MaterialCommunityIcons';
interface ScreenHeaderProps {
title: string,
subTitle?: string,
showArrow?: boolean,
disabled?: boolean,
selected?: boolean,
Icon?: React.ComponentType<any> | React.ReactElement<any> | null,
IconRight?: React.ComponentType<any> | React.ReactElement<any> | null,
onPress?: () => void,
}
const NavigationButton: FunctionComponent<ScreenHeaderProps> = ({
title,
subTitle,
showArrow = true,
disabled = false,
selected = false,
Icon,
IconRight,
onPress,
}) => {
const renderIcon = (I: React.ComponentType<any> | React.ReactElement<any>) => {
if (I) {
const icon = React.isValidElement(I) ? (I) : (<I />)
return icon
}
return <View style={ApplicationStyles.spacer} />
}
return (
<TouchableOpacity key={title} style={styles.container} onPress={onPress} disabled={disabled} >
<View style={{ flexDirection: "row", alignItems: "center" }}>
<View style={ApplicationStyles.spacerHalf} />
<View style={{ width: 30, alignItems: "center" }}>
{ !!Icon && renderIcon(Icon) }
</View>
<View style={ApplicationStyles.spacer} />
<View>
<Text style={[styles.title, selected && { color: Colors.darkYellow }]}>{title}</Text>
{ subTitle && <Text style={[styles.subTitle, selected && { color: Colors.darkYellow }]}>{subTitle}</Text> }
</View>
<View style={ApplicationStyles.spacer} />
{ !!IconRight && renderIcon(IconRight) }
</View>
{ showArrow && !disabled && <IconMaterialCommunity name="chevron-right" size={30} color={Colors.lightGrey} /> }
</TouchableOpacity>
)
}
const styles = StyleSheet.create({
container: {
flexDirection: "row",
width: "100%",
minHeight: Metrics.buttonHeight,
alignItems: "center",
justifyContent: "space-between",
paddingVertical: Metrics.baseMargin,
borderBottomWidth: 1,
borderBottomColor: Colors.lightGrey,
},
title: {
...ApplicationStyles.text,
},
subTitle: {
...Fonts.style.small,
fontStyle: "italic",
color: Colors.darkGrey,
},
})
export default NavigationButton