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: {
|
|
|
|
width: 20,
|
|
|
|
lineHeight: 20,
|
|
|
|
borderRadius: 5,
|
|
|
|
backgroundColor: 'green',
|
|
|
|
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() {
|
|
|
|
return (
|
2017-08-09 18:01:54 +00:00
|
|
|
<View style={styles.container}>
|
|
|
|
<Text onPress={this._onPress} style={styles.roomItem}>{ this.props.item.name }</Text>
|
|
|
|
{this.renderNumber(this.props.item)}
|
|
|
|
</View>
|
2017-08-09 01:40:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|