@tarojs/taro-rn 4.0.1-alpha.0 → 4.0.1
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/LICENSE +8 -8
- package/apiList.js +31 -31
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/lib/Mask.js +2 -2
- package/dist/lib/Mask.js.map +1 -1
- package/dist/lib/Popup.js +13 -20
- package/dist/lib/Popup.js.map +1 -1
- package/dist/lib/StyleSheet.js +1 -1
- package/dist/lib/StyleSheet.js.map +1 -1
- package/dist/lib/accelerometer.js +1 -1
- package/dist/lib/accelerometer.js.map +1 -1
- package/dist/lib/chooseImage/index.js +151 -3
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseVideo/index.js +55 -1
- package/dist/lib/chooseVideo/index.js.map +1 -1
- package/dist/lib/clearStorage/index.js +2 -2
- package/dist/lib/clearStorage/index.js.map +1 -1
- package/dist/lib/compressImage/index.js +1 -1
- package/dist/lib/compressImage/index.js.map +1 -1
- package/dist/lib/connectSocket/index.js.map +1 -1
- package/dist/lib/connectSocket/socketTask.js +1 -1
- package/dist/lib/connectSocket/socketTask.js.map +1 -1
- package/dist/lib/createCameraContext/index.js +3 -3
- package/dist/lib/createCameraContext/index.js.map +1 -1
- package/dist/lib/createInnerAudioContext/index.js +2 -2
- package/dist/lib/createInnerAudioContext/index.js.map +1 -1
- package/dist/lib/createVideoContext/index.js +7 -7
- package/dist/lib/createVideoContext/index.js.map +1 -1
- package/dist/lib/deviceMotion.js +2 -2
- package/dist/lib/deviceMotion.js.map +1 -1
- package/dist/lib/file.js +4 -4
- package/dist/lib/file.js.map +1 -1
- package/dist/lib/getAppBaseInfo/index.js +2 -2
- package/dist/lib/getAppBaseInfo/index.js.map +1 -1
- package/dist/lib/getClipboardData/index.js.map +1 -1
- package/dist/lib/getImageInfo/index.js +2 -2
- package/dist/lib/getImageInfo/index.js.map +1 -1
- package/dist/lib/getLocation/index.js +4 -8
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +6 -11
- package/dist/lib/getRecorderManager/index.js.map +1 -1
- package/dist/lib/getStorage/index.js.map +1 -1
- package/dist/lib/getStorageInfo/index.js +2 -2
- package/dist/lib/getStorageInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfo/index.js +1 -1
- package/dist/lib/getSystemInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfoSync/index.js +2 -2
- package/dist/lib/getSystemInfoSync/index.js.map +1 -1
- package/dist/lib/gyroscope.js +1 -1
- package/dist/lib/gyroscope.js.map +1 -1
- package/dist/lib/index.js +0 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/keyboard.js +3 -3
- package/dist/lib/keyboard.js.map +1 -1
- package/dist/lib/location.js.map +1 -1
- package/dist/lib/makePhoneCall/index.js +1 -1
- package/dist/lib/makePhoneCall/index.js.map +1 -1
- package/dist/lib/media.js +30 -61
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/network.js +1 -1
- package/dist/lib/network.js.map +1 -1
- package/dist/lib/offWindowResize/index.js.map +1 -1
- package/dist/lib/onWindowResize/index.js +1 -1
- package/dist/lib/onWindowResize/index.js.map +1 -1
- package/dist/lib/openUrl/index.js +1 -1
- package/dist/lib/openUrl/index.js.map +1 -1
- package/dist/lib/permission.js +5 -6
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/previewImage/index.js +3 -3
- package/dist/lib/previewImage/index.js.map +1 -1
- package/dist/lib/request/index.js +1 -1
- package/dist/lib/request/index.js.map +1 -1
- package/dist/lib/scanCode/index.js +23 -23
- package/dist/lib/scanCode/index.js.map +1 -1
- package/dist/lib/screen.js +2 -2
- package/dist/lib/screen.js.map +1 -1
- package/dist/lib/setClipboardData/index.js +2 -2
- package/dist/lib/setClipboardData/index.js.map +1 -1
- package/dist/lib/setKeepScreenOn/index.js +1 -1
- package/dist/lib/setKeepScreenOn/index.js.map +1 -1
- package/dist/lib/setStorage/index.js.map +1 -1
- package/dist/lib/showActionSheet/ActionSheet.js +23 -11
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +24 -10
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +36 -22
- package/dist/lib/showModal/Dialog.js.map +1 -1
- package/dist/lib/showModal/index.js.map +1 -1
- package/dist/lib/showModal/toast.js +6 -6
- package/dist/lib/showModal/toast.js.map +1 -1
- package/dist/lib/unsupportedApi.js +4 -2
- package/dist/lib/unsupportedApi.js.map +1 -1
- package/dist/lib/variable.js +1 -1
- package/dist/lib/variable.js.map +1 -1
- package/dist/lib/vibrate.js +1 -1
- package/dist/lib/vibrate.js.map +1 -1
- package/dist/lib/window.js.map +1 -1
- package/dist/setup.js +75 -0
- package/dist/setup.js.map +1 -0
- package/dist/utils/callbackManager.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/libList.js +0 -1
- package/package.json +69 -70
- package/src/__tests__/__mock__/mockAsyncStorage.js +47 -0
- package/src/__tests__/__mock__/mockClipboard.js +15 -0
- package/src/__tests__/__mock__/mockNavigator.js +20 -0
- package/src/__tests__/__mock__/mockNetwork.js +59 -0
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +16 -0
- package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
- package/src/__tests__/__mock__/mockVibrate.js +6 -0
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +125 -0
- package/src/__tests__/clipboard.test.ts +88 -0
- package/src/__tests__/deviceMotion.test.ts +37 -0
- package/src/__tests__/geolocation.test.ts +60 -0
- package/src/__tests__/interactive.test.tsx +101 -0
- package/src/__tests__/keyboard.test.ts +46 -0
- package/src/__tests__/media.test.ts +104 -0
- package/src/__tests__/network.test.ts +57 -0
- package/src/__tests__/others.test.ts +25 -0
- package/src/__tests__/phone.test.ts +31 -0
- package/src/__tests__/request.test.ts +146 -0
- package/src/__tests__/scanCode.test.tsx +14 -0
- package/src/__tests__/storage.test.ts +202 -0
- package/src/__tests__/system.test.ts +69 -0
- package/src/__tests__/vibrate.test.ts +27 -0
- package/src/__tests__/websocket.test.ts +169 -0
- package/src/api/index.ts +31 -31
- package/src/lib/ENV_TYPE/index.ts +1 -1
- package/src/lib/Mask.tsx +2 -2
- package/src/lib/Popup.tsx +19 -26
- package/src/lib/StyleSheet.ts +1 -1
- package/src/lib/accelerometer.ts +1 -2
- package/src/lib/arrayBufferToBase64/index.ts +1 -1
- package/src/lib/base64ToArrayBuffer/index.ts +1 -1
- package/src/lib/chooseImage/index.ts +155 -3
- package/src/lib/chooseVideo/index.ts +56 -1
- package/src/lib/clearStorage/index.ts +0 -1
- package/src/lib/clearStorageSync/index.ts +1 -1
- package/src/lib/compressImage/index.ts +0 -1
- package/src/lib/connectSocket/socketTask.ts +9 -7
- package/src/lib/createCameraContext/index.ts +4 -6
- package/src/lib/createInnerAudioContext/index.ts +0 -1
- package/src/lib/createSelectorQuery/index.ts +1 -1
- package/src/lib/deviceMotion.ts +3 -4
- package/src/lib/file.ts +8 -9
- package/src/lib/getClipboardData/index.ts +0 -1
- package/src/lib/getEnv/index.ts +1 -1
- package/src/lib/getFileSystemManager/index.ts +1 -1
- package/src/lib/getLocation/index.ts +2 -7
- package/src/lib/getRecorderManager/index.ts +2 -7
- package/src/lib/getStorage/index.ts +0 -1
- package/src/lib/getStorageInfo/index.ts +0 -1
- package/src/lib/getStorageInfoSync/index.ts +1 -1
- package/src/lib/getStorageSync/index.ts +1 -1
- package/src/lib/getSystemInfo/index.ts +2 -2
- package/src/lib/getSystemInfoSync/index.ts +3 -3
- package/src/lib/gyroscope.ts +46 -47
- package/src/lib/index.ts +0 -1
- package/src/lib/keyboard.ts +4 -5
- package/src/lib/location.ts +5 -6
- package/src/lib/makePhoneCall/index.ts +1 -2
- package/src/lib/media.ts +31 -83
- package/src/lib/network.ts +5 -5
- package/src/lib/offLocationChange/index.ts +1 -1
- package/src/lib/offUserCaptureScreen/index.ts +1 -1
- package/src/lib/onLocationChange/index.ts +1 -1
- package/src/lib/onUserCaptureScreen/index.ts +1 -1
- package/src/lib/onWindowResize/index.ts +2 -2
- package/src/lib/openUrl/index.d.ts +22 -23
- package/src/lib/openUrl/index.ts +1 -2
- package/src/lib/permission.ts +25 -33
- package/src/lib/previewImage/index.tsx +3 -4
- package/src/lib/removeStorageSync/index.ts +1 -1
- package/src/lib/request/index.ts +2 -2
- package/src/lib/scanCode/index.tsx +16 -18
- package/src/lib/screen.ts +0 -1
- package/src/lib/setClipboardData/index.ts +2 -3
- package/src/lib/setKeepScreenOn/index.ts +1 -2
- package/src/lib/setStorage/index.ts +0 -1
- package/src/lib/setStorageSync/index.ts +1 -1
- package/src/lib/showActionSheet/ActionSheet.tsx +43 -34
- package/src/lib/showActionSheet/index.tsx +36 -11
- package/src/lib/showModal/Dialog.tsx +39 -34
- package/src/lib/showModal/index.tsx +0 -1
- package/src/lib/showModal/toast.tsx +13 -14
- package/src/lib/startGyroscope/index.ts +1 -1
- package/src/lib/startLocationUpdate/index.ts +1 -1
- package/src/lib/unsupportedApi.ts +5 -3
- package/src/lib/vibrate.ts +10 -11
- package/src/lib/window.ts +2 -3
- package/src/setup.ts +84 -0
- package/{types → src/types}/vue/index.d.ts +3 -2
- package/src/utils/callbackManager.ts +5 -5
- package/src/utils/index.ts +4 -4
- package/dist/lib/chooseMedia/index.js +0 -19
- package/dist/lib/chooseMedia/index.js.map +0 -1
- package/src/lib/chooseMedia/index.ts +0 -15
- /package/{types → src/types}/definition.d.ts +0 -0
|
@@ -1,5 +1,157 @@
|
|
|
1
|
-
import
|
|
1
|
+
import SYImagePicker from 'react-native-syan-image-picker'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { shouldBeObject } from '../../utils'
|
|
4
|
+
import { showActionSheet } from '../showActionSheet'
|
|
5
|
+
|
|
6
|
+
const res = { errMsg: 'chooseImage:ok' }
|
|
7
|
+
const defaultOptions = {
|
|
8
|
+
count: 9,
|
|
9
|
+
sizeType: ['original', 'compressed'],
|
|
10
|
+
sourceType: ['album', 'camera']
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getRes(images) {
|
|
14
|
+
const tempFilePaths: string[] = []
|
|
15
|
+
const tempFiles: any[] = []
|
|
16
|
+
images.forEach((item: any) => {
|
|
17
|
+
tempFilePaths.push(item.uri)
|
|
18
|
+
tempFiles.push({
|
|
19
|
+
path: item.uri,
|
|
20
|
+
size: item.size
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
return { tempFilePaths, tempFiles }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function openCamera(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
|
|
27
|
+
const { success, fail, complete } = options
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
SYImagePicker.openCamera({
|
|
30
|
+
compressFocusAlpha: true
|
|
31
|
+
}, (err, photo: any) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
const res = {
|
|
34
|
+
errMsg: err
|
|
35
|
+
}
|
|
36
|
+
fail?.(res)
|
|
37
|
+
complete?.(res)
|
|
38
|
+
reject(res)
|
|
39
|
+
} else {
|
|
40
|
+
try {
|
|
41
|
+
const data = Object.assign({}, getRes(photo), res)
|
|
42
|
+
success?.(data)
|
|
43
|
+
complete?.(data)
|
|
44
|
+
resolve(data)
|
|
45
|
+
} catch (error) {
|
|
46
|
+
// 错误
|
|
47
|
+
reject(error)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// NOTE: 调用此函数会改变图片的像素尺寸
|
|
55
|
+
function openPicker(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
|
|
56
|
+
const { count: imageCount, sizeType = [],success, complete, fail } = options
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
// NOTE:react-native-syan-image-picker 暂不支持 Android 端压缩
|
|
59
|
+
SYImagePicker.showImagePicker({
|
|
60
|
+
compressFocusAlpha: true,
|
|
61
|
+
imageCount,
|
|
62
|
+
quality: sizeType[0] === 'compressed' ? 70 : 90,
|
|
63
|
+
}, (err, photos: any) => {
|
|
64
|
+
if (err) {
|
|
65
|
+
const res = {
|
|
66
|
+
errMsg: err
|
|
67
|
+
}
|
|
68
|
+
fail?.(res)
|
|
69
|
+
complete?.(res)
|
|
70
|
+
reject(res)
|
|
71
|
+
} else {
|
|
72
|
+
try {
|
|
73
|
+
const data = Object.assign({}, getRes(photos), res)
|
|
74
|
+
success?.(data)
|
|
75
|
+
complete?.(data)
|
|
76
|
+
resolve(data)
|
|
77
|
+
} catch (error) {
|
|
78
|
+
reject(error)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @description Display the image picker.
|
|
87
|
+
* @param options
|
|
88
|
+
* @returns {Promise}
|
|
89
|
+
*/
|
|
90
|
+
function showImagePicker(options: Taro.chooseImage.Option):Promise<Taro.chooseImage.SuccessCallbackResult> {
|
|
91
|
+
const { fail, complete } = options
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
showActionSheet({
|
|
94
|
+
itemList: ['拍照', '从手机相册选择'],
|
|
95
|
+
success(res) {
|
|
96
|
+
console.log(res.tapIndex)
|
|
97
|
+
if (res.tapIndex === 0) {
|
|
98
|
+
// 不添加 setTimeout 会有一定概率卡死,肯能是与 sibling.destroy() 冲突
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
openCamera(options).then(res => {
|
|
101
|
+
resolve(res)
|
|
102
|
+
}).catch(e => {
|
|
103
|
+
fail?.({ errMsg: `chooseImage:${e.message}` })
|
|
104
|
+
complete?.({ errMsg: `chooseImage:${e.message}` })
|
|
105
|
+
reject(new Error(`chooseImage:${e.message}`))
|
|
106
|
+
})
|
|
107
|
+
}, 100)
|
|
108
|
+
}
|
|
109
|
+
if (res.tapIndex === 1) {
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
openPicker(options).then(res => {
|
|
112
|
+
resolve(res)
|
|
113
|
+
}).catch(e => {
|
|
114
|
+
fail?.({ errMsg: `chooseImage:${e.message}` })
|
|
115
|
+
complete?.({ errMsg: `chooseImage:${e.message}` })
|
|
116
|
+
reject(new Error(`chooseImage:${e.message}`))
|
|
117
|
+
})
|
|
118
|
+
}, 100)
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
fail(res) {
|
|
122
|
+
console.log('error: ', res.errMsg)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated
|
|
130
|
+
* @description 从本地相册选择图片或使用相机拍照。
|
|
131
|
+
* sizeType ❌
|
|
132
|
+
* @param options
|
|
133
|
+
* @returns {Promise<*>}
|
|
134
|
+
*/
|
|
135
|
+
export function chooseImage(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
|
|
136
|
+
// options must be an Object
|
|
137
|
+
const isObject = shouldBeObject(options)
|
|
138
|
+
if (!isObject.res) {
|
|
139
|
+
const res = { errMsg: `chooseImage${isObject.msg}` }
|
|
140
|
+
console.error(res.errMsg)
|
|
141
|
+
return Promise.reject(res)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
options = Object.assign({}, defaultOptions, options)
|
|
145
|
+
const { sourceType } = options
|
|
146
|
+
|
|
147
|
+
switch (JSON.stringify(sourceType)) {
|
|
148
|
+
case '[\'camera\']':
|
|
149
|
+
case '["camera"]':
|
|
150
|
+
return openCamera(options)
|
|
151
|
+
case '[\'album\']':
|
|
152
|
+
case '["album"]':
|
|
153
|
+
return openPicker(options)
|
|
154
|
+
default:
|
|
155
|
+
return showImagePicker(options)
|
|
156
|
+
}
|
|
5
157
|
}
|
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
import { chooseMedia, MEDIA_TYPE } from '../media'
|
|
2
|
+
import { showActionSheet } from '../showActionSheet'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 拍摄视频或从手机相册中选视频。
|
|
6
|
+
* @param {Object} opts
|
|
7
|
+
* @param {Array} [opts.sourceType=['album', 'camera']] ✔
|
|
8
|
+
* @param {boolean} [opts.compressed=true] ✔
|
|
9
|
+
* @param {number} [opts.maxDuration=60] - 拍摄视频最长拍摄时间,单位秒 ✖
|
|
10
|
+
* @param {string} [opts.camera='back'] - 默认拉起的是前置或者后置摄像头。✖
|
|
11
|
+
* @returns {Promise<*>}
|
|
12
|
+
*/
|
|
3
13
|
export function chooseVideo(opts: Taro.chooseVideo.Option): Promise<any> {
|
|
4
|
-
|
|
14
|
+
const { sourceType, compressed } = opts
|
|
15
|
+
opts = Object.assign(opts, { sizeType: compressed ? ['compressed'] : [] })
|
|
16
|
+
switch (JSON.stringify(sourceType)) {
|
|
17
|
+
case '[\'camera\']':
|
|
18
|
+
case '["camera"]':
|
|
19
|
+
return chooseMedia({...opts, sourceType: ['camera']}, MEDIA_TYPE.VIDEOS)
|
|
20
|
+
case '[\'album\']':
|
|
21
|
+
case '["album"]':
|
|
22
|
+
return chooseMedia({...opts, sourceType: ['album']}, MEDIA_TYPE.VIDEOS)
|
|
23
|
+
default:
|
|
24
|
+
return showVideoPicker(opts)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 视频选择器
|
|
30
|
+
* @param options
|
|
31
|
+
* @returns {Promise}
|
|
32
|
+
*/
|
|
33
|
+
function showVideoPicker(options: Taro.chooseVideo.Option):any {
|
|
34
|
+
const { fail, complete } = options
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
showActionSheet({
|
|
37
|
+
itemList: ['拍摄', '从手机相册选择'],
|
|
38
|
+
success: function (res) {
|
|
39
|
+
if (res.tapIndex === 0) {
|
|
40
|
+
resolve(chooseMedia({...options, sourceType: ['camera']}, MEDIA_TYPE.VIDEOS))
|
|
41
|
+
}
|
|
42
|
+
if (res.tapIndex === 1) {
|
|
43
|
+
resolve(chooseMedia({...options, sourceType: ['album']}, MEDIA_TYPE.VIDEOS))
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
fail: function () {
|
|
47
|
+
const res = { errMsg: 'chooseVideo:fail cancel' }
|
|
48
|
+
reject(res)
|
|
49
|
+
}
|
|
50
|
+
}).catch(err => {
|
|
51
|
+
console.log('error: ', err.errMsg)
|
|
52
|
+
if (/showActionSheet:fail cancel/.test(err.errMsg)) {
|
|
53
|
+
const res = { errMsg: 'chooseVideo:fail cancel' }
|
|
54
|
+
fail?.(res)
|
|
55
|
+
complete?.(res)
|
|
56
|
+
reject(res)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
})
|
|
5
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { clearStorageSync } from '../unsupportedApi'
|
|
1
|
+
export { clearStorageSync } from '../unsupportedApi'
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
ws: WebSocket
|
|
3
|
-
_destroyWhenClose: () => void
|
|
1
|
+
interface SocketTask {
|
|
2
|
+
ws: WebSocket;
|
|
3
|
+
_destroyWhenClose: () => void;
|
|
4
4
|
closeDetail: {
|
|
5
|
-
code: number
|
|
6
|
-
reason: string
|
|
7
|
-
}
|
|
5
|
+
code: number;
|
|
6
|
+
reason: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
8
9
|
|
|
10
|
+
class SocketTask {
|
|
9
11
|
constructor (url: string, protocols: string[] | undefined) {
|
|
10
12
|
if (protocols) {
|
|
11
13
|
// eslint-disable-next-line no-undef
|
|
@@ -103,7 +105,7 @@ class SocketTask {
|
|
|
103
105
|
onError (func?: Taro.SocketTask.OnErrorCallback): void {
|
|
104
106
|
this.ws.onerror = () => {
|
|
105
107
|
func && func({
|
|
106
|
-
errMsg:
|
|
108
|
+
errMsg: "There was an error with your websocket.",
|
|
107
109
|
})
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { Camera } from 'expo-camera'
|
|
2
|
-
|
|
3
1
|
import { errorHandler, successHandler } from '../../utils'
|
|
4
|
-
|
|
2
|
+
import { requestCameraPermissionsAsync, requestMicrophonePermissionsAsync } from 'expo-camera'
|
|
5
3
|
const globalAny: any = global
|
|
6
4
|
|
|
7
5
|
class CameraContext {
|
|
@@ -16,8 +14,8 @@ class CameraContext {
|
|
|
16
14
|
* 开始录像
|
|
17
15
|
*/
|
|
18
16
|
startRecord = (option: Taro.CameraContext.StartRecordOption) => {
|
|
19
|
-
Promise.all([
|
|
20
|
-
if
|
|
17
|
+
Promise.all([requestCameraPermissionsAsync(), requestMicrophonePermissionsAsync()]).then(([cameraPermission, microphonePermission]) => {
|
|
18
|
+
if(cameraPermission.granted && microphonePermission.granted) {
|
|
21
19
|
this.cameraRef?.recordAsync().then((res) => {
|
|
22
20
|
const { uri } = res
|
|
23
21
|
const result = {
|
|
@@ -78,7 +76,7 @@ class CameraContext {
|
|
|
78
76
|
break
|
|
79
77
|
}
|
|
80
78
|
try {
|
|
81
|
-
const { granted } = await
|
|
79
|
+
const { granted } = await requestCameraPermissionsAsync()
|
|
82
80
|
if (granted) {
|
|
83
81
|
if (this.cameraRef?.takePictureAsync) {
|
|
84
82
|
const { uri } = await this.cameraRef.takePictureAsync({ quality: _quality })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createSelectorQuery } from '../unsupportedApi'
|
|
1
|
+
export { createSelectorQuery } from '../unsupportedApi'
|
package/src/lib/deviceMotion.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Taro from '@tarojs/taro'
|
|
2
2
|
import { DeviceMotion } from 'expo-sensors'
|
|
3
|
-
|
|
4
|
-
import { createCallbackManager, errorHandler, successHandler } from '../utils'
|
|
3
|
+
import { createCallbackManager, successHandler, errorHandler } from '../utils'
|
|
5
4
|
|
|
6
5
|
const _cbManager = createCallbackManager()
|
|
7
6
|
let _listener: any
|
|
@@ -45,7 +44,7 @@ function startDeviceMotionListening (object: Taro.startDeviceMotionListening.Opt
|
|
|
45
44
|
_cbManager.trigger(rotation)
|
|
46
45
|
})
|
|
47
46
|
DeviceMotion.setUpdateInterval(intervalMap[interval] || intervalMap.normal)
|
|
48
|
-
|
|
47
|
+
|
|
49
48
|
return successHandler(success, complete)(res)
|
|
50
49
|
} catch (error) {
|
|
51
50
|
res.errMsg = 'startDeviceMotionListening:fail'
|
|
@@ -72,8 +71,8 @@ function stopDeviceMotionListening (object: Taro.stopDeviceMotionListening.Optio
|
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
export {
|
|
75
|
-
offDeviceMotionChange,
|
|
76
74
|
onDeviceMotionChange,
|
|
75
|
+
offDeviceMotionChange,
|
|
77
76
|
startDeviceMotionListening,
|
|
78
77
|
stopDeviceMotionListening
|
|
79
78
|
}
|
package/src/lib/file.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import * as FileSystem from 'expo-file-system'
|
|
2
2
|
import { Platform } from 'react-native'
|
|
3
|
-
|
|
4
|
-
import { errorHandler, shouldBeObject, successHandler } from '../utils'
|
|
3
|
+
import { shouldBeObject, successHandler, errorHandler } from '../utils'
|
|
5
4
|
|
|
6
5
|
interface Func {
|
|
7
6
|
(arg: any): void
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
interface ExtPromise<T> extends Promise<T> {
|
|
11
|
-
onProgressUpdateCb?: Func
|
|
12
|
-
onProgressUpdate?: Func
|
|
10
|
+
onProgressUpdateCb?: Func,
|
|
11
|
+
onProgressUpdate?: Func,
|
|
13
12
|
abort?: Func
|
|
14
13
|
}
|
|
15
14
|
|
|
@@ -340,10 +339,10 @@ async function getFileInfo (opts: Taro.getFileInfo.Option): Promise<Taro.getFile
|
|
|
340
339
|
|
|
341
340
|
export {
|
|
342
341
|
downloadFile,
|
|
343
|
-
|
|
344
|
-
getSavedFileInfo,
|
|
345
|
-
getSavedFileList,
|
|
346
|
-
removeSavedFile,
|
|
342
|
+
uploadFile,
|
|
347
343
|
saveFile,
|
|
348
|
-
|
|
344
|
+
removeSavedFile,
|
|
345
|
+
getSavedFileList,
|
|
346
|
+
getSavedFileInfo,
|
|
347
|
+
getFileInfo
|
|
349
348
|
}
|
package/src/lib/getEnv/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getFileSystemManager } from '../unsupportedApi'
|
|
1
|
+
export { getFileSystemManager } from '../unsupportedApi'
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import Geolocation from '@react-native-community/geolocation'
|
|
2
|
-
|
|
2
|
+
import { requestForegroundPermissionsAsync } from 'expo-location'
|
|
3
3
|
import { errorHandler } from '../../utils'
|
|
4
4
|
|
|
5
5
|
export async function getLocation(opts: Taro.getLocation.Option = {}): Promise<Taro.getLocation.SuccessCallbackResult> {
|
|
6
6
|
const { isHighAccuracy = false, highAccuracyExpireTime = 3000, success, fail, complete } = opts
|
|
7
|
-
const requestAuthorization = () => {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
Geolocation.requestAuthorization(() => resolve({ granted: true }), (err) => reject(err))
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
7
|
|
|
13
8
|
try {
|
|
14
9
|
// @ts-ignore
|
|
15
10
|
// todo: fix types
|
|
16
|
-
const { granted } = await
|
|
11
|
+
const { granted } = await requestForegroundPermissionsAsync()
|
|
17
12
|
if (!granted) {
|
|
18
13
|
const res = { errMsg: 'Permissions denied!' }
|
|
19
14
|
return errorHandler(fail, complete)(res)
|
|
@@ -81,7 +81,7 @@ class RecorderManager {
|
|
|
81
81
|
playsInSilentModeIOS: true,
|
|
82
82
|
staysActiveInBackground: false,
|
|
83
83
|
shouldDuckAndroid: true,
|
|
84
|
-
interruptionModeAndroid: 1, //
|
|
84
|
+
interruptionModeAndroid: 1, //InterruptionModeAndroid.DoNotMix
|
|
85
85
|
playThroughEarpieceAndroid: true
|
|
86
86
|
} as any)
|
|
87
87
|
|
|
@@ -151,12 +151,7 @@ class RecorderManager {
|
|
|
151
151
|
const info = await FileSystem.getInfoAsync(uri)
|
|
152
152
|
// console.log(`FILE INFO: ${JSON.stringify(info)}`)
|
|
153
153
|
|
|
154
|
-
const result = {
|
|
155
|
-
tempFilePath: uri,
|
|
156
|
-
duration: recordStatus.durationMillis,
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
fileSize: info.size
|
|
159
|
-
}
|
|
154
|
+
const result = { tempFilePath: uri, duration: recordStatus.durationMillis, fileSize: info.size }
|
|
160
155
|
this.onStopCallback && this.onStopCallback(result)
|
|
161
156
|
}
|
|
162
157
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getStorageInfoSync } from '../unsupportedApi'
|
|
1
|
+
export { getStorageInfoSync } from '../unsupportedApi'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getStorageSync } from '../unsupportedApi'
|
|
1
|
+
export { getStorageSync } from '../unsupportedApi'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { errorHandler, successHandler } from '../../utils'
|
|
2
1
|
import { getSystemInfoSync } from '../getSystemInfoSync'
|
|
2
|
+
import { successHandler, errorHandler } from '../../utils'
|
|
3
3
|
|
|
4
|
-
export function getSystemInfo(opts: Taro.getSystemInfo.Option
|
|
4
|
+
export function getSystemInfo(opts: Taro.getSystemInfo.Option = {}): Promise<Taro.getSystemInfo.Result> {
|
|
5
5
|
const { success, fail, complete }: any = opts
|
|
6
6
|
try {
|
|
7
7
|
const res = {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Platform,
|
|
2
3
|
Dimensions,
|
|
3
4
|
PixelRatio,
|
|
4
|
-
Platform,
|
|
5
5
|
StatusBar
|
|
6
6
|
} from 'react-native'
|
|
7
|
-
import DeviceInfo from 'react-native-device-info'
|
|
8
7
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
8
|
+
import DeviceInfo from 'react-native-device-info'
|
|
9
9
|
|
|
10
10
|
export function getSystemInfoSync(): Taro.getSystemInfoSync.Result {
|
|
11
11
|
const res: any = {}
|
|
@@ -28,7 +28,7 @@ export function getSystemInfoSync(): Taro.getSystemInfoSync.Result {
|
|
|
28
28
|
let { top = 0, bottom = 0 } = initialWindowMetrics?.insets || {}
|
|
29
29
|
// NOTE:android 在沉浸式切换时,有几率top值为0。
|
|
30
30
|
// https://github.com/th3rdwave/react-native-safe-area-context/issues/364
|
|
31
|
-
if
|
|
31
|
+
if(Platform.OS === 'android') { top = StatusBar.currentHeight || 0; }
|
|
32
32
|
|
|
33
33
|
try {
|
|
34
34
|
const W = Math.min(screenWidth, screenHeight)
|
package/src/lib/gyroscope.ts
CHANGED
|
@@ -1,84 +1,83 @@
|
|
|
1
1
|
import { Gyroscope } from 'expo-sensors'
|
|
2
|
-
|
|
3
2
|
import { createCallbackManager, errorHandler, successHandler } from '../utils'
|
|
4
3
|
|
|
5
4
|
const _cbManager = createCallbackManager()
|
|
6
5
|
let _listener: any
|
|
7
6
|
|
|
8
7
|
const intervalMap: any = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
game: 20,
|
|
9
|
+
ui: 60,
|
|
10
|
+
normal: 200
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* 开始监听陀螺仪数据
|
|
16
|
-
* @param opts
|
|
15
|
+
* @param opts
|
|
17
16
|
* @param {string} [opts.interval='normal'] 监听陀螺仪数据回调函数的执行频率
|
|
18
17
|
*/
|
|
19
18
|
function startGyroscope(opts: Taro.startGyroscope.Option = {}): Promise<TaroGeneral.CallbackResult> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const { interval = 'normal', success, fail, complete } = opts
|
|
20
|
+
const res = { errMsg: 'startGyroscope:ok' }
|
|
21
|
+
try {
|
|
22
|
+
// 适配微信小程序行为:重复 start 失败
|
|
23
|
+
if (_listener) {
|
|
24
|
+
console.error('startGyroscope:fail')
|
|
25
|
+
throw new Error('startGyroscope:fail')
|
|
26
|
+
}
|
|
27
|
+
_listener = Gyroscope.addListener(e => {
|
|
28
|
+
_cbManager.trigger(e)
|
|
29
|
+
})
|
|
30
|
+
Gyroscope.setUpdateInterval(intervalMap[interval])
|
|
31
|
+
|
|
32
|
+
return successHandler(success, complete)(res)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
res.errMsg = 'startGyroscope:fail'
|
|
35
|
+
return errorHandler(fail, complete)(res)
|
|
27
36
|
}
|
|
28
|
-
_listener = Gyroscope.addListener(e => {
|
|
29
|
-
_cbManager.trigger(e)
|
|
30
|
-
})
|
|
31
|
-
Gyroscope.setUpdateInterval(intervalMap[interval])
|
|
32
|
-
|
|
33
|
-
return successHandler(success, complete)(res)
|
|
34
|
-
} catch (error) {
|
|
35
|
-
res.errMsg = 'startGyroscope:fail'
|
|
36
|
-
return errorHandler(fail, complete)(res)
|
|
37
|
-
}
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* 停止监听陀螺仪数据
|
|
42
|
-
* @param opts
|
|
41
|
+
* @param opts
|
|
43
42
|
*/
|
|
44
43
|
function stopGyroscope(opts: Taro.stopGyroscope.Option = {}): Promise<TaroGeneral.CallbackResult> {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
const { success, fail, complete } = opts
|
|
45
|
+
const res = { errMsg: 'stopGyroscope:ok' }
|
|
46
|
+
try {
|
|
47
|
+
_listener && _listener.remove()
|
|
48
|
+
_listener = null
|
|
49
|
+
return successHandler(success, complete)(res)
|
|
50
|
+
} catch (error) {
|
|
51
|
+
res.errMsg = 'stopGyroscope:fail'
|
|
52
|
+
return errorHandler(fail, complete)(res)
|
|
53
|
+
}
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
57
|
* 监听陀螺仪数据变化事件
|
|
59
|
-
* @param opts
|
|
58
|
+
* @param opts
|
|
60
59
|
*/
|
|
61
60
|
function onGyroscopeChange(fnc: Taro.onGyroscopeChange.Callback): void {
|
|
62
|
-
|
|
61
|
+
_cbManager.add(fnc)
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
65
|
* 取消监听陀螺仪数据变化事件
|
|
67
|
-
* @param opts
|
|
66
|
+
* @param opts
|
|
68
67
|
*/
|
|
69
68
|
function offGyroscopeChange(fnc?: Taro.onGyroscopeChange.Callback) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
if (fnc && typeof fnc === 'function') {
|
|
70
|
+
_cbManager.remove(fnc)
|
|
71
|
+
} else if (fnc === undefined) {
|
|
72
|
+
_cbManager.clear()
|
|
73
|
+
} else {
|
|
74
|
+
console.warn('offGyroscopeChange failed')
|
|
75
|
+
}
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
export {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
startGyroscope,
|
|
80
|
+
stopGyroscope,
|
|
81
|
+
onGyroscopeChange,
|
|
82
|
+
offGyroscopeChange,
|
|
84
83
|
}
|
package/src/lib/index.ts
CHANGED
package/src/lib/keyboard.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Keyboard } from 'react-native'
|
|
2
|
-
|
|
3
2
|
import { createCallbackManager, errorHandler, successHandler } from '../utils'
|
|
4
3
|
|
|
5
4
|
const hideKeyboard = (opts: Taro.hideKeyboard.Option = {}): Promise<TaroGeneral.CallbackResult> => {
|
|
@@ -28,8 +27,8 @@ const keyboardHeightListener = (e) => {
|
|
|
28
27
|
const onKeyboardHeightChange = (callback: Taro.onKeyboardHeightChange.Callback): void => {
|
|
29
28
|
_cbManager.add(callback)
|
|
30
29
|
if (!_hasListener) {
|
|
31
|
-
Keyboard.addListener(
|
|
32
|
-
Keyboard.addListener(
|
|
30
|
+
Keyboard.addListener("keyboardDidShow", keyboardHeightListener)
|
|
31
|
+
Keyboard.addListener("keyboardDidHide", keyboardHeightListener)
|
|
33
32
|
_hasListener = true
|
|
34
33
|
}
|
|
35
34
|
}
|
|
@@ -54,7 +53,7 @@ const offKeyboardHeightChange = (callback?: Taro.onKeyboardHeightChange.Callback
|
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
export {
|
|
57
|
-
|
|
56
|
+
onKeyboardHeightChange,
|
|
58
57
|
offKeyboardHeightChange,
|
|
59
|
-
|
|
58
|
+
hideKeyboard
|
|
60
59
|
}
|