Skip to content

Commit 9dd1556

Browse files
committed
chore(avatar) change avatar to
1 parent c1b9a01 commit 9dd1556

File tree

11 files changed

+65
-21
lines changed

11 files changed

+65
-21
lines changed

src/framework/components/avatar/single.tsx

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
2-
import { Image, ImageProps } from 'react-native';
2+
import { Image, ImageProps, View } from 'react-native';
33

4+
import styles from './styles';
45
import {
56
CommonSingleAvatarProps,
67
SingleAvatarOnlySpecificProps,
@@ -28,13 +29,10 @@ const useAvatarStyle = (props: Pick<SingleAvatarProps, 'size' | 'style'>) => {
2829
() => [
2930
props.style,
3031
{
32+
aspectRatio: 1,
3133
backgroundColor: theme.ui.background.card,
32-
borderColor: theme.palette.grey.white,
33-
borderRadius: AvatarSizes[props.size] / 2 + UI_SIZES.border.small * 2,
34-
borderWidth: UI_SIZES.border.small,
35-
height: AvatarSizes[props.size] + UI_SIZES.border.small * 2,
36-
margin: -UI_SIZES.border.small * 2,
37-
width: AvatarSizes[props.size] + UI_SIZES.border.small * 2,
34+
borderRadius: AvatarSizes[props.size] / 2,
35+
width: AvatarSizes[props.size],
3836
},
3937
],
4038
[props.size, props.style],
@@ -125,8 +123,39 @@ export function SingleAvatar(props: SingleAvatarProps) {
125123
setError(true);
126124
}, []);
127125

126+
const sizeValue = AvatarSizes[props.size];
127+
const sizeContainer = React.useMemo(
128+
() => (props.border ? sizeValue + UI_SIZES.border.small * 2 : sizeValue),
129+
[props.border, sizeValue],
130+
);
128131
const computedStyle = useAvatarStyle(props);
129132
const imageSource = useAvatarImage(props as SingleAvatarOnlySpecificProps, error);
130133

131-
return <Image style={computedStyle} source={imageSource} onError={onError} {...otherProps} />;
134+
const sizeBorderStyles: any = React.useMemo(
135+
() => ({
136+
borderRadius: sizeContainer / 2,
137+
width: sizeContainer,
138+
}),
139+
[sizeContainer],
140+
);
141+
142+
const sizeContainerStyles: any = React.useMemo(
143+
() => ({
144+
height: sizeContainer,
145+
width: sizeContainer,
146+
}),
147+
[sizeContainer],
148+
);
149+
150+
const renderBorder = React.useCallback(() => {
151+
if (!props.border) return null;
152+
return <View style={[styles.border, sizeBorderStyles]} />;
153+
}, [props.border, sizeBorderStyles]);
154+
155+
return (
156+
<View style={[styles.container, sizeContainerStyles]}>
157+
{renderBorder()}
158+
<Image style={computedStyle} source={imageSource} onError={onError} {...otherProps} />
159+
</View>
160+
);
132161
}

src/framework/components/avatar/styles.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ImageStyle, StyleSheet } from 'react-native';
22

33
import * as Avatar from './types';
44

5+
import theme from '~/app/theme';
56
import { UI_SIZES } from '~/framework/components/constants';
67

78
export const AvatarSizes = {
@@ -13,5 +14,18 @@ export const AvatarSizes = {
1314
};
1415

1516
export default StyleSheet.create({
17+
border: {
18+
backgroundColor: theme.palette.grey.white,
19+
bottom: 0,
20+
left: 0,
21+
position: 'absolute',
22+
right: 0,
23+
top: 0,
24+
},
25+
container: {
26+
alignItems: 'center',
27+
justifyContent: 'center',
28+
position: 'relative',
29+
},
1630
singleAvatar: {} as ImageStyle,
1731
});

src/framework/components/avatar/types.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export enum Size {
1212

1313
export interface CommonSingleAvatarProps extends Omit<ImageProps, 'source'> {
1414
size: Size | keyof typeof Size; // Override width & height given in style property.
15+
border?: boolean;
1516
}
1617

1718
// User avatar

src/framework/components/list/account/item/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const AccountListItem = <ItemT extends AuthSavedAccount | AuthLoggedAccount>({
5151

5252
return (
5353
<TouchableOpacity style={[styles.container, containerBackgroundColor]} onPress={onSelectAccount}>
54-
<SingleAvatar size="lg" {...avatarProps} />
54+
<SingleAvatar size="lg" {...avatarProps} border />
5555
<View style={styles.textContainer}>
5656
<SmallText numberOfLines={numberOfLines}>{displayName}</SmallText>
5757
<SmallBoldText numberOfLines={numberOfLines} style={typeColor}>

src/framework/components/list/user-horizontal/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const UserListItem = <ItemT extends DisplayUserPublic = DisplayUserPublic>(props
3838
const { renderUserDetails, style, ...info } = props;
3939
return (
4040
<View style={style}>
41-
<SingleAvatar userId={info.item.id} size={Size.xxl} />
41+
<SingleAvatar userId={info.item.id} size={Size.xxl} border />
4242
{(renderUserDetails ?? UserListItemDetails)(info)}
4343
</View>
4444
);

src/framework/modules/auth/components/large-horizontal-user-list/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const UserExternalListItem = <
4040
);
4141
return (
4242
<View style={style}>
43-
<SingleAvatar {...avatarProps} />
43+
<SingleAvatar {...avatarProps} border />
4444
{(renderUserDetails ?? UserListItemDetails)(info)}
4545
</View>
4646
);

src/framework/modules/mails/components/avatar-recipient/component.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import styles from './styles';
55
import { MailsRecipientAvatarProps } from './types';
66

77
import theme from '~/app/theme';
8+
import { SingleAvatar } from '~/framework/components/avatar';
9+
import { AvatarSizes } from '~/framework/components/avatar/styles';
810
import { UI_SIZES } from '~/framework/components/constants';
9-
import { AvatarSize, NewAvatar, NewAvatarSizes } from '~/framework/components/newavatar';
1011
import { Svg } from '~/framework/components/picture';
1112

1213
const iconType = {
@@ -19,11 +20,11 @@ const iconType = {
1920
const MailsRecipientAvatar = (props: MailsRecipientAvatarProps) => {
2021
const { id, type } = props;
2122

22-
if (type === 'User' && id) return <NewAvatar size={props.size ?? AvatarSize.md} userId={id} />;
23+
if (type === 'User' && id) return <SingleAvatar size={props.size ?? 'md'} userId={id} />;
2324

2425
const suppViewStyles: ViewStyle = {
2526
aspectRatio: 1,
26-
width: NewAvatarSizes[props.size ?? AvatarSize.md],
27+
width: AvatarSizes[props.size ?? 'md'],
2728
};
2829

2930
return (
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { AvatarSize } from '~/framework/components/newavatar';
1+
import { Size } from '~/framework/components/avatar';
22

33
export interface MailsRecipientAvatarProps {
44
id?: string;
55
type: string;
6-
size?: AvatarSize;
6+
size?: Size | keyof typeof Size;
77
}

src/framework/modules/mails/components/contact-item/component.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { MailsContactItemProps } from './types';
77

88
import theme from '~/app/theme';
99
import { UI_SIZES } from '~/framework/components/constants';
10-
import { AvatarSize } from '~/framework/components/newavatar';
1110
import { Svg } from '~/framework/components/picture';
1211
import { SmallBoldText, SmallText } from '~/framework/components/text';
1312
import MailsRecipientAvatar from '~/framework/modules/mails/components/avatar-recipient';
@@ -47,7 +46,7 @@ export const MailsContactItem = (props: MailsContactItemProps) => {
4746

4847
return (
4948
<View style={styles.container}>
50-
<MailsRecipientAvatar size={AvatarSize.sm} id={id} type={props.user.type} />
49+
<MailsRecipientAvatar size="sm" id={id} type={props.user.type} />
5150
<SmallText style={styles.text} numberOfLines={1}>
5251
<SmallBoldText>{displayName}</SmallBoldText>
5352
{renderAccountType()}

src/framework/modules/mails/screens/details/screen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { MailsDetailsScreenPrivateProps } from './types';
1212

1313
import { I18n } from '~/app/i18n';
1414
import theme from '~/app/theme';
15+
import { SingleAvatar } from '~/framework/components/avatar';
1516
import SecondaryButton from '~/framework/components/buttons/secondary';
1617
import TertiaryButton from '~/framework/components/buttons/tertiary';
1718
import { UI_SIZES } from '~/framework/components/constants';
@@ -20,7 +21,6 @@ import { RichEditorViewer } from '~/framework/components/inputs/rich-text';
2021
import PopupMenu from '~/framework/components/menus/popup';
2122
import BottomSheetModal, { BottomSheetModalMethods } from '~/framework/components/modals/bottom-sheet';
2223
import { NavBarAction, NavBarActionsGroup } from '~/framework/components/navigation';
23-
import { AvatarSize, NewAvatar } from '~/framework/components/newavatar';
2424
import { PageView } from '~/framework/components/page';
2525
import { Svg } from '~/framework/components/picture';
2626
import ScrollView from '~/framework/components/scrollView';
@@ -580,7 +580,7 @@ const MailsDetailsScreen = (props: MailsDetailsScreenPrivateProps) => {
580580
<ScrollView style={styles.page}>
581581
<HeadingXSText>{renderSubject(mail?.subject, isRecall)}</HeadingXSText>
582582
<View style={styles.topInfos}>
583-
<NewAvatar size={AvatarSize.lg} userId={mail?.from.id} />
583+
<SingleAvatar size="lg" userId={mail?.from.id} />
584584
<View style={styles.topInfosText}>
585585
<View style={styles.sender}>
586586
<TouchableOpacity

0 commit comments

Comments
 (0)