diff --git a/app/components/network_indicator/network_indicator.js b/app/components/network_indicator/network_indicator.js index 5d9340d55..a29476fb2 100644 --- a/app/components/network_indicator/network_indicator.js +++ b/app/components/network_indicator/network_indicator.js @@ -78,6 +78,7 @@ export default class NetworkIndicator extends PureComponent { this.backgroundColor = new Animated.Value(0); this.firstRun = true; + this.statusUpdates = false; this.networkListener = networkConnectionListener(this.handleConnectionChange); } @@ -138,7 +139,7 @@ export default class NetworkIndicator extends PureComponent { } connect = (displayBar = false) => { - const {connection} = this.props.actions; + const {connection, startPeriodicStatusUpdates} = this.props.actions; clearTimeout(this.connectionRetryTimeout); NetInfo.fetch().then(async ({isConnected}) => { @@ -149,7 +150,9 @@ export default class NetworkIndicator extends PureComponent { this.serverReachable = serverReachable; if (serverReachable) { + this.statusUpdates = true; this.initializeWebSocket(); + startPeriodicStatusUpdates(); } else { if (displayBar) { this.show(); @@ -220,9 +223,11 @@ export default class NetworkIndicator extends PureComponent { } = actions; if (open) { + this.statusUpdates = true; this.initializeWebSocket(); startPeriodicStatusUpdates(); - } else { + } else if (this.statusUpdates) { + this.statusUpdates = false; closeWebSocket(true); stopPeriodicStatusUpdates(); } @@ -249,13 +254,12 @@ export default class NetworkIndicator extends PureComponent { }; handleConnectionChange = ({hasInternet, serverReachable}) => { - const {connection, startPeriodicStatusUpdates} = this.props.actions; + const {connection} = this.props.actions; // On first run always initialize the WebSocket // if we have internet connection if (hasInternet && this.firstRun) { this.initializeWebSocket(); - startPeriodicStatusUpdates(); this.firstRun = false; // if the state of the internet connection was previously known to be false,