Skip to content

Commit 70ee098

Browse files
Create component Header
1 parent 6d421dc commit 70ee098

File tree

6 files changed

+141
-4
lines changed

6 files changed

+141
-4
lines changed

src/components/Header/Header.props.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {Ionicons} from '@expo/vector-icons';
2+
3+
export type IIconTypes = keyof typeof Ionicons.glyphMap;

src/components/Header/Header.tsx

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import React from 'react';
2+
import {StyleSheet, Text, View} from 'react-native';
3+
import {NavigationService} from '../../services/navigation-service/navigationService';
4+
import {ColorDefault} from '../../themes/colors';
5+
import {TouchableOpacity} from 'react-native-gesture-handler';
6+
import {IIconTypes} from './Header.props';
7+
import {Ionicons} from '@expo/vector-icons';
8+
9+
type HeaderProps = {
10+
leftIcon?: IIconTypes;
11+
onPressLeft?: () => void;
12+
rightIcon?: IIconTypes;
13+
onPressRight?: () => void;
14+
title?: string;
15+
backEnabled?: boolean;
16+
subRightIcon?: IIconTypes;
17+
onPressSubRight?: () => void;
18+
children?: React.ReactNode;
19+
};
20+
21+
export const Header = (props: HeaderProps) => {
22+
const {
23+
leftIcon,
24+
rightIcon,
25+
title,
26+
onPressLeft,
27+
onPressRight,
28+
backEnabled,
29+
subRightIcon,
30+
onPressSubRight,
31+
children,
32+
} = props;
33+
34+
const iconLeft = leftIcon || (backEnabled ? 'chevron-back-sharp' : undefined);
35+
36+
const onLeftPress =
37+
onPressLeft || backEnabled ? NavigationService.goBack : undefined;
38+
39+
return (
40+
<View
41+
style={[styles.header, {backgroundColor: ColorDefault.navigationBar}]}>
42+
<TouchableOpacity
43+
disabled={!iconLeft}
44+
onPress={onLeftPress}
45+
style={styles.leftButton}>
46+
{!!iconLeft && (
47+
<Ionicons
48+
name={iconLeft}
49+
size={32}
50+
style={{color: ColorDefault.primary}}
51+
/>
52+
)}
53+
</TouchableOpacity>
54+
{!!subRightIcon && <View style={styles.leftButton} />}
55+
56+
{/* Title */}
57+
{children || (
58+
<Text style={[styles.titleText, {color: ColorDefault.primary}]}>
59+
{title}
60+
</Text>
61+
)}
62+
{!!subRightIcon && (
63+
<TouchableOpacity
64+
disabled={!rightIcon}
65+
onPress={onPressSubRight}
66+
style={styles.subRightButton}>
67+
{!!subRightIcon && (
68+
<Ionicons
69+
name={subRightIcon}
70+
size={32}
71+
style={{color: ColorDefault.primary}}
72+
/>
73+
)}
74+
</TouchableOpacity>
75+
)}
76+
{/* Button right */}
77+
<TouchableOpacity
78+
disabled={!rightIcon}
79+
onPress={onPressRight}
80+
style={styles.rightButton}>
81+
{!!rightIcon && (
82+
<Ionicons
83+
name={rightIcon}
84+
size={32}
85+
style={{color: ColorDefault.primary}}
86+
/>
87+
)}
88+
</TouchableOpacity>
89+
</View>
90+
);
91+
};
92+
93+
const styles = StyleSheet.create({
94+
header: {
95+
height: 50,
96+
flexDirection: 'row',
97+
alignItems: 'center',
98+
},
99+
leftButton: {
100+
width: 50,
101+
alignItems: 'center',
102+
},
103+
rightButton: {
104+
width: 50,
105+
alignItems: 'center',
106+
},
107+
subRightButton: {
108+
width: 50,
109+
alignItems: 'center',
110+
},
111+
titleText: {
112+
flex: 1,
113+
textAlign: 'center',
114+
},
115+
searchContainer: {
116+
height: 30,
117+
flex: 1,
118+
borderRadius: 5,
119+
paddingHorizontal: 5,
120+
flexDirection: 'row',
121+
alignItems: 'center',
122+
backgroundColor: '#FFF',
123+
marginRight: 8,
124+
},
125+
});

src/components/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './Button/Button';
66
export * from './Divider/Divider';
77
export * from './Modal/Modal';
88
export * from './BottomMenu/TabBar';
9+
export * from './Header/Header';

src/models/IThemes.ts

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export interface IColors {
8989
blue: string;
9090

9191
grey: string;
92+
93+
navigationBar: string;
9294
}
9395

9496
export interface ISpacing {

src/themes/colors.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const ColorDefault: IColors = {
1010
info: '#ffd700',
1111
blue: '#3A36D5',
1212
grey: '#CFD2D7',
13+
navigationBar: '#ffffff',
1314
};
1415
export const ColorDark: IColors = {
1516
primary: 'rgb(10, 132, 255)',
@@ -22,4 +23,5 @@ export const ColorDark: IColors = {
2223
info: '#ffd700',
2324
blue: '#3A36D5',
2425
grey: '#CFD2D7',
26+
navigationBar: '#ffffff',
2527
};

src/views/HomeScreen/index.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import React from 'react';
22
import {StyleSheet, Text, View} from 'react-native';
3+
import {SafeAreaView} from 'react-native-safe-area-context';
4+
import {Header} from '../../components';
35
import config from '../../config';
46

57
const HomeScreen = () => {
68
return (
7-
<View style={styles.container}>
8-
<Text>{config.BASE_URL}</Text>
9-
</View>
9+
<SafeAreaView style={{flex: 1}}>
10+
<Header title="Header" backEnabled={true} />
11+
<View style={styles.container}>
12+
<Text>{config.BASE_URL}</Text>
13+
</View>
14+
</SafeAreaView>
1015
);
1116
};
1217
const styles = StyleSheet.create({
@@ -17,5 +22,4 @@ const styles = StyleSheet.create({
1722
justifyContent: 'center',
1823
},
1924
});
20-
2125
export default HomeScreen;

0 commit comments

Comments
 (0)