2018-08-31 16:46:33 +00:00
|
|
|
import React from 'react';
|
2019-05-22 20:15:35 +00:00
|
|
|
import { Text, View, StyleSheet } from 'react-native';
|
2018-08-31 16:46:33 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { LongPressGestureHandler, State } from 'react-native-gesture-handler';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
import Avatar from '../containers/Avatar';
|
2019-03-01 16:49:11 +00:00
|
|
|
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';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
button: {
|
2019-12-04 16:39:53 +00:00
|
|
|
height: 54
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
container: {
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
avatar: {
|
|
|
|
marginHorizontal: 15,
|
|
|
|
marginVertical: 12
|
|
|
|
},
|
|
|
|
textContainer: {
|
|
|
|
flex: 1,
|
2019-03-29 19:36:07 +00:00
|
|
|
flexDirection: 'column',
|
|
|
|
justifyContent: 'center'
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
name: {
|
2019-03-29 19:36:07 +00:00
|
|
|
fontSize: 17,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textMedium
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
username: {
|
|
|
|
fontSize: 14,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textRegular
|
2018-08-31 18:13:30 +00:00
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
marginHorizontal: 15,
|
2019-12-04 16:39:53 +00:00
|
|
|
alignSelf: 'center'
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const UserItem = ({
|
2019-12-04 16:39:53 +00:00
|
|
|
name, username, onPress, testID, onLongPress, style, icon, baseUrl, user, theme
|
|
|
|
}) => {
|
|
|
|
const longPress = ({ nativeEvent }) => {
|
|
|
|
if (nativeEvent.state === State.ACTIVE) {
|
2020-03-03 21:25:23 +00:00
|
|
|
if (onLongPress) {
|
|
|
|
onLongPress();
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<LongPressGestureHandler
|
|
|
|
onHandlerStateChange={longPress}
|
|
|
|
minDurationMs={800}
|
|
|
|
>
|
|
|
|
<Touch
|
|
|
|
onPress={onPress}
|
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}
|
|
|
|
testID={testID}
|
|
|
|
theme={theme}
|
|
|
|
>
|
|
|
|
<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 }]}>{name}</Text>
|
|
|
|
<Text style={[styles.username, { color: themes[theme].auxiliaryText }]}>@{username}</Text>
|
|
|
|
</View>
|
|
|
|
{icon ? <CustomIcon name={icon} size={22} style={[styles.icon, { color: themes[theme].actionTintColor }]} /> : null}
|
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
</LongPressGestureHandler>
|
|
|
|
);
|
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
UserItem.propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
username: PropTypes.string.isRequired,
|
2019-02-07 19:58:20 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
token: PropTypes.string
|
|
|
|
}),
|
2018-09-11 16:32:52 +00:00
|
|
|
baseUrl: PropTypes.string.isRequired,
|
2018-08-31 16:46:33 +00:00
|
|
|
onPress: PropTypes.func.isRequired,
|
|
|
|
testID: PropTypes.string.isRequired,
|
2018-08-31 18:13:30 +00:00
|
|
|
onLongPress: PropTypes.func,
|
2019-05-22 20:15:35 +00:00
|
|
|
style: PropTypes.any,
|
2019-12-04 16:39:53 +00:00
|
|
|
icon: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2018-08-31 16:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default UserItem;
|