Skip to content

Commit

Permalink
Merge pull request Expensify#9995 from b1tjoy/fix/9183-prevent-avatar…
Browse files Browse the repository at this point in the history
…-icon-from-flicker

fix: prevent avatar icon from flicker on Web
  • Loading branch information
stitesExpensify authored Jul 26, 2022
2 parents 99def93 + a16482a commit 92186e5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import themeColors from '../styles/themes/default';
import CONST from '../CONST';
import * as StyleUtils from '../styles/StyleUtils';
import * as Expensicons from './Icon/Expensicons';
import getAvatarDefaultSource from '../libs/getAvatarDefaultSource';

const propTypes = {
/** Source for the avatar. Can be a URL or an icon. */
Expand Down Expand Up @@ -70,7 +71,12 @@ class Avatar extends PureComponent {
/>
)
: (
<Image source={{uri: this.props.source}} style={imageStyle} onError={() => this.setState({imageError: true})} />
<Image
source={{uri: this.props.source}}
defaultSource={getAvatarDefaultSource(this.props.source)}
style={imageStyle}
onError={() => this.setState({imageError: true})}
/>
)}
</View>
);
Expand Down
7 changes: 7 additions & 0 deletions src/libs/getAvatarDefaultSource/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Avatar icon flickers when message is sent for the first time, return and set the source as
* defaultSource prop of image to prevent avatar icon from flicker when running on Web/Desktop
* @param {String|Function} source The source of avatar image
* @return {Object} The image source
*/
export default source => ({uri: source});
5 changes: 5 additions & 0 deletions src/libs/getAvatarDefaultSource/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Avatar icon does not flicker when running on Native, return and set undefined as defaultSource prop of image
* @return {Object} undefined
*/
export default () => undefined;

0 comments on commit 92186e5

Please sign in to comment.