Files
notesnook/apps/mobile/src/components/NoteItem/index.js

167 lines
4.3 KiB
JavaScript
Raw Normal View History

2019-12-04 19:38:19 +05:00
import React, {useState, createRef} from 'react';
2019-11-17 16:02:19 +05:00
import {
View,
Text,
TouchableOpacity,
ScrollView,
Dimensions,
FlatList,
2019-11-28 21:40:37 +05:00
TouchableWithoutFeedback,
2019-11-29 11:31:43 +05:00
Platform,
2019-11-17 16:02:19 +05:00
} from 'react-native';
import {
COLOR_SCHEME,
SIZE,
br,
ph,
pv,
opacity,
FONT,
WEIGHT,
} from '../../common/common';
2019-12-04 19:38:19 +05:00
import Icon from 'react-native-vector-icons/Feather';
2019-11-17 16:02:19 +05:00
import {Reminder} from '../Reminder';
2019-11-28 21:40:37 +05:00
import {getElevation, timeSince} from '../../utils/utils';
import NavigationService from '../../services/NavigationService';
2019-12-04 19:38:19 +05:00
import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu';
2019-11-17 16:02:19 +05:00
const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height;
2019-12-04 19:38:19 +05:00
let setMenuRef = {};
2019-11-17 16:02:19 +05:00
const NoteItem = props => {
const [colors, setColors] = useState(COLOR_SCHEME);
const item = props.item;
return (
<View
style={{
marginHorizontal: w * 0.05,
2019-11-30 19:56:40 +05:00
2019-11-17 16:02:19 +05:00
marginVertical: h * 0.015,
borderRadius: br,
justifyContent: 'center',
alignItems: 'center',
2019-11-28 21:40:37 +05:00
flexDirection: 'row',
2019-11-17 16:02:19 +05:00
padding: pv,
2019-11-29 11:31:43 +05:00
width: Platform.isPad ? '95%' : '90%',
alignSelf: 'center',
2019-11-30 19:56:40 +05:00
borderBottomWidth: 1,
borderBottomColor: '#f0f0f0',
2019-11-17 16:02:19 +05:00
}}>
2019-11-28 21:40:37 +05:00
<TouchableOpacity
activeOpacity={1}
onPress={() => {
NavigationService.navigate('Editor', {
note: item,
});
}}
2019-11-17 16:02:19 +05:00
style={{
2019-11-28 21:40:37 +05:00
width: '95%',
2019-11-17 16:02:19 +05:00
}}>
2019-11-28 21:40:37 +05:00
<>
<Text
numberOfLines={1}
style={{
color: colors.pri,
fontSize: SIZE.md,
fontFamily: WEIGHT.bold,
maxWidth: '100%',
marginBottom: 5,
}}>
{item.title.replace('\n', '')}
</Text>
<View
style={{
justifyContent: 'flex-start',
alignItems: 'flex-start',
width: '100%',
}}>
<Text
style={{
2019-11-29 11:31:43 +05:00
fontSize: SIZE.xs + 2,
2019-11-28 21:40:37 +05:00
color: colors.icon,
fontFamily: WEIGHT.regular,
width: '100%',
maxWidth: '100%',
paddingRight: ph,
}}>
{item.headline}
</Text>
2019-11-17 17:48:56 +05:00
2019-11-28 21:40:37 +05:00
<Text
style={{
color: colors.accent,
2019-11-29 11:31:43 +05:00
fontSize: SIZE.xxs + 2,
2019-11-28 21:40:37 +05:00
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
}}>
{timeSince(item.dateCreated) + ' '}
</Text>
</View>
</>
</TouchableOpacity>
2019-12-04 19:38:19 +05:00
<View
2019-11-17 17:48:56 +05:00
style={{
2019-12-04 19:38:19 +05:00
width: w * 0.05,
2019-11-28 21:40:37 +05:00
justifyContent: 'center',
minHeight: 70,
alignItems: 'center',
2019-11-17 17:48:56 +05:00
}}>
2019-12-04 19:38:19 +05:00
<Menu
style={{
borderRadius: 5,
}}
ref={ref => (setMenuRef[props.index] = ref)}
button={
<TouchableOpacity
style={{
width: w * 0.05,
justifyContent: 'center',
minHeight: 70,
alignItems: 'center',
}}
onPress={() => setMenuRef[props.index].show()}>
<Icon name="more-vertical" size={SIZE.lg} color={colors.icon} />
</TouchableOpacity>
}>
<MenuItem
textStyle={{
color: colors.pri,
backgroundColor: colors.bg,
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
}}>
<Icon name="star" size={SIZE.sm} color={colors.icon} />
{' '}Favourite
</MenuItem>
<MenuItem
textStyle={{
color: colors.pri,
backgroundColor: colors.bg,
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
}}>
<Icon name="share" size={SIZE.sm} color={colors.icon} />
{' '}Share
</MenuItem>
<MenuItem
textStyle={{
color: colors.pri,
backgroundColor: colors.bg,
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
}}>
<Icon name="trash" size={SIZE.sm} color={colors.icon} />
{' '}Delete
</MenuItem>
</Menu>
</View>
2019-11-17 16:02:19 +05:00
</View>
);
};
export default NoteItem;