Skip to content

Commit

Permalink
Merge pull request #12808 from hungvu193/fix-12712
Browse files Browse the repository at this point in the history
Fix: Offline default avatar doesn't update after connecting to the internet
  • Loading branch information
yuwenmemon authored Dec 9, 2022
2 parents 23533cf + ada0df2 commit 216bbe9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import CONST from '../CONST';
import * as StyleUtils from '../styles/StyleUtils';
import * as Expensicons from './Icon/Expensicons';
import getAvatarDefaultSource from '../libs/getAvatarDefaultSource';
import {withNetwork} from './OnyxProvider';
import networkPropTypes from './networkPropTypes';
import styles from '../styles/styles';

const propTypes = {
Expand All @@ -30,6 +32,9 @@ const propTypes = {

/** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */
fallbackIcon: PropTypes.func,

/** Props to detect online status */
network: networkPropTypes.isRequired,
};

const defaultProps = {
Expand All @@ -49,6 +54,14 @@ class Avatar extends PureComponent {
};
}

componentDidUpdate(prevProps) {
const isReconnecting = prevProps.network.isOffline && !this.props.network.isOffline;
if (!this.state.imageError || !isReconnecting) {
return;
}
this.setState({imageError: false});
}

render() {
if (!this.props.source) {
return null;
Expand Down Expand Up @@ -94,4 +107,4 @@ class Avatar extends PureComponent {

Avatar.defaultProps = defaultProps;
Avatar.propTypes = propTypes;
export default Avatar;
export default withNetwork()(Avatar);

0 comments on commit 216bbe9

Please sign in to comment.