Rocket.Chat.ReactNative/app/presentation/UserItem.js

82 lines
2.1 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import Avatar from '../containers/Avatar';
import { CustomIcon } from '../lib/Icons';
2019-03-29 19:36:07 +00:00
import sharedStyles from '../views/Styles';
2019-12-04 16:39:53 +00:00
import { themes } from '../constants/colors';
import Touch from '../utils/touch';
import LongPress from '../utils/longPress';
const styles = StyleSheet.create({
button: {
2019-12-04 16:39:53 +00:00
height: 54
},
container: {
flexDirection: 'row'
},
avatar: {
marginHorizontal: 15,
marginVertical: 12
},
textContainer: {
flex: 1,
2019-03-29 19:36:07 +00:00
flexDirection: 'column',
justifyContent: 'center',
marginRight: 15
},
name: {
2019-03-29 19:36:07 +00:00
fontSize: 17,
2019-12-04 16:39:53 +00:00
...sharedStyles.textMedium
},
username: {
fontSize: 14,
2019-12-04 16:39:53 +00:00
...sharedStyles.textRegular
},
icon: {
marginHorizontal: 15,
2019-12-04 16:39:53 +00:00
alignSelf: 'center'
}
});
const UserItem = ({
2019-12-04 16:39:53 +00:00
name, username, onPress, testID, onLongPress, style, icon, baseUrl, user, theme
}) => (
<LongPress onLongPress={onLongPress}>
<Touch
onPress={onPress}
style={{ backgroundColor: themes[theme].backgroundColor }}
testID={testID}
theme={theme}
2019-12-04 16:39:53 +00:00
>
<View style={[styles.container, styles.button, style]}>
<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, { color: themes[theme].titleText }]} numberOfLines={1}>{name}</Text>
<Text style={[styles.username, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>@{username}</Text>
2019-12-04 16:39:53 +00:00
</View>
{icon ? <CustomIcon name={icon} size={22} style={[styles.icon, { color: themes[theme].actionTintColor }]} /> : null}
</View>
</Touch>
</LongPress>
);
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: PropTypes.any,
2019-12-04 16:39:53 +00:00
icon: PropTypes.string,
theme: PropTypes.string
};
export default UserItem;