/
Header.js
121 lines (115 loc) · 3.19 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
import React, { PureComponent } from 'react'
import { TextInput, View, Platform } from 'react-native'
import { Button, Flex, Text } from '.'
import { colors } from '../../constants'
import {
paddingLeft,
paddingRight,
padding,
borderBottom,
paddingBottom,
} from '../../styles'
const [defaultTextColor, defaultBackColor] = [colors.black, colors.white]
const HeaderButton = ({ icon, color, style, ...otherProps }) => {
return <Button icon={icon} large color={color} {...otherProps} />
}
export default class Header extends PureComponent {
render () {
const {
navigation,
title,
titleIcon,
backBtn,
rightBtnIcon,
onPressRightBtn,
searchBar,
searchHandler,
} = this.props
const colorText =
this.props.colorText == null ? defaultTextColor : this.props.colorText
const colorBack =
this.props.colorBack == null ? defaultBackColor : this.props.colorBack
const colorBtnLeft =
this.props.colorBtnLeft == null
? defaultTextColor
: this.props.colorBtnLeft
const colorBtnRight =
this.props.colorBtnRight == null
? defaultTextColor
: this.props.colorBtnRight
return (
<View
style={[
{
backgroundColor: colorBack,
height: searchBar ? 100 : 60,
},
borderBottom,
padding,
]}
>
<Flex.Rows>
<Flex.Cols
size={1}
justify='between'
align='center'
style={[searchBar ? paddingBottom : {}]}
>
{backBtn === true && (
<HeaderButton
icon='arrow-left'
color={colorBtnLeft}
onPress={() => navigation.goBack(null)}
justify='start'
middle
/>
)}
<Text
icon={titleIcon}
left
large
color={colorText}
ellipsis
justify={backBtn ? 'center' : 'start'}
middle
size={5}
>
{title}
</Text>
{rightBtnIcon !== null && (
<HeaderButton
icon={rightBtnIcon}
color={colorBtnRight}
onPress={onPressRightBtn}
justify='end'
middle
/>
)}
</Flex.Cols>
{searchBar === true && (
<Flex.Cols size={1} style={[paddingBottom]}>
<TextInput
underlineColorAndroid='transparent'
autoCorrect={false}
style={[
{
height: 36,
flex: 1,
backgroundColor: colors.grey7,
borderWidth: 0,
borderRadius: 18,
...(Platform.OS === 'web' ? { outline: 'none' } : {}),
},
paddingLeft,
paddingRight,
]}
placeholder='Search...'
onChangeText={text => searchHandler(text)}
/>
</Flex.Cols>
)}
</Flex.Rows>
</View>
)
}
}