CommonTitleBar.js
3.81 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
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
136
137
138
139
140
141
import React, {Component} from 'react';
import Global from '../utils/Global';
import Utils from '../utils/Utils';
import {Button, Dimensions, Image, PixelRatio, StatusBar, StyleSheet, Text, TouchableOpacity, View, Platform} from 'react-native';
const {width} = Dimensions.get('window');
export default class CommonTitleBar extends Component {
constructor(props) {
super(props);
}
renderAndroid() {
return (
<View style={styles.container}>
<StatusBar
backgroundColor='#393A3E'
barStyle="light-content"
/>
<View style={styles.content}>
<TouchableOpacity activeOpacity={0.5} onPress={this.handleBackClick}>
<Image source={require('../../images/ic_back.png')} style={styles.backBtn}/>
</TouchableOpacity>
<View style={styles.btnDivider}/>
<View style={styles.titleContainer}>
<Text style={styles.title}>{this.props.title}</Text>
{
Utils.isEmpty(this.props.rightIcon) ? (null) : (
<TouchableOpacity activeOpacity={0.6} onPress={() => this.handleRightClick()}>
<Image style={styles.img} source={this.props.rightIcon}/>
</TouchableOpacity>
)
}
{
Utils.isEmpty(this.props.rightBtnText) ? (null) : (
<Button
onPress={() => this.props.handleRightBtnClick()}
title={this.props.rightBtnText}
color="#19AD17"
/>
)
}
</View>
</View>
</View>
);
}
renderIOS() {
return (
<View style={styles.container}>
<View style={{height: 20, backgroundColor: Global.titleBackgroundColor}}/>
<View style={styles.content}>
<TouchableOpacity activeOpacity={0.5} onPress={this.handleBackClick}>
<Image source={require('../../images/ic_back.png')} style={styles.backBtn}/>
</TouchableOpacity>
<View style={styles.btnDivider}/>
<View style={styles.titleContainer}>
<Text style={styles.title}>{this.props.title}</Text>
{
Utils.isEmpty(this.props.rightIcon) ? (null) : (
<TouchableOpacity activeOpacity={0.6} onPress={() => this.handleRightClick()}>
<Image style={styles.img} source={this.props.rightIcon}/>
</TouchableOpacity>
)
}
{
Utils.isEmpty(this.props.rightBtnText) ? (null) : (
<Button
onPress={() => this.props.handleRightBtnClick()}
title={this.props.rightBtnText}
color="#19AD17"
/>
)
}
</View>
</View>
</View>
);
}
render() {
if (Platform.OS === 'ios') {
return this.renderIOS();
}
return this.renderAndroid();
}
handleRightClick() {
if (!Utils.isEmpty(this.props.handleRightClick)) {
this.props.handleRightClick();
}
}
handleBackClick = () => {
this.props.nav.goBack();
}
}
const styles = StyleSheet.create({
container: {
flexDirection: 'column',
},
content: {
width: width,
height: 50,
backgroundColor: Global.titleBackgroundColor,
flexDirection: 'row',
alignItems: 'center'
},
backBtn: {
marginLeft: 8,
marginRight: 8,
width: 30,
height: 30,
},
btnDivider: {
width: 1 / PixelRatio.get(),
height: 30,
marginTop: 10,
marginBottom: 10,
backgroundColor: '#888888'
},
titleContainer: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
paddingLeft: 10,
paddingRight: 10,
},
title: {
color: '#FFFFFF',
fontSize: 16,
flex: 1,
},
img: {
width: 30,
height: 30,
marginRight: 5
}
});