@tarojs/taro-rn 4.0.1 → 4.0.2
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 +20 -13
- 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 +3 -151
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseMedia/index.js +19 -0
- package/dist/lib/chooseMedia/index.js.map +1 -0
- package/dist/lib/chooseVideo/index.js +1 -55
- 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 +8 -4
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +11 -6
- 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 +1 -0
- 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 +61 -30
- 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 +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 +11 -23
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +10 -24
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +22 -36
- 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/libList.js +1 -0
- package/package.json +70 -69
- 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 +26 -19
- 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/chooseImage/index.ts +3 -155
- package/src/lib/chooseMedia/index.ts +15 -0
- package/src/lib/chooseVideo/index.ts +1 -56
- 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 +7 -2
- package/src/lib/getRecorderManager/index.ts +7 -2
- 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/index.ts +1 -0
- 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 +83 -31
- 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 +18 -16
- 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 +34 -43
- package/src/lib/showActionSheet/index.tsx +11 -36
- package/src/lib/showModal/Dialog.tsx +34 -39
- package/src/lib/showModal/index.tsx +1 -0
- package/src/lib/showModal/toast.tsx +14 -13
- 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 -75
- package/dist/setup.js.map +0 -1
- package/src/__tests__/__mock__/mockAsyncStorage.js +0 -47
- package/src/__tests__/__mock__/mockClipboard.js +0 -15
- package/src/__tests__/__mock__/mockNavigator.js +0 -20
- package/src/__tests__/__mock__/mockNetwork.js +0 -59
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +0 -16
- package/src/__tests__/__mock__/mockRNCGeolocation.js +0 -13
- package/src/__tests__/__mock__/mockVibrate.js +0 -6
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +0 -125
- 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 -169
- package/src/setup.ts +0 -84
- /package/{src/types → types}/definition.d.ts +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { Camera } from 'expo-camera'
|
|
2
|
+
|
|
1
3
|
import { errorHandler, successHandler } from '../../utils'
|
|
2
|
-
|
|
4
|
+
|
|
3
5
|
const globalAny: any = global
|
|
4
6
|
|
|
5
7
|
class CameraContext {
|
|
@@ -14,8 +16,8 @@ class CameraContext {
|
|
|
14
16
|
* 开始录像
|
|
15
17
|
*/
|
|
16
18
|
startRecord = (option: Taro.CameraContext.StartRecordOption) => {
|
|
17
|
-
Promise.all([requestCameraPermissionsAsync(), requestMicrophonePermissionsAsync()]).then(([cameraPermission, microphonePermission]) => {
|
|
18
|
-
if(cameraPermission.granted && microphonePermission.granted) {
|
|
19
|
+
Promise.all([Camera.requestCameraPermissionsAsync(), Camera.requestMicrophonePermissionsAsync()]).then(([cameraPermission, microphonePermission]) => {
|
|
20
|
+
if (cameraPermission.granted && microphonePermission.granted) {
|
|
19
21
|
this.cameraRef?.recordAsync().then((res) => {
|
|
20
22
|
const { uri } = res
|
|
21
23
|
const result = {
|
|
@@ -76,7 +78,7 @@ class CameraContext {
|
|
|
76
78
|
break
|
|
77
79
|
}
|
|
78
80
|
try {
|
|
79
|
-
const { granted } = await requestCameraPermissionsAsync()
|
|
81
|
+
const { granted } = await Camera.requestCameraPermissionsAsync()
|
|
80
82
|
if (granted) {
|
|
81
83
|
if (this.cameraRef?.takePictureAsync) {
|
|
82
84
|
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,6 +1,7 @@
|
|
|
1
1
|
import Taro from '@tarojs/taro'
|
|
2
2
|
import { DeviceMotion } from 'expo-sensors'
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import { createCallbackManager, errorHandler, successHandler } from '../utils'
|
|
4
5
|
|
|
5
6
|
const _cbManager = createCallbackManager()
|
|
6
7
|
let _listener: any
|
|
@@ -44,7 +45,7 @@ function startDeviceMotionListening (object: Taro.startDeviceMotionListening.Opt
|
|
|
44
45
|
_cbManager.trigger(rotation)
|
|
45
46
|
})
|
|
46
47
|
DeviceMotion.setUpdateInterval(intervalMap[interval] || intervalMap.normal)
|
|
47
|
-
|
|
48
|
+
|
|
48
49
|
return successHandler(success, complete)(res)
|
|
49
50
|
} catch (error) {
|
|
50
51
|
res.errMsg = 'startDeviceMotionListening:fail'
|
|
@@ -71,8 +72,8 @@ function stopDeviceMotionListening (object: Taro.stopDeviceMotionListening.Optio
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export {
|
|
74
|
-
onDeviceMotionChange,
|
|
75
75
|
offDeviceMotionChange,
|
|
76
|
+
onDeviceMotionChange,
|
|
76
77
|
startDeviceMotionListening,
|
|
77
78
|
stopDeviceMotionListening
|
|
78
79
|
}
|
package/src/lib/file.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as FileSystem from 'expo-file-system'
|
|
2
2
|
import { Platform } from 'react-native'
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import { errorHandler, shouldBeObject, successHandler } from '../utils'
|
|
4
5
|
|
|
5
6
|
interface Func {
|
|
6
7
|
(arg: any): void
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
interface ExtPromise<T> extends Promise<T> {
|
|
10
|
-
onProgressUpdateCb?: Func
|
|
11
|
-
onProgressUpdate?: Func
|
|
11
|
+
onProgressUpdateCb?: Func
|
|
12
|
+
onProgressUpdate?: Func
|
|
12
13
|
abort?: Func
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -339,10 +340,10 @@ async function getFileInfo (opts: Taro.getFileInfo.Option): Promise<Taro.getFile
|
|
|
339
340
|
|
|
340
341
|
export {
|
|
341
342
|
downloadFile,
|
|
342
|
-
|
|
343
|
-
saveFile,
|
|
344
|
-
removeSavedFile,
|
|
345
|
-
getSavedFileList,
|
|
343
|
+
getFileInfo,
|
|
346
344
|
getSavedFileInfo,
|
|
347
|
-
|
|
345
|
+
getSavedFileList,
|
|
346
|
+
removeSavedFile,
|
|
347
|
+
saveFile,
|
|
348
|
+
uploadFile
|
|
348
349
|
}
|
package/src/lib/getEnv/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getFileSystemManager } from '../unsupportedApi'
|
|
1
|
+
export { getFileSystemManager } from '../unsupportedApi'
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import Geolocation from '@react-native-community/geolocation'
|
|
2
|
-
|
|
2
|
+
|
|
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
|
+
}
|
|
7
12
|
|
|
8
13
|
try {
|
|
9
14
|
// @ts-ignore
|
|
10
15
|
// todo: fix types
|
|
11
|
-
const { granted } = await
|
|
16
|
+
const { granted } = await requestAuthorization()
|
|
12
17
|
if (!granted) {
|
|
13
18
|
const res = { errMsg: 'Permissions denied!' }
|
|
14
19
|
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, //InterruptionModeAndroid.DoNotMix
|
|
84
|
+
interruptionModeAndroid: 1, // InterruptionModeAndroid.DoNotMix
|
|
85
85
|
playThroughEarpieceAndroid: true
|
|
86
86
|
} as any)
|
|
87
87
|
|
|
@@ -151,7 +151,12 @@ class RecorderManager {
|
|
|
151
151
|
const info = await FileSystem.getInfoAsync(uri)
|
|
152
152
|
// console.log(`FILE INFO: ${JSON.stringify(info)}`)
|
|
153
153
|
|
|
154
|
-
const result = {
|
|
154
|
+
const result = {
|
|
155
|
+
tempFilePath: uri,
|
|
156
|
+
duration: recordStatus.durationMillis,
|
|
157
|
+
// @ts-ignore
|
|
158
|
+
fileSize: info.size
|
|
159
|
+
}
|
|
155
160
|
this.onStopCallback && this.onStopCallback(result)
|
|
156
161
|
}
|
|
157
162
|
} 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'
|
|
1
2
|
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,
|
|
3
2
|
Dimensions,
|
|
4
3
|
PixelRatio,
|
|
4
|
+
Platform,
|
|
5
5
|
StatusBar
|
|
6
6
|
} from 'react-native'
|
|
7
|
-
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
8
7
|
import DeviceInfo from 'react-native-device-info'
|
|
8
|
+
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
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(Platform.OS === 'android') { top = StatusBar.currentHeight || 0
|
|
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,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/index.ts
CHANGED
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,16 +1,21 @@
|
|
|
1
|
-
import { CameraRoll } from
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { CameraRoll } from '@react-native-camera-roll/camera-roll'
|
|
2
|
+
import { Camera } from 'expo-camera'
|
|
3
|
+
import {
|
|
4
|
+
ImagePickerAsset,
|
|
5
|
+
launchCameraAsync,
|
|
6
|
+
launchImageLibraryAsync,
|
|
7
|
+
MediaTypeOptions,
|
|
8
|
+
requestMediaLibraryPermissionsAsync,
|
|
9
|
+
} from 'expo-image-picker'
|
|
5
10
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
import { errorHandler, successHandler } from '../utils'
|
|
12
|
+
import { showActionSheet } from './showActionSheet'
|
|
13
|
+
|
|
14
|
+
export const MEDIA_TYPE = MediaTypeOptions
|
|
10
15
|
|
|
11
16
|
export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.saveVideoToPhotosAlbum.Option, type:string, API:string):Promise<TaroGeneral.CallbackResult> {
|
|
12
17
|
const { filePath, success, fail, complete } = opts
|
|
13
|
-
const { granted } = await
|
|
18
|
+
const { granted } = await requestMediaLibraryPermissionsAsync()
|
|
14
19
|
if (!granted) {
|
|
15
20
|
const res = { errMsg: 'Permissions denied!' }
|
|
16
21
|
return errorHandler(fail, complete)(res)
|
|
@@ -20,7 +25,7 @@ export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.
|
|
|
20
25
|
const saveType = (type === 'video' || type === 'photo') ? type : 'auto'
|
|
21
26
|
try {
|
|
22
27
|
const url: string = await CameraRoll.save(filePath, { type: saveType })
|
|
23
|
-
res.path = url
|
|
28
|
+
res.path = url
|
|
24
29
|
return successHandler(success, complete)(res)
|
|
25
30
|
} catch (err) {
|
|
26
31
|
res.errMsg = err.message
|
|
@@ -28,54 +33,101 @@ export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.
|
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
async function showPicker(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option | Taro.chooseMedia.Option, mediaTypes: MediaTypeOptions):Promise<any> {
|
|
37
|
+
const { fail, complete } = opts
|
|
38
|
+
try {
|
|
39
|
+
const res = await showActionSheet({
|
|
40
|
+
itemList: ['拍摄', '从手机相册选择'],
|
|
41
|
+
})
|
|
42
|
+
if (res.tapIndex === 0) {
|
|
43
|
+
return _chooseMedia({ ...opts, sourceType: ['camera'] }, mediaTypes)
|
|
44
|
+
}
|
|
45
|
+
if (res.tapIndex === 1) {
|
|
46
|
+
return _chooseMedia({ ...opts, sourceType: ['album'] }, mediaTypes)
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
const res = {
|
|
50
|
+
errMsg: `choose${
|
|
51
|
+
mediaTypes === MediaTypeOptions.Images ? 'Image' : mediaTypes === MediaTypeOptions.Videos ? 'Video' : 'Media'
|
|
52
|
+
} fail`
|
|
53
|
+
}
|
|
54
|
+
fail?.(res)
|
|
55
|
+
complete?.(res)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option | Taro.chooseMedia.Option = {}, mediaTypes: MediaTypeOptions): Promise<TaroGeneral.CallbackResult> {
|
|
60
|
+
const {
|
|
61
|
+
sourceType = ['album', 'camera'],
|
|
62
|
+
} = opts
|
|
63
|
+
if (sourceType?.includes('camera') && sourceType?.includes('album')) {
|
|
64
|
+
return showPicker(opts, mediaTypes)
|
|
65
|
+
} else if (sourceType?.includes('camera')) {
|
|
66
|
+
return _chooseMedia({ ...opts, sourceType: ['camera'] }, mediaTypes)
|
|
34
67
|
}
|
|
35
|
-
|
|
68
|
+
return _chooseMedia({ ...opts, sourceType: ['album'] }, mediaTypes)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function _chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option | Taro.chooseMedia.Option = {}, mediaTypes: MediaTypeOptions): Promise<TaroGeneral.CallbackResult> {
|
|
72
|
+
const {
|
|
73
|
+
sizeType = [],
|
|
74
|
+
sourceType = [],
|
|
75
|
+
success,
|
|
76
|
+
fail,
|
|
77
|
+
complete,
|
|
78
|
+
maxDuration,
|
|
79
|
+
count = (mediaTypes === MEDIA_TYPE.Videos ? 1 : 9),
|
|
80
|
+
compressed
|
|
81
|
+
} = opts as any
|
|
36
82
|
const options = {
|
|
37
83
|
mediaTypes,
|
|
38
|
-
quality: sizeType[0] === 'compressed' ? 0.7 : 1,
|
|
39
|
-
videoMaxDuration: maxDuration
|
|
84
|
+
quality: (sizeType[0] === 'compressed' || compressed) ? 0.7 : 1,
|
|
85
|
+
videoMaxDuration: maxDuration,
|
|
86
|
+
allowsMultipleSelection: count > 1,
|
|
87
|
+
selectionLimit: count,
|
|
40
88
|
}
|
|
89
|
+
const messString = mediaTypes === MediaTypeOptions.Images ? 'Image' : mediaTypes === MediaTypeOptions.Videos ? 'Video' : 'Media'
|
|
41
90
|
const isCamera = sourceType[0] === 'camera'
|
|
42
|
-
const { granted } = isCamera ? await requestCameraPermissionsAsync() : await
|
|
91
|
+
const { granted } = isCamera ? await Camera.requestCameraPermissionsAsync() : await requestMediaLibraryPermissionsAsync()
|
|
43
92
|
if (!granted) {
|
|
44
93
|
const res = { errMsg: 'Permissions denied!' }
|
|
45
94
|
return errorHandler(fail, complete)(res)
|
|
46
95
|
}
|
|
47
96
|
|
|
48
|
-
|
|
97
|
+
const launchMediaAsync = isCamera ? launchCameraAsync : launchImageLibraryAsync
|
|
49
98
|
try {
|
|
50
|
-
const resp
|
|
51
|
-
const { uri, duration, width, height } = resp
|
|
52
|
-
resp.path = uri
|
|
53
|
-
|
|
99
|
+
const resp = await launchMediaAsync(options)
|
|
54
100
|
let res: any = {}
|
|
55
|
-
if (mediaTypes === MEDIA_TYPE.
|
|
101
|
+
if (mediaTypes === MEDIA_TYPE.Videos) {
|
|
102
|
+
const asset = resp.assets?.[0]
|
|
56
103
|
res = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
height
|
|
104
|
+
...asset,
|
|
105
|
+
tempFilePath: asset?.uri,
|
|
106
|
+
size: asset?.fileSize,
|
|
61
107
|
}
|
|
62
108
|
} else {
|
|
63
109
|
res = {
|
|
64
|
-
tempFilePaths:
|
|
65
|
-
tempFiles:
|
|
110
|
+
tempFilePaths: resp.assets?.map((item) => item.uri),
|
|
111
|
+
tempFiles: resp.assets?.map((item: ImagePickerAsset) => ({
|
|
112
|
+
...item,
|
|
113
|
+
path: item.uri,
|
|
114
|
+
size: item.fileSize,
|
|
115
|
+
type: item.mimeType,
|
|
116
|
+
fileType: item.mimeType?.startsWith('video') ? 'video' : 'image',
|
|
117
|
+
}))
|
|
66
118
|
}
|
|
67
119
|
}
|
|
68
120
|
if (res.tempFilePath || (!!res.tempFilePaths && res.tempFilePaths.length > 0)) {
|
|
69
121
|
return successHandler(success, complete)(res)
|
|
70
122
|
} else {
|
|
71
123
|
const res = {
|
|
72
|
-
errMsg:
|
|
124
|
+
errMsg: `choose${messString}:fail cancel`
|
|
73
125
|
}
|
|
74
126
|
return errorHandler(fail, complete)(res)
|
|
75
127
|
}
|
|
76
128
|
} catch (err) {
|
|
77
129
|
const res = {
|
|
78
|
-
errMsg:
|
|
130
|
+
errMsg: `choose${messString}:fail`,
|
|
79
131
|
err
|
|
80
132
|
}
|
|
81
133
|
return errorHandler(fail, complete)(res)
|
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
|
+
}
|