From 9b89ab8117817a36445e7c3b9075d19219c81aea Mon Sep 17 00:00:00 2001
From: fzxlzy <810528574@qq.com>
Date: Thu, 11 Jan 2024 11:44:13 +0800
Subject: [PATCH] =?UTF-8?q?[Issues:=20#I8V7U9]=20=E6=9B=B4=E6=96=B0react-n?=
=?UTF-8?q?ative-netinfo=E6=96=87=E6=A1=A3=E5=88=B01224?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
1224/react-native-netinfo.md | 133 +++++++++++++++++------------------
1 file changed, 66 insertions(+), 67 deletions(-)
diff --git a/1224/react-native-netinfo.md b/1224/react-native-netinfo.md
index a9f82644..fd7f9c7d 100644
--- a/1224/react-native-netinfo.md
+++ b/1224/react-native-netinfo.md
@@ -1,4 +1,4 @@
-> 模板版本:v0.0.1
+> 模板版本:v0.1.2
@react-native-community/netinfo
@@ -12,29 +12,24 @@
-## 安装与使用
+> [!tip] [Github 地址](https://github.com/react-native-oh-library/react-native-netinfo)
-> [!tip] 目前部分 React-Native-OpenHarmony(RNOH) 三方库的 npm 包部署在私仓,需要通过 github token 来获取访问权限。
+## 安装与使用
-在与 `package.json` 文件相同的目录中,创建或编辑 `.npmrc` 文件以包含指定 GitHub Packages URL 和托管包的命名空间的行。 将 TOKEN 替换为 RNOH 三方库指定的 token。
-
-```bash
-@react-native-oh-library:registry=https://npm.pkg.github.com
-//npm.pkg.github.com/:_authToken=TOKEN
-```
+
进入到工程目录并输入以下命令:
#### **yarn**
```bash
-yarn add @react-native-community/netinfo@npm:@react-native-oh-library/netinfo
+yarn add @react-native-oh-tpl/netinfo
```
#### **npm**
```bash
-npm install @react-native-community/netinfo@npm:@react-native-oh-library/netinfo
+npm install @react-native-oh-tpl/netinfo
```
下面的代码展示了这个库的基本使用场景:
@@ -88,7 +83,7 @@ const App = () => {
```json
"dependencies": {
"rnoh": "file:../rnoh",
- "rnoh-netinfo": "file:../../node_modules/@react-native-community/netinfo/harmony/netinfo.har"
+ "rnoh-netinfo": "file:../../node_modules/@react-native-oh-tpl/netinfo/harmony/netinfo.har"
}
```
@@ -107,7 +102,7 @@ ohpm install
```json
"dependencies": {
"rnoh": "file:../rnoh",
- "rnoh-netinfo": "file:../../node_modules/@react-native-community/netinfo/harmony/netinfo"
+ "rnoh-netinfo": "file:../../node_modules/@react-native-oh-tpl/netinfo/harmony/netinfo"
}
```
@@ -200,43 +195,47 @@ ohpm install
要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
-请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-library/netinfo Releases](https://github.com/react-native-oh-library/react-native-netinfo/releases)
+请到三方库相应的 Releases 发布地址查看 Release 配套的版本信息:[@react-native-oh-tpl/netinfo Releases](https://github.com/react-native-oh-library/react-native-netinfo/releases)
## 属性
+> [!tip] "Platform"列表示该属性在原三方库上支持的平台。
+
+> [!tip] "HarmonyOS Support"列为 yes 表示 HarmonyOS 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
+
#### NetInfoStateType
-| 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
-| ----------- | ---------------------------------------------------------- | ------ | -------- | ------------ | -------- |
-| `none` | No network connection is active | String | no | All | yes |
-| `unknown` | The network state could not or has yet to be be determined | String | no | All | yes |
-| `cellular` | Active network over cellular | String | no | All | no |
-| `wifi` | Active network over Wifi | String | no | All | yes |
-| `bluetooth` | Active network over Bluetooth | String | no | Android, Web | no |
-| `ethernet` | Active network over wired ethernet | String | no | All | no |
-| `wimax` | Active network over WiMax | String | no | Android, Web | no |
-| `vpn` | Active network over VPN | String | no | Android | no |
-| `other` | Active network over another type of network | String | no | All | no |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ----------- | ---------------------------------------------------------- | ------ | -------- | ------------ | ----------------- |
+| `none` | No network connection is active | String | no | All | yes |
+| `unknown` | The network state could not or has yet to be be determined | String | no | All | yes |
+| `cellular` | Active network over cellular | String | no | All | no |
+| `wifi` | Active network over Wifi | String | no | All | yes |
+| `bluetooth` | Active network over Bluetooth | String | no | Android, Web | no |
+| `ethernet` | Active network over wired ethernet | String | no | All | no |
+| `wimax` | Active network over WiMax | String | no | Android, Web | no |
+| `vpn` | Active network over VPN | String | no | Android | no |
+| `other` | Active network over another type of network | String | no | All | no |
#### NetInfoCellularGeneration
-| 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
-| ------ | ----------------------------------------------------------------------------------------------------------------- | ------ | -------- | --------------------- | -------- |
-| `null` | Either we are not currently connected to a cellular network or type could not be determined | String | no | Android, iOS, Windows | no |
-| `2g` | Currently connected to a 2G cellular network. Includes CDMA, EDGE, GPRS, and IDEN type connections | String | no | Android, iOS, Windows | no |
-| `3g` | Currently connected to a 3G cellular network. Includes EHRPD, EVDO, HSPA, HSUPA, HSDPA, and UTMS type connections | String | no | Android, iOS, Windows | no |
-| `4g` | Currently connected to a 4G cellular network. Includes HSPAP and LTE type connections | String | no | Android, iOS, Windows | no |
-| `5g` | Currently connected to a 5G cellular network. Includes NRNSA (iOS only) and NR type connections | String | no | Android, iOS, Windows | no |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ------ | ----------------------------------------------------------------------------------------------------------------- | ------ | -------- | --------------------- | ----------------- |
+| `null` | Either we are not currently connected to a cellular network or type could not be determined | String | no | Android, iOS, Windows | no |
+| `2g` | Currently connected to a 2G cellular network. Includes CDMA, EDGE, GPRS, and IDEN type connections | String | no | Android, iOS, Windows | no |
+| `3g` | Currently connected to a 3G cellular network. Includes EHRPD, EVDO, HSPA, HSUPA, HSDPA, and UTMS type connections | String | no | Android, iOS, Windows | no |
+| `4g` | Currently connected to a 4G cellular network. Includes HSPAP and LTE type connections | String | no | Android, iOS, Windows | no |
+| `5g` | Currently connected to a 5G cellular network. Includes NRNSA (iOS only) and NR type connections | String | no | Android, iOS, Windows | no |
#### NetInfoState
-| 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
-| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -------- | -------- | -------- |
-| `type` | The type of the current connection. | NetInfoStateType | yes | All | yes |
-| `isConnected` | 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. | boolean, null | yes | All | yes |
-| `isInternetReachable` | If the internet is reachable with the currently active network connection. If unknown defaults to null | boolean, null | yes | All | yes |
-| `isWifiEnabled` | (Android only) Whether the device's WiFi is ON or OFF. | boolean | yes | All | yes |
-| `details` | The value depends on the type value. See below. | | yes | All | yes |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | -------- | -------- | ----------------- |
+| `type` | The type of the current connection. | NetInfoStateType | yes | All | yes |
+| `isConnected` | 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. | boolean, null | yes | All | yes |
+| `isInternetReachable` | If the internet is reachable with the currently active network connection. If unknown defaults to null | boolean, null | yes | All | yes |
+| `isWifiEnabled` | (Android only) Whether the device's WiFi is ON or OFF. | boolean | yes | All | yes |
+| `details` | The value depends on the type value. See below. | | yes | All | yes |
### Details
@@ -246,46 +245,46 @@ ohpm install
#### Type is wifi
-| 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
-| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- | ---------------------------------- | -------- |
-| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | yes |
-| `ssid` | The SSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, your app must meet at least one of the following requirements and you must set the shouldFetchWiFiSSID configuration option or no attempt will be made to fetch the SSID. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user. | string | yes | Android, iOS (not tvOS), Windows | yes |
-| `bssid` | The BSSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, make sure your app meets at least one of the following requirements. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user. | string | yes | Android, iOS (not tvOS), Windows\* | yes |
-| `strength` | An integer number from 0 to 100 for the signal strength. May not be present if the signal strength cannot be determined. | number | yes | Android, Windows | yes |
-| `ipAddress` | The external IP address. Can be in IPv4 or IPv6 format. May not be present if it cannot be determined. | string | yes | Android, iOS, macOS, Windows | yes |
-| `subnet` | The subnet mask in IPv4 format. May not be present if it cannot be determined. | string | yes | Android, iOS, macOS | yes |
-| `frequency` | Network frequency. Example: For 2.4 GHz networks, the method will return 2457. May not be present if it cannot be determined. | number | yes | Android, Windows\* | yes |
-| `linkSpeed` | The link speed in Mbps. | number | yes | Android | yes |
-| `rxLinkSpeed` | The current receive link speed in Mbps. | number | yes | Android | yes |
-| `txLinkSpeed` | The current transmit link speed in Mbps. | number | yes | Android | yes |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | -------- | ---------------------------------- | ----------------- |
+| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | yes |
+| `ssid` | The SSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, your app must meet at least one of the following requirements and you must set the shouldFetchWiFiSSID configuration option or no attempt will be made to fetch the SSID. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user. | string | yes | Android, iOS (not tvOS), Windows | yes |
+| `bssid` | The BSSID of the network. May not be present, null, or an empty string if it cannot be determined. On iOS, make sure your app meets at least one of the following requirements. On Android, you need to have the ACCESS_FINE_LOCATION permission in your AndroidManifest.xml and accepted by the user. | string | yes | Android, iOS (not tvOS), Windows\* | yes |
+| `strength` | An integer number from 0 to 100 for the signal strength. May not be present if the signal strength cannot be determined. | number | yes | Android, Windows | yes |
+| `ipAddress` | The external IP address. Can be in IPv4 or IPv6 format. May not be present if it cannot be determined. | string | yes | Android, iOS, macOS, Windows | yes |
+| `subnet` | The subnet mask in IPv4 format. May not be present if it cannot be determined. | string | yes | Android, iOS, macOS | yes |
+| `frequency` | Network frequency. Example: For 2.4 GHz networks, the method will return 2457. May not be present if it cannot be determined. | number | yes | Android, Windows\* | yes |
+| `linkSpeed` | The link speed in Mbps. | number | yes | Android | yes |
+| `rxLinkSpeed` | The current receive link speed in Mbps. | number | yes | Android | yes |
+| `txLinkSpeed` | The current transmit link speed in Mbps. | number | yes | Android | yes |
#### Type is cellular
-| 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
-| ----------------------- | --------------------------------------------------------------------------------------------------------------------- | :-----------------------: | :------: | :-------------------: | :------: |
-| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | no |
-| `cellularGeneration` | The generation of the cell network the user is connected to. This can give an indication of speed, but no guarantees. | NetInfoCellularGeneration | yes | Android, iOS, Windows | no |
-| `carrier` | The network carrier name. May not be present or may be empty if none can be determined. | +string | yes | Android, iOS | no |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ----------------------- | --------------------------------------------------------------------------------------------------------------------- | :-----------------------: | :------: | :-------------------: | :---------------: |
+| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | no |
+| `cellularGeneration` | The generation of the cell network the user is connected to. This can give an indication of speed, but no guarantees. | NetInfoCellularGeneration | yes | Android, iOS, Windows | no |
+| `carrier` | The network carrier name. May not be present or may be empty if none can be determined. | +string | yes | Android, iOS | no |
#### Type is bluetooth, ethernet, wimax, vpn, or other
-| 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
-| ----------------------- | ------------------------------------------------------------------------------------------------------ | :-----: | :------: | :------: | :------: |
-| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | no |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ----------------------- | ------------------------------------------------------------------------------------------------------ | :-----: | :------: | :------: | :---------------: |
+| `isConnectionExpensive` | If the network connection is considered "expensive". This could be in either energy or monetary terms. | boolean | yes | All | no |
## 静态方法
-| 名称 | 说明 | 类型 | 是否必填 | 原库平台 | 鸿蒙支持 |
-| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :------: | :------: | :------: |
-| `fetch()` | Returns a Promise that resolves to a NetInfoState object. | function | yes | All | yes |
-| `refresh()` | Updates NetInfo's internal state, then returns a Promise that resolves to a NetInfoState object. This is similar to fetch(), but really only useful on platforms that do not supply internet reachability natively. For example, you can use it to immediately re-run an internet reachability test if a network request fails unexpectedly. | function | yes | All | yes |
-| `addEventListener()` | Subscribe to connection information. The callback is called with a parameter of type NetInfoState whenever the connection state changes. Your listener will be called with the latest information soon after you subscribe and then with any subsequent changes afterwards. You should not assume that the listener is called in the same way across devices or platforms. | function | yes | All | yes |
-| `useNetInfo()` | A React Hook which can be used to get access to the latest state from the global instance. It returns a hook with the NetInfoState type. | function | yes | All | yes |
-| `useNetInfoInstance()` | A React Hook which can be used to create and manage an isolated instance of a network manager class. It returns a refresh function and the current NetInfoState. | function | yes | All | no |
+| Name | Description | Type | Required | Platform | HarmonyOS Support |
+| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | :------: | :------: | :---------------: |
+| `fetch()` | Returns a Promise that resolves to a NetInfoState object. | function | yes | All | yes |
+| `refresh()` | Updates NetInfo's internal state, then returns a Promise that resolves to a NetInfoState object. This is similar to fetch(), but really only useful on platforms that do not supply internet reachability natively. For example, you can use it to immediately re-run an internet reachability test if a network request fails unexpectedly. | function | yes | All | yes |
+| `addEventListener()` | Subscribe to connection information. The callback is called with a parameter of type NetInfoState whenever the connection state changes. Your listener will be called with the latest information soon after you subscribe and then with any subsequent changes afterwards. You should not assume that the listener is called in the same way across devices or platforms. | function | yes | All | yes |
+| `useNetInfo()` | A React Hook which can be used to get access to the latest state from the global instance. It returns a hook with the NetInfoState type. | function | yes | All | yes |
+| `useNetInfoInstance()` | A React Hook which can be used to create and manage an isolated instance of a network manager class. It returns a refresh function and the current NetInfoState. | function | yes | All | yes |
## 遗留问题
-- 新版本 useNetInfoInstance 暂未适配验证,涉及非 wifi 环境下的接口属性未适配
+- 涉及非 wifi 环境下的接口属性未适配
## 其他
--
Gitee