2017-08-09 01:40:55 +00:00
|
|
|
import React from 'react';
|
2017-08-10 16:25:50 +00:00
|
|
|
|
2017-08-10 20:26:11 +00:00
|
|
|
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',
|
2017-08-10 16:25:50 +00:00
|
|
|
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',
|
2017-08-10 16:25:50 +00:00
|
|
|
marginRight: 15,
|
|
|
|
fontSize: 14
|
2017-08-09 18:01:54 +00:00
|
|
|
},
|
2017-08-09 01:40:55 +00:00
|
|
|
roomItem: {
|
2017-08-10 16:25:50 +00:00
|
|
|
flexGrow: 1,
|
2017-08-10 20:26:11 +00:00
|
|
|
fontSize: 20,
|
|
|
|
color: '#444'
|
2017-08-10 16:25:50 +00:00
|
|
|
},
|
|
|
|
icon: {
|
2017-08-10 20:26:11 +00:00
|
|
|
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 = {
|
2017-08-10 16:25:50 +00:00
|
|
|
item: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
get icon() {
|
|
|
|
const icon = {
|
|
|
|
d: 'at',
|
2017-08-10 20:26:11 +00:00
|
|
|
c: 'pound',
|
|
|
|
p: 'lock',
|
|
|
|
l: 'account'
|
2017-08-10 16:25:50 +00:00
|
|
|
}[this.props.item.t];
|
|
|
|
if (!icon) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-08-10 20:26:11 +00:00
|
|
|
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() {
|
2017-08-10 16:25:50 +00:00
|
|
|
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}>
|
2017-08-10 16:25:50 +00:00
|
|
|
{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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|