diff --git a/src/components/Avatar.js b/src/components/Avatar.js index ff51d2c427b8..eb5f28f64efe 100644 --- a/src/components/Avatar.js +++ b/src/components/Avatar.js @@ -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. */ @@ -70,7 +71,12 @@ class Avatar extends PureComponent { /> ) : ( - this.setState({imageError: true})} /> + this.setState({imageError: true})} + /> )} ); diff --git a/src/libs/getAvatarDefaultSource/index.js b/src/libs/getAvatarDefaultSource/index.js new file mode 100644 index 000000000000..54c2a7d04b01 --- /dev/null +++ b/src/libs/getAvatarDefaultSource/index.js @@ -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}); diff --git a/src/libs/getAvatarDefaultSource/index.native.js b/src/libs/getAvatarDefaultSource/index.native.js new file mode 100644 index 000000000000..1c1c79caf151 --- /dev/null +++ b/src/libs/getAvatarDefaultSource/index.native.js @@ -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;