From 8e8ba33916d9a3a5ba1ee250c0371f763c8c887f Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 1 May 2024 19:14:12 +0700 Subject: [PATCH 1/2] fix App does not go offline when Force offline --- src/hooks/useNetwork.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hooks/useNetwork.ts b/src/hooks/useNetwork.ts index 778fed200b7b..d8b271944b74 100644 --- a/src/hooks/useNetwork.ts +++ b/src/hooks/useNetwork.ts @@ -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 @@ -30,5 +29,5 @@ export default function useNetwork({onReconnect = () => {}}: UseNetworkProps = { prevOfflineStatusRef.current = isOffline; }, [isOffline]); - return {isOffline}; + return {isOffline: networkStatus === CONST.NETWORK.NETWORK_STATUS.UNKNOWN ? false : isOffline}; } From 8df51213e1705b6289c8eac6a7ff9c9cf5673cf5 Mon Sep 17 00:00:00 2001 From: tienifr Date: Sat, 4 May 2024 14:47:17 +0700 Subject: [PATCH 2/2] fix comment --- src/hooks/useNetwork.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hooks/useNetwork.ts b/src/hooks/useNetwork.ts index d8b271944b74..950d0592b59c 100644 --- a/src/hooks/useNetwork.ts +++ b/src/hooks/useNetwork.ts @@ -29,5 +29,6 @@ export default function useNetwork({onReconnect = () => {}}: UseNetworkProps = { prevOfflineStatusRef.current = isOffline; }, [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}; }