ForumHeader.js
3.39 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
142
143
144
145
146
147
148
149
150
151
import React from 'react'
import {
View,
Text,
Image,
StyleSheet,
TouchableOpacity,
StatusBar,
Platform,
PixelRatio,
Dimensions
} from 'react-native'
import {NavigationActions,SafeAreaView} from 'react-navigation'
import {observer} from 'mobx-react/native'
export const line = 1 / PixelRatio.get()
const isX=Dimensions.get("window").height>=812&&Dimensions.get("window").width===375
export const XOffset=isX?20:0
export const headerHeight = 44
const styles = StyleSheet.create({
container: {
height: headerHeight,
backgroundColor: '#fafafa',
flexDirection: 'row',
alignItems: 'center',
borderBottomColor:"#dddddd"
},
leftView: {
paddingLeft: 15,
height:headerHeight,
flex: 1,
justifyContent:'center',
},
rightView: {
flex: 1,
paddingRight: 15,
alignItems: 'flex-end',
},
titleView: {
flex: 1,
alignItems: 'center',
},
title: {
fontSize: 18,
color: "#000",
fontWeight:"bold"
},
backIcon: {
height: 16.5,
width: 9,
},
codeIcon:{
width:20,
height:20
},
rightText:{
fontSize:16,
color:"#333333",
}
})
@observer
export default class ForumHeader extends React.Component {
left() {
const {navigation, pop, left, leftPress,backKey,popToHome,code} = this.props
if (pop||popToHome) {
return (
<TouchableOpacity style={styles.leftView} onPress={() => {
if(pop){navigation.dispatch(NavigationActions.back({key:backKey}))}
if(popToHome){
const resetAction = NavigationActions.reset({
index: 0,
key:null,
actions: [
NavigationActions.navigate({ routeName: 'BottomModal'})
]
})
this.props.navigation.dispatch(resetAction)
}
}}>
<Image style={styles.backIcon} resizeModa="contain" source={require('../img/loadBack.png')}/>
</TouchableOpacity>
)
}
if (left) {
return (
<TouchableOpacity style={styles.leftView} onPress={() => leftPress && leftPress()}>
{left}
</TouchableOpacity>
)
}
if(code){
return (
<TouchableOpacity style={styles.leftView} onPress={() => leftPress && leftPress()}>
</TouchableOpacity>
)
}
return <View style={styles.leftView}/>
}
center() {
const {center, title} = this.props
if (title) {
return (
<View style={styles.titleView}>
<Text style={styles.title}>{title}</Text>
</View>
)
}
if (center) {
return center
}
return null
}
right() {
const {right,rightText, rightPress} = this.props
if (right) {
return (
<TouchableOpacity onPress={() => rightPress && rightPress()} style={styles.rightView}>
{right}
</TouchableOpacity>
)
}
if(rightText){
return(
<TouchableOpacity onPress={() => rightPress && rightPress()} style={styles.rightView}>
<Text style={styles.rightText}>{rightText}</Text>
</TouchableOpacity>
)
}
return <View style={styles.rightView}/>
}
render() {
const border={borderBottomWidth:this.props.noborder?0:line,}
const {offset}=this.props
let marginTopSize = (Platform.OS === "ios" ? 20 : 0);
marginTopSize = marginTopSize + XOffset;
// debugger
return (
<View style={{backgroundColor:"#fafafa",marginTop:marginTopSize}}>
<StatusBar barStyle={'default'}></StatusBar>
<SafeAreaView style={[styles.container,border,offset&&{paddingTop:offset+XOffset,height:headerHeight+offset+XOffset}]} >
{this.left()}
{this.center()}
{this.right()}
</SafeAreaView>
</View>
)
}
}