Rocket.Chat.ReactNative/app/containers/message/User.js

71 lines
1.5 KiB
JavaScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet } from 'react-native';
import moment from 'moment';
2019-03-29 19:36:07 +00:00
import sharedStyles from '../../views/Styles';
2019-04-08 12:35:28 +00:00
import messageStyles from './styles';
2019-03-29 19:36:07 +00:00
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
2019-03-29 19:36:07 +00:00
alignItems: 'center'
},
username: {
fontSize: 16,
2019-03-29 19:36:07 +00:00
lineHeight: 22,
...sharedStyles.textColorNormal,
...sharedStyles.textMedium
},
titleContainer: {
flex: 1,
flexDirection: 'row',
alignItems: 'center'
},
alias: {
fontSize: 14,
2019-03-29 19:36:07 +00:00
...sharedStyles.textColorDescription,
...sharedStyles.textRegular
}
});
2017-11-24 20:44:52 +00:00
export default class User extends React.PureComponent {
static propTypes = {
timeFormat: PropTypes.string.isRequired,
username: PropTypes.string,
alias: PropTypes.string,
ts: PropTypes.oneOfType([
PropTypes.instanceOf(Date),
PropTypes.string
]),
temp: PropTypes.bool
}
render() {
const {
username, alias, ts, temp, timeFormat
} = this.props;
const extraStyle = {};
if (temp) {
extraStyle.opacity = 0.3;
}
2019-03-29 19:36:07 +00:00
const aliasUsername = alias ? (<Text style={styles.alias}> @{username}</Text>) : null;
const time = moment(ts).format(timeFormat);
return (
<View style={styles.container}>
<View style={styles.titleContainer}>
2019-03-29 19:36:07 +00:00
<Text style={styles.username} numberOfLines={1}>
{alias || username}
2019-03-29 19:36:07 +00:00
{aliasUsername}
</Text>
</View>
2019-04-08 12:35:28 +00:00
<Text style={messageStyles.time}>{time}</Text>
</View>
);
}
}