2017-08-09 01:40:55 +00:00
|
|
|
import React from 'react';
|
|
|
|
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',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
number: {
|
2017-08-09 20:08:50 +00:00
|
|
|
minWidth: 20,
|
|
|
|
fontSize: 14,
|
|
|
|
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
|
|
|
|
},
|
2017-08-09 01:40:55 +00:00
|
|
|
roomItem: {
|
|
|
|
lineHeight: 18,
|
2017-08-09 18:01:54 +00:00
|
|
|
padding: 14,
|
|
|
|
flexGrow: 1
|
2017-08-09 01:40:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default class RoomItem extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
onPressItem: PropTypes.func.isRequired,
|
2017-08-09 18:01:54 +00:00
|
|
|
item: PropTypes.object.isRequired,
|
2017-08-09 01:40:55 +00:00
|
|
|
id: PropTypes.string.isRequired
|
|
|
|
}
|
|
|
|
|
|
|
|
_onPress = () => {
|
|
|
|
this.props.onPressItem(this.props.id);
|
|
|
|
};
|
|
|
|
|
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-09 20:08:50 +00:00
|
|
|
let name = this.props.item.name;
|
|
|
|
if (this.props.item.t === 'd') {
|
|
|
|
name = `@ ${ name }`;
|
|
|
|
} else {
|
|
|
|
name = `# ${ name }`;
|
|
|
|
}
|
2017-08-09 01:40:55 +00:00
|
|
|
return (
|
2017-08-09 18:01:54 +00:00
|
|
|
<View style={styles.container}>
|
2017-08-09 20:08:50 +00:00
|
|
|
<Text onPress={this._onPress} 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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|