@tarojs/taro-rn 3.3.5 → 3.3.9
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/dist/lib/chooseImage/index.js +1 -0
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/clearStorage/index.js +20 -13
- package/dist/lib/clearStorage/index.js.map +1 -1
- package/dist/lib/compressImage/index.js +29 -14
- package/dist/lib/compressImage/index.js.map +1 -1
- package/dist/lib/connectSocket/index.js +6 -6
- package/dist/lib/connectSocket/index.js.map +1 -1
- package/dist/lib/connectSocket/socketTask.js +8 -8
- package/dist/lib/connectSocket/socketTask.js.map +1 -1
- package/dist/lib/createCameraContext/index.js +53 -21
- package/dist/lib/createCameraContext/index.js.map +1 -1
- package/dist/lib/file.js +26 -42
- package/dist/lib/file.js.map +1 -1
- package/dist/lib/getClipboardData/index.js +2 -3
- package/dist/lib/getClipboardData/index.js.map +1 -1
- package/dist/lib/getLocation/index.js +5 -7
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getStorage/index.js +21 -16
- package/dist/lib/getStorage/index.js.map +1 -1
- package/dist/lib/getStorageInfo/index.js +12 -13
- package/dist/lib/getStorageInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfo/index.js +3 -6
- package/dist/lib/getSystemInfo/index.js.map +1 -1
- package/dist/lib/keyboard.js +3 -5
- package/dist/lib/keyboard.js.map +1 -1
- package/dist/lib/makePhoneCall/index.js +3 -6
- package/dist/lib/makePhoneCall/index.js.map +1 -1
- package/dist/lib/media.js +46 -55
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/network.js +4 -4
- package/dist/lib/network.js.map +1 -1
- package/dist/lib/openUrl/index.js +3 -6
- package/dist/lib/openUrl/index.js.map +1 -1
- package/dist/lib/permission.js +20 -29
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/previewImage/index.js +7 -1
- package/dist/lib/previewImage/index.js.map +1 -1
- package/dist/lib/removeStorage/index.js +4 -4
- package/dist/lib/removeStorage/index.js.map +1 -1
- package/dist/lib/request/index.js +31 -42
- package/dist/lib/request/index.js.map +1 -1
- package/dist/lib/setClipboardData/index.js +3 -6
- package/dist/lib/setClipboardData/index.js.map +1 -1
- package/dist/lib/setStorage/index.js +20 -13
- package/dist/lib/setStorage/index.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +4 -4
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/index.js +6 -6
- package/dist/lib/showModal/index.js.map +1 -1
- package/dist/lib/showModal/toast.js +8 -8
- package/dist/lib/showModal/toast.js.map +1 -1
- package/dist/lib/vibrate.js +10 -15
- package/dist/lib/vibrate.js.map +1 -1
- package/package.json +4 -4
- package/src/lib/chooseImage/index.ts +1 -0
- package/src/lib/clearStorage/index.ts +9 -16
- package/src/lib/compressImage/index.ts +17 -15
- package/src/lib/connectSocket/index.ts +6 -6
- package/src/lib/connectSocket/socketTask.ts +8 -8
- package/src/lib/createCameraContext/index.ts +41 -22
- package/src/lib/file.ts +27 -44
- package/src/lib/getClipboardData/index.ts +2 -4
- package/src/lib/getLocation/index.ts +6 -8
- package/src/lib/getStorage/index.ts +18 -28
- package/src/lib/getStorageInfo/index.ts +16 -22
- package/src/lib/getSystemInfo/index.ts +4 -9
- package/src/lib/keyboard.ts +4 -6
- package/src/lib/makePhoneCall/index.ts +3 -8
- package/src/lib/media.ts +43 -53
- package/src/lib/network.ts +4 -4
- package/src/lib/openUrl/index.ts +3 -8
- package/src/lib/permission.ts +15 -34
- package/src/lib/previewImage/index.tsx +9 -1
- package/src/lib/removeStorage/index.ts +4 -4
- package/src/lib/request/index.ts +37 -48
- package/src/lib/setClipboardData/index.ts +3 -8
- package/src/lib/setStorage/index.ts +9 -16
- package/src/lib/showActionSheet/index.tsx +4 -4
- package/src/lib/showModal/index.tsx +6 -6
- package/src/lib/showModal/toast.tsx +8 -8
- package/src/lib/vibrate.ts +3 -10
package/src/lib/openUrl/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Linking } from 'react-native'
|
|
2
|
+
import { successHandler, errorHandler } from '../../utils'
|
|
2
3
|
|
|
3
4
|
export async function openUrl <T>(opts: Taro.OpenUrl.Option): Promise<T> {
|
|
4
5
|
const { url, success, fail, complete } = opts || {} as Taro.OpenUrl.Option
|
|
@@ -7,16 +8,10 @@ export async function openUrl <T>(opts: Taro.OpenUrl.Option): Promise<T> {
|
|
|
7
8
|
const isSupport = await Linking.canOpenURL(url)
|
|
8
9
|
if (isSupport) {
|
|
9
10
|
await Linking.openURL(url)
|
|
10
|
-
success
|
|
11
|
-
complete && complete(res)
|
|
12
|
-
|
|
13
|
-
return Promise.resolve(res)
|
|
11
|
+
return successHandler(success, complete)(res)
|
|
14
12
|
} else {
|
|
15
13
|
res.errMsg = 'openUrl:fail. Do not support the openUrl Api'
|
|
16
|
-
fail
|
|
17
|
-
complete && complete(res)
|
|
18
|
-
|
|
19
|
-
return Promise.reject(res)
|
|
14
|
+
return errorHandler(fail, complete)(res)
|
|
20
15
|
}
|
|
21
16
|
}
|
|
22
17
|
|
package/src/lib/permission.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Linking, AppState } from 'react-native';
|
|
2
2
|
import * as Permissions from 'expo-permissions';
|
|
3
|
+
import { errorHandler, successHandler } from '../utils';
|
|
3
4
|
|
|
4
5
|
const scopeMap = {
|
|
5
6
|
'scope.userLocation': Permissions.LOCATION,
|
|
@@ -39,79 +40,59 @@ const handleAppStateChange = async (nextAppState, resolve, reject, opts) => {
|
|
|
39
40
|
try {
|
|
40
41
|
res.authSetting = await getAuthSetting()
|
|
41
42
|
res.errMsg = 'openSetting:ok'
|
|
42
|
-
success
|
|
43
|
-
complete
|
|
44
|
-
|
|
43
|
+
success?.(res)
|
|
44
|
+
complete?.(res)
|
|
45
|
+
|
|
45
46
|
AppState.removeEventListener('change', stateListener as any);
|
|
46
47
|
resolve(res)
|
|
47
48
|
} catch (error) {
|
|
48
49
|
res.errMsg = 'openSetting:fail'
|
|
49
|
-
fail
|
|
50
|
-
complete
|
|
51
|
-
|
|
50
|
+
fail?.(res)
|
|
51
|
+
complete?.(res)
|
|
52
|
+
|
|
52
53
|
reject(error)
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
// AppState.currentState = nextAppState;
|
|
56
57
|
};
|
|
57
58
|
|
|
58
|
-
export function authorize(opts: Taro.authorize.Option): Promise<Taro.General.CallbackResult> {
|
|
59
|
+
export async function authorize(opts: Taro.authorize.Option): Promise<Taro.General.CallbackResult> {
|
|
59
60
|
const { scope, success, fail, complete } = opts
|
|
60
61
|
const res: any = {}
|
|
61
62
|
|
|
62
|
-
return new Promise(async (resolve, reject) => {
|
|
63
63
|
try {
|
|
64
64
|
const { status } = await Permissions.askAsync(scopeMap[scope])
|
|
65
65
|
if (status === 'granted') {
|
|
66
66
|
res.errMsg = 'authorize:ok'
|
|
67
|
-
success
|
|
68
|
-
complete && complete(res)
|
|
69
|
-
|
|
70
|
-
resolve(res)
|
|
67
|
+
return successHandler(success, complete)(res)
|
|
71
68
|
} else {
|
|
72
69
|
res.errMsg = 'authorize:denied/undetermined'
|
|
73
|
-
fail
|
|
74
|
-
complete && complete(res)
|
|
75
|
-
|
|
76
|
-
resolve(res)
|
|
70
|
+
return errorHandler(fail, complete)(res)
|
|
77
71
|
}
|
|
78
72
|
} catch (error) {
|
|
79
73
|
res.errMsg = 'authorize:fail'
|
|
80
|
-
fail
|
|
81
|
-
complete && complete(res)
|
|
82
|
-
|
|
83
|
-
reject(error)
|
|
74
|
+
return errorHandler(fail, complete)(res)
|
|
84
75
|
}
|
|
85
|
-
})
|
|
86
76
|
}
|
|
87
77
|
|
|
88
|
-
export function getSetting(opts: Taro.getSetting.Option): Promise<Taro.getSetting.SuccessCallbackResult> {
|
|
78
|
+
export async function getSetting(opts: Taro.getSetting.Option = {}): Promise<Taro.getSetting.SuccessCallbackResult> {
|
|
89
79
|
const { success, fail, complete } = opts
|
|
90
80
|
const res: any = {}
|
|
91
81
|
|
|
92
|
-
return new Promise(async (resolve, reject) => {
|
|
93
82
|
try {
|
|
94
83
|
res.authSetting = await getAuthSetting()
|
|
95
84
|
res.errMsg = 'getSetting:ok'
|
|
96
|
-
success
|
|
97
|
-
complete && complete(res)
|
|
98
|
-
|
|
99
|
-
resolve(res)
|
|
85
|
+
return successHandler(success, complete)(res)
|
|
100
86
|
} catch (error) {
|
|
101
87
|
res.errMsg = 'getSetting:fail'
|
|
102
|
-
fail
|
|
103
|
-
complete && complete(res)
|
|
104
|
-
|
|
105
|
-
reject(error)
|
|
88
|
+
return errorHandler(fail, complete)(res)
|
|
106
89
|
}
|
|
107
|
-
})
|
|
108
90
|
}
|
|
109
91
|
|
|
110
|
-
export function openSetting(opts: Taro.openSetting.Option): Promise<Taro.openSetting.SuccessCallbackResult> {
|
|
92
|
+
export function openSetting(opts: Taro.openSetting.Option = {}): Promise<Taro.openSetting.SuccessCallbackResult> {
|
|
111
93
|
return new Promise((resolve, reject) => {
|
|
112
94
|
stateListener = (next) => handleAppStateChange(next, resolve, reject, opts)
|
|
113
95
|
AppState.addEventListener('change', stateListener)
|
|
114
96
|
Linking.openSettings()
|
|
115
97
|
})
|
|
116
98
|
}
|
|
117
|
-
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { View, ActivityIndicator, StyleSheet, Alert } from 'react-native'
|
|
2
|
+
import { View, ActivityIndicator, StyleSheet, Alert, BackHandler } from 'react-native'
|
|
3
3
|
import RootSiblings from 'react-native-root-siblings'
|
|
4
4
|
import ImageViewer from 'react-native-image-zoom-viewer'
|
|
5
5
|
import { saveMedia } from '../media'
|
|
@@ -28,8 +28,15 @@ export function previewImage(obj: Taro.previewImage.Option): void {
|
|
|
28
28
|
if (index === -1) {
|
|
29
29
|
throw new Error('"current" or "urls" is invalid')
|
|
30
30
|
}
|
|
31
|
+
|
|
31
32
|
let sibling
|
|
33
|
+
function backhandler() {
|
|
34
|
+
onSwipeDown()
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
function onSwipeDown() {
|
|
39
|
+
BackHandler.removeEventListener('hardwareBackPress', backhandler)
|
|
33
40
|
sibling?.destroy()
|
|
34
41
|
sibling = undefined
|
|
35
42
|
}
|
|
@@ -113,6 +120,7 @@ export function previewImage(obj: Taro.previewImage.Option): void {
|
|
|
113
120
|
/>
|
|
114
121
|
</View>
|
|
115
122
|
)
|
|
123
|
+
BackHandler.addEventListener('hardwareBackPress', backhandler)
|
|
116
124
|
} catch (e) {
|
|
117
125
|
onFail(e)
|
|
118
126
|
}
|
|
@@ -7,14 +7,14 @@ export function removeStorage(option: Taro.removeStorage.Option): Promise<Taro.G
|
|
|
7
7
|
return new Promise((resolve, reject) => {
|
|
8
8
|
AsyncStorage.removeItem(key)
|
|
9
9
|
.then(() => {
|
|
10
|
-
success
|
|
11
|
-
complete
|
|
10
|
+
success?.(res)
|
|
11
|
+
complete?.(res)
|
|
12
12
|
|
|
13
13
|
resolve(res)
|
|
14
14
|
}).catch((err) => {
|
|
15
15
|
res.errMsg = err.message
|
|
16
|
-
fail
|
|
17
|
-
complete
|
|
16
|
+
fail?.(res)
|
|
17
|
+
complete?.(res)
|
|
18
18
|
|
|
19
19
|
reject(err)
|
|
20
20
|
})
|
package/src/lib/request/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { errorHandler, successHandler } from "../../utils"
|
|
2
2
|
|
|
3
|
-
function serializeParams
|
|
3
|
+
function serializeParams(params) {
|
|
4
4
|
if (!params) {
|
|
5
5
|
return ''
|
|
6
6
|
}
|
|
@@ -8,14 +8,14 @@ function serializeParams (params) {
|
|
|
8
8
|
.map(key => (`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)).join('&')
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function generateRequestUrlWithParams
|
|
11
|
+
function generateRequestUrlWithParams(url, params) {
|
|
12
12
|
params = typeof params === 'string' ? params : serializeParams(params)
|
|
13
13
|
url += (~url.indexOf('?') ? '&' : '?') + params
|
|
14
14
|
url = url.replace('?&', '?')
|
|
15
15
|
return url
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function _request
|
|
18
|
+
function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
|
|
19
19
|
options = options || {}
|
|
20
20
|
if (typeof options === 'string') {
|
|
21
21
|
options = {
|
|
@@ -60,42 +60,40 @@ function _request <T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
|
|
|
60
60
|
params.signal = signal
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
originSuccess && originSuccess(res)
|
|
88
|
-
resolve(res)
|
|
89
|
-
})
|
|
90
|
-
.catch(error => {
|
|
91
|
-
completeRes = error.message === 'Aborted' ? { code: 20, message: 'Aborted', name: 'AbortError' } : Object.assign({}, error)
|
|
92
|
-
originFail && originFail(error)
|
|
93
|
-
reject(error)
|
|
94
|
-
})
|
|
95
|
-
.finally(() => {
|
|
96
|
-
originComplete && originComplete(completeRes)
|
|
97
|
-
})
|
|
63
|
+
const { success, fail, complete } = options
|
|
64
|
+
|
|
65
|
+
const fetchPromise = fetch(url, params)
|
|
66
|
+
.then(response => {
|
|
67
|
+
res.statusCode = response.status
|
|
68
|
+
res.header = response.headers
|
|
69
|
+
if (options.dataType === 'json' || typeof options.dataType === 'undefined') {
|
|
70
|
+
return response.json()
|
|
71
|
+
}
|
|
72
|
+
if (options.responseType === 'arraybuffer') {
|
|
73
|
+
return response.arrayBuffer()
|
|
74
|
+
}
|
|
75
|
+
if (options.responseType === 'text') {
|
|
76
|
+
return response.text()
|
|
77
|
+
}
|
|
78
|
+
return response
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const timeoutPromise = new Promise((resolve, reject) => {
|
|
82
|
+
const timer = setTimeout(() => {
|
|
83
|
+
controller?.abort()
|
|
84
|
+
reject(Error('request:fail timeout'))
|
|
85
|
+
clearTimeout?.(timer)
|
|
86
|
+
}, options.timeout ?? 2000)
|
|
98
87
|
})
|
|
88
|
+
|
|
89
|
+
const p: any = Promise.race([fetchPromise, timeoutPromise]).then(resData => {
|
|
90
|
+
res.data = resData
|
|
91
|
+
return successHandler(success, complete)(res)
|
|
92
|
+
}).catch(err => {
|
|
93
|
+
res.errMsg = err.message
|
|
94
|
+
return errorHandler(fail, complete)(res)
|
|
95
|
+
})
|
|
96
|
+
|
|
99
97
|
p.abort = function () {
|
|
100
98
|
if (controller) {
|
|
101
99
|
controller.abort()
|
|
@@ -107,12 +105,3 @@ function _request <T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
|
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
export const request = _request
|
|
110
|
-
|
|
111
|
-
// function taroInterceptor (chain) {
|
|
112
|
-
// return _request(chain.requestParams)
|
|
113
|
-
// }
|
|
114
|
-
|
|
115
|
-
// const link = new Link(taroInterceptor)
|
|
116
|
-
|
|
117
|
-
// export const request = link.request.bind(link)
|
|
118
|
-
// export const addInterceptor = link.addInterceptor.bind(link)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Clipboard from '@react-native-community/clipboard'
|
|
2
2
|
import { showToast } from '../showModal/toast'
|
|
3
|
+
import { successHandler, errorHandler } from '../../utils'
|
|
3
4
|
|
|
4
5
|
export function setClipboardData(opts: Taro.setClipboardData.Option): Promise<Taro.setClipboardData.Promised> {
|
|
5
6
|
const { data, success, fail, complete } = opts
|
|
@@ -8,10 +9,7 @@ export function setClipboardData(opts: Taro.setClipboardData.Option): Promise<Ta
|
|
|
8
9
|
const res = {
|
|
9
10
|
errMsg: 'setClipboardData:fail parameter error: parameter.data should be String'
|
|
10
11
|
}
|
|
11
|
-
fail
|
|
12
|
-
complete?.(res)
|
|
13
|
-
|
|
14
|
-
return Promise.reject(res)
|
|
12
|
+
return errorHandler(fail, complete)(res)
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
Clipboard.setString(data)
|
|
@@ -22,8 +20,5 @@ export function setClipboardData(opts: Taro.setClipboardData.Option): Promise<Ta
|
|
|
22
20
|
showToast({
|
|
23
21
|
title: '内容已复制'
|
|
24
22
|
})
|
|
25
|
-
success
|
|
26
|
-
complete?.(res)
|
|
27
|
-
|
|
28
|
-
return Promise.resolve(res)
|
|
23
|
+
return successHandler(success, complete)(res)
|
|
29
24
|
}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
2
|
+
import { errorHandler, successHandler } from '../../utils'
|
|
2
3
|
|
|
3
|
-
export function setStorage(option: Taro.setStorage.Option): Promise<Taro.General.CallbackResult> {
|
|
4
|
+
export async function setStorage(option: Taro.setStorage.Option): Promise<Taro.General.CallbackResult> {
|
|
4
5
|
const { key, data, success, fail, complete } = option
|
|
5
6
|
const res = { errMsg: 'setStorage:ok' }
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
AsyncStorage.setItem(key, JSON.stringify(data))
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}).catch((err) => {
|
|
15
|
-
res.errMsg = err.message
|
|
16
|
-
fail?.(res)
|
|
17
|
-
complete?.(res)
|
|
18
|
-
|
|
19
|
-
reject(err)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
8
|
+
try {
|
|
9
|
+
await AsyncStorage.setItem(key, JSON.stringify(data))
|
|
10
|
+
return successHandler(success, complete)(res)
|
|
11
|
+
} catch (err) {
|
|
12
|
+
res.errMsg = err.message
|
|
13
|
+
return errorHandler(fail, complete)(res)
|
|
14
|
+
}
|
|
22
15
|
}
|
|
@@ -20,8 +20,8 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
20
20
|
sibling && sibling.destroy()
|
|
21
21
|
sibling = undefined
|
|
22
22
|
const res = { tapIndex, errMsg: 'showActionSheet:ok' }
|
|
23
|
-
success
|
|
24
|
-
complete
|
|
23
|
+
success?.(res)
|
|
24
|
+
complete?.(res)
|
|
25
25
|
resolve(res)
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -29,8 +29,8 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
29
29
|
const res = { errMsg: 'showActionSheet:fail cancel' }
|
|
30
30
|
sibling && sibling.destroy()
|
|
31
31
|
sibling = undefined
|
|
32
|
-
fail
|
|
33
|
-
complete
|
|
32
|
+
fail?.(res)
|
|
33
|
+
complete?.(res)
|
|
34
34
|
reject(res)
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -24,8 +24,8 @@ function showModal (obj: Taro.showModal.Option): Promise<Taro.showModal.SuccessC
|
|
|
24
24
|
const res = { errMsg: 'showModal:ok', confirm: true, cancel: false }
|
|
25
25
|
sibling && sibling.destroy()
|
|
26
26
|
sibling = undefined
|
|
27
|
-
success
|
|
28
|
-
complete
|
|
27
|
+
success?.(res)
|
|
28
|
+
complete?.(res)
|
|
29
29
|
resolve(res)
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -33,8 +33,8 @@ function showModal (obj: Taro.showModal.Option): Promise<Taro.showModal.SuccessC
|
|
|
33
33
|
const res = { errMsg: 'showModal:cancel', confirm: false, cancel: true }
|
|
34
34
|
sibling && sibling.destroy()
|
|
35
35
|
sibling = undefined
|
|
36
|
-
success
|
|
37
|
-
complete
|
|
36
|
+
success?.(res)
|
|
37
|
+
complete?.(res)
|
|
38
38
|
resolve(res)
|
|
39
39
|
}
|
|
40
40
|
try {
|
|
@@ -60,8 +60,8 @@ function showModal (obj: Taro.showModal.Option): Promise<Taro.showModal.SuccessC
|
|
|
60
60
|
)
|
|
61
61
|
} catch (e) {
|
|
62
62
|
const res = { errMsg: `showModal fail:${e.message}` }
|
|
63
|
-
fail
|
|
64
|
-
complete
|
|
63
|
+
fail?.(res)
|
|
64
|
+
complete?.(res)
|
|
65
65
|
reject(res)
|
|
66
66
|
}
|
|
67
67
|
})
|
|
@@ -202,12 +202,12 @@ function hideToast (opts: Taro.hideToast.Option = {}): void {
|
|
|
202
202
|
(global as any).wxToastRootSiblings && (global as any).wxToastRootSiblings.destroy();
|
|
203
203
|
(global as any).wxToastRootSiblings = undefined
|
|
204
204
|
const res = { errMsg: 'showToast:ok' }
|
|
205
|
-
success
|
|
206
|
-
complete
|
|
205
|
+
success?.(res)
|
|
206
|
+
complete?.(res)
|
|
207
207
|
} catch (e) {
|
|
208
208
|
const res = { errMsg: e }
|
|
209
|
-
fail
|
|
210
|
-
complete
|
|
209
|
+
fail?.(res)
|
|
210
|
+
complete?.(res)
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
|
|
@@ -218,12 +218,12 @@ function hideLoading (opts: Taro.hideLoading.Option = {}): void {
|
|
|
218
218
|
(global as any).wxToastRootSiblings && (global as any).wxToastRootSiblings.destroy();
|
|
219
219
|
(global as any).wxToastRootSiblings = undefined
|
|
220
220
|
const res = { errMsg: 'showLoading:ok' }
|
|
221
|
-
success
|
|
222
|
-
complete
|
|
221
|
+
success?.(res)
|
|
222
|
+
complete?.(res)
|
|
223
223
|
} catch (e) {
|
|
224
224
|
const res = { errMsg: e }
|
|
225
|
-
fail
|
|
226
|
-
complete
|
|
225
|
+
fail?.(res)
|
|
226
|
+
complete?.(res)
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
|
package/src/lib/vibrate.ts
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { Vibration } from 'react-native'
|
|
2
|
+
import { errorHandler, successHandler } from '../utils'
|
|
2
3
|
|
|
3
4
|
function vibrate (DURATION, API, OPTS): Promise<Taro.General.CallbackResult> {
|
|
4
5
|
const res = { errMsg: `${API}:ok` }
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
6
|
const { success, fail, complete } = OPTS
|
|
7
7
|
try {
|
|
8
8
|
Vibration.vibrate(DURATION)
|
|
9
|
-
success
|
|
10
|
-
complete && complete(res)
|
|
11
|
-
|
|
12
|
-
resolve(res)
|
|
9
|
+
return successHandler(success, complete)(res)
|
|
13
10
|
} catch (err) {
|
|
14
11
|
res.errMsg = err.message
|
|
15
|
-
fail
|
|
16
|
-
complete && complete(res)
|
|
17
|
-
|
|
18
|
-
reject(res)
|
|
12
|
+
return errorHandler(fail, complete)(res)
|
|
19
13
|
}
|
|
20
|
-
})
|
|
21
14
|
}
|
|
22
15
|
|
|
23
16
|
function vibrateShort (opts: Taro.vibrateShort.Option = {}): Promise<Taro.General.CallbackResult> {
|