-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add indicator to avatar #10065
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
Merged
Merged
Add indicator to avatar #10065
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
29ac710
Add indicator to avatar
iwiznia 27125ba
Add RBR to workspace page (kind of)
iwiznia 983d192
Add more RBR for policy members
iwiznia 4b3db1c
Fix proptypes and some code that uses them
iwiznia 78fa853
Fix more proptypes
iwiznia 85b44a3
Merge from main
iwiznia 4ca144d
Use utility and common props
iwiznia 0930025
Remove test code
iwiznia f122f03
Use utility method, remove hardcoded values
iwiznia 75a6ed4
Fix lint errors
iwiznia 56dbe68
Lint again
iwiznia c3ccb28
Address comments from review
iwiznia 1803d86
Merge from main
iwiznia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,126 +1,66 @@ | ||
| import React, {PureComponent} from 'react'; | ||
| import { | ||
| View, StyleSheet, Animated, | ||
| } from 'react-native'; | ||
| import _ from 'underscore'; | ||
| import React from 'react'; | ||
| import {StyleSheet, View} from 'react-native'; | ||
| import PropTypes from 'prop-types'; | ||
| import {withOnyx} from 'react-native-onyx'; | ||
| import Avatar from './Avatar'; | ||
| import themeColors from '../styles/themes/default'; | ||
| import styles from '../styles/styles'; | ||
| import Icon from './Icon'; | ||
| import * as Expensicons from './Icon/Expensicons'; | ||
| import SpinningIndicatorAnimation from '../styles/animation/SpinningIndicatorAnimation'; | ||
| import Tooltip from './Tooltip'; | ||
| import withLocalize, {withLocalizePropTypes} from './withLocalize'; | ||
| import ONYXKEYS from '../ONYXKEYS'; | ||
| import policyMemberPropType from '../pages/policyMemberPropType'; | ||
| import * as Policy from '../libs/actions/Policy'; | ||
|
|
||
| const propTypes = { | ||
| /** Is user active? */ | ||
| isActive: PropTypes.bool, | ||
|
|
||
| /** URL for the avatar */ | ||
| source: PropTypes.string.isRequired, | ||
|
|
||
| /** Avatar size */ | ||
| size: PropTypes.string, | ||
|
|
||
| // Whether we show the sync indicator | ||
| isSyncing: PropTypes.bool, | ||
|
|
||
| /** To show a tooltip on hover */ | ||
| tooltipText: PropTypes.string, | ||
|
|
||
| ...withLocalizePropTypes, | ||
| /** The employee list of all policies (coming from Onyx) */ | ||
| policiesMemberList: PropTypes.objectOf(policyMemberPropType), | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| isActive: false, | ||
| size: 'default', | ||
| isSyncing: false, | ||
| tooltipText: '', | ||
| policiesMemberList: {}, | ||
| }; | ||
|
|
||
| class AvatarWithIndicator extends PureComponent { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.animation = new SpinningIndicatorAnimation(); | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| if (!this.props.isSyncing) { | ||
| return; | ||
| } | ||
|
|
||
| this.animation.start(); | ||
| } | ||
|
|
||
| componentDidUpdate(prevProps) { | ||
| if (!prevProps.isSyncing && this.props.isSyncing) { | ||
| this.animation.start(); | ||
| } else if (prevProps.isSyncing && !this.props.isSyncing) { | ||
| this.animation.stop(); | ||
| } | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| this.animation.stop(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns user status as text | ||
| * | ||
| * @returns {String} | ||
| */ | ||
| userStatus() { | ||
| if (this.props.isSyncing) { | ||
| return this.props.translate('profilePage.syncing'); | ||
| } | ||
|
|
||
| if (this.props.isActive) { | ||
| return this.props.translate('profilePage.online'); | ||
| } | ||
|
|
||
| if (!this.props.isActive) { | ||
| return this.props.translate('profilePage.offline'); | ||
| } | ||
| } | ||
|
|
||
| render() { | ||
| const indicatorStyles = [ | ||
| styles.alignItemsCenter, | ||
| styles.justifyContentCenter, | ||
| this.props.size === 'large' ? styles.statusIndicatorLarge : styles.statusIndicator, | ||
| this.props.isActive ? styles.statusIndicatorOnline : styles.statusIndicatorOffline, | ||
| this.animation.getSyncingStyles(), | ||
| ]; | ||
|
|
||
| return ( | ||
| <View | ||
| style={[this.props.size === 'large' ? styles.avatarLarge : styles.sidebarAvatar]} | ||
| > | ||
| <Tooltip text={this.props.tooltipText}> | ||
| <Avatar | ||
| imageStyles={[this.props.size === 'large' ? styles.avatarLarge : null]} | ||
| source={this.props.source} | ||
| size={this.props.size} | ||
| /> | ||
| </Tooltip> | ||
| <Tooltip text={this.userStatus()} absolute> | ||
| <Animated.View style={StyleSheet.flatten(indicatorStyles)}> | ||
| {this.props.isSyncing && ( | ||
| <Icon | ||
| src={Expensicons.Sync} | ||
| fill={themeColors.textReversed} | ||
| width={6} | ||
| height={6} | ||
| /> | ||
| )} | ||
| </Animated.View> | ||
| </Tooltip> | ||
| </View> | ||
| ); | ||
| } | ||
| } | ||
| const AvatarWithIndicator = (props) => { | ||
| const isLarge = props.size === 'large'; | ||
| const indicatorStyles = [ | ||
| styles.alignItemsCenter, | ||
| styles.justifyContentCenter, | ||
| isLarge ? styles.statusIndicatorLarge : styles.statusIndicator, | ||
| ]; | ||
|
|
||
| const hasPolicyMemberError = _.some(props.policiesMemberList, policyMembers => Policy.hasPolicyMemberError(policyMembers)); | ||
| return ( | ||
| <View style={[isLarge ? styles.avatarLarge : styles.sidebarAvatar]}> | ||
| <Tooltip text={props.tooltipText}> | ||
| <Avatar | ||
| imageStyles={[isLarge ? styles.avatarLarge : null]} | ||
| source={props.source} | ||
| size={props.size} | ||
| /> | ||
| {hasPolicyMemberError && ( | ||
| <View style={StyleSheet.flatten(indicatorStyles)} /> | ||
| )} | ||
| </Tooltip> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| AvatarWithIndicator.defaultProps = defaultProps; | ||
| AvatarWithIndicator.propTypes = propTypes; | ||
| export default withLocalize(AvatarWithIndicator); | ||
| AvatarWithIndicator.displayName = 'AvatarWithIndicator'; | ||
|
|
||
| export default withOnyx({ | ||
| policiesMemberList: { | ||
| key: ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST, | ||
| }, | ||
| })(AvatarWithIndicator); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we purposely removing the sync icon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes