verdnatura-chat/app/components/RoomItem.js

75 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-08-09 01:40:55 +00:00
import React from 'react';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
2017-08-09 01:40:55 +00:00
import PropTypes from 'prop-types';
2017-08-09 18:01:54 +00:00
import { View, Text, StyleSheet } from 'react-native';
2017-08-09 01:40:55 +00:00
const styles = StyleSheet.create({
2017-08-09 18:01:54 +00:00
container: {
flex: 1,
flexDirection: 'row',
padding: 24,
2017-08-09 18:01:54 +00:00
alignItems: 'center'
},
number: {
2017-08-09 20:08:50 +00:00
minWidth: 20,
padding: 2,
2017-08-09 18:01:54 +00:00
borderRadius: 5,
2017-08-09 20:08:50 +00:00
backgroundColor: '#aaa',
2017-08-09 18:01:54 +00:00
color: '#fff',
textAlign: 'center',
overflow: 'hidden',
marginRight: 15,
fontSize: 14
2017-08-09 18:01:54 +00:00
},
2017-08-09 01:40:55 +00:00
roomItem: {
flexGrow: 1,
fontSize: 20,
color: '#444'
},
icon: {
fontSize: 18,
marginTop: 5,
marginRight: 5,
color: '#aaa'
2017-08-09 01:40:55 +00:00
}
});
export default class RoomItem extends React.PureComponent {
static propTypes = {
item: PropTypes.object.isRequired
}
get icon() {
const icon = {
d: 'at',
c: 'pound',
p: 'lock',
l: 'account'
}[this.props.item.t];
if (!icon) {
return null;
}
return <MaterialCommunityIcons name={icon} style={styles.icon} />;
2017-08-09 01:40:55 +00:00
}
2017-08-09 18:01:54 +00:00
renderNumber = (item) => {
if (item.unread) {
return (
<Text style={styles.number}>
{ item.unread }
</Text>
);
}
}
2017-08-09 01:40:55 +00:00
render() {
const name = this.props.item.name;
2017-08-09 01:40:55 +00:00
return (
2017-08-09 18:01:54 +00:00
<View style={styles.container}>
{this.icon}
<Text style={styles.roomItem}>{ name }</Text>
2017-08-09 18:01:54 +00:00
{this.renderNumber(this.props.item)}
</View>
2017-08-09 01:40:55 +00:00
);
}
}