import React from 'react'; import { Platform, ScrollView, StatusBar, Text, TouchableOpacity, View, DeviceEventEmitter, } from 'react-native'; import FastStorage from 'react-native-fast-storage'; import Icon from 'react-native-vector-icons/Feather'; import { ACCENT, COLOR_SCHEME, COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT, opacity, pv, setColorScheme, SIZE, WEIGHT, } from '../../common/common'; import {useTracked} from '../../provider'; import {ACTIONS} from '../../provider/actions'; import NavigationService from '../../services/NavigationService'; import {AnimatedSafeAreaView} from '../../views/Home'; import {DDS} from '../../../App'; import { eOpenLoginDialog, eOpenModalMenu, eSendSideMenuOverlayRef, } from '../../services/events'; import {eSendEvent} from '../../services/eventManager'; export const Menu = ({ close = () => {}, hide, update = () => {}, noTextMode = false, }) => { const [state, dispatch] = useTracked(); const {colors} = state; // todo let overlayRef; function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) { let newColors = setColorScheme(colors, accent); StatusBar.setBarStyle(newColors.night ? 'light-content' : 'dark-content'); dispatch({type: ACTIONS.THEME, colors: newColors}); } const listItems = [ { name: 'Home', icon: 'home', func: () => NavigationService.navigate('Home'), close: true, }, { name: 'Notebooks', icon: 'book', func: () => NavigationService.navigate('Folders', { title: 'Notebooks', canGoBack: false, }), close: true, }, { name: 'Lists', icon: 'list', func: () => NavigationService.navigate('Lists'), close: true, }, { name: 'Favorites', icon: 'star', func: () => NavigationService.navigate('Favorites'), close: true, }, { name: 'Dark Mode', icon: 'moon', func: () => { if (!colors.night) { FastStorage.setItem('theme', JSON.stringify({night: true})); changeColorScheme(COLOR_SCHEME_DARK); } else { FastStorage.setItem('theme', JSON.stringify({night: false})); changeColorScheme(COLOR_SCHEME_LIGHT); } }, switch: true, on: colors.night ? true : false, close: false, }, { name: 'Trash', icon: 'trash', func: () => NavigationService.navigate('Trash'), close: true, }, { name: 'Settings', icon: 'settings', func: () => NavigationService.navigate('Settings'), close: true, }, ]; return ( {noTextMode ? null : ( notesnook )} {DDS.isTab ? ( { noTextMode ? eSendEvent(eOpenModalMenu) : close(); }} style={{ alignItems: 'center', height: 35, justifyContent: 'center', }}> ) : null} {DDS.isTab ? null : ( (overlayRef = ref)} onLayout={() => { eSendEvent(eSendSideMenuOverlayRef, {ref: overlayRef}); }} style={{ height: '100%', width: '100%', position: 'absolute', zIndex: 999, backgroundColor: colors.bg, display: 'flex', transform: [ { translateX: 0, }, ], }} /> )} {listItems.map((item, index) => ( { item.close === false ? null : close(); item.func(); }} style={{ width: '100%', alignSelf: 'center', flexDirection: 'row', justifyContent: noTextMode ? 'center' : 'space-between', alignItems: 'center', paddingBottom: noTextMode ? 12 : 15, paddingTop: index === 0 ? 10 : noTextMode ? 12 : 15, }}> {noTextMode ? null : ( {item.name} )} {item.switch && !noTextMode ? ( ) : ( undefined )} ))} { close(); NavigationService.navigate('Tags'); }} style={{ width: '100%', alignSelf: 'center', flexDirection: 'row', justifyContent: noTextMode ? 'center' : 'space-between', alignItems: 'flex-end', marginTop: noTextMode ? 10 : 15, }}> {noTextMode ? null : ( Tags )} {noTextMode ? null : ( {[ 'home', 'office', 'work', 'book_notes', 'poem', 'lists', 'water', ].map(item => ( { close(); NavigationService.navigate('Notes', { heading: item, }); }} style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', padding: 5, paddingLeft: 2.5, }}> #{item} ))} )} {['red', 'yellow', 'green', 'blue', 'purple', 'orange', 'gray'].map( item => ( ), )} {/* Upgrade to Pro */} { close(); DDS.isTab ? eSendEvent(eOpenLoginDialog) : NavigationService.navigate('Login'); }} activeOpacity={opacity / 2} style={{ paddingVertical: pv + 5, paddingHorizontal: 12, width: '100%', justifyContent: 'flex-start', alignItems: 'center', flexDirection: 'row', }}> {noTextMode ? null : ( {' '}Login )} {/* Hi, Ammar! 80.45/100 MB */} {/* Basic User */} ); };