vn-verdnaturachat/app/components/Message.js

70 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-08-09 01:40:55 +00:00
import React from 'react';
import PropTypes from 'prop-types';
2017-08-09 19:02:09 +00:00
import { View, Text, StyleSheet } from 'react-native';
import { CachedImage } from 'react-native-img-cache';
2017-08-10 14:27:28 +00:00
import Markdown from 'react-native-easy-markdown';
import { emojify } from 'react-emojione';
2017-08-09 01:40:55 +00:00
const styles = StyleSheet.create({
message: {
borderColor: '#aaa',
padding: 14,
flexDirection: 'row',
transform: [{ scaleY: -1 }]
2017-08-09 02:20:34 +00:00
},
2017-08-09 19:02:09 +00:00
avatarContainer: {
2017-08-09 02:20:34 +00:00
backgroundColor: '#ccc',
width: 40,
height: 40,
marginRight: 10,
borderRadius: 5
},
2017-08-09 19:02:09 +00:00
avatar: {
width: 40,
height: 40,
borderRadius: 5
},
2017-08-09 02:20:34 +00:00
texts: {
flex: 1
},
msg: {
flex: 1
},
username: {
fontWeight: 'bold',
marginBottom: 5
2017-08-09 01:40:55 +00:00
}
});
export default class Message extends React.PureComponent {
static propTypes = {
item: PropTypes.object.isRequired,
baseUrl: PropTypes.string.isRequired
}
render() {
const extraStyle = {};
if (this.props.item.temp) {
extraStyle.opacity = 0.3;
}
2017-08-10 14:27:28 +00:00
const msg = emojify(this.props.item.msg || 'asd', { output: 'unicode' });
2017-08-09 01:40:55 +00:00
return (
<View style={[styles.message, extraStyle]}>
2017-08-09 19:02:09 +00:00
<View style={styles.avatarContainer}>
<CachedImage style={styles.avatar} source={{ uri: `${ this.props.baseUrl }/avatar/${ this.props.item.u.username }` }} />
</View>
2017-08-09 01:40:55 +00:00
<View style={styles.texts}>
<Text onPress={this._onPress} style={styles.username}>
{this.props.item.u.username}
</Text>
2017-08-10 14:27:28 +00:00
<Markdown>
{msg}
</Markdown>
2017-08-09 01:40:55 +00:00
</View>
</View>
);
}
}