@tarojs/taro-rn 3.4.1 → 3.4.4

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 (79) hide show
  1. package/dist/lib/Mask.js +1 -1
  2. package/dist/lib/Mask.js.map +1 -1
  3. package/dist/lib/Popup.js +3 -2
  4. package/dist/lib/Popup.js.map +1 -1
  5. package/dist/lib/chooseImage/index.js +4 -1
  6. package/dist/lib/chooseImage/index.js.map +1 -1
  7. package/dist/lib/chooseVideo/index.js +1 -1
  8. package/dist/lib/chooseVideo/index.js.map +1 -1
  9. package/dist/lib/connectSocket/index.js +0 -1
  10. package/dist/lib/connectSocket/index.js.map +1 -1
  11. package/dist/lib/connectSocket/socketTask.js +2 -2
  12. package/dist/lib/connectSocket/socketTask.js.map +1 -1
  13. package/dist/lib/createCameraContext/index.js +3 -0
  14. package/dist/lib/createCameraContext/index.js.map +1 -1
  15. package/dist/lib/createInnerAudioContext/index.js +10 -10
  16. package/dist/lib/createInnerAudioContext/index.js.map +1 -1
  17. package/dist/lib/createVideoContext/index.js +9 -0
  18. package/dist/lib/createVideoContext/index.js.map +1 -1
  19. package/dist/lib/file.js +2 -1
  20. package/dist/lib/file.js.map +1 -1
  21. package/dist/lib/getFileSystemManager/index.js +2 -0
  22. package/dist/lib/getFileSystemManager/index.js.map +1 -0
  23. package/dist/lib/getLocation/index.js +1 -1
  24. package/dist/lib/getLocation/index.js.map +1 -1
  25. package/dist/lib/index.js +1 -0
  26. package/dist/lib/index.js.map +1 -1
  27. package/dist/lib/location.js +1 -1
  28. package/dist/lib/location.js.map +1 -1
  29. package/dist/lib/permission.js +1 -1
  30. package/dist/lib/permission.js.map +1 -1
  31. package/dist/lib/previewImage/index.js +1 -0
  32. package/dist/lib/previewImage/index.js.map +1 -1
  33. package/dist/lib/request/index.js +4 -4
  34. package/dist/lib/request/index.js.map +1 -1
  35. package/dist/lib/scanCode/index.js +1 -1
  36. package/dist/lib/scanCode/index.js.map +1 -1
  37. package/dist/lib/showModal/toast.js +9 -8
  38. package/dist/lib/showModal/toast.js.map +1 -1
  39. package/dist/lib/unsupportedApi.js +2 -0
  40. package/dist/lib/unsupportedApi.js.map +1 -1
  41. package/dist/setup.js +64 -0
  42. package/dist/setup.js.map +1 -0
  43. package/libList.js +1 -0
  44. package/package.json +13 -15
  45. package/src/__tests__/__mock__/mockAsyncStorage.js +0 -1
  46. package/src/__tests__/__mock__/mockExpoPermissions.js +1 -1
  47. package/src/__tests__/__snapshots__/scanCode.test.js.snap +113 -0
  48. package/src/__tests__/interactive.test.js +40 -66
  49. package/src/__tests__/keyboard.test.js +6 -6
  50. package/src/__tests__/request.test.js +1 -1
  51. package/src/__tests__/scanCode.test.js +14 -0
  52. package/src/__tests__/storage.test.js +1 -1
  53. package/src/__tests__/system.test.js +8 -8
  54. package/src/lib/Mask.tsx +1 -0
  55. package/src/lib/Popup.tsx +2 -2
  56. package/src/lib/chooseImage/index.ts +4 -1
  57. package/src/lib/chooseVideo/index.ts +1 -1
  58. package/src/lib/connectSocket/index.ts +0 -1
  59. package/src/lib/connectSocket/socketTask.ts +2 -2
  60. package/src/lib/createCameraContext/index.ts +4 -0
  61. package/src/lib/createInnerAudioContext/index.ts +10 -10
  62. package/src/lib/createVideoContext/index.ts +12 -0
  63. package/src/lib/file.ts +2 -1
  64. package/src/lib/getFileSystemManager/index.ts +1 -0
  65. package/src/lib/getImageInfo/index.ts +1 -1
  66. package/src/lib/getLocation/index.ts +1 -1
  67. package/src/lib/index.ts +1 -0
  68. package/src/lib/location.ts +1 -1
  69. package/src/lib/network.ts +2 -2
  70. package/src/lib/permission.ts +1 -1
  71. package/src/lib/previewImage/index.tsx +1 -0
  72. package/src/lib/request/index.ts +4 -4
  73. package/src/lib/scanCode/index.tsx +1 -1
  74. package/src/lib/showModal/toast.tsx +10 -8
  75. package/src/lib/unsupportedApi.ts +3 -0
  76. package/src/setup.ts +71 -0
  77. package/src/types/definition.d.ts +2 -0
  78. package/src/__tests__/__snapshots__/interactive.test.js.snap +0 -1690
  79. package/src/__tests__/scanCode.test_.js +0 -24
@@ -0,0 +1,14 @@
1
+ // eslint-disable-next-line
2
+ import React from 'react'
3
+ import { RootSiblingParent } from 'react-native-root-siblings';
4
+ import { render, waitFor } from '@testing-library/react-native';
5
+ import { scanCode } from '../lib/scanCode'
6
+
7
+ describe('scanCode', () => {
8
+ it('should render scanCode success', async () => {
9
+ const { toJSON, getByLabelText } = render(<RootSiblingParent />)
10
+ scanCode()
11
+ await waitFor(() => getByLabelText('Close'));
12
+ expect(toJSON()).toMatchSnapshot()
13
+ })
14
+ })
@@ -63,7 +63,7 @@ describe('storage', () => {
63
63
  fail,
64
64
  complete
65
65
  }).catch(err => {
66
- const expectErrMsg = err.message
66
+ const expectErrMsg = err.errMsg
67
67
  expect(fail.mock.calls.length).toBe(1)
68
68
  expect(fail.mock.calls[0][0]).toEqual({ errMsg: expectErrMsg })
69
69
  expect(complete.mock.calls.length).toBe(1)
@@ -7,8 +7,8 @@ describe('system', () => {
7
7
  describe('getSystemInfoSync', () => {
8
8
  test('能同步返回正确的系统信息', () => {
9
9
  const expectRes = {
10
- brand: null,
11
- model: null,
10
+ brand: expect.any(String),
11
+ model: expect.any(String),
12
12
  pixelRatio: expect.any(Number),
13
13
  safeArea: expect.any(Object),
14
14
  screenWidth: expect.any(Number),
@@ -17,8 +17,8 @@ describe('system', () => {
17
17
  windowHeight: expect.any(Number),
18
18
  statusBarHeight: expect.any(Number),
19
19
  language: null,
20
- version: null,
21
- system: undefined,
20
+ version: expect.any(String),
21
+ system: expect.any(String),
22
22
  platform: expect.any(String),
23
23
  fontSizeSetting: expect.any(Number),
24
24
  SDKVersion: null
@@ -35,8 +35,8 @@ describe('system', () => {
35
35
  const fail = jest.fn()
36
36
  const complete = jest.fn()
37
37
  const expectRes = {
38
- brand: null,
39
- model: null,
38
+ brand: expect.any(String),
39
+ model: expect.any(String),
40
40
  pixelRatio: expect.any(Number),
41
41
  safeArea: expect.any(Object),
42
42
  screenWidth: expect.any(Number),
@@ -45,8 +45,8 @@ describe('system', () => {
45
45
  windowHeight: expect.any(Number),
46
46
  statusBarHeight: expect.any(Number),
47
47
  language: null,
48
- version: null,
49
- system: undefined,
48
+ version: expect.any(String),
49
+ system: expect.any(String),
50
50
  platform: expect.any(String),
51
51
  fontSizeSetting: expect.any(Number),
52
52
  SDKVersion: null
package/src/lib/Mask.tsx CHANGED
@@ -12,6 +12,7 @@ const styles = StyleSheet.create({
12
12
  const Mask: React.FC<any> = ({ transparent = false, style, onPress, children }) =>
13
13
  <TouchableWithoutFeedback onPress={onPress}>
14
14
  <View
15
+ accessibilityLabel='mask'
15
16
  style={[styles.mask, { backgroundColor: transparent ? 'transparent' : 'rgba(0,0,0,.6)' }, style]}
16
17
  >
17
18
  <TouchableWithoutFeedback>{children}</TouchableWithoutFeedback>
package/src/lib/Popup.tsx CHANGED
@@ -34,7 +34,7 @@ class Popup extends Component<any, any> {
34
34
 
35
35
  constructor (props:Props) {
36
36
  super(props)
37
- this.state = { visible: false, translateY: new Animated.Value(height) }
37
+ this.state = { visible: props.visible ?? false, translateY: new Animated.Value(height) }
38
38
  this.handleLayout = this.handleLayout.bind(this)
39
39
  }
40
40
 
@@ -54,7 +54,7 @@ class Popup extends Component<any, any> {
54
54
  }
55
55
 
56
56
  handleLayout ():void {
57
- this.popup.measure((x, y, w, h) => {
57
+ this.popup.measure((_x, _y, _w, h) => {
58
58
  this.height = h
59
59
  this.setState({ translateY: new Animated.Value(h) })
60
60
  Animated.timing(this.state.translateY, {
@@ -26,7 +26,9 @@ function getRes(images) {
26
26
  function openCamera(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
27
27
  const { success, fail, complete } = options
28
28
  return new Promise((resolve, reject) => {
29
- SYImagePicker.openCamera({}, (err, photo: any) => {
29
+ SYImagePicker.openCamera({
30
+ compressFocusAlpha: true
31
+ }, (err, photo: any) => {
30
32
  if (err) {
31
33
  const res = {
32
34
  errMsg: err
@@ -55,6 +57,7 @@ function openPicker(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.
55
57
  return new Promise((resolve, reject) => {
56
58
  // NOTE:react-native-syan-image-picker 暂不支持 Android 端压缩
57
59
  SYImagePicker.showImagePicker({
60
+ compressFocusAlpha: true,
58
61
  imageCount,
59
62
  quality: sizeType[0] === 'compressed' ? 70 : 90,
60
63
  }, (err, photos: any) => {
@@ -43,7 +43,7 @@ function showVideoPicker(options: Taro.chooseVideo.Option):any {
43
43
  resolve(chooseMedia({...options, sourceType: ['album']}, MEDIA_TYPE.VIDEOS))
44
44
  }
45
45
  },
46
- fail: function (err) {
46
+ fail: function () {
47
47
  const res = { errMsg: 'chooseVideo:fail cancel' }
48
48
  reject(res)
49
49
  }
@@ -25,7 +25,6 @@ export function connectSocket(opts: Taro.connectSocket.Option): Promise<Taro.Soc
25
25
  if (socketTasks.length >= 2) {
26
26
  const error = new Error('同时最多发起 2 个 socket 请求,更多请参考文档。')
27
27
  res.errMsg = error.message
28
- console.error(res.errMsg)
29
28
  fail?.(res)
30
29
  complete?.(res)
31
30
  return reject(res)
@@ -87,9 +87,9 @@ class SocketTask {
87
87
  }
88
88
 
89
89
  onError (func?: Taro.SocketTask.OnErrorCallback): void {
90
- this.ws.onerror = (res) => {
90
+ this.ws.onerror = () => {
91
91
  func && func({
92
- errMsg: res.message
92
+ errMsg: "There was an error with your websocket.",
93
93
  })
94
94
  }
95
95
  }
@@ -113,6 +113,10 @@ class CameraContext {
113
113
  }
114
114
  }
115
115
  }
116
+
117
+ setZoom = () => {
118
+ console.log('not support')
119
+ }
116
120
  }
117
121
  /**
118
122
  * 创建 video 上下文 VideoContext 对象。
@@ -224,7 +224,7 @@ class InnerAudioContext {
224
224
  * @param callback
225
225
  */
226
226
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
227
- offCanplay (callback) {
227
+ offCanplay (_callback) {
228
228
  this.onCanplayCallback = undefined
229
229
  }
230
230
 
@@ -241,7 +241,7 @@ class InnerAudioContext {
241
241
  * @param callback
242
242
  */
243
243
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
244
- offPlay (callback) {
244
+ offPlay (_callback) {
245
245
  this.onPlayCallback = undefined
246
246
  }
247
247
 
@@ -258,7 +258,7 @@ class InnerAudioContext {
258
258
  * @param callback
259
259
  */
260
260
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
261
- offPause (callback) {
261
+ offPause (_callback) {
262
262
  this.onPauseCallback = undefined
263
263
  }
264
264
 
@@ -275,7 +275,7 @@ class InnerAudioContext {
275
275
  * @param callback
276
276
  */
277
277
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
278
- offStop (callback) {
278
+ offStop (_callback) {
279
279
  this.onStopCallback = undefined
280
280
  }
281
281
 
@@ -292,7 +292,7 @@ class InnerAudioContext {
292
292
  * @param callback
293
293
  */
294
294
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
295
- offEnded (callback) {
295
+ offEnded (_callback) {
296
296
  this.onEndedCallback = undefined
297
297
  }
298
298
 
@@ -309,7 +309,7 @@ class InnerAudioContext {
309
309
  * @param callback
310
310
  */
311
311
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
312
- offTimeUpdate (callback) {
312
+ offTimeUpdate (_callback) {
313
313
  this.onTimeUpdateCallback = undefined
314
314
  }
315
315
 
@@ -326,7 +326,7 @@ class InnerAudioContext {
326
326
  * @param callback
327
327
  */
328
328
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
329
- offError (callback) {
329
+ offError (_callback) {
330
330
  this.onErrorCallback = undefined
331
331
  }
332
332
 
@@ -343,7 +343,7 @@ class InnerAudioContext {
343
343
  * @param callback
344
344
  */
345
345
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
346
- offWaiting (callback) {
346
+ offWaiting (_callback) {
347
347
  this.onWaitingCallback = undefined
348
348
  }
349
349
 
@@ -360,7 +360,7 @@ class InnerAudioContext {
360
360
  * @param callback
361
361
  */
362
362
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
363
- offSeeking (callback) {
363
+ offSeeking (_callback) {
364
364
  this.onSeekingCallback = undefined
365
365
  }
366
366
 
@@ -377,7 +377,7 @@ class InnerAudioContext {
377
377
  * @param callback
378
378
  */
379
379
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
380
- offSeeked (callback) {
380
+ offSeeked (_callback) {
381
381
  this.onSeekedCallback = undefined
382
382
  }
383
383
  }
@@ -108,6 +108,18 @@ class VideoContext {
108
108
  console.log('not support')
109
109
  }
110
110
 
111
+ exitBackgroundPlayback () {
112
+ console.log('not support')
113
+ }
114
+
115
+ exitPictureInPicture () {
116
+ console.log('not support')
117
+ }
118
+
119
+ requestBackgroundPlayback () {
120
+ console.log('not support')
121
+ }
122
+
111
123
  /**
112
124
  * 停止视频
113
125
  */
package/src/lib/file.ts CHANGED
@@ -16,7 +16,7 @@ let timer: any
16
16
 
17
17
  const _fetch = (requestPromise, timeout) => {
18
18
  let timeoutAction
19
- const timerPromise = new Promise((resolve, reject) => {
19
+ const timerPromise = new Promise((_resolve, reject) => {
20
20
  timeoutAction = () => {
21
21
  reject(new Error('网络请求超时'))
22
22
  }
@@ -40,6 +40,7 @@ const createFormData = (filePath, body, name) => {
40
40
  data.append(key, body[key])
41
41
  })
42
42
 
43
+ // @ts-ignore
43
44
  data.append(name, fileObj)
44
45
 
45
46
  return data
@@ -0,0 +1 @@
1
+ export { getFileSystemManager } from '../unsupportedApi'
@@ -7,7 +7,7 @@ export function getImageInfo(option: Taro.getImageInfo.Option): Promise<Taro.get
7
7
  Image.getSize(
8
8
  src,
9
9
  (width, height) => {
10
- const orientation: keyof Taro.getImageInfo.orientation = 'up'
10
+ const orientation: keyof Taro.getImageInfo.Orientation = 'up'
11
11
  const res = {
12
12
  width,
13
13
  height,
@@ -20,7 +20,7 @@ export async function getLocation(opts: Taro.getLocation.Option = {}): Promise<T
20
20
  return new Promise((resolve, reject) => {
21
21
  Geolocation.getCurrentPosition(
22
22
  ({ coords }) => {
23
- const { latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed } = coords
23
+ const { latitude, longitude, altitude, accuracy, speed } = coords
24
24
  const res = {
25
25
  latitude,
26
26
  longitude,
package/src/lib/index.ts CHANGED
@@ -17,6 +17,7 @@ export * from './downloadFile'
17
17
  export * from './getClipboardData'
18
18
  export * from './getEnv'
19
19
  export * from './getFileInfo'
20
+ export * from './getFileSystemManager'
20
21
  export * from './getImageInfo'
21
22
  export * from './getLocation'
22
23
  export * from './getNetworkType'
@@ -32,7 +32,7 @@ export function startLocationUpdate(opts: Taro.startLocationUpdate.Option): Prom
32
32
  throw new Error('startLocationUpdate:fail')
33
33
  } else {
34
34
  _watchID = Geolocation.watchPosition(({ coords }) => {
35
- const { latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed } = coords
35
+ const { latitude, longitude, altitude, accuracy, speed } = coords
36
36
  _cbManager.trigger({
37
37
  accuracy,
38
38
  altitude,
@@ -4,8 +4,8 @@ let _unsubscribe: any = null
4
4
 
5
5
  let _callbacks: Set<Function> = new Set()
6
6
 
7
- function getTypeFromState(connectionInfo:NetInfoState): keyof Taro.getNetworkType.networkType {
8
- let type: keyof Taro.getNetworkType.networkType
7
+ function getTypeFromState(connectionInfo:NetInfoState): keyof Taro.getNetworkType.NetworkType {
8
+ let type: keyof Taro.getNetworkType.NetworkType
9
9
  if(connectionInfo.type === NetInfoStateType.wifi) {
10
10
  type = NetInfoStateType.wifi
11
11
  } else if(connectionInfo.type === NetInfoStateType.cellular && connectionInfo.details.cellularGeneration) {
@@ -33,7 +33,7 @@ const getAuthSetting = async () => {
33
33
  return auths
34
34
  }
35
35
 
36
- const handleAppStateChange = async (nextAppState, resolve, reject, opts) => {
36
+ const handleAppStateChange = async (_nextAppState, resolve, reject, opts) => {
37
37
  const { success, fail, complete } = opts
38
38
  const res: any = {}
39
39
 
@@ -7,6 +7,7 @@ import { downloadFile } from '../file'
7
7
 
8
8
  const styles = StyleSheet.create({
9
9
  mask: {
10
+ elevation: 1,
10
11
  position: 'absolute',
11
12
  backgroundColor: '#000000',
12
13
  top: 0,
@@ -34,9 +34,9 @@ function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
34
34
  } else {
35
35
  if (typeof data === 'object') {
36
36
  const contentType = options.header && (options.header['content-type'] || options.header['Content-Type'])
37
- if (contentType === 'application/json') {
37
+ if (contentType.startsWith('application/json')) {
38
38
  data = JSON.stringify(data)
39
- } else if (contentType === 'application/x-www-form-urlencoded') {
39
+ } else if (contentType.startsWith('application/x-www-form-urlencoded')) {
40
40
  data = serializeParams(data)
41
41
  }
42
42
  }
@@ -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 (AbortController) {
56
+ if (typeof(AbortController) !== 'undefined' ) {
57
57
  // eslint-disable-next-line no-undef
58
58
  controller = new AbortController()
59
59
  const signal = controller.signal
@@ -78,7 +78,7 @@ function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
78
78
  return response
79
79
  })
80
80
 
81
- const timeoutPromise = new Promise((resolve, reject) => {
81
+ const timeoutPromise = new Promise((_resolve, reject) => {
82
82
  const timer = setTimeout(() => {
83
83
  controller?.abort()
84
84
  reject(Error('request:fail timeout'))
@@ -182,7 +182,7 @@ export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.
182
182
  style={{ width, height }}
183
183
  ratio='16:9'
184
184
  />
185
- <TouchableOpacity style={styles.closeIcon} onPress={() => hide(scannerView)}>
185
+ <TouchableOpacity accessibilityLabel="Close" style={styles.closeIcon} onPress={() => hide(scannerView)}>
186
186
  {safeViewWrapper(<Image source={iconClose} style={styles.closeImg}/>)}
187
187
  </TouchableOpacity>
188
188
  {!onlyFromCamera && (<TouchableOpacity style={styles.albumIcon} onPress={() => {
@@ -5,6 +5,8 @@ import RootSiblings from 'react-native-root-siblings'
5
5
  import successPng from './success.png'
6
6
  import { errorHandler, shouldBeObject, successHandler } from '../../utils'
7
7
 
8
+ const globalAny: any = global
9
+
8
10
  const styles = StyleSheet.create({
9
11
  toastView: {
10
12
  width: 76,
@@ -156,15 +158,15 @@ function showToast (options: Taro.showToast.Option): Promise<TaroGeneral.Callbac
156
158
  try {
157
159
  // setTimeout fires incorrectly when using chrome debug #4470
158
160
  // https://github.com/facebook/react-native/issues/4470
159
- (global as any).wxToastRootSiblings && (global as any).wxToastRootSiblings.destroy();
161
+ globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy();
160
162
 
161
- (global as any).wxToastRootSiblings = new RootSiblings(ToastView)
163
+ globalAny.wxToastRootSiblings = new RootSiblings(ToastView)
162
164
  setTimeout(() => {
163
- (global as any).wxToastRootSiblings && (global as any).wxToastRootSiblings.update(ToastView)
165
+ globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.update(ToastView)
164
166
  }, 100)
165
167
  if (duration > 0) {
166
168
  setTimeout(() => {
167
- (global as any).wxToastRootSiblings && (global as any).wxToastRootSiblings.destroy()
169
+ globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy()
168
170
  }, duration)
169
171
  }
170
172
  return successHandler(success, complete)(res)
@@ -199,8 +201,8 @@ function hideToast (opts: Taro.hideToast.Option = {}): void {
199
201
  const { success, fail, complete } = opts
200
202
 
201
203
  try {
202
- (global as any).wxToastRootSiblings && (global as any).wxToastRootSiblings.destroy();
203
- (global as any).wxToastRootSiblings = undefined
204
+ globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy();
205
+ globalAny.wxToastRootSiblings = undefined
204
206
  const res = { errMsg: 'showToast:ok' }
205
207
  success?.(res)
206
208
  complete?.(res)
@@ -215,8 +217,8 @@ function hideLoading (opts: Taro.hideLoading.Option = {}): void {
215
217
  const { success, fail, complete } = opts
216
218
 
217
219
  try {
218
- (global as any).wxToastRootSiblings && (global as any).wxToastRootSiblings.destroy();
219
- (global as any).wxToastRootSiblings = undefined
220
+ globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy();
221
+ globalAny.wxToastRootSiblings = undefined
220
222
  const res = { errMsg: 'showLoading:ok' }
221
223
  success?.(res)
222
224
  complete?.(res)
@@ -25,3 +25,6 @@ export const clearStorageSync = temporarilyNotSupport('clearStorageSync', 'clear
25
25
  // 屏幕
26
26
  export const onUserCaptureScreen = temporarilyNotSupport('onUserCaptureScreen', '', false)
27
27
  export const offUserCaptureScreen = temporarilyNotSupport('offUserCaptureScreen', '', false)
28
+
29
+ // 文件
30
+ export const getFileSystemManager = temporarilyNotSupport('getFileSystemManager', '', false)
package/src/setup.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { jest } from '@jest/globals'
2
+ import '@testing-library/jest-native/extend-expect'
3
+ import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js'
4
+ import { NetInfoStateType } from '@react-native-community/netinfo'
5
+ import mockRNCAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock.js'
6
+ import mockRNCDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock'
7
+
8
+ jest.doMock('@react-native-community/netinfo', () => ({ ...mockRNCNetInfo, NetInfoStateType }))
9
+ jest.doMock('@react-native-async-storage/async-storage', () => mockRNCAsyncStorage)
10
+ jest.doMock('react-native-device-info', () => mockRNCDeviceInfo)
11
+
12
+ jest.doMock('react-native', () => {
13
+ const ReactNative = jest.requireActual('react-native') as any
14
+
15
+ // Vibration readonly so you need use defineProperty rewrite this property descriptor.
16
+ const Vibration = (jest.requireActual('./__tests__/__mock__/mockVibrate') as any).default
17
+ Object.defineProperty(ReactNative, 'Vibration', {
18
+ enumerable: false,
19
+ configurable: false,
20
+ writable: false,
21
+ value: Vibration
22
+ })
23
+
24
+ // mockNativeModules: react-native/Libraries/BatchedBridge/NativeModules
25
+ const RNCCameraRoll = (jest.requireActual('./__tests__/__mock__/mockRNCCameraRoll') as any).default
26
+ const MockClipboard = (jest.requireActual('./__tests__/__mock__/mockClipboard') as any).default
27
+ const RNCGeolocation = (jest.requireActual('./__tests__/__mock__/mockRNCGeolocation') as any).default
28
+ ReactNative.NativeModules.RNCCameraRoll = RNCCameraRoll
29
+ ReactNative.NativeModules.RNCClipboard = new MockClipboard()
30
+ ReactNative.NativeModules.RNCGeolocation = RNCGeolocation
31
+ Object.defineProperty(ReactNative.NativeModules, 'ImageLoader', {
32
+ configurable: true,
33
+ enumerable: true,
34
+ get: () => ({
35
+ prefetchImage: jest.fn(),
36
+ getSize: jest.fn((_uri, success: any) => {
37
+ process.nextTick(() => success && success(320, 240))
38
+ return Promise.resolve([320, 240])
39
+ }),
40
+ }),
41
+ })
42
+ return ReactNative
43
+ })
44
+
45
+ jest.doMock('@unimodules/core', () => {
46
+ const unimodules = jest.requireActual('@unimodules/core') as any
47
+ const permisson = jest.requireActual('./__tests__/__mock__/mockExpoPermissions')
48
+ const { NativeModulesProxy } = unimodules
49
+
50
+ NativeModulesProxy.ExpoLocation = {
51
+ getCurrentPositionAsync: jest.fn(() => Promise.resolve({
52
+ coords: {
53
+ latitude: 0,
54
+ longitude: 0,
55
+ speed: 0,
56
+ accuracy: 0,
57
+ altitude: 0
58
+ }
59
+ }))
60
+ }
61
+ NativeModulesProxy.ExpoPermissions = permisson
62
+
63
+ return unimodules
64
+ })
65
+
66
+ jest.doMock('react-native-unimodules', () => {
67
+ const unimodules = jest.requireActual('react-native-unimodules') as any
68
+ const permisson = jest.requireActual('./__tests__/__mock__/mockExpoPermissions')
69
+ unimodules.Permissions = permisson
70
+ return unimodules
71
+ })
@@ -13,3 +13,5 @@ declare interface HTMLMediaElement {}
13
13
  declare interface File {}
14
14
 
15
15
  declare interface MediaTrackSettings {}
16
+
17
+ declare const global: any