UNPKG

zl-react-native-gifted-chat

Version:

The most complete chat UI for React Native, based on 'react-native-gifted-chat'

74 lines (67 loc) 1.71 kB
import React from 'react'; import { StyleSheet, Text, View, } from 'react-native'; import moment from 'moment/min/moment-with-locales.min'; export default class Day extends React.Component { render() { if (!this.props.isSameDay(this.props.currentMessage, this.props.previousMessage)) { return ( <View style={[styles.container, this.props.containerStyle]}> <View style={[styles.wrapper, this.props.wrapperStyle]}> <Text style={[styles.text, this.props.textStyle]}> {moment(this.props.currentMessage.createdAt).locale(this.context.getLocale()).format('ll').toUpperCase()} </Text> </View> </View> ); } return null; } } const styles = StyleSheet.create({ container: { alignItems: 'center', justifyContent: 'center', marginTop: 5, marginBottom: 10, }, wrapper: { // backgroundColor: '#ccc', // borderRadius: 10, // paddingLeft: 10, // paddingRight: 10, // paddingTop: 5, // paddingBottom: 5, }, text: { backgroundColor: 'transparent', color: '#b2b2b2', fontSize: 12, fontWeight: '600', }, }); Day.contextTypes = { getLocale: React.PropTypes.func, }; Day.defaultProps = { containerStyle: {}, wrapperStyle: {}, textStyle: {}, isSameDay: () => {}, currentMessage: { // TODO test if crash when createdAt === null createdAt: null, }, previousMessage: {}, }; Day.propTypes = { containerStyle: React.PropTypes.object, wrapperStyle: React.PropTypes.object, textStyle: React.PropTypes.object, isSameDay: React.PropTypes.func, currentMessage: React.PropTypes.object, previousMessage: React.PropTypes.object, };