Rocket.Chat.ReactNative/app/components/RoomItem.js

73 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-08-09 01:40:55 +00:00
import React from 'react';
import Ionicons from 'react-native-vector-icons/Ionicons';
import FontAwesome from 'react-native-vector-icons/FontAwesome';
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
},
icon: {
fontSize: 20,
height: 22,
width: 22
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: 'hashtag',
p: 'md-lock'
}[this.props.item.t];
if (!icon) {
return null;
}
return ['p'].includes(this.props.item.t) ? <Ionicons name={icon} style={styles.icon} /> : <FontAwesome 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
);
}
}