1 | import PropTypes from 'prop-types';
|
2 | import React, { PureComponent } from 'react';
|
3 | import { StyleSheet, Text, View, } from 'react-native';
|
4 | import dayjs from 'dayjs';
|
5 | import Color from './Color';
|
6 | import { StylePropType, isSameDay } from './utils';
|
7 | import { DATE_FORMAT } from './Constant';
|
8 | const 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 | });
|
22 | export 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 | }
|
39 | Day.contextTypes = {
|
40 | getLocale: PropTypes.func,
|
41 | };
|
42 | Day.defaultProps = {
|
43 | currentMessage: {
|
44 | createdAt: null,
|
45 | },
|
46 | previousMessage: {},
|
47 | nextMessage: {},
|
48 | containerStyle: {},
|
49 | wrapperStyle: {},
|
50 | textStyle: {},
|
51 | dateFormat: DATE_FORMAT,
|
52 | };
|
53 | Day.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 |
|
\ | No newline at end of file |