import React from 'react';
import { CachedImage } from 'react-native-img-cache';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import PropTypes from 'prop-types';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import avatarInitialsAndColor from '../utils/avatarInitialsAndColor';
const styles = StyleSheet.create({
container: {
// flex: 1,
flexDirection: 'row',
paddingLeft: 16,
paddingRight: 16,
height: 56,
alignItems: 'center'
},
number: {
minWidth: 20,
borderRadius: 5,
backgroundColor: '#1d74f5',
color: '#fff',
textAlign: 'center',
overflow: 'hidden',
fontSize: 14,
paddingLeft: 5,
paddingRight: 5
},
roomName: {
flex: 1,
fontSize: 16,
color: '#444',
marginLeft: 16,
marginRight: 4
},
iconContainer: {
height: 40,
width: 40,
borderRadius: 20,
overflow: 'hidden',
justifyContent: 'center',
alignItems: 'center'
},
icon: {
fontSize: 20,
color: '#fff'
},
avatar: {
width: 40,
height: 40,
position: 'absolute',
borderRadius: 20
},
avatarInitials: {
fontSize: 20,
color: '#ffffff'
}
});
export default class RoomItem extends React.PureComponent {
static propTypes = {
type: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
unread: PropTypes.number,
baseUrl: PropTypes.string,
onPress: PropTypes.func
}
get icon() {
const { type, name, baseUrl } = this.props;
const icon = {
d: 'at',
c: 'pound',
p: 'lock',
l: 'account'
}[type];
if (!icon) {
return null;
}
if (type === 'd') {
const { initials, color } = avatarInitialsAndColor(name);
return (
{initials}
);
}
const { color } = avatarInitialsAndColor(name);
return (
);
}
renderNumber = (unread) => {
if (!unread || unread <= 0) {
return;
}
if (unread >= 1000) {
unread = '999+';
}
return (
{ unread }
);
}
render() {
const { unread, name } = this.props;
return (
{this.icon}
{ name }
{this.renderNumber(unread)}
);
}
}