@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.
Files changed (199) hide show
  1. package/LICENSE +8 -8
  2. package/apiList.js +31 -31
  3. package/dist/api/index.js +1 -1
  4. package/dist/api/index.js.map +1 -1
  5. package/dist/lib/Mask.js +2 -2
  6. package/dist/lib/Mask.js.map +1 -1
  7. package/dist/lib/Popup.js +13 -20
  8. package/dist/lib/Popup.js.map +1 -1
  9. package/dist/lib/StyleSheet.js +1 -1
  10. package/dist/lib/StyleSheet.js.map +1 -1
  11. package/dist/lib/accelerometer.js +1 -1
  12. package/dist/lib/accelerometer.js.map +1 -1
  13. package/dist/lib/chooseImage/index.js +151 -3
  14. package/dist/lib/chooseImage/index.js.map +1 -1
  15. package/dist/lib/chooseVideo/index.js +55 -1
  16. package/dist/lib/chooseVideo/index.js.map +1 -1
  17. package/dist/lib/clearStorage/index.js +2 -2
  18. package/dist/lib/clearStorage/index.js.map +1 -1
  19. package/dist/lib/compressImage/index.js +1 -1
  20. package/dist/lib/compressImage/index.js.map +1 -1
  21. package/dist/lib/connectSocket/index.js.map +1 -1
  22. package/dist/lib/connectSocket/socketTask.js +1 -1
  23. package/dist/lib/connectSocket/socketTask.js.map +1 -1
  24. package/dist/lib/createCameraContext/index.js +3 -3
  25. package/dist/lib/createCameraContext/index.js.map +1 -1
  26. package/dist/lib/createInnerAudioContext/index.js +2 -2
  27. package/dist/lib/createInnerAudioContext/index.js.map +1 -1
  28. package/dist/lib/createVideoContext/index.js +7 -7
  29. package/dist/lib/createVideoContext/index.js.map +1 -1
  30. package/dist/lib/deviceMotion.js +2 -2
  31. package/dist/lib/deviceMotion.js.map +1 -1
  32. package/dist/lib/file.js +4 -4
  33. package/dist/lib/file.js.map +1 -1
  34. package/dist/lib/getAppBaseInfo/index.js +2 -2
  35. package/dist/lib/getAppBaseInfo/index.js.map +1 -1
  36. package/dist/lib/getClipboardData/index.js.map +1 -1
  37. package/dist/lib/getImageInfo/index.js +2 -2
  38. package/dist/lib/getImageInfo/index.js.map +1 -1
  39. package/dist/lib/getLocation/index.js +4 -8
  40. package/dist/lib/getLocation/index.js.map +1 -1
  41. package/dist/lib/getRecorderManager/index.js +6 -11
  42. package/dist/lib/getRecorderManager/index.js.map +1 -1
  43. package/dist/lib/getStorage/index.js.map +1 -1
  44. package/dist/lib/getStorageInfo/index.js +2 -2
  45. package/dist/lib/getStorageInfo/index.js.map +1 -1
  46. package/dist/lib/getSystemInfo/index.js +1 -1
  47. package/dist/lib/getSystemInfo/index.js.map +1 -1
  48. package/dist/lib/getSystemInfoSync/index.js +2 -2
  49. package/dist/lib/getSystemInfoSync/index.js.map +1 -1
  50. package/dist/lib/gyroscope.js +1 -1
  51. package/dist/lib/gyroscope.js.map +1 -1
  52. package/dist/lib/index.js +0 -1
  53. package/dist/lib/index.js.map +1 -1
  54. package/dist/lib/keyboard.js +3 -3
  55. package/dist/lib/keyboard.js.map +1 -1
  56. package/dist/lib/location.js.map +1 -1
  57. package/dist/lib/makePhoneCall/index.js +1 -1
  58. package/dist/lib/makePhoneCall/index.js.map +1 -1
  59. package/dist/lib/media.js +30 -61
  60. package/dist/lib/media.js.map +1 -1
  61. package/dist/lib/network.js +1 -1
  62. package/dist/lib/network.js.map +1 -1
  63. package/dist/lib/offWindowResize/index.js.map +1 -1
  64. package/dist/lib/onWindowResize/index.js +1 -1
  65. package/dist/lib/onWindowResize/index.js.map +1 -1
  66. package/dist/lib/openUrl/index.js +1 -1
  67. package/dist/lib/openUrl/index.js.map +1 -1
  68. package/dist/lib/permission.js +5 -6
  69. package/dist/lib/permission.js.map +1 -1
  70. package/dist/lib/previewImage/index.js +3 -3
  71. package/dist/lib/previewImage/index.js.map +1 -1
  72. package/dist/lib/request/index.js +1 -1
  73. package/dist/lib/request/index.js.map +1 -1
  74. package/dist/lib/scanCode/index.js +23 -23
  75. package/dist/lib/scanCode/index.js.map +1 -1
  76. package/dist/lib/screen.js +2 -2
  77. package/dist/lib/screen.js.map +1 -1
  78. package/dist/lib/setClipboardData/index.js +2 -2
  79. package/dist/lib/setClipboardData/index.js.map +1 -1
  80. package/dist/lib/setKeepScreenOn/index.js +1 -1
  81. package/dist/lib/setKeepScreenOn/index.js.map +1 -1
  82. package/dist/lib/setStorage/index.js.map +1 -1
  83. package/dist/lib/showActionSheet/ActionSheet.js +23 -11
  84. package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
  85. package/dist/lib/showActionSheet/index.js +24 -10
  86. package/dist/lib/showActionSheet/index.js.map +1 -1
  87. package/dist/lib/showModal/Dialog.js +36 -22
  88. package/dist/lib/showModal/Dialog.js.map +1 -1
  89. package/dist/lib/showModal/index.js.map +1 -1
  90. package/dist/lib/showModal/toast.js +6 -6
  91. package/dist/lib/showModal/toast.js.map +1 -1
  92. package/dist/lib/unsupportedApi.js +4 -2
  93. package/dist/lib/unsupportedApi.js.map +1 -1
  94. package/dist/lib/variable.js +1 -1
  95. package/dist/lib/variable.js.map +1 -1
  96. package/dist/lib/vibrate.js +1 -1
  97. package/dist/lib/vibrate.js.map +1 -1
  98. package/dist/lib/window.js.map +1 -1
  99. package/dist/setup.js +75 -0
  100. package/dist/setup.js.map +1 -0
  101. package/dist/utils/callbackManager.js.map +1 -1
  102. package/dist/utils/index.js.map +1 -1
  103. package/libList.js +0 -1
  104. package/package.json +69 -70
  105. package/src/__tests__/__mock__/mockAsyncStorage.js +47 -0
  106. package/src/__tests__/__mock__/mockClipboard.js +15 -0
  107. package/src/__tests__/__mock__/mockNavigator.js +20 -0
  108. package/src/__tests__/__mock__/mockNetwork.js +59 -0
  109. package/src/__tests__/__mock__/mockRNCCameraRoll.js +16 -0
  110. package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
  111. package/src/__tests__/__mock__/mockVibrate.js +6 -0
  112. package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +125 -0
  113. package/src/__tests__/clipboard.test.ts +88 -0
  114. package/src/__tests__/deviceMotion.test.ts +37 -0
  115. package/src/__tests__/geolocation.test.ts +60 -0
  116. package/src/__tests__/interactive.test.tsx +101 -0
  117. package/src/__tests__/keyboard.test.ts +46 -0
  118. package/src/__tests__/media.test.ts +104 -0
  119. package/src/__tests__/network.test.ts +57 -0
  120. package/src/__tests__/others.test.ts +25 -0
  121. package/src/__tests__/phone.test.ts +31 -0
  122. package/src/__tests__/request.test.ts +146 -0
  123. package/src/__tests__/scanCode.test.tsx +14 -0
  124. package/src/__tests__/storage.test.ts +202 -0
  125. package/src/__tests__/system.test.ts +69 -0
  126. package/src/__tests__/vibrate.test.ts +27 -0
  127. package/src/__tests__/websocket.test.ts +169 -0
  128. package/src/api/index.ts +31 -31
  129. package/src/lib/ENV_TYPE/index.ts +1 -1
  130. package/src/lib/Mask.tsx +2 -2
  131. package/src/lib/Popup.tsx +19 -26
  132. package/src/lib/StyleSheet.ts +1 -1
  133. package/src/lib/accelerometer.ts +1 -2
  134. package/src/lib/arrayBufferToBase64/index.ts +1 -1
  135. package/src/lib/base64ToArrayBuffer/index.ts +1 -1
  136. package/src/lib/chooseImage/index.ts +155 -3
  137. package/src/lib/chooseVideo/index.ts +56 -1
  138. package/src/lib/clearStorage/index.ts +0 -1
  139. package/src/lib/clearStorageSync/index.ts +1 -1
  140. package/src/lib/compressImage/index.ts +0 -1
  141. package/src/lib/connectSocket/socketTask.ts +9 -7
  142. package/src/lib/createCameraContext/index.ts +4 -6
  143. package/src/lib/createInnerAudioContext/index.ts +0 -1
  144. package/src/lib/createSelectorQuery/index.ts +1 -1
  145. package/src/lib/deviceMotion.ts +3 -4
  146. package/src/lib/file.ts +8 -9
  147. package/src/lib/getClipboardData/index.ts +0 -1
  148. package/src/lib/getEnv/index.ts +1 -1
  149. package/src/lib/getFileSystemManager/index.ts +1 -1
  150. package/src/lib/getLocation/index.ts +2 -7
  151. package/src/lib/getRecorderManager/index.ts +2 -7
  152. package/src/lib/getStorage/index.ts +0 -1
  153. package/src/lib/getStorageInfo/index.ts +0 -1
  154. package/src/lib/getStorageInfoSync/index.ts +1 -1
  155. package/src/lib/getStorageSync/index.ts +1 -1
  156. package/src/lib/getSystemInfo/index.ts +2 -2
  157. package/src/lib/getSystemInfoSync/index.ts +3 -3
  158. package/src/lib/gyroscope.ts +46 -47
  159. package/src/lib/index.ts +0 -1
  160. package/src/lib/keyboard.ts +4 -5
  161. package/src/lib/location.ts +5 -6
  162. package/src/lib/makePhoneCall/index.ts +1 -2
  163. package/src/lib/media.ts +31 -83
  164. package/src/lib/network.ts +5 -5
  165. package/src/lib/offLocationChange/index.ts +1 -1
  166. package/src/lib/offUserCaptureScreen/index.ts +1 -1
  167. package/src/lib/onLocationChange/index.ts +1 -1
  168. package/src/lib/onUserCaptureScreen/index.ts +1 -1
  169. package/src/lib/onWindowResize/index.ts +2 -2
  170. package/src/lib/openUrl/index.d.ts +22 -23
  171. package/src/lib/openUrl/index.ts +1 -2
  172. package/src/lib/permission.ts +25 -33
  173. package/src/lib/previewImage/index.tsx +3 -4
  174. package/src/lib/removeStorageSync/index.ts +1 -1
  175. package/src/lib/request/index.ts +2 -2
  176. package/src/lib/scanCode/index.tsx +16 -18
  177. package/src/lib/screen.ts +0 -1
  178. package/src/lib/setClipboardData/index.ts +2 -3
  179. package/src/lib/setKeepScreenOn/index.ts +1 -2
  180. package/src/lib/setStorage/index.ts +0 -1
  181. package/src/lib/setStorageSync/index.ts +1 -1
  182. package/src/lib/showActionSheet/ActionSheet.tsx +43 -34
  183. package/src/lib/showActionSheet/index.tsx +36 -11
  184. package/src/lib/showModal/Dialog.tsx +39 -34
  185. package/src/lib/showModal/index.tsx +0 -1
  186. package/src/lib/showModal/toast.tsx +13 -14
  187. package/src/lib/startGyroscope/index.ts +1 -1
  188. package/src/lib/startLocationUpdate/index.ts +1 -1
  189. package/src/lib/unsupportedApi.ts +5 -3
  190. package/src/lib/vibrate.ts +10 -11
  191. package/src/lib/window.ts +2 -3
  192. package/src/setup.ts +84 -0
  193. package/{types → src/types}/vue/index.d.ts +3 -2
  194. package/src/utils/callbackManager.ts +5 -5
  195. package/src/utils/index.ts +4 -4
  196. package/dist/lib/chooseMedia/index.js +0 -19
  197. package/dist/lib/chooseMedia/index.js.map +0 -1
  198. package/src/lib/chooseMedia/index.ts +0 -15
  199. /package/{types → src/types}/definition.d.ts +0 -0
@@ -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 '@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'
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
- import { errorHandler, successHandler } from '../utils'
12
- import { showActionSheet } from './showActionSheet'
13
-
14
- export const MEDIA_TYPE = MediaTypeOptions
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 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)
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
- 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
35
+ const { sizeType = [], sourceType = [], success, fail, complete, maxDuration } = opts as any
82
36
  const options = {
83
37
  mediaTypes,
84
- quality: (sizeType[0] === 'compressed' || compressed) ? 0.7 : 1,
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 Camera.requestCameraPermissionsAsync() : await requestMediaLibraryPermissionsAsync()
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
- const launchMediaAsync = isCamera ? launchCameraAsync : launchImageLibraryAsync
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.Videos) {
102
- const asset = resp.assets?.[0]
55
+ if (mediaTypes === MEDIA_TYPE.VIDEOS) {
103
56
  res = {
104
- ...asset,
105
- tempFilePath: asset?.uri,
106
- size: asset?.fileSize,
57
+ tempFilePath: uri,
58
+ duration,
59
+ width,
60
+ height
107
61
  }
108
62
  } else {
109
63
  res = {
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
- }))
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: `choose${messString}:fail cancel`
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: `choose${messString}:fail`,
78
+ errMsg: mediaTypes === MEDIA_TYPE.VIDEOS ? 'chooseVideo fail' : 'chooseImage fail',
131
79
  err
132
80
  }
133
81
  return errorHandler(fail, complete)(res)
@@ -1,16 +1,16 @@
1
- import NetInfo, { NetInfoState, NetInfoStateType } from '@react-native-community/netinfo'
1
+ import NetInfo, { NetInfoStateType, NetInfoState } from '@react-native-community/netinfo'
2
2
 
3
3
  let _unsubscribe: any = null
4
4
 
5
- const _callbacks: Set<Function> = new Set()
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 (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 { addListener, callbackManager } from '../window'
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
- 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>
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
  }
@@ -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
@@ -1,4 +1,5 @@
1
- import { Camera } from 'expo-camera'
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 { 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
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
- const auths = {}
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
- 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'
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
- 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
- }
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 { ActivityIndicator, Alert, Modal, StyleSheet, View } from 'react-native'
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'
@@ -1,4 +1,4 @@
1
- import { errorHandler, successHandler } from '../../utils'
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,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 { chooseMedia, MEDIA_TYPE } from '../media'
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[]): BarcodeType[] {
52
- const result: BarcodeType[] = []
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.Images).catch(errorCallBack)
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 barcodeTypes = getBarCodeTypes(scanType)
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
- <CameraView
167
- onBarcodeScanned={({ type, data }: {type: string, data: string}) => {
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
- barcodeScannerSettings={{
182
- barcodeTypes,
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,5 +1,4 @@
1
1
  import * as Brightness from 'expo-brightness'
2
-
3
2
  import { errorHandler, shouldBeObject, successHandler } from '../utils'
4
3
 
5
4
  /**
@@ -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: 'none',
21
+ icon: "none",
23
22
  title: '内容已复制'
24
23
  })
25
24
  return successHandler(success, complete)(res)
@@ -1,6 +1,5 @@
1
1
  import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake'
2
-
3
- import { errorHandler, successHandler } from '../../utils'
2
+ import { successHandler, errorHandler } from '../../utils'
4
3
 
5
4
  /**
6
5
  * keepScreenOn
@@ -1,5 +1,4 @@
1
1
  import AsyncStorage from '@react-native-async-storage/async-storage'
2
-
3
2
  import { errorHandler, successHandler } from '../../utils'
4
3
 
5
4
  export async function setStorage(option: Taro.setStorage.Option): Promise<TaroGeneral.CallbackResult> {
@@ -1 +1 @@
1
- export { setStorageSync } from '../unsupportedApi'
1
+ export { setStorageSync } from '../unsupportedApi'