Rocket.Chat.ReactNative/app/containers/Message.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-08-09 01:40:55 +00:00
import React from 'react';
import PropTypes from 'prop-types';
import { View, StyleSheet } from 'react-native';
2017-08-10 14:27:28 +00:00
import { emojify } from 'react-emojione';
import Markdown from 'react-native-easy-markdown';
import Card from './message/card';
import Avatar from './message/Avatar';
import User from './message/User';
2017-08-09 01:40:55 +00:00
const styles = StyleSheet.create({
content: {
flexGrow: 1
},
2017-08-09 01:40:55 +00:00
message: {
2017-08-10 15:16:47 +00:00
padding: 12,
paddingTop: 6,
paddingBottom: 6,
2017-08-09 01:40:55 +00:00
flexDirection: 'row',
transform: [{ scaleY: -1 }]
}
});
export default class Message extends React.PureComponent {
static propTypes = {
item: PropTypes.object.isRequired,
baseUrl: PropTypes.string.isRequired,
Message_TimeFormat: PropTypes.string.isRequired
2017-08-09 01:40:55 +00:00
}
attachments() {
return this.props.item.attachments.length ? <Card data={this.props.item.attachments[0]} /> : null;
}
2017-08-09 01:40:55 +00:00
render() {
const { item } = this.props;
2017-08-09 01:40:55 +00:00
const extraStyle = {};
if (item.temp) {
2017-08-09 01:40:55 +00:00
extraStyle.opacity = 0.3;
}
const msg = emojify(item.msg, { output: 'unicode' });
2017-08-10 14:27:28 +00:00
2017-08-09 01:40:55 +00:00
return (
<View style={[styles.message, extraStyle]}>
<Avatar item={item} baseUrl={this.props.baseUrl} />
<View style={[styles.content]}>
<User
onPress={this._onPress}
item={item}
Message_TimeFormat={this.props.Message_TimeFormat}
/>
{this.attachments()}
2017-08-10 14:27:28 +00:00
<Markdown>
{msg}
</Markdown>
2017-08-09 01:40:55 +00:00
</View>
</View>
);
}
}