import React from 'react' import { Linking, SafeAreaView, StyleProp, StyleSheet, TouchableOpacity, View, ViewStyle, } from 'react-native' import { useNavigation, useNavigationState, StackActions, } from '@react-navigation/native' import {observer} from 'mobx-react-lite' import { FontAwesomeIcon, FontAwesomeIconStyle, } from '@fortawesome/react-native-fontawesome' import {s, colors} from 'lib/styles' import {FEEDBACK_FORM_URL} from 'lib/constants' import {useStores} from 'state/index' import { HomeIcon, HomeIconSolid, BellIcon, BellIconSolid, UserIcon, CogIcon, MagnifyingGlassIcon2, MagnifyingGlassIcon2Solid, MoonIcon, } from 'lib/icons' import {UserAvatar} from 'view/com/util/UserAvatar' import {Text} from 'view/com/util/text/Text' import {useTheme} from 'lib/ThemeContext' import {usePalette} from 'lib/hooks/usePalette' import {useAnalytics} from 'lib/analytics' import {pluralize} from 'lib/strings/helpers' import {getTabState, TabState} from 'lib/routes/helpers' import {NavigationProp} from 'lib/routes/types' export const DrawerContent = observer(() => { const theme = useTheme() const pal = usePalette('default') const store = useStores() const navigation = useNavigation() const {track} = useAnalytics() const {isAtHome, isAtSearch, isAtNotifications} = useNavigationState( state => { return { isAtHome: getTabState(state, 'Home') !== TabState.Outside, isAtSearch: getTabState(state, 'Search') !== TabState.Outside, isAtNotifications: getTabState(state, 'Notifications') !== TabState.Outside, } }, ) // events // = const onPressTab = React.useCallback( (tab: string) => { track('Menu:ItemClicked', {url: tab}) const state = navigation.getState() store.shell.closeDrawer() const tabState = getTabState(state, tab) if (tabState === TabState.InsideAtRoot) { store.emitScreenSoftReset() } else if (tabState === TabState.Inside) { navigation.dispatch(StackActions.popToTop()) } else { // @ts-ignore must be Home, Search, or Notifications navigation.navigate(`${tab}Tab`) } }, [store, track, navigation], ) const onPressHome = React.useCallback(() => onPressTab('Home'), [onPressTab]) const onPressSearch = React.useCallback( () => onPressTab('Search'), [onPressTab], ) const onPressNotifications = React.useCallback( () => onPressTab('Notifications'), [onPressTab], ) const onPressProfile = React.useCallback(() => { track('Menu:ItemClicked', {url: 'Profile'}) navigation.navigate('Profile', {name: store.me.handle}) store.shell.closeDrawer() }, [navigation, track, store.me.handle, store.shell]) const onPressSettings = React.useCallback(() => { track('Menu:ItemClicked', {url: 'Settings'}) navigation.navigate('Settings') store.shell.closeDrawer() }, [navigation, track, store.shell]) const onPressFeedback = () => { track('Menu:FeedbackClicked') Linking.openURL(FEEDBACK_FORM_URL) } // rendering // = const MenuItem = ({ icon, label, count, bold, onPress, }: { icon: JSX.Element label: string count?: number bold?: boolean onPress: () => void }) => ( {icon} {count ? ( 99 ? styles.menuItemCountHundreds : count > 9 ? styles.menuItemCountTens : undefined, ]}> {count > 999 ? `${Math.round(count / 1000)}k` : count} ) : undefined} {label} ) const onDarkmodePress = () => { track('Menu:ItemClicked', {url: '/darkmode'}) store.shell.setDarkMode(!store.shell.darkMode) } return ( {store.me.displayName || store.me.handle} @{store.me.handle} {store.me.followersCount || 0} {' '} {pluralize(store.me.followersCount || 0, 'follower')} ·{' '} {store.me.followsCount || 0} {' '} following } size={24} strokeWidth={1.7} /> ) : ( } size={24} strokeWidth={1.7} /> ) } label="Search" bold={isAtSearch} onPress={onPressSearch} /> } size="24" strokeWidth={3.25} /> ) : ( } size="24" strokeWidth={3.25} /> ) } label="Home" bold={isAtHome} onPress={onPressHome} /> } size="24" strokeWidth={1.7} /> ) : ( } size="24" strokeWidth={1.7} /> ) } label="Notifications" count={store.me.notifications.unreadCount} bold={isAtNotifications} onPress={onPressNotifications} /> } size="26" strokeWidth={1.5} /> } label="Profile" onPress={onPressProfile} /> } size="26" strokeWidth={1.75} /> } label="Settings" onPress={onPressSettings} /> } strokeWidth={2} /> Feedback ) }) const styles = StyleSheet.create({ view: { flex: 1, paddingTop: 20, paddingBottom: 50, paddingLeft: 20, }, viewDarkMode: { backgroundColor: '#1B1919', }, profileCardDisplayName: { marginTop: 20, paddingRight: 30, }, profileCardHandle: { marginTop: 4, paddingRight: 30, }, profileCardFollowers: { marginTop: 16, paddingRight: 30, }, menuItem: { flexDirection: 'row', alignItems: 'center', paddingVertical: 16, paddingRight: 10, }, menuItemIconWrapper: { width: 24, height: 24, alignItems: 'center', justifyContent: 'center', marginRight: 12, }, menuItemCount: { position: 'absolute', width: 'auto', right: -6, top: -4, backgroundColor: colors.blue3, paddingHorizontal: 4, paddingBottom: 1, borderRadius: 6, }, menuItemCountTens: { width: 25, }, menuItemCountHundreds: { right: -12, width: 34, }, menuItemCountLabel: { fontSize: 12, fontWeight: 'bold', fontVariant: ['tabular-nums'], color: colors.white, }, footer: { flexDirection: 'row', justifyContent: 'space-between', paddingRight: 30, paddingTop: 80, }, footerBtn: { flexDirection: 'row', alignItems: 'center', padding: 10, borderRadius: 25, }, footerBtnDarkMode: { backgroundColor: colors.black, }, footerBtnFeedback: { paddingHorizontal: 24, }, footerBtnFeedbackLight: { backgroundColor: '#DDEFFF', }, footerBtnFeedbackDark: { backgroundColor: colors.blue6, }, })