-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathSubscriptAvatar.js
92 lines (80 loc) · 3.45 KB
/
SubscriptAvatar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React, {memo} from 'react';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import _ from 'underscore';
import styles from '../styles/styles';
import Tooltip from './Tooltip';
import themeColors from '../styles/themes/default';
import Avatar from './Avatar';
import CONST from '../CONST';
import * as StyleUtils from '../styles/StyleUtils';
import avatarPropTypes from './avatarPropTypes';
const propTypes = {
/** Avatar URL or icon */
mainAvatar: avatarPropTypes,
/** Subscript avatar URL or icon */
secondaryAvatar: avatarPropTypes,
/** Tooltip for the main avatar */
mainTooltip: PropTypes.string,
/** Tooltip for the subscript avatar */
secondaryTooltip: PropTypes.string,
/** Set the size of avatars */
size: PropTypes.oneOf(_.values(CONST.AVATAR_SIZE)),
/** Background color used for subscript avatar border */
backgroundColor: PropTypes.string,
/** Removes margin from around the avatar, used for the chat view */
noMargin: PropTypes.bool,
};
const defaultProps = {
mainTooltip: '',
secondaryTooltip: '',
size: CONST.AVATAR_SIZE.DEFAULT,
backgroundColor: themeColors.componentBG,
mainAvatar: {},
secondaryAvatar: {},
noMargin: false,
};
function SubscriptAvatar(props) {
const containerStyle = props.size === CONST.AVATAR_SIZE.SMALL ? styles.emptyAvatarSmall : styles.emptyAvatar;
// Default the margin style to what is normal for small or normal sized avatars
let marginStyle = props.size === CONST.AVATAR_SIZE.SMALL ? styles.emptyAvatarMarginSmall : styles.emptyAvatarMargin;
// Some views like the chat view require that there be no margins
if (props.noMargin) {
marginStyle = {};
}
return (
<View style={[containerStyle, marginStyle]}>
<Tooltip text={props.mainTooltip}>
<View>
<Avatar
source={props.mainAvatar.source}
size={props.size === CONST.AVATAR_SIZE.SMALL ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT}
name={props.mainAvatar.name}
type={props.mainAvatar.type}
/>
</View>
</Tooltip>
<Tooltip text={props.secondaryTooltip}>
<View>
<Avatar
imageStyles={null}
containerStyles={[props.size === CONST.AVATAR_SIZE.SMALL ? styles.secondAvatarSubscriptCompact : styles.secondAvatarSubscript]}
iconAdditionalStyles={[
StyleUtils.getAvatarBorderWidth(props.size === CONST.AVATAR_SIZE.SMALL ? CONST.AVATAR_SIZE.SMALL_SUBSCRIPT : CONST.AVATAR_SIZE.SUBSCRIPT),
StyleUtils.getBorderColorStyle(props.backgroundColor),
]}
source={props.secondaryAvatar.source}
size={props.size === CONST.AVATAR_SIZE.SMALL ? CONST.AVATAR_SIZE.SMALL_SUBSCRIPT : CONST.AVATAR_SIZE.SUBSCRIPT}
fill={themeColors.iconSuccessFill}
name={props.secondaryAvatar.name}
type={props.secondaryAvatar.type}
/>
</View>
</Tooltip>
</View>
);
}
SubscriptAvatar.displayName = 'SubscriptAvatar';
SubscriptAvatar.propTypes = propTypes;
SubscriptAvatar.defaultProps = defaultProps;
export default memo(SubscriptAvatar);