@tarojs/taro-rn 4.0.1-alpha.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -8
- package/apiList.js +31 -31
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/lib/Mask.js +2 -2
- package/dist/lib/Mask.js.map +1 -1
- package/dist/lib/Popup.js +13 -20
- package/dist/lib/Popup.js.map +1 -1
- package/dist/lib/StyleSheet.js +1 -1
- package/dist/lib/StyleSheet.js.map +1 -1
- package/dist/lib/accelerometer.js +1 -1
- package/dist/lib/accelerometer.js.map +1 -1
- package/dist/lib/chooseImage/index.js +151 -3
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseVideo/index.js +55 -1
- package/dist/lib/chooseVideo/index.js.map +1 -1
- package/dist/lib/clearStorage/index.js +2 -2
- package/dist/lib/clearStorage/index.js.map +1 -1
- package/dist/lib/compressImage/index.js +1 -1
- package/dist/lib/compressImage/index.js.map +1 -1
- package/dist/lib/connectSocket/index.js.map +1 -1
- package/dist/lib/connectSocket/socketTask.js +1 -1
- package/dist/lib/connectSocket/socketTask.js.map +1 -1
- package/dist/lib/createCameraContext/index.js +3 -3
- package/dist/lib/createCameraContext/index.js.map +1 -1
- package/dist/lib/createInnerAudioContext/index.js +2 -2
- package/dist/lib/createInnerAudioContext/index.js.map +1 -1
- package/dist/lib/createVideoContext/index.js +7 -7
- package/dist/lib/createVideoContext/index.js.map +1 -1
- package/dist/lib/deviceMotion.js +2 -2
- package/dist/lib/deviceMotion.js.map +1 -1
- package/dist/lib/file.js +4 -4
- package/dist/lib/file.js.map +1 -1
- package/dist/lib/getAppBaseInfo/index.js +2 -2
- package/dist/lib/getAppBaseInfo/index.js.map +1 -1
- package/dist/lib/getClipboardData/index.js.map +1 -1
- package/dist/lib/getImageInfo/index.js +2 -2
- package/dist/lib/getImageInfo/index.js.map +1 -1
- package/dist/lib/getLocation/index.js +4 -8
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +6 -11
- package/dist/lib/getRecorderManager/index.js.map +1 -1
- package/dist/lib/getStorage/index.js.map +1 -1
- package/dist/lib/getStorageInfo/index.js +2 -2
- package/dist/lib/getStorageInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfo/index.js +1 -1
- package/dist/lib/getSystemInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfoSync/index.js +2 -2
- package/dist/lib/getSystemInfoSync/index.js.map +1 -1
- package/dist/lib/gyroscope.js +1 -1
- package/dist/lib/gyroscope.js.map +1 -1
- package/dist/lib/index.js +0 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/keyboard.js +3 -3
- package/dist/lib/keyboard.js.map +1 -1
- package/dist/lib/location.js.map +1 -1
- package/dist/lib/makePhoneCall/index.js +1 -1
- package/dist/lib/makePhoneCall/index.js.map +1 -1
- package/dist/lib/media.js +30 -61
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/network.js +1 -1
- package/dist/lib/network.js.map +1 -1
- package/dist/lib/offWindowResize/index.js.map +1 -1
- package/dist/lib/onWindowResize/index.js +1 -1
- package/dist/lib/onWindowResize/index.js.map +1 -1
- package/dist/lib/openUrl/index.js +1 -1
- package/dist/lib/openUrl/index.js.map +1 -1
- package/dist/lib/permission.js +5 -6
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/previewImage/index.js +3 -3
- package/dist/lib/previewImage/index.js.map +1 -1
- package/dist/lib/request/index.js +1 -1
- package/dist/lib/request/index.js.map +1 -1
- package/dist/lib/scanCode/index.js +23 -23
- package/dist/lib/scanCode/index.js.map +1 -1
- package/dist/lib/screen.js +2 -2
- package/dist/lib/screen.js.map +1 -1
- package/dist/lib/setClipboardData/index.js +2 -2
- package/dist/lib/setClipboardData/index.js.map +1 -1
- package/dist/lib/setKeepScreenOn/index.js +1 -1
- package/dist/lib/setKeepScreenOn/index.js.map +1 -1
- package/dist/lib/setStorage/index.js.map +1 -1
- package/dist/lib/showActionSheet/ActionSheet.js +23 -11
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +24 -10
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +36 -22
- package/dist/lib/showModal/Dialog.js.map +1 -1
- package/dist/lib/showModal/index.js.map +1 -1
- package/dist/lib/showModal/toast.js +6 -6
- package/dist/lib/showModal/toast.js.map +1 -1
- package/dist/lib/unsupportedApi.js +4 -2
- package/dist/lib/unsupportedApi.js.map +1 -1
- package/dist/lib/variable.js +1 -1
- package/dist/lib/variable.js.map +1 -1
- package/dist/lib/vibrate.js +1 -1
- package/dist/lib/vibrate.js.map +1 -1
- package/dist/lib/window.js.map +1 -1
- package/dist/setup.js +75 -0
- package/dist/setup.js.map +1 -0
- package/dist/utils/callbackManager.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/libList.js +0 -1
- package/package.json +69 -70
- package/src/__tests__/__mock__/mockAsyncStorage.js +47 -0
- package/src/__tests__/__mock__/mockClipboard.js +15 -0
- package/src/__tests__/__mock__/mockNavigator.js +20 -0
- package/src/__tests__/__mock__/mockNetwork.js +59 -0
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +16 -0
- package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
- package/src/__tests__/__mock__/mockVibrate.js +6 -0
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +125 -0
- package/src/__tests__/clipboard.test.ts +88 -0
- package/src/__tests__/deviceMotion.test.ts +37 -0
- package/src/__tests__/geolocation.test.ts +60 -0
- package/src/__tests__/interactive.test.tsx +101 -0
- package/src/__tests__/keyboard.test.ts +46 -0
- package/src/__tests__/media.test.ts +104 -0
- package/src/__tests__/network.test.ts +57 -0
- package/src/__tests__/others.test.ts +25 -0
- package/src/__tests__/phone.test.ts +31 -0
- package/src/__tests__/request.test.ts +146 -0
- package/src/__tests__/scanCode.test.tsx +14 -0
- package/src/__tests__/storage.test.ts +202 -0
- package/src/__tests__/system.test.ts +69 -0
- package/src/__tests__/vibrate.test.ts +27 -0
- package/src/__tests__/websocket.test.ts +169 -0
- package/src/api/index.ts +31 -31
- package/src/lib/ENV_TYPE/index.ts +1 -1
- package/src/lib/Mask.tsx +2 -2
- package/src/lib/Popup.tsx +19 -26
- package/src/lib/StyleSheet.ts +1 -1
- package/src/lib/accelerometer.ts +1 -2
- package/src/lib/arrayBufferToBase64/index.ts +1 -1
- package/src/lib/base64ToArrayBuffer/index.ts +1 -1
- package/src/lib/chooseImage/index.ts +155 -3
- package/src/lib/chooseVideo/index.ts +56 -1
- package/src/lib/clearStorage/index.ts +0 -1
- package/src/lib/clearStorageSync/index.ts +1 -1
- package/src/lib/compressImage/index.ts +0 -1
- package/src/lib/connectSocket/socketTask.ts +9 -7
- package/src/lib/createCameraContext/index.ts +4 -6
- package/src/lib/createInnerAudioContext/index.ts +0 -1
- package/src/lib/createSelectorQuery/index.ts +1 -1
- package/src/lib/deviceMotion.ts +3 -4
- package/src/lib/file.ts +8 -9
- package/src/lib/getClipboardData/index.ts +0 -1
- package/src/lib/getEnv/index.ts +1 -1
- package/src/lib/getFileSystemManager/index.ts +1 -1
- package/src/lib/getLocation/index.ts +2 -7
- package/src/lib/getRecorderManager/index.ts +2 -7
- package/src/lib/getStorage/index.ts +0 -1
- package/src/lib/getStorageInfo/index.ts +0 -1
- package/src/lib/getStorageInfoSync/index.ts +1 -1
- package/src/lib/getStorageSync/index.ts +1 -1
- package/src/lib/getSystemInfo/index.ts +2 -2
- package/src/lib/getSystemInfoSync/index.ts +3 -3
- package/src/lib/gyroscope.ts +46 -47
- package/src/lib/index.ts +0 -1
- package/src/lib/keyboard.ts +4 -5
- package/src/lib/location.ts +5 -6
- package/src/lib/makePhoneCall/index.ts +1 -2
- package/src/lib/media.ts +31 -83
- package/src/lib/network.ts +5 -5
- package/src/lib/offLocationChange/index.ts +1 -1
- package/src/lib/offUserCaptureScreen/index.ts +1 -1
- package/src/lib/onLocationChange/index.ts +1 -1
- package/src/lib/onUserCaptureScreen/index.ts +1 -1
- package/src/lib/onWindowResize/index.ts +2 -2
- package/src/lib/openUrl/index.d.ts +22 -23
- package/src/lib/openUrl/index.ts +1 -2
- package/src/lib/permission.ts +25 -33
- package/src/lib/previewImage/index.tsx +3 -4
- package/src/lib/removeStorageSync/index.ts +1 -1
- package/src/lib/request/index.ts +2 -2
- package/src/lib/scanCode/index.tsx +16 -18
- package/src/lib/screen.ts +0 -1
- package/src/lib/setClipboardData/index.ts +2 -3
- package/src/lib/setKeepScreenOn/index.ts +1 -2
- package/src/lib/setStorage/index.ts +0 -1
- package/src/lib/setStorageSync/index.ts +1 -1
- package/src/lib/showActionSheet/ActionSheet.tsx +43 -34
- package/src/lib/showActionSheet/index.tsx +36 -11
- package/src/lib/showModal/Dialog.tsx +39 -34
- package/src/lib/showModal/index.tsx +0 -1
- package/src/lib/showModal/toast.tsx +13 -14
- package/src/lib/startGyroscope/index.ts +1 -1
- package/src/lib/startLocationUpdate/index.ts +1 -1
- package/src/lib/unsupportedApi.ts +5 -3
- package/src/lib/vibrate.ts +10 -11
- package/src/lib/window.ts +2 -3
- package/src/setup.ts +84 -0
- package/{types → src/types}/vue/index.d.ts +3 -2
- package/src/utils/callbackManager.ts +5 -5
- package/src/utils/index.ts +4 -4
- package/dist/lib/chooseMedia/index.js +0 -19
- package/dist/lib/chooseMedia/index.js.map +0 -1
- package/src/lib/chooseMedia/index.ts +0 -15
- /package/{types → src/types}/definition.d.ts +0 -0
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,21 +1,16 @@
|
|
|
1
|
-
import { CameraRoll } from
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
launchCameraAsync,
|
|
6
|
-
launchImageLibraryAsync,
|
|
7
|
-
MediaTypeOptions,
|
|
8
|
-
requestMediaLibraryPermissionsAsync,
|
|
9
|
-
} from 'expo-image-picker'
|
|
1
|
+
import { CameraRoll } from "@react-native-camera-roll/camera-roll"
|
|
2
|
+
import { requestCameraPermissionsAsync } from 'expo-camera'
|
|
3
|
+
import * as ImagePicker from 'expo-image-picker'
|
|
4
|
+
import { successHandler, errorHandler } from '../utils'
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export const MEDIA_TYPE = {
|
|
7
|
+
VIDEOS: 'Videos',
|
|
8
|
+
IMAGES: 'Images'
|
|
9
|
+
}
|
|
15
10
|
|
|
16
11
|
export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.saveVideoToPhotosAlbum.Option, type:string, API:string):Promise<TaroGeneral.CallbackResult> {
|
|
17
12
|
const { filePath, success, fail, complete } = opts
|
|
18
|
-
const { granted } = await requestMediaLibraryPermissionsAsync()
|
|
13
|
+
const { granted } = await ImagePicker.requestMediaLibraryPermissionsAsync()
|
|
19
14
|
if (!granted) {
|
|
20
15
|
const res = { errMsg: 'Permissions denied!' }
|
|
21
16
|
return errorHandler(fail, complete)(res)
|
|
@@ -25,7 +20,7 @@ export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.
|
|
|
25
20
|
const saveType = (type === 'video' || type === 'photo') ? type : 'auto'
|
|
26
21
|
try {
|
|
27
22
|
const url: string = await CameraRoll.save(filePath, { type: saveType })
|
|
28
|
-
res.path = url
|
|
23
|
+
res.path = url;
|
|
29
24
|
return successHandler(success, complete)(res)
|
|
30
25
|
} catch (err) {
|
|
31
26
|
res.errMsg = err.message
|
|
@@ -33,101 +28,54 @@ export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.
|
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
async function
|
|
37
|
-
|
|
38
|
-
|
|
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)
|
|
31
|
+
export async function chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option, mediaTypes: string): Promise<TaroGeneral.CallbackResult> {
|
|
32
|
+
if (!opts || typeof opts !== 'object') {
|
|
33
|
+
opts = {}
|
|
67
34
|
}
|
|
68
|
-
|
|
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
|
|
35
|
+
const { sizeType = [], sourceType = [], success, fail, complete, maxDuration } = opts as any
|
|
82
36
|
const options = {
|
|
83
37
|
mediaTypes,
|
|
84
|
-
quality:
|
|
85
|
-
videoMaxDuration: maxDuration
|
|
86
|
-
allowsMultipleSelection: count > 1,
|
|
87
|
-
selectionLimit: count,
|
|
38
|
+
quality: sizeType[0] === 'compressed' ? 0.7 : 1,
|
|
39
|
+
videoMaxDuration: maxDuration
|
|
88
40
|
}
|
|
89
|
-
const messString = mediaTypes === MediaTypeOptions.Images ? 'Image' : mediaTypes === MediaTypeOptions.Videos ? 'Video' : 'Media'
|
|
90
41
|
const isCamera = sourceType[0] === 'camera'
|
|
91
|
-
const { granted } = isCamera ? await
|
|
42
|
+
const { granted } = isCamera ? await requestCameraPermissionsAsync() : await ImagePicker.requestMediaLibraryPermissionsAsync()
|
|
92
43
|
if (!granted) {
|
|
93
44
|
const res = { errMsg: 'Permissions denied!' }
|
|
94
45
|
return errorHandler(fail, complete)(res)
|
|
95
46
|
}
|
|
96
47
|
|
|
97
|
-
|
|
48
|
+
let launchMediaAsync = isCamera ? ImagePicker.launchCameraAsync : ImagePicker.launchImageLibraryAsync
|
|
98
49
|
try {
|
|
99
|
-
const resp = await launchMediaAsync(options)
|
|
50
|
+
const resp: any = await launchMediaAsync(options as any)
|
|
51
|
+
const { uri, duration, width, height } = resp
|
|
52
|
+
resp.path = uri
|
|
53
|
+
|
|
100
54
|
let res: any = {}
|
|
101
|
-
if (mediaTypes === MEDIA_TYPE.
|
|
102
|
-
const asset = resp.assets?.[0]
|
|
55
|
+
if (mediaTypes === MEDIA_TYPE.VIDEOS) {
|
|
103
56
|
res = {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
57
|
+
tempFilePath: uri,
|
|
58
|
+
duration,
|
|
59
|
+
width,
|
|
60
|
+
height
|
|
107
61
|
}
|
|
108
62
|
} else {
|
|
109
63
|
res = {
|
|
110
|
-
tempFilePaths:
|
|
111
|
-
tempFiles: resp
|
|
112
|
-
...item,
|
|
113
|
-
path: item.uri,
|
|
114
|
-
size: item.fileSize,
|
|
115
|
-
type: item.mimeType,
|
|
116
|
-
fileType: item.mimeType?.startsWith('video') ? 'video' : 'image',
|
|
117
|
-
}))
|
|
64
|
+
tempFilePaths: [uri],
|
|
65
|
+
tempFiles: [resp]
|
|
118
66
|
}
|
|
119
67
|
}
|
|
120
68
|
if (res.tempFilePath || (!!res.tempFilePaths && res.tempFilePaths.length > 0)) {
|
|
121
69
|
return successHandler(success, complete)(res)
|
|
122
70
|
} else {
|
|
123
71
|
const res = {
|
|
124
|
-
errMsg:
|
|
72
|
+
errMsg: mediaTypes === MEDIA_TYPE.VIDEOS ? 'chooseVideo:fail cancel' : 'chooseImage:fail cancel',
|
|
125
73
|
}
|
|
126
74
|
return errorHandler(fail, complete)(res)
|
|
127
75
|
}
|
|
128
76
|
} catch (err) {
|
|
129
77
|
const res = {
|
|
130
|
-
errMsg:
|
|
78
|
+
errMsg: mediaTypes === MEDIA_TYPE.VIDEOS ? 'chooseVideo fail' : 'chooseImage fail',
|
|
131
79
|
err
|
|
132
80
|
}
|
|
133
81
|
return errorHandler(fail, complete)(res)
|
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
|
|
|
@@ -146,25 +143,25 @@ function scanFromPhoto(callback, errorCallBack) {
|
|
|
146
143
|
})
|
|
147
144
|
}
|
|
148
145
|
}
|
|
149
|
-
}, MEDIA_TYPE.
|
|
146
|
+
}, MEDIA_TYPE.IMAGES).catch(errorCallBack)
|
|
150
147
|
}
|
|
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)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { setStorageSync } from '../unsupportedApi'
|
|
1
|
+
export { setStorageSync } from '../unsupportedApi'
|