Skip to content

Commit

Permalink
Merge pull request #41412 from tienifr/fix/38212-regression-offline-i…
Browse files Browse the repository at this point in the history
…ndicator

fix app does not go offline when Force offline
  • Loading branch information
puneetlath authored May 4, 2024
2 parents 2f5173c + 8df5121 commit 550e83b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/hooks/useNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export default function useNetwork({onReconnect = () => {}}: UseNetworkProps = {
const callback = useRef(onReconnect);
callback.current = onReconnect;

const {networkStatus} = useContext(NetworkContext) ?? {...CONST.DEFAULT_NETWORK_DATA, networkStatus: CONST.NETWORK.NETWORK_STATUS.UNKNOWN};
const isOffline = networkStatus === CONST.NETWORK.NETWORK_STATUS.OFFLINE;
const {isOffline, networkStatus} = useContext(NetworkContext) ?? {...CONST.DEFAULT_NETWORK_DATA, networkStatus: CONST.NETWORK.NETWORK_STATUS.UNKNOWN};
const prevOfflineStatusRef = useRef(isOffline);
useEffect(() => {
// If we were offline before and now we are not offline then we just reconnected
Expand All @@ -30,5 +29,6 @@ export default function useNetwork({onReconnect = () => {}}: UseNetworkProps = {
prevOfflineStatusRef.current = isOffline;
}, [isOffline]);

return {isOffline};
// If the network status is undefined, we don't treat it as offline. Otherwise, we utilize the isOffline prop.
return {isOffline: networkStatus === CONST.NETWORK.NETWORK_STATUS.UNKNOWN ? false : isOffline};
}

0 comments on commit 550e83b

Please sign in to comment.