import React from 'react'; import {View, Text, TouchableOpacity, Dimensions} from 'react-native'; import {SIZE, ph, pv, WEIGHT} from '../../common/common'; import Icon from 'react-native-vector-icons/Feather'; import {timeSince, ToastEvent, getElevation} from '../../utils/utils'; import NavigationService from '../../services/NavigationService'; import {Dialog} from '../Dialog'; import {VaultDialog} from '../VaultDialog'; import {db} from '../../../App'; import {DDS} from '../../../App'; import _ from 'lodash'; import {ActionSheetEvent} from '../DialogManager'; 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.state = { unlockNote: false, vaultDialog: false, isPerm: 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 {unlock, vaultDialog, isPerm, visible} = this.state; let { colors, item, width, customStyle, onLongPress, isTrash, pinned, update, index, } = this.props; console.log('rendering', index); return ( {pinned ? ( ) : null} onLongPress()} onPress={() => { if (item.locked) { this.setState({ unlock: true, vaultDialog: true, }); } else { 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, true, true, ['Add to', 'Share', 'Export', 'Delete'], ['Add to Vault', 'Pin', 'Favorite'], ); }}> ); } }