import React, {useEffect, useState, createRef, useRef} from 'react'; import { ScrollView, View, Text, TouchableOpacity, SafeAreaView, Platform, FlatList, DeviceEventEmitter, ActivityIndicator, KeyboardAvoidingView, } from 'react-native'; import NavigationService from '../../services/NavigationService'; import { COLOR_SCHEME, SIZE, br, ph, pv, opacity, FONT, WEIGHT, COLOR_SCHEME_DARK, setColorScheme, COLOR_SCHEME_LIGHT, clearThemeUpdateListener, onThemeUpdate, } from '../../common/common'; import Icon from 'react-native-vector-icons/Feather'; import {getElevation, w, h, Toast} from '../../utils/utils'; import AsyncStorage from '@react-native-community/async-storage'; import {useForceUpdate} from '../../views/ListsEditor'; import {AnimatedSafeAreaView} from '../../views/Home'; import {TextInput} from 'react-native-gesture-handler'; import {useAppContext} from '../../provider/useAppContext'; let tagsInputRef; export const EditorMenu = ({close = () => {}, hide, update = () => {}}) => { const {colors} = useAppContext(); const forceUpdate = useForceUpdate(); const [tags, setTags] = useState([]); const [selectedColor, setSelectedColor] = useState([]); let tagToAdd = null; let backPressCount = 0; return ( { if (!colors.night) { AsyncStorage.setItem( 'theme', JSON.stringify(COLOR_SCHEME_DARK), ); setColorScheme(COLOR_SCHEME_DARK); } else { AsyncStorage.setItem( 'theme', JSON.stringify(COLOR_SCHEME_LIGHT), ); setColorScheme(COLOR_SCHEME_LIGHT); } }, switch: true, on: colors.night ? true : false, close: false, }, { name: 'Pinned', icon: 'tag', func: () => NavigationService.push('Home'), close: true, check: true, on: true, }, { name: 'Add to Favorites', icon: 'star', func: () => NavigationService.push('Folders', { title: 'Notebooks', }), close: true, check: true, on: false, }, { name: 'Share ', icon: 'share', func: () => NavigationService.push('Lists'), close: true, }, { name: 'Move to Notebook', icon: 'arrow-right', func: () => NavigationService.push('Favorites'), close: true, }, { name: 'Delete', icon: 'trash', func: () => NavigationService.push('Trash'), close: true, }, { name: 'Locked', icon: 'lock', func: () => NavigationService.push('Settings'), close: true, check: true, on: false, }, ]} keyExtractor={(item, index) => item.name} renderItem={({item, index}) => ( { item.close === false ? null : close(); item.func(); }} style={{ width: '100%', alignSelf: 'center', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-end', paddingHorizontal: '5%', paddingVertical: pv + 5, }}> {item.name} {item.switch ? ( ) : ( undefined )} {item.check ? ( {item.on ? ( ) : null} ) : null} )} /> Add Tags {tags.map(item => ( {item} ))} (tagsInputRef = ref)} placeholderTextColor={colors.icon} placeholder="#hashtag" onChangeText={value => { tagToAdd = value; if (tagToAdd.length > 0) backPressCount = 0; }} onKeyPress={event => { if (event.nativeEvent.key === 'Backspace') { if (backPressCount === 0 && !tagToAdd) { backPressCount = 1; return; } if (backPressCount === 1 && !tagToAdd) { backPressCount = 0; let tagInputValue = tags[tags.length - 1]; let allTags = tags; if (allTags.length === 1) return; allTags.splice(allTags.length - 1); setTags(allTags); tagsInputRef.setNativeProps({ text: tagInputValue, }); forceUpdate(); setTimeout(() => { tagsInputRef.focus(); }, 300); } } }} onSubmitEditing={() => { if (!tagToAdd || tagToAdd === '#') return; let tag = tagToAdd; if (tag[0] !== '#') { tag = '#' + tag; } if (tag.includes(' ')) { tag = tag.replace(' ', '_'); } let allTags = [...tags]; allTags.push(tag); tagsInputRef.setNativeProps({ text: '#', }); setTags(allTags); tagToAdd = ''; setTimeout(() => { tagsInputRef.focus(); }, 300); }} /> { close(); NavigationService.navigate('Tags'); }} style={{ width: '100%', alignSelf: 'center', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-end', paddingHorizontal: '5%', marginTop: 15, }}> Add to Color {[ 'red', 'yellow', 'green', 'blue', 'purple', 'orange', 'gray', ].map(item => ( { setSelectedColor(item); }} style={{ flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'center', marginRight: 5, marginBottom: 5, borderWidth: 1.5, borderRadius: 100, padding: 3, borderColor: selectedColor === item ? colors.pri : colors.navbg, }}> {selectedColor === item ? ( ) : null} ))} Last Synced: 5 secs ago. {} ); };