verdnatura-chat/app/presentation/UserItem.js

78 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
import {
Text, View, StyleSheet, ViewPropTypes
} from 'react-native';
import PropTypes from 'prop-types';
import Avatar from '../containers/Avatar';
import Touch from '../utils/touch';
import { CustomIcon } from '../lib/Icons';
2019-03-29 19:36:07 +00:00
import sharedStyles from '../views/Styles';
import { COLOR_PRIMARY, COLOR_WHITE } from '../constants/colors';
const styles = StyleSheet.create({
button: {
height: 54,
2019-03-29 19:36:07 +00:00
backgroundColor: COLOR_WHITE
},
container: {
flexDirection: 'row'
},
avatar: {
marginHorizontal: 15,
marginVertical: 12
},
textContainer: {
flex: 1,
2019-03-29 19:36:07 +00:00
flexDirection: 'column',
justifyContent: 'center'
},
name: {
2019-03-29 19:36:07 +00:00
fontSize: 17,
...sharedStyles.textMedium,
...sharedStyles.textColorNormal
},
username: {
fontSize: 14,
2019-03-29 19:36:07 +00:00
...sharedStyles.textRegular,
...sharedStyles.textColorDescription
},
icon: {
marginHorizontal: 15,
alignSelf: 'center',
2019-03-29 19:36:07 +00:00
color: COLOR_PRIMARY
}
});
const UserItem = ({
name, username, onPress, testID, onLongPress, style, icon, baseUrl, user
}) => (
<Touch onPress={onPress} onLongPress={onLongPress} style={styles.button} testID={testID}>
<View style={[styles.container, style]}>
2019-04-18 20:57:35 +00:00
<Avatar text={username} size={30} type='d' style={styles.avatar} baseUrl={baseUrl} userId={user.id} token={user.token} />
<View style={styles.textContainer}>
<Text style={styles.name}>{name}</Text>
<Text style={styles.username}>@{username}</Text>
</View>
{icon ? <CustomIcon name={icon} size={22} style={styles.icon} /> : null}
</View>
</Touch>
);
UserItem.propTypes = {
name: PropTypes.string.isRequired,
username: PropTypes.string.isRequired,
user: PropTypes.shape({
id: PropTypes.string,
token: PropTypes.string
}),
baseUrl: PropTypes.string.isRequired,
onPress: PropTypes.func.isRequired,
testID: PropTypes.string.isRequired,
onLongPress: PropTypes.func,
style: ViewPropTypes.style,
icon: PropTypes.string
};
export default UserItem;