Skip to content

Commit

Permalink
fix(web, isConnected): Return actual connection state even if network…
Browse files Browse the repository at this point in the history
… type is 'unknown' (#544)

* Return actual connection state then network type is unknown
* Allow isConnected property in NetInfoUnknownState to be of null type
* Add note about isConnected property for unknown network type to the docs
  • Loading branch information
eVoloshchak committed Nov 29, 2021
1 parent bc9b80d commit 36d6dc9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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. |
Expand Down
2 changes: 1 addition & 1 deletion src/internal/nativeModule.web.ts
Expand Up @@ -213,7 +213,7 @@ const getCurrentState = (
} else if (type === NetInfoStateType.unknown) {
const state: NetInfoUnknownState = {
...baseState,
isConnected: null,
isConnected,
isInternetReachable: null,
type,
details: null,
Expand Down
2 changes: 1 addition & 1 deletion src/internal/types.ts
Expand Up @@ -50,7 +50,7 @@ interface NetInfoDisconnectedState<T extends NetInfoStateType> {

export interface NetInfoUnknownState {
type: NetInfoStateType.unknown;
isConnected: null;
isConnected: boolean | null;
isInternetReachable: null;
details: null;
}
Expand Down

0 comments on commit 36d6dc9

Please sign in to comment.