Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add avatars based on svg icons for default rooms #3891

Merged
merged 5 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions assets/images/avatars/room.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 14 additions & 9 deletions src/components/Avatar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, {PureComponent} from 'react';
import {Image, View} from 'react-native';
import {Image, View, StyleSheet} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import RoomAvatar from '../../assets/images/avatars/room.svg';

const propTypes = {
/** Url source for the avatar */
Expand All @@ -15,30 +16,34 @@ const propTypes = {

/** Set the size of Avatar */
size: PropTypes.oneOf(['default', 'small']),

/** Whether this avatar is for a default room */
isDefaultChatRoom: PropTypes.bool,
};

const defaultProps = {
source: '',
imageStyles: [],
containerStyles: [],
size: 'default',
isDefaultChatRoom: false,
};

class Avatar extends PureComponent {
render() {
if (!this.props.source) {
if (!this.props.source && !this.props.isDefaultChatRoom) {
return null;
}

const imageStyle = [
this.props.size === 'small' ? styles.avatarSmall : styles.avatarNormal,
...this.props.imageStyles,
];
return (
<View pointerEvents="none" style={this.props.containerStyles}>
<Image
source={{uri: this.props.source}}
style={[
this.props.size === 'small' ? styles.avatarSmall : styles.avatarNormal,
...this.props.imageStyles,
]}
/>
{this.props.isDefaultChatRoom
? <RoomAvatar style={StyleSheet.flatten(imageStyle)} />
: <Image source={{uri: this.props.source}} style={imageStyle} />}
</View>
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/MultipleAvatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ const propTypes = {
/** Style for Second Avatar */
// eslint-disable-next-line react/forbid-prop-types
secondAvatarStyle: PropTypes.arrayOf(PropTypes.object),

/** Whether this avatar is for a default room */
isDefaultChatRoom: PropTypes.bool,
};

const defaultProps = {
avatarImageURLs: [],
size: 'default',
secondAvatarStyle: [styles.secondAvatarHovered],
isDefaultChatRoom: false,
};

const MultipleAvatars = ({
avatarImageURLs, size, secondAvatarStyle,
avatarImageURLs, size, secondAvatarStyle, isDefaultChatRoom,
}) => {
const avatarContainerStyles = size === 'small' ? styles.emptyAvatarSmall : styles.emptyAvatar;
const singleAvatarStyles = size === 'small' ? styles.singleAvatarSmall : styles.singleAvatar;
Expand All @@ -40,7 +44,7 @@ const MultipleAvatars = ({
if (avatarImageURLs.length === 1) {
return (
<View style={avatarContainerStyles}>
<Avatar source={avatarImageURLs[0]} size={size} />
<Avatar source={avatarImageURLs[0]} size={size} isDefaultChatRoom={isDefaultChatRoom} />
</View>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,9 @@ function getCurrencyListForSections(currencyOptions, searchValue) {
* @returns {String}
*/
function getReportIcons(report, personalDetails) {
// Default rooms have a specific avatar so we can return any non-empty array
if (isDefaultRoom(report)) {
// Placeholder image for default rooms soon to be updated
return [`${CONST.CLOUDFRONT_URL}/images/avatars/default_avatar_external.png`];
return [''];
}
return _.map(report.participants, dmParticipant => ({
firstName: lodashGet(personalDetails, [dmParticipant, 'firstName'], ''),
Expand Down
9 changes: 6 additions & 3 deletions src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import _ from 'underscore';
import {Image, View} from 'react-native';
import {View} from 'react-native';
import lodashGet from 'lodash/get';
import Avatar from '../components/Avatar';
import compose from '../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import ONYXKEYS from '../ONYXKEYS';
Expand Down Expand Up @@ -125,9 +126,11 @@ class ReportDetailsPage extends Component {
<View
style={styles.reportDetailsTitleContainer}
>
<Image
<Avatar
isDefaultChatRoom={isDefaultRoom(this.props.report)}
containerStyles={[styles.singleAvatarLarge, styles.mb4]}
imageStyles={[styles.singleAvatarLarge]}
source={{uri: this.props.report.icons[0]}}
style={[styles.singleAvatarLarge, styles.mb4]}
/>
<View style={styles.reportDetailsRoomInfo}>
<DisplayNames
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const HeaderView = (props) => {
<MultipleAvatars
avatarImageURLs={props.report.icons}
secondAvatarStyle={[styles.secondAvatarHovered]}
isDefaultChatRoom={isDefaultChatRoom}
/>
<View style={[styles.flex1, styles.flexColumn]}>
<DisplayNames
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/sidebar/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const OptionRow = ({
? getBackgroundAndBorderStyle(hoveredBackgroundColor)
: undefined,
]}
isDefaultChatRoom={option.isDefaultChatRoom}
/>
)
}
Expand Down