@tarojs/taro-rn 3.3.14 → 3.5.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/network.js +26 -7
- package/dist/lib/network.js.map +1 -1
- package/package.json +28 -30
- package/src/lib/network.ts +24 -7
package/dist/lib/network.js
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
import NetInfo from '@react-native-community/netinfo';
|
|
1
|
+
import NetInfo, { NetInfoStateType } from '@react-native-community/netinfo';
|
|
2
2
|
let _unsubscribe = null;
|
|
3
3
|
let _callbacks = new Set();
|
|
4
|
+
function getTypeFromState(connectionInfo) {
|
|
5
|
+
let type;
|
|
6
|
+
if (connectionInfo.type === NetInfoStateType.wifi) {
|
|
7
|
+
type = NetInfoStateType.wifi;
|
|
8
|
+
}
|
|
9
|
+
else if (connectionInfo.type === NetInfoStateType.cellular && connectionInfo.details.cellularGeneration) {
|
|
10
|
+
type = connectionInfo.details.cellularGeneration;
|
|
11
|
+
}
|
|
12
|
+
else if (connectionInfo.type === NetInfoStateType.none) {
|
|
13
|
+
type = 'none';
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
type = 'unknown';
|
|
17
|
+
}
|
|
18
|
+
return type;
|
|
19
|
+
}
|
|
4
20
|
export function getNetworkType(opts = {}) {
|
|
5
21
|
const { success, fail, complete } = opts;
|
|
6
|
-
const res = {};
|
|
7
22
|
return new Promise((resolve, reject) => {
|
|
8
23
|
NetInfo.fetch()
|
|
9
24
|
.then((connectionInfo) => {
|
|
10
|
-
res
|
|
11
|
-
|
|
25
|
+
const res = {
|
|
26
|
+
errMsg: 'getNetworkType:ok',
|
|
27
|
+
networkType: getTypeFromState(connectionInfo),
|
|
28
|
+
};
|
|
12
29
|
success === null || success === void 0 ? void 0 : success(res);
|
|
13
30
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
14
31
|
resolve(res);
|
|
15
32
|
}).catch((err) => {
|
|
16
|
-
res
|
|
33
|
+
const res = {
|
|
34
|
+
errMsg: err.message
|
|
35
|
+
};
|
|
17
36
|
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
18
37
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
19
38
|
reject(err);
|
|
@@ -25,8 +44,8 @@ export function onNetworkStatusChange(fnc) {
|
|
|
25
44
|
if (!_unsubscribe) {
|
|
26
45
|
_unsubscribe = NetInfo.addEventListener((connectionInfo) => {
|
|
27
46
|
_callbacks.forEach(cb => {
|
|
28
|
-
const {
|
|
29
|
-
cb === null || cb === void 0 ? void 0 : cb({ isConnected, networkType:
|
|
47
|
+
const { isConnected } = connectionInfo;
|
|
48
|
+
cb === null || cb === void 0 ? void 0 : cb({ isConnected, networkType: getTypeFromState(connectionInfo) });
|
|
30
49
|
});
|
|
31
50
|
});
|
|
32
51
|
}
|
package/dist/lib/network.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/lib/network.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,iCAAiC,CAAA;
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/lib/network.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,gBAAgB,EAAgB,MAAM,iCAAiC,CAAA;AAEzF,IAAI,YAAY,GAAQ,IAAI,CAAA;AAE5B,IAAI,UAAU,GAAkB,IAAI,GAAG,EAAE,CAAA;AAEzC,SAAS,gBAAgB,CAAC,cAA2B;IACnD,IAAI,IAA2C,CAAA;IAC/C,IAAG,cAAc,CAAC,IAAI,KAAK,gBAAgB,CAAC,IAAI,EAAE;QAChD,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAA;KAC7B;SAAM,IAAG,cAAc,CAAC,IAAI,KAAK,gBAAgB,CAAC,QAAQ,IAAI,cAAc,CAAC,OAAO,CAAC,kBAAkB,EAAE;QACxG,IAAI,GAAG,cAAc,CAAC,OA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AAgB,CAAC,CAAC,cAAc,EAAE,EAAE;YACzD,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;gBACtB,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,CAAA;gBACtC,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAG,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,CAAC,CAAA;YACtE,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;KACH;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,GAAyC;IAC9E,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;QACpC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;KACvB;SAAM,IAAI,GAAG,KAAK,SAAS,EAAE;QAC5B,UAAU,CAAC,KAAK,EAAE,CAAA;QAClB,YAAY,aAAZ,YAAY,uBAAZ,YAAY,EAAI,CAAA;QAChB,YAAY,GAAG,IAAI,CAAA;KACpB;SAAM;QACL,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAA;KAC9C;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/taro-rn",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0-canary.0",
|
|
4
4
|
"description": "Taro RN framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "types/index.d.ts",
|
|
@@ -32,38 +32,37 @@
|
|
|
32
32
|
"author": "O2Team",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@react-native-async-storage/async-storage": "
|
|
36
|
-
"@react-native-community/cameraroll": "
|
|
37
|
-
"@react-native-community/clipboard": "
|
|
38
|
-
"@react-native-community/geolocation": "
|
|
39
|
-
"@react-native-community/netinfo": "
|
|
40
|
-
"@tarojs/runtime-rn": "3.
|
|
41
|
-
"babel-preset-expo": "
|
|
35
|
+
"@react-native-async-storage/async-storage": "~1.15.11",
|
|
36
|
+
"@react-native-community/cameraroll": "~4.1.2",
|
|
37
|
+
"@react-native-community/clipboard": "~1.5.1",
|
|
38
|
+
"@react-native-community/geolocation": "~2.0.2",
|
|
39
|
+
"@react-native-community/netinfo": "~7.1.2",
|
|
40
|
+
"@tarojs/runtime-rn": "3.5.0-canary.0",
|
|
41
|
+
"babel-preset-expo": "~8.5.1",
|
|
42
42
|
"base64-js": "^1.3.0",
|
|
43
43
|
"expo-av": "~9.2.3",
|
|
44
44
|
"expo-barcode-scanner": "~10.2.2",
|
|
45
|
-
"expo-brightness": "
|
|
45
|
+
"expo-brightness": "~9.2.2",
|
|
46
46
|
"expo-camera": "~11.2.2",
|
|
47
47
|
"expo-file-system": "~11.1.3",
|
|
48
48
|
"expo-image-picker": "~10.2.3",
|
|
49
49
|
"expo-keep-awake": "~9.2.0",
|
|
50
|
-
"expo-location": "^12.1.2",
|
|
51
50
|
"expo-permissions": "~12.1.1",
|
|
52
|
-
"expo-sensors": "
|
|
51
|
+
"expo-sensors": "~10.2.2",
|
|
53
52
|
"nullthrows": "^1.1.1",
|
|
54
|
-
"react-native-device-info": "
|
|
55
|
-
"react-native-image-resizer": "
|
|
53
|
+
"react-native-device-info": "~8.4.8",
|
|
54
|
+
"react-native-image-resizer": "~1.4.5",
|
|
56
55
|
"react-native-image-zoom-viewer": "^3.0.1",
|
|
57
56
|
"react-native-root-siblings": "^3.1.0",
|
|
58
57
|
"react-native-root-toast": "^3.0.1",
|
|
59
|
-
"react-native-safe-area-context": "
|
|
58
|
+
"react-native-safe-area-context": "~3.3.2",
|
|
60
59
|
"react-native-stylekit": "^1.0.0",
|
|
61
60
|
"react-native-syan-image-picker": "0.4.10",
|
|
62
|
-
"react-native-unimodules": "
|
|
61
|
+
"react-native-unimodules": "~0.14.10"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"@tarojs/taro": "3.
|
|
66
|
-
"@types/react-native": "0.
|
|
64
|
+
"@tarojs/taro": "3.5.0-canary.0",
|
|
65
|
+
"@types/react-native": "0.66.5",
|
|
67
66
|
"babel-plugin-jest-hoist": "^26.6.2",
|
|
68
67
|
"cpy-cli": "^3.1.1",
|
|
69
68
|
"jest-expo": "^39.0.0",
|
|
@@ -72,30 +71,29 @@
|
|
|
72
71
|
"rimraf": "^3.0.0"
|
|
73
72
|
},
|
|
74
73
|
"peerDependencies": {
|
|
75
|
-
"@react-native-async-storage/async-storage": "
|
|
76
|
-
"@react-native-community/cameraroll": "
|
|
77
|
-
"@react-native-community/clipboard": "
|
|
78
|
-
"@react-native-community/geolocation": "
|
|
79
|
-
"@react-native-community/netinfo": "
|
|
74
|
+
"@react-native-async-storage/async-storage": "~1.15.11",
|
|
75
|
+
"@react-native-community/cameraroll": "~4.1.2",
|
|
76
|
+
"@react-native-community/clipboard": "~1.5.1",
|
|
77
|
+
"@react-native-community/geolocation": "~2.0.2",
|
|
78
|
+
"@react-native-community/netinfo": "~7.1.2",
|
|
80
79
|
"expo-av": "~9.2.3",
|
|
81
80
|
"expo-barcode-scanner": "~10.2.2",
|
|
82
|
-
"expo-brightness": "
|
|
81
|
+
"expo-brightness": "~9.2.2",
|
|
83
82
|
"expo-camera": "~11.2.2",
|
|
84
83
|
"expo-file-system": "~11.1.3",
|
|
85
84
|
"expo-image-picker": "~10.2.3",
|
|
86
85
|
"expo-keep-awake": "~9.2.0",
|
|
87
|
-
"expo-location": "^12.1.2",
|
|
88
86
|
"expo-permissions": "~12.1.1",
|
|
89
|
-
"expo-sensors": "
|
|
90
|
-
"react-native-device-info": "
|
|
91
|
-
"react-native-image-resizer": "
|
|
92
|
-
"react-native-safe-area-context": "
|
|
87
|
+
"expo-sensors": "~10.2.2",
|
|
88
|
+
"react-native-device-info": "~8.4.8",
|
|
89
|
+
"react-native-image-resizer": "~1.4.5",
|
|
90
|
+
"react-native-safe-area-context": "~3.3.2",
|
|
93
91
|
"react-native-syan-image-picker": "0.4.10",
|
|
94
|
-
"react-native-unimodules": "
|
|
92
|
+
"react-native-unimodules": "~0.14.10"
|
|
95
93
|
},
|
|
96
94
|
"resolutions": {
|
|
97
95
|
"@types/react": "17.0.11",
|
|
98
96
|
"@types/node": "^14.14.41"
|
|
99
97
|
},
|
|
100
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "a0222bc41bc05b0e34413d6db3de963d777a5015"
|
|
101
99
|
}
|
package/src/lib/network.ts
CHANGED
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
import NetInfo from '@react-native-community/netinfo'
|
|
1
|
+
import NetInfo, { NetInfoStateType, NetInfoState } from '@react-native-community/netinfo'
|
|
2
2
|
|
|
3
3
|
let _unsubscribe: any = null
|
|
4
4
|
|
|
5
5
|
let _callbacks: Set<Function> = new Set()
|
|
6
6
|
|
|
7
|
+
function getTypeFromState(connectionInfo:NetInfoState): keyof Taro.getNetworkType.networkType {
|
|
8
|
+
let type: keyof Taro.getNetworkType.networkType
|
|
9
|
+
if(connectionInfo.type === NetInfoStateType.wifi) {
|
|
10
|
+
type = NetInfoStateType.wifi
|
|
11
|
+
} else if(connectionInfo.type === NetInfoStateType.cellular && connectionInfo.details.cellularGeneration) {
|
|
12
|
+
type = connectionInfo.details.cellularGeneration
|
|
13
|
+
} else if(connectionInfo.type === NetInfoStateType.none) {
|
|
14
|
+
type = 'none'
|
|
15
|
+
} else {
|
|
16
|
+
type = 'unknown'
|
|
17
|
+
}
|
|
18
|
+
return type
|
|
19
|
+
}
|
|
20
|
+
|
|
7
21
|
export function getNetworkType(opts: Taro.getNetworkType.Option = {}): Promise<Taro.getNetworkType.SuccessCallbackResult> {
|
|
8
22
|
const { success, fail, complete } = opts
|
|
9
|
-
const res: any = {}
|
|
10
23
|
|
|
11
24
|
return new Promise((resolve, reject) => {
|
|
12
25
|
NetInfo.fetch()
|
|
13
26
|
.then((connectionInfo) => {
|
|
14
|
-
res.
|
|
15
|
-
|
|
27
|
+
const res: Taro.getNetworkType.SuccessCallbackResult = {
|
|
28
|
+
errMsg: 'getNetworkType:ok',
|
|
29
|
+
networkType: getTypeFromState(connectionInfo),
|
|
30
|
+
}
|
|
16
31
|
success?.(res)
|
|
17
32
|
complete?.(res)
|
|
18
33
|
|
|
19
34
|
resolve(res)
|
|
20
35
|
}).catch((err) => {
|
|
21
|
-
res.
|
|
36
|
+
const res: TaroGeneral.CallbackResult = {
|
|
37
|
+
errMsg: err.message
|
|
38
|
+
}
|
|
22
39
|
fail?.(res)
|
|
23
40
|
complete?.(res)
|
|
24
41
|
|
|
@@ -32,8 +49,8 @@ export function onNetworkStatusChange(fnc: Taro.onNetworkStatusChange.Callback):
|
|
|
32
49
|
if (!_unsubscribe) {
|
|
33
50
|
_unsubscribe = NetInfo.addEventListener((connectionInfo) => {
|
|
34
51
|
_callbacks.forEach(cb => {
|
|
35
|
-
const {
|
|
36
|
-
cb?.({ isConnected, networkType:
|
|
52
|
+
const { isConnected } = connectionInfo
|
|
53
|
+
cb?.({ isConnected, networkType: getTypeFromState(connectionInfo) })
|
|
37
54
|
})
|
|
38
55
|
})
|
|
39
56
|
}
|