import React from 'react'; import { Dimensions, Text, TouchableOpacity, View, DeviceEventEmitter, } from 'react-native'; import Icon from 'react-native-vector-icons/Feather'; import {DDS} from '../../../App'; import {ph, pv, SIZE, WEIGHT} from '../../common/common'; import NavigationService from '../../services/NavigationService'; import {getElevation, timeSince} from '../../utils/utils'; import { ActionSheetEvent, TEMPLATE_TRASH, simpleDialogEvent, } from '../DialogManager'; import {eSendEvent} from '../../services/eventManager'; import {eOnLoadNote, eOpenSimpleDialog} from '../../services/events'; const w = Dimensions.get('window').width; const h = Dimensions.get('window').height; export default class NoteItem extends React.Component { constructor(props) { super(props); this.cipher = { value: false, }; this.actionSheet; this.show = null; this.setMenuRef = {}; this.willRefresh = false; } shouldComponentUpdate(nextProps, nextState) { if (nextProps.item.locked !== this.cipher.value) { return true; } else { return ( JSON.stringify(nextProps) !== JSON.stringify(this.props) || nextState !== this.state ); } } componentDidUpdate() { this.cipher.value = this.props.item.locked ? true : false; } componentWillUnmount() { this.cipher.value = false; } componentDidMount() { if (this.props.item.locked) { this.cipher.value = true; } } render() { let { colors, item, customStyle, onLongPress, isTrash, pinned, index, } = this.props; console.log('rendering', index); return ( {pinned ? ( ) : null} onLongPress()} onPress={() => { if (item.locked) { this.setState({ unlock: true, vaultDialog: true, }); } else { DDS.isTab ? eSendEvent(eOnLoadNote, item) : isTrash ? simpleDialogEvent(TEMPLATE_TRASH(item.type)) : NavigationService.navigate('Editor', { note: item, }); } }} style={{ paddingLeft: 0, width: '95%', }}> <> {item.title.replace('\n', '')} {item.headline[item.headline.length - 1] === '\n' ? item.headline.slice(0, item.headline.length - 1) : item.headline} {!isTrash ? ( <> {item.colors.length > 0 ? ( {item.colors.map(item => ( ))} ) : null} {item.locked ? ( ) : null} {item.favorite ? ( ) : null} {timeSince(item.dateCreated)} ) : null} {isTrash ? ( <> {'Deleted on: ' + new Date(item.dateDeleted).toISOString().slice(0, 10) + ' '} {item.type[0].toUpperCase() + item.type.slice(1) + ' '} ) : null} { ActionSheetEvent( item, isTrash ? false : true, isTrash ? false : true, isTrash ? ['Remove', 'Restore'] : ['Add to', 'Share', 'Export', 'Delete'], isTrash ? [] : ['Pin', 'Favorite', 'Add to Vault'], ); }}> ); } }