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