verdnatura-chat/app/views/RoomView/Separator.js

73 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

import React from 'react';
import { View, StyleSheet, Text } from 'react-native';
import PropTypes from 'prop-types';
import moment from 'moment';
2019-03-29 19:36:07 +00:00
import I18n from '../../i18n';
2019-03-29 19:36:07 +00:00
import sharedStyles from '../Styles';
2019-12-04 16:39:53 +00:00
import { themes } from '../../constants/colors';
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
2019-03-27 20:06:57 +00:00
marginTop: 16,
marginBottom: 4,
marginHorizontal: 14
},
line: {
height: 1,
flex: 1
},
text: {
fontSize: 14,
2019-12-04 16:39:53 +00:00
...sharedStyles.textMedium
},
marginLeft: {
2019-03-29 19:36:07 +00:00
marginLeft: 14
},
marginRight: {
2019-03-29 19:36:07 +00:00
marginRight: 14
},
marginHorizontal: {
2019-03-29 19:36:07 +00:00
marginHorizontal: 14
}
});
2019-12-04 16:39:53 +00:00
const DateSeparator = React.memo(({ ts, unread, theme }) => {
const date = ts ? moment(ts).format('MMM DD, YYYY') : null;
2019-12-04 16:39:53 +00:00
const unreadLine = { backgroundColor: themes[theme].dangerColor };
const unreadText = { color: themes[theme].dangerColor };
if (ts && unread) {
return (
<View style={styles.container}>
2019-12-04 16:39:53 +00:00
<Text style={[styles.text, unreadText]}>{I18n.t('unread_messages')}</Text>
<View style={[styles.line, unreadLine, styles.marginHorizontal]} />
<Text style={[styles.text, unreadText]}>{date}</Text>
</View>
);
}
if (ts) {
return (
<View style={styles.container}>
2019-12-04 16:39:53 +00:00
<View style={[styles.line, { backgroundColor: themes[theme].borderColor }]} />
<Text style={[styles.text, { color: themes[theme].auxiliaryText }, styles.marginLeft]}>{date}</Text>
</View>
);
}
return (
<View style={styles.container}>
2019-12-04 16:39:53 +00:00
<Text style={[styles.text, unreadText, styles.marginRight]}>{I18n.t('unread_messages')}</Text>
<View style={[styles.line, unreadLine]} />
</View>
);
2019-03-27 20:06:57 +00:00
});
DateSeparator.propTypes = {
ts: PropTypes.instanceOf(Date),
2019-12-04 16:39:53 +00:00
unread: PropTypes.bool,
theme: PropTypes.string
};
export default DateSeparator;