import React from 'react' import { ScrollView, StyleProp, StyleSheet, TouchableOpacity, View, ViewStyle, } from 'react-native' import {observer} from 'mobx-react-lite' import VersionNumber from 'react-native-version-number' import {s, colors} from '../../lib/styles' import {useStores} from '../../../state' import { HomeIcon, BellIcon, UserIcon, CogIcon, MagnifyingGlassIcon, } from '../../lib/icons' import {UserAvatar} from '../../com/util/UserAvatar' import {Text} from '../../com/util/text/Text' import {ToggleButton} from '../../com/util/forms/ToggleButton' import {usePalette} from '../../lib/hooks/usePalette' export const Menu = observer(({onClose}: {onClose: () => void}) => { const pal = usePalette('default') const store = useStores() // events // = const onNavigate = (url: string) => { onClose() if (url === '/notifications') { store.nav.switchTo(1, true) } else { store.nav.switchTo(0, true) if (url !== '/') { store.nav.navigate(url) } } } // rendering // = const MenuItem = ({ icon, label, count, url, bold, onPress, }: { icon: JSX.Element label: string count?: number url?: string bold?: boolean onPress?: () => void }) => ( onNavigate(url || '/')}> {icon} {count ? ( {count} ) : undefined} {label} ) return ( onNavigate(`/profile/${store.me.handle}`)} style={styles.profileCard}> {store.me.displayName || store.me.handle} @{store.me.handle} onNavigate('/search')}> } size={25} /> Search } size="26" />} label="Home" url="/" /> } size="28" />} label="Notifications" url="/notifications" count={store.me.notificationCount} /> } size="30" strokeWidth={2} /> } label="Profile" url={`/profile/${store.me.handle}`} /> } size="30" strokeWidth={2} /> } label="Settings" url="/settings" /> store.shell.setDarkMode(!store.shell.darkMode)} /> Build version {VersionNumber.appVersion} ({VersionNumber.buildVersion} ) ) }) const styles = StyleSheet.create({ view: { flex: 1, }, section: { paddingHorizontal: 10, paddingTop: 10, paddingBottom: 10, borderBottomWidth: 1, }, heading: { paddingVertical: 8, paddingHorizontal: 4, }, profileCard: { flexDirection: 'row', alignItems: 'center', margin: 10, marginBottom: 6, }, profileCardDisplayName: { marginLeft: 12, }, profileCardHandle: { marginLeft: 12, }, searchBtn: { flexDirection: 'row', borderRadius: 8, margin: 10, marginBottom: 0, paddingVertical: 10, paddingHorizontal: 12, }, searchBtnLabel: { marginLeft: 14, fontWeight: 'normal', }, menuItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: 6, paddingLeft: 6, paddingRight: 10, }, menuItemIconWrapper: { width: 36, height: 36, alignItems: 'center', justifyContent: 'center', marginRight: 12, }, menuItemLabel: { flex: 1, fontWeight: 'normal', }, menuItemLabelBold: { flex: 1, fontWeight: 'bold', }, menuItemCount: { position: 'absolute', right: -6, top: -2, backgroundColor: colors.red3, paddingHorizontal: 4, paddingBottom: 1, borderRadius: 6, }, menuItemCountLabel: { fontSize: 12, fontWeight: 'bold', color: colors.white, }, footer: { paddingHorizontal: 14, paddingVertical: 18, }, })