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
|
import React from 'react'
import {observer} from 'mobx-react-lite'
import {
ActivityIndicator,
StyleSheet,
TouchableOpacity,
View,
} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {UserAvatar} from './UserAvatar'
import {Text} from './text/Text'
import {s, colors} from '../../lib/styles'
import {MagnifyingGlassIcon} from '../../lib/icons'
import {useStores} from '../../../state'
const HITSLOP = {left: 10, top: 10, right: 10, bottom: 10}
const BACK_HITSLOP = {left: 10, top: 10, right: 30, bottom: 10}
export const ViewHeader = observer(function ViewHeader({
title,
subtitle,
canGoBack,
onPost,
}: {
title: string
subtitle?: string
canGoBack?: boolean
onPost?: () => void
}) {
const store = useStores()
const onPressBack = () => {
store.nav.tab.goBack()
}
const onPressMenu = () => {
store.shell.setMainMenuOpen(true)
}
const onPressCompose = () => {
store.shell.openComposer({onPost})
}
const onPressSearch = () => {
store.nav.navigate(`/search`)
}
const onPressReconnect = () => {
store.session.connect().catch(e => {
// log for debugging but ignore otherwise
console.log(e)
})
}
if (typeof canGoBack === 'undefined') {
canGoBack = store.nav.tab.canGoBack
}
return (
<View style={styles.header}>
<TouchableOpacity
onPress={canGoBack ? onPressBack : onPressMenu}
hitSlop={BACK_HITSLOP}
style={canGoBack ? styles.backIcon : styles.backIconWide}>
{canGoBack ? (
<FontAwesomeIcon
size={18}
icon="angle-left"
style={{marginTop: 6, color: colors.black}}
/>
) : (
<UserAvatar
size={30}
handle={store.me.handle}
displayName={store.me.displayName}
avatar={store.me.avatar}
/>
)}
</TouchableOpacity>
<View style={styles.titleContainer} pointerEvents="none">
<Text style={styles.title}>{title}</Text>
{subtitle ? (
<Text style={styles.subtitle} numberOfLines={1}>
{subtitle}
</Text>
) : undefined}
</View>
<TouchableOpacity
onPress={onPressCompose}
hitSlop={HITSLOP}
style={styles.btn}>
<FontAwesomeIcon size={18} icon="plus" />
</TouchableOpacity>
<TouchableOpacity
onPress={onPressSearch}
hitSlop={HITSLOP}
style={[styles.btn, {marginLeft: 8}]}>
<MagnifyingGlassIcon
size={18}
strokeWidth={3}
style={styles.searchBtnIcon}
/>
</TouchableOpacity>
{!store.session.online ? (
<TouchableOpacity
style={[styles.btn, {marginLeft: 8}, styles.offline]}
onPress={onPressReconnect}>
{store.session.attemptingConnect ? (
<ActivityIndicator />
) : (
<>
<FontAwesomeIcon icon="signal" style={[s.black]} size={18} />
<FontAwesomeIcon
icon="x"
style={{
backgroundColor: colors.white,
color: colors.red4,
position: 'relative',
left: -4,
top: 6,
}}
size={12}
/>
</>
)}
</TouchableOpacity>
) : undefined}
</View>
)
})
const styles = StyleSheet.create({
header: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: colors.white,
paddingHorizontal: 12,
paddingTop: 6,
paddingBottom: 6,
borderBottomColor: colors.gray1,
borderBottomWidth: 1,
},
titleContainer: {
flexDirection: 'row',
alignItems: 'baseline',
marginRight: 'auto',
},
title: {
fontSize: 21,
fontWeight: '600',
color: colors.black,
},
subtitle: {
fontSize: 18,
marginLeft: 6,
color: colors.gray4,
maxWidth: 200,
},
backIcon: {width: 30, height: 30},
backIconWide: {width: 40, height: 30},
btn: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: colors.gray1,
width: 36,
height: 36,
borderRadius: 20,
},
searchBtnIcon: {
color: colors.black,
position: 'relative',
top: -1,
},
offline: {
backgroundColor: colors.white,
},
offlineBtn: {
backgroundColor: colors.white,
borderRadius: 5,
paddingVertical: 5,
paddingHorizontal: 10,
},
})
|