import React, {useEffect} from 'react' import {observer} from 'mobx-react-lite' import { StyleSheet, SafeAreaView, Text, TouchableOpacity, TouchableWithoutFeedback, View, } from 'react-native' import Animated, { useSharedValue, useAnimatedStyle, withTiming, interpolate, } from 'react-native-reanimated' import {IconProp} from '@fortawesome/fontawesome-svg-core' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {HomeIcon, UserGroupIcon, BellIcon} from '../../lib/icons' import {UserAvatar} from '../../com/util/UserAvatar' import {useStores} from '../../../state' import {s, colors} from '../../lib/styles' export const MainMenu = observer( ({active, onClose}: {active: boolean; onClose: () => void}) => { const store = useStores() const initInterp = useSharedValue(0) useEffect(() => { if (active) { initInterp.value = withTiming(1, {duration: 150}) } else { initInterp.value = 0 } }, [initInterp, active]) const wrapperAnimStyle = useAnimatedStyle(() => ({ opacity: interpolate(initInterp.value, [0, 1.0], [0, 1.0]), })) const menuItemsAnimStyle = useAnimatedStyle(() => ({ top: interpolate(initInterp.value, [0, 1.0], [15, 0]), })) // events // = const onNavigate = (url: string) => { store.nav.navigate(url) onClose() } // rendering // = const MenuItem = ({ icon, label, url, count, }: { icon: IconProp label: string url: string count?: number }) => ( onNavigate(url)}> {icon === 'home' ? ( ) : icon === 'user-group' ? ( ) : icon === 'bell' ? ( ) : ( )} {count ? ( {count} ) : undefined} {label} ) const MenuItemActor = ({ label, url, count, }: { label: string url: string count?: number }) => ( onNavigate(url)}> {count ? ( {count} ) : undefined} {label} ) if (!active) { return } return ( <> onNavigate(`/profile/${store.me.name || ''}`)}> {store.me.displayName || store.me.name || 'My profile'} onNavigate(`/settings`)}> Scenes ) }, ) const styles = StyleSheet.create({ bg: { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0, // backgroundColor: '#000', opacity: 0, }, wrapper: { position: 'absolute', top: 0, bottom: 75, width: '100%', backgroundColor: '#fff', }, topSection: { flexDirection: 'row', alignItems: 'center', height: 40, paddingHorizontal: 10, marginBottom: 10, }, section: { paddingHorizontal: 10, }, heading: { fontSize: 21, fontWeight: 'bold', paddingHorizontal: 10, paddingTop: 6, paddingBottom: 12, }, profile: { paddingVertical: 10, paddingHorizontal: 10, flexDirection: 'row', alignItems: 'center', }, profileImage: { marginRight: 8, }, profileText: { fontSize: 15, fontWeight: 'bold', }, settings: {}, settingsIcon: { color: colors.gray5, marginRight: 10, }, menuItemsAnimContainer: { position: 'relative', }, menuItems: { flexDirection: 'row', marginBottom: 20, }, menuItem: { width: 82, alignItems: 'center', }, menuItemMargin: { marginRight: 10, }, menuItemIconWrapper: { borderRadius: 6, width: 60, height: 60, justifyContent: 'center', alignItems: 'center', marginBottom: 5, backgroundColor: colors.gray1, }, menuItemIcon: { color: colors.gray5, }, menuItemLabel: { fontSize: 13, textAlign: 'center', }, menuItemCount: { position: 'absolute', left: 48, top: 10, backgroundColor: colors.red3, paddingHorizontal: 4, paddingBottom: 1, borderRadius: 6, }, menuItemCountLabel: { fontSize: 12, fontWeight: 'bold', color: colors.white, }, })