UNPKG

zl-react-native-gifted-chat

Version:

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

74 lines (65 loc) 1.46 kB
import React from 'react'; import { StyleSheet, Text, View, } from 'react-native'; import moment from 'moment/min/moment-with-locales.min'; export default class Time extends React.Component { render() { return ( <View style={[styles[this.props.position].container, this.props.containerStyle[this.props.position]]}> <Text style={[styles[this.props.position].text, this.props.textStyle[this.props.position]]}> {moment(this.props.currentMessage.createdAt).locale(this.context.getLocale()).format('LT')} </Text> </View> ); } } const containerStyle = { marginLeft: 10, marginRight: 10, marginBottom: 5, }; const textStyle = { fontSize: 10, backgroundColor: 'transparent', textAlign: 'right', }; const styles = { left: StyleSheet.create({ container: { ...containerStyle, }, text: { color: '#aaa', ...textStyle, }, }), right: StyleSheet.create({ container: { ...containerStyle, }, text: { color: '#fff', ...textStyle, }, }), }; Time.contextTypes = { getLocale: React.PropTypes.func, }; Time.defaultProps = { position: 'left', containerStyle: {}, textStyle: {}, currentMessage: { createdAt: null, }, }; Time.propTypes = { position: React.PropTypes.oneOf(['left', 'right']), containerStyle: React.PropTypes.object, textStyle: React.PropTypes.object, currentMessage: React.PropTypes.object, };