2018-08-31 16:46:33 +00:00
|
|
|
import React from 'react';
|
2021-11-10 21:18:35 +00:00
|
|
|
import { Pressable, StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2022-04-09 02:43:31 +00:00
|
|
|
import Avatar from './Avatar';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon, TIconsName } from './CustomIcon';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../views/Styles';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../lib/constants';
|
2020-07-29 21:03:17 +00:00
|
|
|
import { isIOS } from '../utils/deviceInfo';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes } from '../theme';
|
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',
|
2020-05-08 17:09:36 +00:00
|
|
|
justifyContent: 'center',
|
|
|
|
marginRight: 15
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IUserItem {
|
|
|
|
name: string;
|
|
|
|
username: string;
|
|
|
|
onPress(): void;
|
|
|
|
testID: string;
|
2021-11-10 21:18:35 +00:00
|
|
|
onLongPress?: () => void;
|
|
|
|
style?: StyleProp<ViewStyle>;
|
2022-05-02 19:21:15 +00:00
|
|
|
icon?: TIconsName | null;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, theme }: IUserItem) => (
|
2020-07-29 21:03:17 +00:00
|
|
|
<Pressable
|
|
|
|
onPress={onPress}
|
|
|
|
onLongPress={onLongPress}
|
|
|
|
testID={testID}
|
|
|
|
android_ripple={{
|
|
|
|
color: themes[theme].bannerBackground
|
|
|
|
}}
|
2021-09-13 20:41:05 +00:00
|
|
|
style={({ pressed }: any) => ({
|
|
|
|
backgroundColor: isIOS && pressed ? themes[theme].bannerBackground : 'transparent'
|
|
|
|
})}>
|
2020-07-29 21:03:17 +00:00
|
|
|
<View style={[styles.container, styles.button, style]}>
|
2020-10-30 13:12:02 +00:00
|
|
|
<Avatar text={username} size={30} style={styles.avatar} />
|
2020-07-29 21:03:17 +00:00
|
|
|
<View style={styles.textContainer}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Text style={[styles.name, { color: themes[theme].titleText }]} numberOfLines={1}>
|
|
|
|
{name}
|
|
|
|
</Text>
|
|
|
|
<Text style={[styles.username, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>
|
|
|
|
@{username}
|
|
|
|
</Text>
|
2020-05-04 20:20:45 +00:00
|
|
|
</View>
|
2022-05-02 19:21:15 +00:00
|
|
|
{icon ? <CustomIcon name={icon} size={22} color={themes[theme].actionTintColor} style={styles.icon} /> : null}
|
2020-07-29 21:03:17 +00:00
|
|
|
</View>
|
|
|
|
</Pressable>
|
2020-05-04 20:20:45 +00:00
|
|
|
);
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
export default UserItem;
|