From f7fd94c2a0959d00711f0aa8afc0e8073a99b755 Mon Sep 17 00:00:00 2001 From: eVoloshchak Date: Sun, 28 Nov 2021 20:23:04 +0200 Subject: [PATCH 1/3] Return actual connection state then network type is unknown --- src/internal/nativeModule.web.ts | 2 +- src/internal/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal/nativeModule.web.ts b/src/internal/nativeModule.web.ts index e03ff108..392348e9 100644 --- a/src/internal/nativeModule.web.ts +++ b/src/internal/nativeModule.web.ts @@ -213,7 +213,7 @@ const getCurrentState = ( } else if (type === NetInfoStateType.unknown) { const state: NetInfoUnknownState = { ...baseState, - isConnected: null, + isConnected, isInternetReachable: null, type, details: null, diff --git a/src/internal/types.ts b/src/internal/types.ts index 1eb81406..b3263fce 100644 --- a/src/internal/types.ts +++ b/src/internal/types.ts @@ -50,7 +50,7 @@ interface NetInfoDisconnectedState { export interface NetInfoUnknownState { type: NetInfoStateType.unknown; - isConnected: null; + isConnected: boolean; isInternetReachable: null; details: null; } From 8990254bcb8d3ee2829327d5136ee97ef877e6d6 Mon Sep 17 00:00:00 2001 From: eVoloshchak Date: Mon, 29 Nov 2021 13:44:44 +0200 Subject: [PATCH 2/3] Allow isConnected property in NetInfoUnknownState to be of null type --- src/internal/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/types.ts b/src/internal/types.ts index b3263fce..f21cf00b 100644 --- a/src/internal/types.ts +++ b/src/internal/types.ts @@ -50,7 +50,7 @@ interface NetInfoDisconnectedState { export interface NetInfoUnknownState { type: NetInfoStateType.unknown; - isConnected: boolean; + isConnected: boolean | null; isInternetReachable: null; details: null; } From c534c3341128750f42202395a028e2fa35038a48 Mon Sep 17 00:00:00 2001 From: eVoloshchak Date: Mon, 29 Nov 2021 16:45:23 +0200 Subject: [PATCH 3/3] Add note about isConnected property for unknown network type to the docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88c93fd7..48346181 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Describes the current state of the network. It is an object with these propertie | Property | Type | Description | | --------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------- | | `type` | [`NetInfoStateType`](#netinfostatetype) | The type of the current connection. | -| `isConnected` | `boolean`, `null` | If there is an active network connection. If unknown defaults to `null`. | +| `isConnected` | `boolean`, `null` | If there is an active network connection. Defaults to `null` on most platforms for `unknown` networks. Note: Web browsers report network type `unknown` for many otherwise valid networks (https://caniuse.com/netinfo), so `isConnected` may be `true` or `false` and represent a real connection status even for unknown network types in certain cases.| | `isInternetReachable` | `boolean`, `null` | If the internet is reachable with the currently active network connection. If unknown defaults to `null` | | `isWifiEnabled` | `boolean` | *(Android only)* Whether the device's WiFi is ON or OFF. | | `details` | | The value depends on the `type` value. See below. |