import React from 'react'; import {Dimensions, Text, TouchableOpacity, View} from 'react-native'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import {DDS} from '../../../App'; import {ph, pv, SIZE, WEIGHT} from '../../common/common'; import {eSendEvent} from '../../services/eventManager'; import {eOnLoadNote, eOpenVaultDialog} from '../../services/events'; import NavigationService from '../../services/NavigationService'; import {getElevation, timeSince} from '../../utils/utils'; import { ActionSheetEvent, simpleDialogEvent, TEMPLATE_TRASH, } from '../DialogManager'; import {openEditorAnimation} from '../../utils/animations'; 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.colors = []; this.actionSheet; this.show = null; this.setMenuRef = {}; this.willRefresh = false; } shouldComponentUpdate(nextProps, nextState) { if ( nextProps.item.locked !== this.cipher.value || nextProps.item.colors.length !== this.colors.length || nextProps.selectionMode !== this.props.selectionMode ) { return true; } else { return ( JSON.stringify(nextProps) !== JSON.stringify(this.props) || nextState !== this.state ); } } componentDidUpdate() { this.colors = [...this.props.item.colors]; this.cipher.value = this.props.item.locked ? true : false; } componentWillUnmount() { this.colors = []; this.cipher.value = false; } componentDidMount() { this.colors = []; if (this.props.item.locked) { this.cipher.value = true; } } render() { let { colors, item, customStyle, onLongPress, isTrash, pinned, index, } = this.props; console.log('rerendering again', index); return ( {pinned ? ( ) : null} onLongPress()} onPress={() => { if (this.props.selectionMode) { this.props.onLongPress(); return; } else if (item.locked) { eSendEvent(eOpenVaultDialog, {unlock: true, i: item}); return; } if (DDS.isTab) { eSendEvent(eOnLoadNote, item); } else if (isTrash) { simpleDialogEvent(TEMPLATE_TRASH(item.type)); } else { eSendEvent(eOnLoadNote, item); openEditorAnimation(); } }} 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', 'Open'], isTrash ? [] : ['Pin', 'Favorite', 'Add to Vault'], ); }}> ); } }