import React from 'react'
import {observer} from 'mobx-react-lite'
import {
ActivityIndicator,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {UserAvatar} from './UserAvatar'
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)
})
}
canGoBack ??= store.nav.tab.canGoBack
return (
<>
{canGoBack ? (
) : (
)}
{title}
{subtitle ? (
{subtitle}
) : undefined}
{!store.session.online ? (
{store.session.attemptingConnect ? (
<>
Connecting...
>
) : (
<>
Unable to connect
Try again
>
)}
) : undefined}
>
)
})
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',
},
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: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: colors.gray6,
paddingLeft: 15,
paddingRight: 10,
paddingVertical: 8,
borderRadius: 8,
marginHorizontal: 4,
marginTop: 4,
},
offlineBtn: {
backgroundColor: colors.gray5,
borderRadius: 5,
paddingVertical: 5,
paddingHorizontal: 10,
},
offlineBtnText: {
color: colors.white,
fontWeight: 'bold',
},
})