@tarojs/taro-rn 3.5.0-alpha.13 → 3.5.0-alpha.16

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 (58) hide show
  1. package/dist/lib/Mask.js +2 -1
  2. package/dist/lib/Mask.js.map +1 -1
  3. package/dist/lib/Popup.js +2 -1
  4. package/dist/lib/Popup.js.map +1 -1
  5. package/dist/lib/createCameraContext/index.js +38 -28
  6. package/dist/lib/createCameraContext/index.js.map +1 -1
  7. package/dist/lib/getLocation/index.js +3 -4
  8. package/dist/lib/getLocation/index.js.map +1 -1
  9. package/dist/lib/getRecorderManager/index.js +7 -11
  10. package/dist/lib/getRecorderManager/index.js.map +1 -1
  11. package/dist/lib/media.js +5 -6
  12. package/dist/lib/media.js.map +1 -1
  13. package/dist/lib/permission.js +18 -17
  14. package/dist/lib/permission.js.map +1 -1
  15. package/dist/lib/request/index.js +1 -1
  16. package/dist/lib/request/index.js.map +1 -1
  17. package/dist/lib/scanCode/index.js +4 -6
  18. package/dist/lib/scanCode/index.js.map +1 -1
  19. package/dist/lib/showActionSheet/ActionSheet.js +2 -1
  20. package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
  21. package/dist/lib/showModal/Dialog.js +4 -3
  22. package/dist/lib/showModal/Dialog.js.map +1 -1
  23. package/dist/setup.js +18 -2
  24. package/dist/setup.js.map +1 -1
  25. package/package.json +48 -47
  26. package/src/__tests__/__snapshots__/{scanCode.test.js.snap → scanCode.test.tsx.snap} +20 -2
  27. package/src/__tests__/{clipboard.test.js → clipboard.test.ts} +1 -0
  28. package/src/__tests__/{deviceMotion.test.js → deviceMotion.test.ts} +0 -0
  29. package/src/__tests__/{geolocation.test.js → geolocation.test.ts} +10 -11
  30. package/src/__tests__/{interactive.test.js → interactive.test.tsx} +0 -0
  31. package/src/__tests__/{keyboard.test.js → keyboard.test.ts} +0 -0
  32. package/src/__tests__/{media.test.js → media.test.ts} +2 -0
  33. package/src/__tests__/{network.test.js → network.test.ts} +0 -2
  34. package/src/__tests__/{others.test.js → others.test.ts} +0 -0
  35. package/src/__tests__/{phone.test.js → phone.test.ts} +0 -0
  36. package/src/__tests__/{request.test.js → request.test.ts} +6 -1
  37. package/src/__tests__/{scanCode.test.js → scanCode.test.tsx} +1 -0
  38. package/src/__tests__/{storage.test.js → storage.test.ts} +9 -5
  39. package/src/__tests__/{system.test.js → system.test.ts} +0 -0
  40. package/src/__tests__/{vibrate.test.js → vibrate.test.ts} +0 -0
  41. package/src/__tests__/{websocket.test.js → websocket.test.ts} +8 -6
  42. package/src/lib/Mask.tsx +2 -1
  43. package/src/lib/Popup.tsx +2 -1
  44. package/src/lib/createCameraContext/index.ts +30 -21
  45. package/src/lib/getLocation/index.ts +3 -4
  46. package/src/lib/getRecorderManager/index.ts +7 -11
  47. package/src/lib/media.ts +5 -6
  48. package/src/lib/permission.ts +21 -17
  49. package/src/lib/request/index.ts +1 -1
  50. package/src/lib/scanCode/index.tsx +3 -6
  51. package/src/lib/showActionSheet/ActionSheet.tsx +2 -2
  52. package/src/lib/showModal/Dialog.tsx +4 -4
  53. package/src/setup.ts +22 -3
  54. package/types/overlay.d.ts +9 -0
  55. package/dist/utils/premissions.js +0 -17
  56. package/dist/utils/premissions.js.map +0 -1
  57. package/src/__tests__/__mock__/mockExpoPermissions.js +0 -8
  58. package/src/utils/premissions.ts +0 -6
package/src/lib/media.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import CameraRoll from '@react-native-community/cameraroll'
2
- import * as Permissions from 'expo-permissions'
2
+ import { requestCameraPermissionsAsync } from 'expo-camera'
3
3
  import * as ImagePicker from 'expo-image-picker'
4
- import { askAsyncPermissions } from '../utils/premissions'
5
4
  import { successHandler, errorHandler } from '../utils'
6
5
 
7
6
  export const MEDIA_TYPE = {
@@ -11,8 +10,8 @@ export const MEDIA_TYPE = {
11
10
 
12
11
  export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.saveVideoToPhotosAlbum.Option, type:string, API:string):Promise<TaroGeneral.CallbackResult> {
13
12
  const { filePath, success, fail, complete } = opts
14
- const status = await askAsyncPermissions(Permissions.CAMERA_ROLL)
15
- if (status !== 'granted') {
13
+ const { granted } = await ImagePicker.requestMediaLibraryPermissionsAsync()
14
+ if (!granted) {
16
15
  const res = { errMsg: 'Permissions denied!' }
17
16
  return errorHandler(fail, complete)(res)
18
17
  }
@@ -40,8 +39,8 @@ export async function chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVid
40
39
  videoMaxDuration: maxDuration
41
40
  }
42
41
  const isCamera = sourceType[0] === 'camera'
43
- const status = isCamera ? await askAsyncPermissions(Permissions.CAMERA) : await askAsyncPermissions(Permissions.CAMERA_ROLL)
44
- if (status !== 'granted') {
42
+ const { granted } = isCamera ? await requestCameraPermissionsAsync() : await ImagePicker.requestMediaLibraryPermissionsAsync()
43
+ if (!granted) {
45
44
  const res = { errMsg: 'Permissions denied!' }
46
45
  return errorHandler(fail, complete)(res)
47
46
  }
@@ -1,12 +1,20 @@
1
1
  import { Linking, AppState, NativeEventSubscription } from 'react-native';
2
- import * as Permissions from 'expo-permissions';
2
+ import { getCameraPermissionsAsync, getMicrophonePermissionsAsync, requestCameraPermissionsAsync, requestMicrophonePermissionsAsync } from 'expo-camera'
3
+ import { getMediaLibraryPermissionsAsync, requestMediaLibraryPermissionsAsync } from 'expo-image-picker'
4
+ import {
5
+ getForegroundPermissionsAsync,
6
+ // getBackgroundPermissionsAsync,
7
+ requestForegroundPermissionsAsync,
8
+ // requestBackgroundPermissionsAsync
9
+ } from 'expo-location'
3
10
  import { errorHandler, successHandler } from '../utils';
4
11
 
5
12
  const scopeMap = {
6
- 'scope.userLocation': Permissions.LOCATION,
7
- 'scope.record': Permissions.AUDIO_RECORDING,
8
- 'scope.writePhotosAlbum': Permissions.CAMERA_ROLL,
9
- 'scope.camera': Permissions.CAMERA,
13
+ 'scope.userLocation': [getForegroundPermissionsAsync, requestForegroundPermissionsAsync],
14
+ 'scope.record': [getMicrophonePermissionsAsync, requestMicrophonePermissionsAsync],
15
+ 'scope.writePhotosAlbum': [getMediaLibraryPermissionsAsync, requestMediaLibraryPermissionsAsync],
16
+ 'scope.camera': [getCameraPermissionsAsync, requestCameraPermissionsAsync],
17
+ // 'scope.userLocationBackground': [getBackgroundPermissionsAsync, requestBackgroundPermissionsAsync],
10
18
  // 'scope.NOTIFICATIONS': Permissions.NOTIFICATIONS,
11
19
  // 'scope.USER_FACING_NOTIFICATIONS': Permissions.USER_FACING_NOTIFICATIONS,
12
20
  // 'scope.CONTACTS': Permissions.CONTACTS,
@@ -19,17 +27,13 @@ let stateListener // 缓存监听函数
19
27
  let appStateSubscription: NativeEventSubscription | undefined
20
28
 
21
29
  const getAuthSetting = async () => {
22
- const keyArr = Object.keys(scopeMap)
23
- const scopeArr = keyArr.map(key => scopeMap[key])
24
30
  let auths = {}
25
- const { permissions } = await Permissions.getAsync(...scopeArr)
26
- Object.keys(permissions).forEach(pkey => {
27
- keyArr.forEach((skey) => {
28
- if (scopeMap[skey] === pkey) {
29
- auths[skey] = permissions[pkey].status === 'granted'
30
- }
31
- })
32
- })
31
+
32
+ await Promise.all(Object.keys(scopeMap).map(async key => {
33
+ const { granted } = await scopeMap[key][0]()
34
+ auths[key] = granted
35
+ }))
36
+
33
37
  return auths
34
38
  }
35
39
 
@@ -62,8 +66,8 @@ export async function authorize(opts: Taro.authorize.Option): Promise<TaroGenera
62
66
  const res: any = {}
63
67
 
64
68
  try {
65
- const { status } = await Permissions.askAsync(scopeMap[scope])
66
- if (status === 'granted') {
69
+ const { granted } = await scopeMap[scope][1]()
70
+ if (granted) {
67
71
  res.errMsg = 'authorize:ok'
68
72
  return successHandler(success, complete)(res)
69
73
  } else {
@@ -33,7 +33,7 @@ function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
33
33
  url = generateRequestUrlWithParams(url, data)
34
34
  } else {
35
35
  if (typeof data === 'object') {
36
- const contentType = options.header && (options.header['content-type'] || options.header['Content-Type'])
36
+ const contentType = options.header && (options.header['content-type'] || options.header['Content-Type']) || 'application/json'
37
37
  if (contentType.startsWith('application/json')) {
38
38
  data = JSON.stringify(data)
39
39
  } else if (contentType.startsWith('application/x-www-form-urlencoded')) {
@@ -1,10 +1,9 @@
1
1
  import { SafeAreaView } from 'react-native-safe-area-context'
2
2
  import { Camera } from 'expo-camera'
3
- import { BarCodeScanner } from 'expo-barcode-scanner'
3
+ import { BarCodeScanner, requestPermissionsAsync } from 'expo-barcode-scanner'
4
4
  import { BackHandler, Image, TouchableOpacity, StyleSheet, View, Dimensions, Platform, StatusBar } from 'react-native'
5
5
  import iconClose from './icon_close.png'
6
6
  import iconPic from './icon_pic.png'
7
- import * as Permissions from 'expo-permissions'
8
7
  import RootSiblings from 'react-native-root-siblings'
9
8
  import { chooseMedia, MEDIA_TYPE } from '../media'
10
9
  import React from 'react'
@@ -147,15 +146,14 @@ function scanFromPhoto(callback, errorCallBack) {
147
146
 
148
147
  export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.scanCode.SuccessCallbackResult> {
149
148
  const { success, fail, complete, onlyFromCamera, scanType = ['barCode', 'qrCode'] } = option
150
- const { status } = await Permissions.askAsync(Permissions.CAMERA)
151
- if (status !== 'granted') {
149
+ const { granted } = await requestPermissionsAsync();
150
+ if (!granted) {
152
151
  const res = { errMsg: 'Permissions denied!' }
153
152
  fail?.(res)
154
153
  complete?.(res)
155
154
  return Promise.reject(res)
156
155
  }
157
156
  const barCodeTypes = getBarCodeTypes(scanType)
158
- const cameraRef = React.createRef<Camera>()
159
157
  return new Promise((resolve, reject) => {
160
158
  scannerView = new RootSiblings(
161
159
  (<View style={[styles.container]}>
@@ -175,7 +173,6 @@ export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.
175
173
  hide(scannerView)
176
174
  resolve(res)
177
175
  }}
178
- ref={cameraRef}
179
176
  barCodeScannerSettings={{
180
177
  barCodeTypes,
181
178
  }}
@@ -5,9 +5,9 @@ import {
5
5
  Text,
6
6
  TouchableHighlight,
7
7
  StyleSheet,
8
- Platform,
9
- ViewPropTypes
8
+ Platform
10
9
  } from 'react-native'
10
+ import { ViewPropTypes } from 'deprecated-react-native-prop-types'
11
11
  import { initialWindowMetrics } from 'react-native-safe-area-context';
12
12
  import { Mask } from '../Mask'
13
13
  import { Popup } from '../Popup'
@@ -6,9 +6,9 @@ import {
6
6
  TouchableHighlight,
7
7
  Dimensions,
8
8
  StyleSheet,
9
- Platform,
10
- ViewPropTypes
9
+ Platform
11
10
  } from 'react-native'
11
+ import { ViewPropTypes, TextPropTypes } from 'deprecated-react-native-prop-types'
12
12
  import { Mask } from '../Mask'
13
13
  import { create } from '../StyleSheet'
14
14
  import V from '../variable'
@@ -223,9 +223,9 @@ Index.propTypes = {
223
223
  style: ViewPropTypes.style,
224
224
  maskStyle: ViewPropTypes.style,
225
225
  headerStyle: ViewPropTypes.style,
226
- titleStyle: (Text as any).propTypes.style,
226
+ titleStyle: TextPropTypes.style,
227
227
  bodyStyle: ViewPropTypes.style,
228
- bodyTextStyle: (Text as any).propTypes.style,
228
+ bodyTextStyle: TextPropTypes.style,
229
229
  footerStyle: ViewPropTypes.style,
230
230
  children: PropTypes.node
231
231
  }
package/src/setup.ts CHANGED
@@ -44,7 +44,6 @@ jest.doMock('react-native', () => {
44
44
 
45
45
  jest.doMock('expo-modules-core', () => {
46
46
  const unimodules = jest.requireActual('expo-modules-core') as any
47
- const permisson = jest.requireActual('./__tests__/__mock__/mockExpoPermissions')
48
47
  const { NativeModulesProxy } = unimodules
49
48
 
50
49
  NativeModulesProxy.ExpoLocation = {
@@ -58,7 +57,27 @@ jest.doMock('expo-modules-core', () => {
58
57
  }
59
58
  }))
60
59
  }
61
- NativeModulesProxy.ExpoPermissions = permisson
62
-
63
60
  return unimodules
64
61
  })
62
+
63
+ const grantedPromise = jest.fn(() => Promise.resolve({
64
+ granted: true
65
+ }))
66
+
67
+ jest.doMock('expo-image-picker', () => {
68
+ const expoImagePicker = jest.requireActual('expo-image-picker') as any
69
+ expoImagePicker.requestMediaLibraryPermissionsAsync = grantedPromise
70
+ return expoImagePicker
71
+ })
72
+
73
+ jest.doMock('expo-location', () => {
74
+ const expoLocation = jest.requireActual('expo-location') as any
75
+ expoLocation.requestForegroundPermissionsAsync = grantedPromise
76
+ return expoLocation
77
+ })
78
+
79
+ jest.doMock('expo-barcode-scanner', () => {
80
+ const expoBarcodeSacnner = jest.requireActual('expo-barcode-scanner') as any
81
+ expoBarcodeSacnner.requestPermissionsAsync = grantedPromise
82
+ return expoBarcodeSacnner
83
+ })
@@ -0,0 +1,9 @@
1
+ import Taro from '@tarojs/taro'
2
+
3
+ declare module '@tarojs/taro' {
4
+ namespace vibrateShort {
5
+ interface Option {
6
+ type?: 'heavy' | 'medium' | 'light'
7
+ }
8
+ }
9
+ }
@@ -1,17 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import * as Permissions from 'expo-permissions';
11
- export function askAsyncPermissions(PermissionsType) {
12
- return __awaiter(this, void 0, void 0, function* () {
13
- const { status } = yield Permissions.askAsync(PermissionsType);
14
- return status;
15
- });
16
- }
17
- //# sourceMappingURL=premissions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"premissions.js","sourceRoot":"","sources":["../../src/utils/premissions.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAE/C,MAAM,UAAgB,mBAAmB,CAAE,eAA2C;;QACpF,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAA;QAC9D,OAAO,MAAM,CAAA;IACf,CAAC;CAAA"}
@@ -1,8 +0,0 @@
1
- export const CAMERA = 'camera'
2
- export const CAMERA_ROLL = 'mediaLibrary'
3
- export const LOCATION = 'location'
4
- export const askAsync = jest.fn().mockImplementation((permissionType) => {
5
- const hasPermission = [CAMERA, CAMERA_ROLL, LOCATION].includes(permissionType)
6
- const responseData = hasPermission ? { status: 'granted' } : { status: 'undetermined' } // you could also pass `denied` instead of `undetermined`
7
- return Promise.resolve(responseData)
8
- })
@@ -1,6 +0,0 @@
1
- import * as Permissions from 'expo-permissions'
2
-
3
- export async function askAsyncPermissions (PermissionsType: Permissions.PermissionType): Promise<string> {
4
- const { status } = await Permissions.askAsync(PermissionsType)
5
- return status
6
- }