UNPKG

1.87 kBJavaScriptView Raw
1import PropTypes from 'prop-types';
2import React, { PureComponent } from 'react';
3import { StyleSheet, Text, View, } from 'react-native';
4import dayjs from 'dayjs';
5import Color from './Color';
6import { StylePropType, isSameDay } from './utils';
7import { DATE_FORMAT } from './Constant';
8const styles = StyleSheet.create({
9 container: {
10 alignItems: 'center',
11 justifyContent: 'center',
12 marginTop: 5,
13 marginBottom: 10,
14 },
15 text: {
16 backgroundColor: Color.backgroundTransparent,
17 color: Color.defaultColor,
18 fontSize: 12,
19 fontWeight: '600',
20 },
21});
22export default class Day extends PureComponent {
23 render() {
24 const { dateFormat, currentMessage, previousMessage, containerStyle, wrapperStyle, textStyle, } = this.props;
25 if (currentMessage && !isSameDay(currentMessage, previousMessage)) {
26 return (<View style={[styles.container, containerStyle]}>
27 <View style={wrapperStyle}>
28 <Text style={[styles.text, textStyle]}>
29 {dayjs(currentMessage.createdAt)
30 .locale(this.context.getLocale())
31 .format(dateFormat)}
32 </Text>
33 </View>
34 </View>);
35 }
36 return null;
37 }
38}
39Day.contextTypes = {
40 getLocale: PropTypes.func,
41};
42Day.defaultProps = {
43 currentMessage: {
44 createdAt: null,
45 },
46 previousMessage: {},
47 nextMessage: {},
48 containerStyle: {},
49 wrapperStyle: {},
50 textStyle: {},
51 dateFormat: DATE_FORMAT,
52};
53Day.propTypes = {
54 currentMessage: PropTypes.object,
55 previousMessage: PropTypes.object,
56 nextMessage: PropTypes.object,
57 inverted: PropTypes.bool,
58 containerStyle: StylePropType,
59 wrapperStyle: StylePropType,
60 textStyle: StylePropType,
61 dateFormat: PropTypes.string,
62};
63//# sourceMappingURL=Day.js.map
\No newline at end of file