@tarojs/taro-rn 4.0.0-beta.78 → 4.0.0-beta.79
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 -1
- 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 +3 -3
- 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/chooseMedia/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 +2 -2
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +5 -5
- 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/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 +13 -15
- 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 +22 -22
- 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 +3 -3
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +3 -3
- 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 +58 -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/package.json +60 -65
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +7 -0
- package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +154 -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 +170 -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 +6 -8
- 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/chooseMedia/index.ts +1 -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 +3 -4
- package/src/lib/getRecorderManager/index.ts +1 -1
- 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/keyboard.ts +4 -5
- package/src/lib/location.ts +5 -6
- package/src/lib/makePhoneCall/index.ts +1 -2
- package/src/lib/media.ts +18 -21
- 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 +15 -17
- 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 +6 -7
- package/src/lib/showActionSheet/index.tsx +0 -1
- package/src/lib/showModal/Dialog.tsx +6 -7
- package/src/lib/showModal/index.tsx +0 -1
- package/src/lib/showModal/toast.tsx +11 -12
- 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 +64 -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/{types → src/types}/definition.d.ts +0 -0
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/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
|
}
|
package/src/lib/location.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Geolocation from '@react-native-community/geolocation'
|
|
2
|
-
|
|
3
2
|
import { createCallbackManager, errorHandler, successHandler } from '../utils'
|
|
4
3
|
|
|
5
4
|
const _cbManager = createCallbackManager()
|
|
@@ -21,8 +20,8 @@ export function offLocationChange(callback: Taro.onLocationChange.Callback): voi
|
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* 开始监听位置信息
|
|
24
|
-
* @param opts
|
|
25
|
-
* @returns
|
|
23
|
+
* @param opts
|
|
24
|
+
* @returns
|
|
26
25
|
*/
|
|
27
26
|
export function startLocationUpdate(opts: Taro.startLocationUpdate.Option): Promise<TaroGeneral.CallbackResult> {
|
|
28
27
|
const { success, fail, complete } = opts
|
|
@@ -64,8 +63,8 @@ export function startLocationUpdate(opts: Taro.startLocationUpdate.Option): Prom
|
|
|
64
63
|
|
|
65
64
|
/**
|
|
66
65
|
* 停止监听位置信息
|
|
67
|
-
* @param opts
|
|
68
|
-
* @returns
|
|
66
|
+
* @param opts
|
|
67
|
+
* @returns
|
|
69
68
|
*/
|
|
70
69
|
export function stopLocationUpdate(opts: Taro.stopLocationUpdate.Option): Promise<TaroGeneral.CallbackResult> {
|
|
71
70
|
const { success, fail, complete } = opts
|
|
@@ -80,4 +79,4 @@ export function stopLocationUpdate(opts: Taro.stopLocationUpdate.Option): Promis
|
|
|
80
79
|
|
|
81
80
|
return errorHandler(fail, complete)(res)
|
|
82
81
|
}
|
|
83
|
-
}
|
|
82
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Linking } from 'react-native'
|
|
2
|
-
|
|
3
|
-
import { errorHandler, successHandler } from '../../utils'
|
|
2
|
+
import { successHandler, errorHandler } from '../../utils'
|
|
4
3
|
|
|
5
4
|
export async function makePhoneCall(opts: Taro.makePhoneCall.Option): Promise<TaroGeneral.CallbackResult> {
|
|
6
5
|
const { phoneNumber, success, fail, complete } = opts
|
package/src/lib/media.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { CameraRoll } from
|
|
2
|
-
import {
|
|
1
|
+
import { CameraRoll } from "@react-native-camera-roll/camera-roll"
|
|
2
|
+
import { requestCameraPermissionsAsync } from 'expo-camera'
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
launchCameraAsync,
|
|
4
|
+
requestMediaLibraryPermissionsAsync,
|
|
6
5
|
launchImageLibraryAsync,
|
|
6
|
+
launchCameraAsync,
|
|
7
7
|
MediaTypeOptions,
|
|
8
|
-
|
|
8
|
+
ImagePickerAsset,
|
|
9
9
|
} from 'expo-image-picker'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
import { showActionSheet } from './showActionSheet'
|
|
10
|
+
import { successHandler, errorHandler } from '../utils'
|
|
11
|
+
import { showActionSheet } from "./showActionSheet"
|
|
13
12
|
|
|
14
13
|
export const MEDIA_TYPE = MediaTypeOptions
|
|
15
14
|
|
|
@@ -25,7 +24,7 @@ export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.
|
|
|
25
24
|
const saveType = (type === 'video' || type === 'photo') ? type : 'auto'
|
|
26
25
|
try {
|
|
27
26
|
const url: string = await CameraRoll.save(filePath, { type: saveType })
|
|
28
|
-
res.path = url
|
|
27
|
+
res.path = url;
|
|
29
28
|
return successHandler(success, complete)(res)
|
|
30
29
|
} catch (err) {
|
|
31
30
|
res.errMsg = err.message
|
|
@@ -40,17 +39,15 @@ async function showPicker(opts: Taro.chooseImage.Option | Taro.chooseVideo.Optio
|
|
|
40
39
|
itemList: ['拍摄', '从手机相册选择'],
|
|
41
40
|
})
|
|
42
41
|
if (res.tapIndex === 0) {
|
|
43
|
-
return _chooseMedia({
|
|
42
|
+
return _chooseMedia({...opts, sourceType: ['camera']}, mediaTypes)
|
|
44
43
|
}
|
|
45
44
|
if (res.tapIndex === 1) {
|
|
46
|
-
return _chooseMedia({
|
|
45
|
+
return _chooseMedia({...opts, sourceType: ['album']}, mediaTypes)
|
|
47
46
|
}
|
|
48
47
|
} catch (err) {
|
|
49
|
-
const res = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} fail`
|
|
53
|
-
}
|
|
48
|
+
const res = { errMsg: `choose${
|
|
49
|
+
mediaTypes === MediaTypeOptions.Images ? 'Image' : mediaTypes === MediaTypeOptions.Videos ? 'Video' : 'Media'
|
|
50
|
+
} fail` }
|
|
54
51
|
fail?.(res)
|
|
55
52
|
complete?.(res)
|
|
56
53
|
}
|
|
@@ -60,12 +57,12 @@ export async function chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVid
|
|
|
60
57
|
const {
|
|
61
58
|
sourceType = ['album', 'camera'],
|
|
62
59
|
} = opts
|
|
63
|
-
if
|
|
60
|
+
if(sourceType?.includes('camera') && sourceType?.includes('album')) {
|
|
64
61
|
return showPicker(opts, mediaTypes)
|
|
65
62
|
} else if (sourceType?.includes('camera')) {
|
|
66
|
-
return _chooseMedia({
|
|
63
|
+
return _chooseMedia({...opts, sourceType: ['camera']}, mediaTypes)
|
|
67
64
|
}
|
|
68
|
-
return _chooseMedia({
|
|
65
|
+
return _chooseMedia({...opts, sourceType: ['album']}, mediaTypes)
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
export async function _chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option | Taro.chooseMedia.Option = {}, mediaTypes: MediaTypeOptions): Promise<TaroGeneral.CallbackResult> {
|
|
@@ -88,13 +85,13 @@ export async function _chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVi
|
|
|
88
85
|
}
|
|
89
86
|
const messString = mediaTypes === MediaTypeOptions.Images ? 'Image' : mediaTypes === MediaTypeOptions.Videos ? 'Video' : 'Media'
|
|
90
87
|
const isCamera = sourceType[0] === 'camera'
|
|
91
|
-
const { granted } = isCamera ? await
|
|
88
|
+
const { granted } = isCamera ? await requestCameraPermissionsAsync() : await requestMediaLibraryPermissionsAsync()
|
|
92
89
|
if (!granted) {
|
|
93
90
|
const res = { errMsg: 'Permissions denied!' }
|
|
94
91
|
return errorHandler(fail, complete)(res)
|
|
95
92
|
}
|
|
96
93
|
|
|
97
|
-
|
|
94
|
+
let launchMediaAsync = isCamera ? launchCameraAsync : launchImageLibraryAsync
|
|
98
95
|
try {
|
|
99
96
|
const resp = await launchMediaAsync(options)
|
|
100
97
|
let res: any = {}
|
package/src/lib/network.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import 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
7
|
function getTypeFromState(connectionInfo:NetInfoState): keyof Taro.getNetworkType.NetworkType {
|
|
8
8
|
let type: keyof Taro.getNetworkType.NetworkType
|
|
9
|
-
if
|
|
9
|
+
if(connectionInfo.type === NetInfoStateType.wifi) {
|
|
10
10
|
type = NetInfoStateType.wifi
|
|
11
|
-
} else if
|
|
11
|
+
} else if(connectionInfo.type === NetInfoStateType.cellular && connectionInfo.details.cellularGeneration) {
|
|
12
12
|
type = connectionInfo.details.cellularGeneration
|
|
13
|
-
} else if
|
|
13
|
+
} else if(connectionInfo.type === NetInfoStateType.none) {
|
|
14
14
|
type = 'none'
|
|
15
15
|
} else {
|
|
16
16
|
type = 'unknown'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { offLocationChange } from '../location'
|
|
1
|
+
export { offLocationChange } from '../location'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { offUserCaptureScreen } from '../unsupportedApi'
|
|
1
|
+
export { offUserCaptureScreen } from '../unsupportedApi'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { onLocationChange } from '../location'
|
|
1
|
+
export { onLocationChange } from '../location'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { onUserCaptureScreen } from '../unsupportedApi'
|
|
1
|
+
export { onUserCaptureScreen } from '../unsupportedApi'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { callbackManager, addListener } from '../window'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {Object} WindowResizeParam
|
|
@@ -15,4 +15,4 @@ export const onWindowResize = (callback: Taro.onWindowResize.Callback): void =>
|
|
|
15
15
|
if (callbackManager.count() === 1) {
|
|
16
16
|
addListener()
|
|
17
17
|
}
|
|
18
|
-
}
|
|
18
|
+
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
declare namespace Taro {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function openUrl<T>(opts: Taro.OpenUrl.Option): Promise<T>
|
|
2
|
+
namespace OpenUrl {
|
|
3
|
+
interface Option {
|
|
4
|
+
/** 跳转链接 */
|
|
5
|
+
url: string
|
|
6
|
+
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
|
|
7
|
+
complete?: (res: TaroGeneral.CallbackResult) => void
|
|
8
|
+
/** 接口调用失败的回调函数 */
|
|
9
|
+
fail?: (res: TaroGeneral.CallbackResult) => void
|
|
10
|
+
/** 接口调用成功的回调函数 */
|
|
11
|
+
success?: (res: TaroGeneral.CallbackResult) => void
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 由于 Expo 不支持原生的 SDK,所以无法通过集成原生的 SDK 的方式使用微信/支付宝支付。
|
|
16
|
+
* 所以 RN 端提供了 `Taro.openUrl({url:''})`的 API 打开手机浏览器,然后走 [手机网站支付](https://docs.open.alipay.com/203/105288/) 的流程。
|
|
17
|
+
* @param {Object} opts
|
|
18
|
+
* @param {string} [opts.url] 跳转链接
|
|
19
|
+
* @param {function} [opts.success] 接口调用成功的回调函数
|
|
20
|
+
* @param {function} [opts.fail] 接口调用失败的回调函数
|
|
21
|
+
* @param {function} [opts.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
22
|
+
*/
|
|
23
|
+
function openUrl<T>(opts: Taro.OpenUrl.Option): Promise<T>
|
|
25
24
|
}
|
package/src/lib/openUrl/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Linking } from 'react-native'
|
|
2
|
-
|
|
3
|
-
import { errorHandler, successHandler } from '../../utils'
|
|
2
|
+
import { successHandler, errorHandler } from '../../utils'
|
|
4
3
|
|
|
5
4
|
export async function openUrl <T>(opts: Taro.OpenUrl.Option): Promise<T> {
|
|
6
5
|
const { url, success, fail, complete } = opts || {} as Taro.OpenUrl.Option
|
package/src/lib/permission.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Linking, AppState, NativeEventSubscription } from 'react-native';
|
|
2
|
+
import { getCameraPermissionsAsync, getMicrophonePermissionsAsync, requestCameraPermissionsAsync, requestMicrophonePermissionsAsync } from 'expo-camera'
|
|
2
3
|
import { getMediaLibraryPermissionsAsync, requestMediaLibraryPermissionsAsync } from 'expo-image-picker'
|
|
3
4
|
import {
|
|
4
5
|
getForegroundPermissionsAsync,
|
|
@@ -6,16 +7,7 @@ import {
|
|
|
6
7
|
requestForegroundPermissionsAsync,
|
|
7
8
|
// requestBackgroundPermissionsAsync
|
|
8
9
|
} from 'expo-location'
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import { errorHandler, successHandler } from '../utils'
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
getCameraPermissionsAsync,
|
|
15
|
-
getMicrophonePermissionsAsync,
|
|
16
|
-
requestCameraPermissionsAsync,
|
|
17
|
-
requestMicrophonePermissionsAsync
|
|
18
|
-
} = Camera
|
|
10
|
+
import { errorHandler, successHandler } from '../utils';
|
|
19
11
|
|
|
20
12
|
const scopeMap = {
|
|
21
13
|
'scope.userLocation': [getForegroundPermissionsAsync, requestForegroundPermissionsAsync],
|
|
@@ -35,7 +27,7 @@ let stateListener // 缓存监听函数
|
|
|
35
27
|
let appStateSubscription: NativeEventSubscription | undefined
|
|
36
28
|
|
|
37
29
|
const getAuthSetting = async () => {
|
|
38
|
-
|
|
30
|
+
let auths = {}
|
|
39
31
|
|
|
40
32
|
await Promise.all(Object.keys(scopeMap).map(async key => {
|
|
41
33
|
const { granted } = await scopeMap[key][0]()
|
|
@@ -55,7 +47,7 @@ const handleAppStateChange = async (_nextAppState, resolve, reject, opts) => {
|
|
|
55
47
|
res.errMsg = 'openSetting:ok'
|
|
56
48
|
success?.(res)
|
|
57
49
|
complete?.(res)
|
|
58
|
-
|
|
50
|
+
|
|
59
51
|
appStateSubscription?.remove()
|
|
60
52
|
resolve(res)
|
|
61
53
|
} catch (error) {
|
|
@@ -67,39 +59,39 @@ const handleAppStateChange = async (_nextAppState, resolve, reject, opts) => {
|
|
|
67
59
|
}
|
|
68
60
|
}
|
|
69
61
|
// AppState.currentState = nextAppState;
|
|
70
|
-
}
|
|
62
|
+
};
|
|
71
63
|
|
|
72
64
|
export async function authorize(opts: Taro.authorize.Option): Promise<TaroGeneral.CallbackResult> {
|
|
73
65
|
const { scope, success, fail, complete } = opts
|
|
74
66
|
const res: any = {}
|
|
75
67
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
try {
|
|
69
|
+
const { granted } = await scopeMap[scope][1]()
|
|
70
|
+
if (granted) {
|
|
71
|
+
res.errMsg = 'authorize:ok'
|
|
72
|
+
return successHandler(success, complete)(res)
|
|
73
|
+
} else {
|
|
74
|
+
res.errMsg = 'authorize:denied/undetermined'
|
|
75
|
+
return errorHandler(fail, complete)(res)
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
res.errMsg = 'authorize:fail'
|
|
83
79
|
return errorHandler(fail, complete)(res)
|
|
84
80
|
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
res.errMsg = 'authorize:fail'
|
|
87
|
-
return errorHandler(fail, complete)(res)
|
|
88
|
-
}
|
|
89
81
|
}
|
|
90
82
|
|
|
91
83
|
export async function getSetting(opts: Taro.getSetting.Option = {}): Promise<Taro.getSetting.SuccessCallbackResult> {
|
|
92
84
|
const { success, fail, complete } = opts
|
|
93
85
|
const res: any = {}
|
|
94
86
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
try {
|
|
88
|
+
res.authSetting = await getAuthSetting()
|
|
89
|
+
res.errMsg = 'getSetting:ok'
|
|
90
|
+
return successHandler(success, complete)(res)
|
|
91
|
+
} catch (error) {
|
|
92
|
+
res.errMsg = 'getSetting:fail'
|
|
93
|
+
return errorHandler(fail, complete)(res)
|
|
94
|
+
}
|
|
103
95
|
}
|
|
104
96
|
|
|
105
97
|
export function openSetting(opts: Taro.openSetting.Option = {}): Promise<Taro.openSetting.SuccessCallbackResult> {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
import ImageViewer from 'react-native-image-zoom-viewer'
|
|
2
|
+
import { View, ActivityIndicator, StyleSheet, Alert, Modal } from 'react-native'
|
|
4
3
|
import RootSiblings from 'react-native-root-siblings'
|
|
5
|
-
|
|
6
|
-
import { downloadFile } from '../file'
|
|
4
|
+
import ImageViewer from 'react-native-image-zoom-viewer'
|
|
7
5
|
import { saveMedia } from '../media'
|
|
6
|
+
import { downloadFile } from '../file'
|
|
8
7
|
|
|
9
8
|
const styles = StyleSheet.create({
|
|
10
9
|
mask: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { removeStorageSync } from '../unsupportedApi'
|
|
1
|
+
export { removeStorageSync } from '../unsupportedApi'
|
package/src/lib/request/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { errorHandler, successHandler } from
|
|
1
|
+
import { errorHandler, successHandler } from "../../utils"
|
|
2
2
|
|
|
3
3
|
function serializeParams(params) {
|
|
4
4
|
if (!params) {
|
|
@@ -53,7 +53,7 @@ function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
|
|
|
53
53
|
params.method = method
|
|
54
54
|
let controller
|
|
55
55
|
// eslint-disable-next-line no-undef
|
|
56
|
-
if (typeof
|
|
56
|
+
if (typeof(AbortController) !== 'undefined' ) {
|
|
57
57
|
// eslint-disable-next-line no-undef
|
|
58
58
|
controller = new AbortController()
|
|
59
59
|
const signal = controller.signal
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { BarCodeScanner, requestPermissionsAsync } from 'expo-barcode-scanner'
|
|
2
|
-
import { BarcodeType, CameraView } from 'expo-camera'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
import { BackHandler, Dimensions, Image, Platform, StatusBar, StyleSheet, TouchableOpacity, View } from 'react-native'
|
|
5
|
-
import RootSiblings from 'react-native-root-siblings'
|
|
6
1
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
7
|
-
|
|
8
|
-
import {
|
|
2
|
+
import { Camera } from 'expo-camera'
|
|
3
|
+
import { BarCodeScanner, requestPermissionsAsync } from 'expo-barcode-scanner'
|
|
4
|
+
import { BackHandler, Image, TouchableOpacity, StyleSheet, View, Dimensions, Platform, StatusBar } from 'react-native'
|
|
9
5
|
import iconClose from './icon_close.png'
|
|
10
6
|
import iconPic from './icon_pic.png'
|
|
7
|
+
import RootSiblings from 'react-native-root-siblings'
|
|
8
|
+
import { chooseMedia, MEDIA_TYPE } from '../media'
|
|
9
|
+
import React from 'react'
|
|
11
10
|
|
|
12
11
|
export let scannerView
|
|
13
12
|
|
|
@@ -48,15 +47,13 @@ function findKey (value:string, data, compare = (a, b) => a === b):string {
|
|
|
48
47
|
|
|
49
48
|
const { width, height } = Dimensions.get('screen')
|
|
50
49
|
|
|
51
|
-
function getBarCodeTypes(types:string[]):
|
|
52
|
-
const result:
|
|
53
|
-
|
|
50
|
+
function getBarCodeTypes(types:string[]):string[] {
|
|
51
|
+
const result:string[] = []
|
|
54
52
|
for (const t of types) {
|
|
55
53
|
result.push(...typeMap[t].map(type => {
|
|
56
54
|
return BarCodeType[type]
|
|
57
55
|
}))
|
|
58
56
|
}
|
|
59
|
-
|
|
60
57
|
return result.filter(r => !!r)
|
|
61
58
|
}
|
|
62
59
|
|
|
@@ -151,20 +148,20 @@ function scanFromPhoto(callback, errorCallBack) {
|
|
|
151
148
|
|
|
152
149
|
export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.scanCode.SuccessCallbackResult> {
|
|
153
150
|
const { success, fail, complete, onlyFromCamera, scanType = ['barCode', 'qrCode'] } = option
|
|
154
|
-
const { granted } = await requestPermissionsAsync()
|
|
151
|
+
const { granted } = await requestPermissionsAsync();
|
|
155
152
|
if (!granted) {
|
|
156
153
|
const res = { errMsg: 'Permissions denied!' }
|
|
157
154
|
fail?.(res)
|
|
158
155
|
complete?.(res)
|
|
159
156
|
return Promise.reject(res)
|
|
160
157
|
}
|
|
161
|
-
const
|
|
158
|
+
const barCodeTypes = getBarCodeTypes(scanType)
|
|
162
159
|
return new Promise((resolve, reject) => {
|
|
163
160
|
scannerView = new RootSiblings(
|
|
164
161
|
(<View style={[styles.container]}>
|
|
165
162
|
<StatusBar backgroundColor="rgba(0, 0, 0, 0)" translucent hidden={Platform.OS === 'ios'} />
|
|
166
|
-
<
|
|
167
|
-
|
|
163
|
+
<Camera
|
|
164
|
+
onBarCodeScanned={({ type, data }: {type: string, data: string}) => {
|
|
168
165
|
const res = {
|
|
169
166
|
charSet: 'UTF-8', // todo
|
|
170
167
|
path: '', // todo
|
|
@@ -178,10 +175,11 @@ export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.
|
|
|
178
175
|
hide(scannerView)
|
|
179
176
|
resolve(res)
|
|
180
177
|
}}
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
barCodeScannerSettings={{
|
|
179
|
+
barCodeTypes,
|
|
183
180
|
}}
|
|
184
181
|
style={{ width, height }}
|
|
182
|
+
ratio='16:9'
|
|
185
183
|
/>
|
|
186
184
|
<TouchableOpacity accessibilityLabel="Close" style={styles.closeIcon} onPress={() => hide(scannerView)}>
|
|
187
185
|
{safeViewWrapper(<Image source={iconClose} style={styles.closeImg}/>)}
|
package/src/lib/screen.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Clipboard from '@react-native-clipboard/clipboard'
|
|
2
|
-
|
|
3
|
-
import { errorHandler, successHandler } from '../../utils'
|
|
4
2
|
import { showToast } from '../showModal/toast'
|
|
3
|
+
import { successHandler, errorHandler } from '../../utils'
|
|
5
4
|
|
|
6
5
|
export function setClipboardData(opts: Taro.setClipboardData.Option): Promise<Taro.setClipboardData.Promised> {
|
|
7
6
|
const { data, success, fail, complete } = opts
|
|
@@ -19,7 +18,7 @@ export function setClipboardData(opts: Taro.setClipboardData.Option): Promise<Ta
|
|
|
19
18
|
data,
|
|
20
19
|
}
|
|
21
20
|
showToast({
|
|
22
|
-
icon:
|
|
21
|
+
icon: "none",
|
|
23
22
|
title: '内容已复制'
|
|
24
23
|
})
|
|
25
24
|
return successHandler(success, complete)(res)
|