forked from iamshadmirza/react-native-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeader.js
135 lines (128 loc) · 3.62 KB
/
Header.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React from 'react';
import { View, TouchableOpacity, TouchableNativeFeedback, Text, StyleSheet, Platform, StatusBar, SafeAreaView } from 'react-native';
import PropTypes from 'prop-types';
import { useThemeContext } from '../util/ThemeProvider';
const getContainerStyle = ({ theme, color }) => {
const headerStyle = [styles.container];
headerStyle.push({
backgroundColor: theme.brandColor[color],
});
return headerStyle;
};
const getTextStyle = ({ theme, color, textAlign, fontSize }) => {
const textStyle = [styles.text];
textStyle.push({
backgroundColor: theme.brandColor[color],
fontSize: theme.fontSize[fontSize],
});
if (textAlign) {
textStyle.push({
textAlign: textAlign,
});
}
return textStyle;
};
const Header = ({ style, textStyle, ...props }) => {
const theme = useThemeContext();
const TouchableElement = Platform.OS === 'android' ? TouchableNativeFeedback : TouchableOpacity;
return (
<SafeAreaView style={[styles.safeAreaView, { backgroundColor: theme.brandColor[props.barColor] }]}>
<StatusBar
barStyle={props.barStyle}
backgroundColor={theme.brandColor[props.barColor]}
/>
<View style={StyleSheet.flatten([getContainerStyle({ ...props, theme }), style])}>
{props.leftIcon &&
<TouchableElement {...props} onPress={props.onLeftIconPress}>
<View style={StyleSheet.flatten([styles.iconStyle, props.iconStyle])}>
{props.leftIcon}
</View>
</TouchableElement>
}
{!!props.children &&
<Text style={StyleSheet.flatten([getTextStyle({ ...props, theme }), textStyle])}>
{props.children}
</Text>}
{props.rightIcon &&
<TouchableElement {...props} onPress={props.onRightIconPress}>
<View style={StyleSheet.flatten([styles.iconStyle, props.iconStyle])}>
{props.rightIcon}
</View>
</TouchableElement>
}
</View>
</SafeAreaView>
);
};
Header.propTypes = {
style: PropTypes.object,
textStyle: PropTypes.object,
textAlign: PropTypes.oneOf(['auto', 'left', 'center', 'right', 'justify']),
fontSize: PropTypes.oneOf(['xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'xxlarge']),
children: PropTypes.string,
color: PropTypes.string,
leftIcon: PropTypes.element,
onLeftIconPress: PropTypes.func,
rightIcon: PropTypes.element,
onRightIconPress: PropTypes.func,
iconStyle: PropTypes.object,
barColor: PropTypes.string,
barStyle: PropTypes.oneOf(['default', 'dark-content', 'light-content']),
};
Header.defaultProps = {
color: 'primary',
barColor: 'primary',
barStyle: 'light-content',
fontSize: 'medium',
};
const styles = StyleSheet.create({
safeAreaView: {
...Platform.select({
android: {
elevation: 3,
},
ios: {
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.25,
shadowRadius: 3,
},
web: {
boxShadow: '0 5px 5px rgba(0,0,0,0.10), 1px 5px 5px rgba(0,0,0,0.10)',
},
}),
zIndex: 10,
},
container: {
width: '100%',
height: Platform.select({
android: 56,
ios: 56,
web: 64,
}),
flexDirection: 'row',
alignItems: 'center',
zIndex: 10,
},
text: {
flex: 1,
fontWeight: Platform.select({
android: 'bold',
ios: '500',
}),
textAlign: Platform.select({
android: 'left',
ios: 'center',
web: 'center',
}),
color: '#fff',
paddingHorizontal: 10,
},
iconStyle: {
padding: 10,
},
});
export default Header;