@mpxjs/api-proxy 2.9.18 → 2.9.19-react.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/package.json +9 -2
- package/src/common/js/utils.js +22 -1
- package/src/platform/api/base/index.android.js +1 -0
- package/src/platform/api/base/index.ios.js +1 -0
- package/src/platform/api/clipboard-data/index.android.js +1 -0
- package/src/platform/api/clipboard-data/index.ios.js +1 -0
- package/src/platform/api/clipboard-data/rnClipboard.js +41 -0
- package/src/platform/api/device/network/index.android.js +1 -0
- package/src/platform/api/device/network/index.ios.js +1 -0
- package/src/platform/api/device/network/rnNetwork.js +59 -0
- package/src/platform/api/make-phone-call/index.andriod.js +1 -0
- package/src/platform/api/make-phone-call/index.ios.js +1 -0
- package/src/platform/api/make-phone-call/rnMakePhone.js +27 -0
- package/src/platform/api/request/index.android.js +1 -0
- package/src/platform/api/request/index.ios.js +1 -0
- package/src/platform/api/request/index.web.js +2 -1
- package/src/platform/api/socket/SocketTask.js +15 -5
- package/src/platform/api/socket/index.andriod.js +1 -0
- package/src/platform/api/socket/index.ios.js +1 -0
- package/src/platform/api/storage/index.android.js +1 -0
- package/src/platform/api/storage/index.ios.js +1 -0
- package/src/platform/api/storage/rnStorage.js +139 -0
- package/src/platform/api/system/index.ali.js +9 -3
- package/src/platform/api/system/index.android.js +1 -0
- package/src/platform/api/system/index.ios.js +1 -0
- package/src/platform/api/system/index.js +7 -1
- package/src/platform/api/system/index.web.js +8 -2
- package/src/platform/api/system/rnSystem.js +118 -0
- package/src/platform/api/window/index.android.js +1 -0
- package/src/platform/api/window/index.ios.js +1 -0
- package/src/platform/api/window/rnWindow.js +44 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.19-react.0",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -39,5 +39,12 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"axios": "^1.6.7"
|
|
41
41
|
},
|
|
42
|
-
"
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@react-native-async-storage/async-storage": "^1.23.1",
|
|
44
|
+
"@react-native-clipboard/clipboard": "^1.14.0",
|
|
45
|
+
"@react-native-community/netinfo": "^11.2.1",
|
|
46
|
+
"react-native-device-info": "^10.13.2",
|
|
47
|
+
"react-native-safe-area-context": "^4.10.1"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "a09ab1b994eaf20b1772491709580fe75499e688"
|
|
43
50
|
}
|
package/src/common/js/utils.js
CHANGED
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
*/
|
|
15
15
|
const hasOwnProperty = Object.prototype.hasOwnProperty
|
|
16
16
|
|
|
17
|
+
function type (n) {
|
|
18
|
+
return Object.prototype.toString.call(n).slice(8, -1)
|
|
19
|
+
}
|
|
20
|
+
|
|
17
21
|
function hasOwn (obj, key) {
|
|
18
22
|
return hasOwnProperty.call(obj, key)
|
|
19
23
|
}
|
|
@@ -68,6 +72,8 @@ function getEnvObj () {
|
|
|
68
72
|
case 'dd':
|
|
69
73
|
return dd
|
|
70
74
|
case 'web':
|
|
75
|
+
case 'ios':
|
|
76
|
+
case 'android':
|
|
71
77
|
return {}
|
|
72
78
|
}
|
|
73
79
|
}
|
|
@@ -95,6 +101,19 @@ function makeMap (arr) {
|
|
|
95
101
|
}, {})
|
|
96
102
|
}
|
|
97
103
|
|
|
104
|
+
function defineUnsupportedProps (resObj, props) {
|
|
105
|
+
const defineProps = {}
|
|
106
|
+
props.forEach((item) => {
|
|
107
|
+
defineProps[item] = {
|
|
108
|
+
get () {
|
|
109
|
+
warn(`The ${item} attribute is not supported in ${__mpx_mode__} environment`)
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
Object.defineProperties(resObj, defineProps)
|
|
115
|
+
}
|
|
116
|
+
|
|
98
117
|
const isBrowser = typeof window !== 'undefined'
|
|
99
118
|
|
|
100
119
|
function throwSSRWarning (info) {
|
|
@@ -111,5 +130,7 @@ export {
|
|
|
111
130
|
makeMap,
|
|
112
131
|
isBrowser,
|
|
113
132
|
hasOwn,
|
|
114
|
-
throwSSRWarning
|
|
133
|
+
throwSSRWarning,
|
|
134
|
+
type,
|
|
135
|
+
defineUnsupportedProps
|
|
115
136
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnClipboard'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnClipboard'
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Clipboard from '@react-native-clipboard/clipboard'
|
|
2
|
+
import { webHandleSuccess, webHandleFail } from '../../../common/js/web'
|
|
3
|
+
import { type } from '@mpxjs/utils'
|
|
4
|
+
const setClipboardData = function (options) {
|
|
5
|
+
const { data, success, fail, complete } = options
|
|
6
|
+
if (!data || type(data) !== 'String') {
|
|
7
|
+
const errStr = !data ? 'parameter.data should be String instead of Undefined;' : `parameter.data should be String instead of ${type(data)};`
|
|
8
|
+
const result = {
|
|
9
|
+
errno: 1001,
|
|
10
|
+
errMsg: errStr
|
|
11
|
+
}
|
|
12
|
+
webHandleFail(result, fail, complete)
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
Clipboard.setString(data)
|
|
16
|
+
const result = {
|
|
17
|
+
errMsg: 'setClipboardData:ok'
|
|
18
|
+
}
|
|
19
|
+
webHandleSuccess(result, success, complete)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const getClipboardData = function (options) {
|
|
23
|
+
const { success, fail, complete } = options
|
|
24
|
+
Clipboard.getString().then((data) => {
|
|
25
|
+
const result = {
|
|
26
|
+
data,
|
|
27
|
+
errMsg: 'getClipboardData:ok'
|
|
28
|
+
}
|
|
29
|
+
webHandleSuccess(result, success, complete)
|
|
30
|
+
}).catch(() => {
|
|
31
|
+
const result = {
|
|
32
|
+
errMsg: 'setClipboardData:fail'
|
|
33
|
+
}
|
|
34
|
+
webHandleFail(result, fail, complete)
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
setClipboardData,
|
|
40
|
+
getClipboardData
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnNetwork'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnNetwork'
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../../common/js'
|
|
2
|
+
import NetInfo, { NetInfoStateType } from '@react-native-community/netinfo'
|
|
3
|
+
|
|
4
|
+
let _unsubscribe = null
|
|
5
|
+
const _callbacks = new Set()
|
|
6
|
+
const getConnectionType = function (connectionInfo) {
|
|
7
|
+
let type = 'unknown'
|
|
8
|
+
if (connectionInfo.type === NetInfoStateType.cellular && connectionInfo.details.cellularGeneration) {
|
|
9
|
+
type = connectionInfo.details.cellularGeneration
|
|
10
|
+
} else if (connectionInfo.type === NetInfoStateType.wifi || connectionInfo.type === NetInfoStateType.none) {
|
|
11
|
+
type = connectionInfo.type
|
|
12
|
+
}
|
|
13
|
+
return type
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const getNetworkType = function (options) {
|
|
17
|
+
const { success, fail, complete } = options
|
|
18
|
+
NetInfo.fetch().then((connectionInfo) => {
|
|
19
|
+
const result = {
|
|
20
|
+
networkType: getConnectionType(connectionInfo),
|
|
21
|
+
errMsg: 'getNetworkType:ok'
|
|
22
|
+
}
|
|
23
|
+
defineUnsupportedProps(result, ['signalStrength', 'hasSystemProxy'])
|
|
24
|
+
webHandleSuccess(result, success, complete)
|
|
25
|
+
}).catch((err) => {
|
|
26
|
+
const result = {
|
|
27
|
+
errMsg: err.message
|
|
28
|
+
}
|
|
29
|
+
webHandleFail(result, fail, complete)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const onNetworkStatusChange = function (callback) {
|
|
34
|
+
_callbacks.add(callback)
|
|
35
|
+
if (!_unsubscribe) {
|
|
36
|
+
_unsubscribe = NetInfo.addEventListener((connectionInfo) => {
|
|
37
|
+
_callbacks.forEach(cb => {
|
|
38
|
+
const { isConnected } = connectionInfo
|
|
39
|
+
// eslint-disable-next-line node/no-callback-literal
|
|
40
|
+
cb && cb({ isConnected, networkType: getConnectionType(connectionInfo) })
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const offNetworkStatusChange = function (callback) {
|
|
46
|
+
if (callback && typeof callback === 'function') {
|
|
47
|
+
_callbacks.delete(callback)
|
|
48
|
+
} else if (callback === undefined) {
|
|
49
|
+
_callbacks.clear()
|
|
50
|
+
_unsubscribe && _unsubscribe()
|
|
51
|
+
_unsubscribe = null
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
getNetworkType,
|
|
57
|
+
offNetworkStatusChange,
|
|
58
|
+
onNetworkStatusChange
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnMakePhone'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnMakePhone'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
2
|
+
import { Linking } from 'react-native'
|
|
3
|
+
|
|
4
|
+
const makePhoneCall = function (options) {
|
|
5
|
+
const {
|
|
6
|
+
phoneNumber = '',
|
|
7
|
+
success = null,
|
|
8
|
+
fail = null,
|
|
9
|
+
complete = null
|
|
10
|
+
} = options
|
|
11
|
+
|
|
12
|
+
Linking.openURL(`tel:${phoneNumber}`).then(() => {
|
|
13
|
+
const result = {
|
|
14
|
+
errMsg: 'makePhoneCall:ok'
|
|
15
|
+
}
|
|
16
|
+
webHandleSuccess(result, success, complete)
|
|
17
|
+
}).catch(() => {
|
|
18
|
+
const result = {
|
|
19
|
+
errMsg: 'makePhoneCall:fail cancel'
|
|
20
|
+
}
|
|
21
|
+
webHandleFail(result, fail, complete)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
makePhoneCall
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
|
-
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
2
|
+
import { webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../common/js'
|
|
3
3
|
import RequestTask from './RequestTask'
|
|
4
4
|
|
|
5
5
|
function request (options = { url: '' }) {
|
|
@@ -69,6 +69,7 @@ function request (options = { url: '' }) {
|
|
|
69
69
|
statusCode: res.status,
|
|
70
70
|
header: res.headers
|
|
71
71
|
}
|
|
72
|
+
defineUnsupportedProps(result, ['cookies', 'profile', 'exception'])
|
|
72
73
|
webHandleSuccess(result, success, complete)
|
|
73
74
|
return result
|
|
74
75
|
}).catch(err => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
1
|
+
import { webHandleSuccess, webHandleFail, type } from '../../../common/js'
|
|
2
2
|
|
|
3
3
|
const socketTasks = new Set()
|
|
4
4
|
|
|
@@ -41,7 +41,11 @@ class SocketTask {
|
|
|
41
41
|
|
|
42
42
|
send (options) {
|
|
43
43
|
const { data = '', success, fail, complete } = options
|
|
44
|
-
|
|
44
|
+
if (typeof data !== 'string' || type(data) !== 'ArrayBuffer') {
|
|
45
|
+
const res = { errMsg: 'sendSocketMessage:fail Unsupported data type' }
|
|
46
|
+
webHandleFail(res, fail, complete)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
45
49
|
if (this._socket.readyState === 1) {
|
|
46
50
|
this._socket.send(data)
|
|
47
51
|
const res = { errMsg: 'sendSocketMessage:ok' }
|
|
@@ -77,8 +81,14 @@ class SocketTask {
|
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
addListener (socket) {
|
|
80
|
-
socket.
|
|
81
|
-
|
|
84
|
+
socket.onopen = event => {
|
|
85
|
+
typeof this._openCb === 'function' && this._openCb(event)
|
|
86
|
+
}
|
|
87
|
+
socket.onmessage = event => {
|
|
88
|
+
typeof this._messageCb === 'function' && this._messageCb({
|
|
89
|
+
data: event.data
|
|
90
|
+
})
|
|
91
|
+
}
|
|
82
92
|
socket.onerror = event => {
|
|
83
93
|
socketTasks.delete(this._socket)
|
|
84
94
|
typeof this._errorCb === 'function' && this._errorCb(event)
|
|
@@ -91,7 +101,7 @@ class SocketTask {
|
|
|
91
101
|
if (this._closeData) {
|
|
92
102
|
this._closeCb(event)
|
|
93
103
|
} else {
|
|
94
|
-
this._closeCb({ code:
|
|
104
|
+
this._closeCb({ code: event.code, reason: event.reason })
|
|
95
105
|
}
|
|
96
106
|
}
|
|
97
107
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.web'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnStorage'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnStorage'
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
import { envError, webHandleSuccess, webHandleFail, hasOwn, defineUnsupportedProps } from '../../../common/js'
|
|
3
|
+
import { loop } from '@mpxjs/utils'
|
|
4
|
+
function setStorage (options) {
|
|
5
|
+
const { key, data, success, fail, complete } = options
|
|
6
|
+
let obj = {}
|
|
7
|
+
if (typeof data === 'symbol') {
|
|
8
|
+
obj = { data: '' }
|
|
9
|
+
} else {
|
|
10
|
+
obj = { data }
|
|
11
|
+
}
|
|
12
|
+
AsyncStorage.setItem(key, JSON.stringify(obj), (err) => {
|
|
13
|
+
if (err) {
|
|
14
|
+
const result = {
|
|
15
|
+
errMsg: `setStorage:fail ${err}`
|
|
16
|
+
}
|
|
17
|
+
webHandleFail(result, fail, complete)
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
const result = {
|
|
21
|
+
errMsg: 'setStorage:ok'
|
|
22
|
+
}
|
|
23
|
+
webHandleSuccess(result, success, complete)
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const setStorageSync = envError('setStorageSync')
|
|
28
|
+
|
|
29
|
+
function getStorage (options) {
|
|
30
|
+
const { key, success, fail, complete } = options
|
|
31
|
+
if (!key) {
|
|
32
|
+
const result = {
|
|
33
|
+
errMsg: 'getStorage:fail parameter error: parameter.key should be String instead of Undefined;'
|
|
34
|
+
}
|
|
35
|
+
webHandleFail(result, fail, complete)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
AsyncStorage.getItem(key, (err, res) => {
|
|
39
|
+
if (err || !res) {
|
|
40
|
+
const result = {
|
|
41
|
+
errMsg: `getStorage:fail ${err || 'data not found'}`
|
|
42
|
+
}
|
|
43
|
+
webHandleFail(result, fail, complete)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
let item
|
|
47
|
+
let data = null
|
|
48
|
+
try {
|
|
49
|
+
item = JSON.parse(res)
|
|
50
|
+
} catch (e) {
|
|
51
|
+
}
|
|
52
|
+
if (item && typeof item === 'object' && hasOwn(item, 'data')) {
|
|
53
|
+
data = item.data
|
|
54
|
+
}
|
|
55
|
+
const result = {
|
|
56
|
+
errMsg: 'getStorage:ok',
|
|
57
|
+
data
|
|
58
|
+
}
|
|
59
|
+
webHandleSuccess(result, success, complete)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const getStorageSync = envError('getStorageSync')
|
|
64
|
+
|
|
65
|
+
function getStorageInfo (options) {
|
|
66
|
+
const { success, fail, complete } = options
|
|
67
|
+
AsyncStorage.getAllKeys((err, keys) => {
|
|
68
|
+
if (err) {
|
|
69
|
+
const result = {
|
|
70
|
+
errMsg: `getStorage:fail ${err}`
|
|
71
|
+
}
|
|
72
|
+
webHandleFail(result, fail, complete)
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
const result = {
|
|
76
|
+
keys,
|
|
77
|
+
errMsg: 'getStorageInfo:ok'
|
|
78
|
+
}
|
|
79
|
+
defineUnsupportedProps(result, ['currentSize', 'limitSize'])
|
|
80
|
+
webHandleSuccess(result, success, complete)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const getStorageInfoSync = envError('getStorageInfoSync')
|
|
85
|
+
|
|
86
|
+
function removeStorage (options) {
|
|
87
|
+
const { key, success, fail, complete } = options
|
|
88
|
+
AsyncStorage.removeItem(key, (err) => {
|
|
89
|
+
if (err) {
|
|
90
|
+
const result = {
|
|
91
|
+
errMsg: `removeStorage:fail ${err}`
|
|
92
|
+
}
|
|
93
|
+
webHandleFail(result, fail, complete)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
const result = {
|
|
97
|
+
errMsg: 'removeStorage:ok'
|
|
98
|
+
}
|
|
99
|
+
webHandleSuccess(result, success, complete)
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function removeStorageSync (key) {
|
|
104
|
+
AsyncStorage.removeItem([key], loop)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function clearStorage (options) {
|
|
108
|
+
const { success, fail, complete } = options
|
|
109
|
+
AsyncStorage.clear((err) => {
|
|
110
|
+
if (err) {
|
|
111
|
+
const result = {
|
|
112
|
+
errMsg: `clearStorage:fail ${err}`
|
|
113
|
+
}
|
|
114
|
+
webHandleFail(result, fail, complete)
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
const result = {
|
|
118
|
+
errMsg: 'clearStorage:ok'
|
|
119
|
+
}
|
|
120
|
+
webHandleSuccess(result, success, complete)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function clearStorageSync () {
|
|
125
|
+
AsyncStorage.clear(loop)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
setStorage,
|
|
130
|
+
setStorageSync,
|
|
131
|
+
getStorage,
|
|
132
|
+
getStorageSync,
|
|
133
|
+
getStorageInfo,
|
|
134
|
+
getStorageInfoSync,
|
|
135
|
+
removeStorage,
|
|
136
|
+
removeStorageSync,
|
|
137
|
+
clearStorage,
|
|
138
|
+
clearStorageSync
|
|
139
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { changeOpts, handleSuccess } from '../../../common/js'
|
|
2
|
-
|
|
1
|
+
import { changeOpts, envError, handleSuccess, getEnvObj } from '../../../common/js'
|
|
2
|
+
const ENV_OBJ = getEnvObj()
|
|
3
3
|
function getSystemInfo (options = {}) {
|
|
4
4
|
const opts = changeOpts(options)
|
|
5
5
|
|
|
@@ -32,7 +32,13 @@ function getSystemInfoSync () {
|
|
|
32
32
|
return res
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const getDeviceInfo = ENV_OBJ.getDeviceInfo || envError('getDeviceInfo')
|
|
36
|
+
|
|
37
|
+
const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
|
|
38
|
+
|
|
35
39
|
export {
|
|
36
40
|
getSystemInfo,
|
|
37
|
-
getSystemInfoSync
|
|
41
|
+
getSystemInfoSync,
|
|
42
|
+
getDeviceInfo,
|
|
43
|
+
getWindowInfo
|
|
38
44
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnSystem'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnSystem'
|
|
@@ -6,7 +6,13 @@ const getSystemInfo = ENV_OBJ.getSystemInfo || envError('getSystemInfo')
|
|
|
6
6
|
|
|
7
7
|
const getSystemInfoSync = ENV_OBJ.getSystemInfoSync || envError('getSystemInfoSync')
|
|
8
8
|
|
|
9
|
+
const getDeviceInfo = ENV_OBJ.getDeviceInfo || envError('getDeviceInfo')
|
|
10
|
+
|
|
11
|
+
const getWindowInfo = ENV_OBJ.getWindowInfo || envError('getWindowInfo')
|
|
12
|
+
|
|
9
13
|
export {
|
|
10
14
|
getSystemInfo,
|
|
11
|
-
getSystemInfoSync
|
|
15
|
+
getSystemInfoSync,
|
|
16
|
+
getDeviceInfo,
|
|
17
|
+
getWindowInfo
|
|
12
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBrowser, throwSSRWarning, webHandleSuccess } from '../../../common/js'
|
|
1
|
+
import { envError, isBrowser, throwSSRWarning, webHandleSuccess } from '../../../common/js'
|
|
2
2
|
|
|
3
3
|
function getSystemInfoSync () {
|
|
4
4
|
if (!isBrowser) {
|
|
@@ -79,7 +79,13 @@ function getSystemInfo (options = {}) {
|
|
|
79
79
|
webHandleSuccess(res, options.success, options.complete)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
const getDeviceInfo = envError('getDeviceInfo')
|
|
83
|
+
|
|
84
|
+
const getWindowInfo = envError('getWindowInfo')
|
|
85
|
+
|
|
82
86
|
export {
|
|
83
87
|
getSystemInfo,
|
|
84
|
-
getSystemInfoSync
|
|
88
|
+
getSystemInfoSync,
|
|
89
|
+
getDeviceInfo,
|
|
90
|
+
getWindowInfo
|
|
85
91
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import DeviceInfo from 'react-native-device-info'
|
|
2
|
+
import { Platform, PixelRatio, Dimensions, StatusBar } from 'react-native'
|
|
3
|
+
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
4
|
+
import { webHandleSuccess, webHandleFail, defineUnsupportedProps } from '../../../common/js'
|
|
5
|
+
|
|
6
|
+
const getWindowInfo = function () {
|
|
7
|
+
const dimensionsWindow = Dimensions.get('window')
|
|
8
|
+
const dimensionsScreen = Dimensions.get('screen')
|
|
9
|
+
const result = {
|
|
10
|
+
pixelRatio: PixelRatio.get(),
|
|
11
|
+
windowWidth: dimensionsWindow.width,
|
|
12
|
+
windowHeight: dimensionsWindow.height,
|
|
13
|
+
screenWidth: dimensionsScreen.width,
|
|
14
|
+
screenHeight: dimensionsScreen.height
|
|
15
|
+
}
|
|
16
|
+
defineUnsupportedProps(result, ['screenTop'])
|
|
17
|
+
return result
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getSystemInfoSync = function () {
|
|
21
|
+
const windowInfo = getWindowInfo()
|
|
22
|
+
const { screenWidth, screenHeight } = windowInfo
|
|
23
|
+
let safeArea = {}
|
|
24
|
+
let { top = 0, bottom = 0 } = initialWindowMetrics?.insets || {}
|
|
25
|
+
if (Platform.OS === 'android') {
|
|
26
|
+
top = StatusBar.currentHeight || 0
|
|
27
|
+
}
|
|
28
|
+
const iosRes = {}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const width = Math.min(screenWidth, screenHeight)
|
|
32
|
+
const height = Math.max(screenWidth, screenHeight)
|
|
33
|
+
safeArea = {
|
|
34
|
+
left: 0,
|
|
35
|
+
right: width,
|
|
36
|
+
top,
|
|
37
|
+
bottom: height - bottom,
|
|
38
|
+
height: height - bottom - top,
|
|
39
|
+
width
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
}
|
|
43
|
+
const result = {
|
|
44
|
+
brand: DeviceInfo.getBrand(),
|
|
45
|
+
model: DeviceInfo.getModel(),
|
|
46
|
+
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
|
|
47
|
+
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
|
|
48
|
+
deviceOrientation: screenWidth > screenHeight ? 'portrait' : 'landscape',
|
|
49
|
+
statusBarHeight: top,
|
|
50
|
+
fontSizeSetting: PixelRatio.getFontScale(),
|
|
51
|
+
safeArea,
|
|
52
|
+
...windowInfo,
|
|
53
|
+
...iosRes
|
|
54
|
+
}
|
|
55
|
+
defineUnsupportedProps(result, [
|
|
56
|
+
'language',
|
|
57
|
+
'version',
|
|
58
|
+
'SDKVersion',
|
|
59
|
+
'benchmarkLevel',
|
|
60
|
+
'albumAuthorized',
|
|
61
|
+
'cameraAuthorized',
|
|
62
|
+
'locationAuthorized',
|
|
63
|
+
'microphoneAuthorized',
|
|
64
|
+
'notificationAuthorized',
|
|
65
|
+
'phoneCalendarAuthorized',
|
|
66
|
+
'host',
|
|
67
|
+
'enableDebug',
|
|
68
|
+
'notificationAlertAuthorized',
|
|
69
|
+
'notificationBadgeAuthorized',
|
|
70
|
+
'notificationSoundAuthorized',
|
|
71
|
+
'bluetoothEnabled',
|
|
72
|
+
'locationEnabled',
|
|
73
|
+
'wifiEnabled',
|
|
74
|
+
'locationReducedAccuracy',
|
|
75
|
+
'theme'
|
|
76
|
+
])
|
|
77
|
+
return result
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const getSystemInfo = function (options) {
|
|
81
|
+
const { success, fail, complete } = options
|
|
82
|
+
try {
|
|
83
|
+
const systemInfo = getSystemInfoSync()
|
|
84
|
+
Object.assign(systemInfo, {
|
|
85
|
+
errMsg: 'setStorage:ok'
|
|
86
|
+
})
|
|
87
|
+
webHandleSuccess(systemInfo, success, complete)
|
|
88
|
+
} catch (err) {
|
|
89
|
+
const result = {
|
|
90
|
+
errMsg: `getSystemInfo:fail ${err}`
|
|
91
|
+
}
|
|
92
|
+
webHandleFail(result, fail, complete)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const getDeviceInfo = function () {
|
|
97
|
+
const deviceInfo = {}
|
|
98
|
+
if (Platform.OS === 'android') {
|
|
99
|
+
const deviceAbi = DeviceInfo.supported64BitAbisSync() || []
|
|
100
|
+
deviceInfo.deviceAbi = deviceAbi[0] || null
|
|
101
|
+
}
|
|
102
|
+
defineUnsupportedProps(deviceInfo, ['benchmarkLevel', 'abi', 'cpuType'])
|
|
103
|
+
Object.assign(deviceInfo, {
|
|
104
|
+
brand: DeviceInfo.getBrand(),
|
|
105
|
+
model: DeviceInfo.getModel(),
|
|
106
|
+
system: `${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()}`,
|
|
107
|
+
platform: DeviceInfo.isEmulatorSync() ? 'emulator' : DeviceInfo.getSystemName(),
|
|
108
|
+
memorySize: DeviceInfo.getTotalMemorySync() / (1024 * 1024)
|
|
109
|
+
})
|
|
110
|
+
return deviceInfo
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
getSystemInfo,
|
|
115
|
+
getSystemInfoSync,
|
|
116
|
+
getDeviceInfo,
|
|
117
|
+
getWindowInfo
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnWindow'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rnWindow'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Dimensions } from 'react-native'
|
|
2
|
+
|
|
3
|
+
const callbacks = []
|
|
4
|
+
let subscription
|
|
5
|
+
const addListener = function () {
|
|
6
|
+
subscription = Dimensions.addEventListener(
|
|
7
|
+
'change',
|
|
8
|
+
({ window }) => {
|
|
9
|
+
const result = {
|
|
10
|
+
size: {
|
|
11
|
+
windowWidth: window.width,
|
|
12
|
+
windowHeight: window.height
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
callbacks.forEach(cb => cb(result))
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const removeListener = function () {
|
|
21
|
+
subscription && subscription.remove()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function onWindowResize (callback) {
|
|
25
|
+
if (callbacks.length === 0) {
|
|
26
|
+
addListener()
|
|
27
|
+
}
|
|
28
|
+
callbacks.push(callback)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function offWindowResize (callback) {
|
|
32
|
+
const index = callbacks.indexOf(callback)
|
|
33
|
+
if (index > -1) {
|
|
34
|
+
callbacks.splice(index, 1)
|
|
35
|
+
}
|
|
36
|
+
if (callbacks.length === 0) {
|
|
37
|
+
removeListener()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
onWindowResize,
|
|
43
|
+
offWindowResize
|
|
44
|
+
}
|