Repository navigation
Expand file tree
/
Copy pathHeader.js
More file actions
executable file
·203 lines (190 loc) · 5.27 KB
/
Copy pathHeader.js
File metadata and controls
executable file
·203 lines (190 loc) · 5.27 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
Copyright © SuperMap. All rights reserved.
Author: Yang Shanglong
E-mail: yangshanglong@supermap.com
*/
import React, { Component } from 'react'
import { Text, View, Image, TouchableOpacity, Animated } from 'react-native'
import styles, * as stylesConst from './styles'
class NavigationHeader extends Component {
props: {
header?: any, // 自定义Header
headerStyle?: StyleSheet, // 自定义Header Style
withoutBack?: boolean, // 是否有返回按钮
backBtnType?: string, // 返回按钮类型(white, gray)
backAction?: any, // 返回事件
title?: string, // 标题
headerViewStyle?: StyleSheet, // Header Style
headerLeftStyle?: StyleSheet, //
headerRightStyle?: StyleSheet, //
headerTitleViewStyle?: StyleSheet, //
headerTitleStyle?: StyleSheet, //
headerLeft?: any, // Header左端组件,可为Array
headerRight?: any, // Header右端组件,可为Array
opacity?: number, // 透明度
activeOpacity?: number, // 返回键点击透明度
type?: string, // default | float:浮动Header | floatNoTitle:浮动无title,透明背景 | fix:固定顶部,绝对定位
navigation?: any, // navigation
count?: any,
darkBackBtn?: boolean, // 黑色透明背景,返回按钮
headerCenter?: any,
backImg?: any, // 返回按钮图片
/** 转态栏是否可见*/
statusVisible?: boolean,
}
static defaultProps = {
title: '',
withoutBack: false,
backBtnType: 'gray',
opacity: 1,
activeOpacity: 0.2,
type: 'default',
headerViewStyle: styles.navigationHeader,
headerLeftStyle: styles.headerLeftView,
headerTitleViewStyle: styles.headerTitleView,
headerTitleStyle: styles.headerTitle,
count: 0,
darkBackBtn: false,
headerCenter: null,
}
constructor(props) {
super(props)
this.state = {
headerTop: new Animated.Value(0),
}
this.visible = true
this.clickable = true
}
setVisible = visible => {
if (this.visible === visible) return
Animated.timing(this.state.headerTop, {
toValue: visible ? 0 : -stylesConst.HEADER_HEIGHT,
duration: 300,
}).start()
this.visible = visible
}
handleBack = navigation => {
if (this.props.backAction && typeof this.props.backAction === 'function') {
this.props.backAction()
} else if (!this.props.backAction && navigation) {
if (this.clickable) {
this.clickable = false
navigation.goBack(null)
}
}
}
renderDefaultHeader = () => {
const {
title,
headerLeft,
darkBackBtn,
headerRight,
withoutBack,
activeOpacity,
type,
headerViewStyle,
headerLeftStyle,
headerTitleViewStyle,
headerTitleStyle,
headerRightStyle,
navigation,
count,
headerCenter,
backImg,
} = this.props
let backBtnSource =
backImg || require('../../assets/public/Frenchgrey/icon-back-white.png')
// backBtnType === 'white'
// ? require('../../assets/common/icon-back-white.png')
// : require('../../assets/common/icon-back-gray.png')
let backBtn = (
<TouchableOpacity
accessible={true}
accessibilityLabel={'返回'}
style={styles.backBtn}
activeOpacity={activeOpacity}
onPress={() => {
this.handleBack(navigation)
}}
>
{count ? <Text style={styles.count}>({count})</Text> : null}
<View
style={[styles.iconBtnBg, darkBackBtn && styles.iconBtnBgDarkColor]}
>
<Image source={backBtnSource} style={styles.backIcon} />
</View>
</TouchableOpacity>
)
let titleView = null
if (type !== 'floatNoTitle') {
titleView = (
<View style={headerTitleViewStyle}>
{headerCenter ? (
headerCenter
) : (
<Text
style={headerTitleStyle}
ellipsizeMode="tail"
numberOfLines={1}
>
{title}
</Text>
)}
</View>
)
}
return (
<View style={[styles.navigationHeader, headerViewStyle]}>
{headerLeft ? (
<View style={[styles.headerLeftView, headerLeftStyle]}>
{headerLeft}
</View>
) : (
!withoutBack && backBtn
)}
{titleView}
{headerRight && (
<View style={[styles.headerRightView, headerRightStyle]}>
{headerRight}
</View>
)}
</View>
)
}
render() {
const {
header,
// backAction,
opacity,
type,
headerStyle,
} = this.props
let currentHeaderStyle
switch (type) {
case 'floatNoTitle':
currentHeaderStyle = styles.floatNoTitleHeaderView
break
case 'float':
currentHeaderStyle = styles.floatHeaderView
break
case 'fix':
currentHeaderStyle = styles.fixHeaderView
break
default:
currentHeaderStyle = styles.defaultHeaderView
break
}
return (
<Animated.View
style={[
currentHeaderStyle,
headerStyle,
{ opacity: opacity, top: this.state.headerTop },
]}
>
{header ? header : this.renderDefaultHeader()}
</Animated.View>
)
}
}
export default NavigationHeader