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-12-12 17:47:12 +00:00
|
|
|
import { useAppSelector } from '../lib/hooks';
|
|
|
|
import { getUserSelector } from '../selectors/login';
|
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-06-06 14:17:51 +00:00
|
|
|
import { isIOS } from '../lib/methods/helpers';
|
2022-08-26 13:21:25 +00:00
|
|
|
import { useTheme } 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: {
|
2022-08-26 19:16:45 +00:00
|
|
|
fontSize: 16,
|
2019-12-04 16:39:53 +00:00
|
|
|
...sharedStyles.textMedium
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
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-08-26 19:16:45 +00:00
|
|
|
iconColor?: string;
|
2022-12-12 17:47:12 +00:00
|
|
|
id?: string;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-12-12 17:47:12 +00:00
|
|
|
const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, iconColor, id }: IUserItem) => {
|
2022-08-26 13:21:25 +00:00
|
|
|
const { colors } = useTheme();
|
2022-12-12 17:47:12 +00:00
|
|
|
const { userId } = useAppSelector(state => ({ userId: getUserSelector(state).id }));
|
2022-08-26 19:16:45 +00:00
|
|
|
|
2022-08-26 13:21:25 +00:00
|
|
|
return (
|
|
|
|
<Pressable
|
|
|
|
onPress={onPress}
|
|
|
|
onLongPress={onLongPress}
|
|
|
|
testID={testID}
|
|
|
|
android_ripple={{
|
|
|
|
color: colors.bannerBackground
|
|
|
|
}}
|
|
|
|
style={({ pressed }: any) => ({
|
|
|
|
backgroundColor: isIOS && pressed ? colors.bannerBackground : 'transparent'
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<View style={[styles.container, styles.button, style]}>
|
2022-12-12 17:47:12 +00:00
|
|
|
<Avatar text={username} size={30} style={styles.avatar} isUserProfile={userId === id} />
|
2022-08-26 13:21:25 +00:00
|
|
|
<View style={styles.textContainer}>
|
2022-08-26 19:16:45 +00:00
|
|
|
<Text style={[styles.name, { color: colors.bodyText }]} numberOfLines={1}>
|
2022-08-26 13:21:25 +00:00
|
|
|
{name}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2022-08-26 19:16:45 +00:00
|
|
|
{icon ? <CustomIcon name={icon} size={22} color={iconColor || colors.actionTintColor} style={styles.icon} /> : null}
|
2020-05-04 20:20:45 +00:00
|
|
|
</View>
|
2022-08-26 13:21:25 +00:00
|
|
|
</Pressable>
|
|
|
|
);
|
|
|
|
};
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
export default UserItem;
|