@tarojs/taro-rn 4.0.0-alpha.0 → 4.0.0-alpha.2

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 (39) hide show
  1. package/LICENSE +14 -0
  2. package/dist/lib/chooseImage/index.js +3 -151
  3. package/dist/lib/chooseImage/index.js.map +1 -1
  4. package/dist/lib/chooseMedia/index.js +19 -0
  5. package/dist/lib/chooseMedia/index.js.map +1 -0
  6. package/dist/lib/chooseVideo/index.js +1 -55
  7. package/dist/lib/chooseVideo/index.js.map +1 -1
  8. package/dist/lib/index.js +1 -0
  9. package/dist/lib/index.js.map +1 -1
  10. package/dist/lib/media.js +56 -27
  11. package/dist/lib/media.js.map +1 -1
  12. package/dist/lib/request/index.js +1 -1
  13. package/dist/lib/request/index.js.map +1 -1
  14. package/dist/lib/scanCode/index.js +1 -1
  15. package/dist/lib/showActionSheet/index.js +10 -24
  16. package/dist/lib/showActionSheet/index.js.map +1 -1
  17. package/dist/setup.js +13 -30
  18. package/dist/setup.js.map +1 -1
  19. package/libList.js +1 -0
  20. package/package.json +45 -48
  21. package/src/__tests__/__mock__/mockRNCCameraRoll.js +3 -12
  22. package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +11 -16
  23. package/src/__tests__/clipboard.test.ts +2 -2
  24. package/src/lib/chooseImage/index.ts +3 -155
  25. package/src/lib/chooseMedia/index.ts +15 -0
  26. package/src/lib/chooseVideo/index.ts +1 -56
  27. package/src/lib/file.ts +1 -1
  28. package/src/lib/index.ts +1 -0
  29. package/src/lib/media.ts +76 -27
  30. package/src/lib/request/index.ts +1 -1
  31. package/src/lib/scanCode/index.tsx +1 -1
  32. package/src/lib/showActionSheet/index.tsx +10 -36
  33. package/src/setup.ts +13 -33
  34. package/types/runtime.d.ts +3 -0
  35. package/src/__tests__/__mock__/mockAsyncStorage.js +0 -47
  36. package/src/__tests__/__mock__/mockClipboard.js +0 -15
  37. package/src/__tests__/__mock__/mockNavigator.js +0 -20
  38. package/src/__tests__/__mock__/mockNetwork.js +0 -59
  39. package/src/__tests__/__mock__/mockVibrate.js +0 -6
package/dist/setup.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AACpC,OAAO,4CAA4C,CAAA;AACnD,OAAO,cAAc,MAAM,sDAAsD,CAAA;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,mBAAmB,MAAM,sEAAsE,CAAA;AACtG,OAAO,iBAAiB,MAAM,6DAA6D,CAAA;AAE3F,IAAI,CAAC,MAAM,CAAC,iCAAiC,EAAE,GAAG,EAAE,CAAC,iCAAM,cAAc,KAAE,gBAAgB,IAAG,CAAC,CAAA;AAC/F,IAAI,CAAC,MAAM,CAAC,2CAA2C,EAAE,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAA;AACnF,IAAI,CAAC,MAAM,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,CAAA;AAEhE,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,GAAG,EAAE;IAC/B,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,cAAc,CAAQ,CAAA;IAE7D,sFAAsF;IACtF,MAAM,SAAS,GAAI,IAAI,CAAC,aAAa,CAAC,kCAAkC,CAAS,CAAC,OAAO,CAAA;IACzF,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,WAAW,EAAE;QAC9C,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;QACnB,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,SAAS;KACjB,CAAC,CAAA;IAEF,wEAAwE;IACxE,MAAM,aAAa,GAAI,IAAI,CAAC,aAAa,CAAC,wCAAwC,CAAS,CAAC,OAAO,CAAA;IACnG,MAAM,aAAa,GAAI,IAAI,CAAC,aAAa,C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AC5E,kBAAkB,CAAC,uBAAuB,GAAG,cAAc,CAAA;IAC3D,OAAO,kBAAkB,CAAA;AAC3B,CAAC,CAAC,CAAA"}
package/libList.js CHANGED
@@ -6,6 +6,7 @@ module.exports = [
6
6
  'base64ToArrayBuffer',
7
7
  'canIUse',
8
8
  'chooseImage',
9
+ 'chooseMedia',
9
10
  'chooseVideo',
10
11
  'clearStorage',
11
12
  'clearStorageSync',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-rn",
3
- "version": "4.0.0-alpha.0",
3
+ "version": "4.0.0-alpha.2",
4
4
  "description": "Taro RN framework",
5
5
  "main": "dist/index.js",
6
6
  "typings": "types/index.d.ts",
@@ -21,73 +21,70 @@
21
21
  "author": "O2Team",
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@bam.tech/react-native-image-resizer": "~3.0.4",
25
- "@react-native-async-storage/async-storage": "~1.17.7",
26
- "@react-native-camera-roll/camera-roll": "~5.2.3",
27
- "@react-native-clipboard/clipboard": "~1.11.1",
28
- "@react-native-community/geolocation": "~3.0.2",
29
- "@react-native-community/netinfo": "~9.3.0",
30
- "babel-preset-expo": "~9.2.1",
24
+ "@bam.tech/react-native-image-resizer": "~3.0.5",
25
+ "@react-native-async-storage/async-storage": "~1.21.0",
26
+ "@react-native-camera-roll/camera-roll": "~7.2.0",
27
+ "@react-native-clipboard/clipboard": "~1.13.0",
28
+ "@react-native-community/geolocation": "~3.1.0",
29
+ "@react-native-community/netinfo": "~11.2.0",
30
+ "babel-preset-expo": "~10.0.0",
31
31
  "base64-js": "^1.3.0",
32
32
  "deprecated-react-native-prop-types": "^2.3.0",
33
- "expo-av": "~13.2.1",
34
- "expo-barcode-scanner": "~12.3.1",
35
- "expo-brightness": "~11.2.1",
36
- "expo-camera": "~13.2.1",
37
- "expo-file-system": "~15.2.2",
38
- "expo-image-picker": "~14.1.1",
39
- "expo-keep-awake": "~12.0.1",
40
- "expo-location": "~15.1.1",
41
- "expo-sensors": "~12.1.1",
33
+ "expo-av": "~13.10.0",
34
+ "expo-barcode-scanner": "~12.9.0",
35
+ "expo-brightness": "~11.8.0",
36
+ "expo-camera": "~14.0.0",
37
+ "expo-file-system": "~16.0.0",
38
+ "expo-image-picker": "~14.7.0",
39
+ "expo-keep-awake": "~12.8.0",
40
+ "expo-location": "~16.5.1",
41
+ "expo-sensors": "~12.9.0",
42
42
  "nullthrows": "^1.1.1",
43
43
  "prop-types": "^15.8.1",
44
- "react-native-device-info": "~10.4.0",
44
+ "react-native-device-info": "~10.12.0",
45
45
  "react-native-image-zoom-viewer": "^3.0.1",
46
- "react-native-root-siblings": "^4.1.1",
47
- "react-native-root-toast": "^3.0.1",
48
- "react-native-safe-area-context": "~4.5.0",
46
+ "react-native-root-siblings": "^5.0.1",
47
+ "react-native-root-toast": "^3.5.1",
48
+ "react-native-safe-area-context": "~4.8.0",
49
49
  "react-native-stylekit": "^1.0.0",
50
- "react-native-syan-image-picker": "0.5.3",
51
- "@tarojs/runtime-rn": "4.0.0-alpha.0"
50
+ "@tarojs/runtime-rn": "4.0.0-alpha.2"
52
51
  },
53
52
  "devDependencies": {
54
53
  "@babel/core": "^7.14.5",
55
54
  "@babel/preset-env": "^7.14.5",
56
- "@jest/globals": "^26.6.2",
55
+ "@react-native/babel-preset": "^0.73.18",
57
56
  "@testing-library/jest-native": "^5.4.2",
58
- "@testing-library/react-native": "^12.0.1",
57
+ "@testing-library/react-native": "^12.4.1",
59
58
  "@types/jest": "^27.4.1",
60
- "expo": "~48.0.0",
59
+ "expo": "~50.0.2",
61
60
  "fbjs-scripts": "^3.0.1",
62
61
  "jest": "^29.3.1",
63
62
  "jest-cli": "^29.3.1",
64
63
  "jest-environment-node": "^29.5.0",
65
- "jest-expo": "^48.0.2",
66
- "metro-react-native-babel-preset": "^0.73.7",
64
+ "jest-expo": "^50.0.0",
67
65
  "mock-socket": "^7.1.0",
68
66
  "react": "18.2.0",
69
- "react-native": "^0.71.3",
67
+ "react-native": "^0.73.1",
70
68
  "react-test-renderer": "18.2.0"
71
69
  },
72
70
  "peerDependencies": {
73
- "@bam.tech/react-native-image-resizer": "~3.0.4",
74
- "@react-native-async-storage/async-storage": "~1.17.7",
75
- "@react-native-camera-roll/camera-roll": "~5.2.3",
76
- "@react-native-clipboard/clipboard": "~1.11.1",
77
- "@react-native-community/geolocation": "~3.0.2",
78
- "@react-native-community/netinfo": "~9.3.0",
79
- "expo-av": "~13.2.1",
80
- "expo-barcode-scanner": "~12.3.1",
81
- "expo-brightness": "~11.2.1",
82
- "expo-camera": "~13.2.1",
83
- "expo-file-system": "~15.2.2",
84
- "expo-image-picker": "~14.1.1",
85
- "expo-keep-awake": "~12.0.1",
86
- "expo-location": "~15.1.1",
87
- "expo-sensors": "~12.1.1",
88
- "react-native-device-info": "~10.4.0",
89
- "react-native-safe-area-context": "~4.5.0",
90
- "react-native-syan-image-picker": "0.5.3"
71
+ "@bam.tech/react-native-image-resizer": "~3.0.5",
72
+ "@react-native-async-storage/async-storage": "~1.21.0",
73
+ "@react-native-camera-roll/camera-roll": "~7.2.0",
74
+ "@react-native-clipboard/clipboard": "~1.13.0",
75
+ "@react-native-community/geolocation": "~3.1.0",
76
+ "@react-native-community/netinfo": "~11.2.0",
77
+ "expo-av": "~13.10.0",
78
+ "expo-barcode-scanner": "~12.9.0",
79
+ "expo-brightness": "~11.8.0",
80
+ "expo-camera": "~14.0.0",
81
+ "expo-file-system": "~16.0.0",
82
+ "expo-image-picker": "~14.7.0",
83
+ "expo-keep-awake": "~12.8.0",
84
+ "expo-location": "~16.5.1",
85
+ "expo-sensors": "~12.9.0",
86
+ "react-native-device-info": "~10.12.0",
87
+ "react-native-safe-area-context": "~4.8.0"
91
88
  },
92
89
  "scripts": {
93
90
  "assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist",
@@ -95,7 +92,7 @@
95
92
  "dev": "pnpm run assets && tsc --watch",
96
93
  "lint": "eslint .",
97
94
  "test": "jest --silent",
98
- "test:ci": "jest --ci -i --silent --coverage false",
95
+ "test:ci": "jest --ci -i --coverage --silent",
99
96
  "test:coverage": "jest --coverage",
100
97
  "test:dev": "jest --watch",
101
98
  "script": "node ./script"
@@ -1,16 +1,7 @@
1
- const RNCCameraRoll = {
2
- deletePhotos: jest.fn(),
3
- saveToCameraRoll: jest.fn((url, { type }) => Promise.resolve(`${type}://${url}`)),
4
- getPhotos: jest.fn(() => Promise.resolve()),
5
- }
6
- const RNCCameraRollPermissionModule = {
7
- checkPermission: jest.fn(),
8
- requestReadWritePermission: jest.fn(),
9
- requestAddOnlyPermission: jest.fn(),
10
- refreshPhotoSelection: jest.fn(),
1
+ const CameraRoll = {
2
+ save: jest.fn((url, { type }) => Promise.resolve(`${type}://${url}`)),
11
3
  }
12
4
 
13
5
  export default {
14
- RNCCameraRoll,
15
- RNCCameraRollPermissionModule,
6
+ CameraRoll,
16
7
  }
@@ -15,33 +15,28 @@ exports[`scanCode should render scanCode success 1`] = `
15
15
  ]
16
16
  }
17
17
  >
18
- <ViewManagerAdapter_ExponentCamera
18
+ <ViewManagerAdapter_ExpoCamera
19
+ barCodeScannerEnabled={true}
20
+ barCodeScannerSettings={
21
+ {
22
+ "barCodeTypes": [],
23
+ }
24
+ }
25
+ faceDetectorSettings={{}}
26
+ focusDepth={0}
19
27
  onBarCodeScanned={[Function]}
20
28
  onCameraReady={[Function]}
21
29
  onFacesDetected={[Function]}
22
30
  onMountError={[Function]}
23
31
  onPictureSaved={[Function]}
24
- proxiedProperties={
25
- {
26
- "autoFocus": undefined,
27
- "barCodeScannerEnabled": true,
28
- "barCodeScannerSettings": {
29
- "barCodeTypes": [],
30
- },
31
- "faceDetectorSettings": {},
32
- "flashMode": undefined,
33
- "focusDepth": 0,
34
- "type": undefined,
35
- "whiteBalance": undefined,
36
- "zoom": 0,
37
- }
38
- }
32
+ onResponsiveOrientationChanged={[Function]}
39
33
  style={
40
34
  {
41
35
  "height": 1334,
42
36
  "width": 750,
43
37
  }
44
38
  }
39
+ zoom={0}
45
40
  />
46
41
  <View
47
42
  accessibilityLabel="Close"
@@ -12,7 +12,7 @@ const Taro = {
12
12
  describe('clipboard', () => {
13
13
  describe('setClipboardData', () => {
14
14
  test('should set value into Clipboard', async () => {
15
- const data = 'foo'
15
+ const data = 'mockString'
16
16
  const success = jest.fn()
17
17
  const fail = jest.fn()
18
18
  const complete = jest.fn()
@@ -63,7 +63,7 @@ describe('clipboard', () => {
63
63
 
64
64
  describe('getClipboardData', () => {
65
65
  test('可以获得正确的剪切板数据', async () => {
66
- const data = 'hey!hey!hey!'
66
+ const data = 'mockString'
67
67
  const success = jest.fn()
68
68
  const fail = jest.fn()
69
69
  const complete = jest.fn()
@@ -1,157 +1,5 @@
1
- import SYImagePicker from 'react-native-syan-image-picker'
1
+ import { chooseMedia, MEDIA_TYPE } from '../media'
2
2
 
3
- import { shouldBeObject } from '../../utils'
4
- import { showActionSheet } from '../showActionSheet'
5
-
6
- const res = { errMsg: 'chooseImage:ok' }
7
- const defaultOptions = {
8
- count: 9,
9
- sizeType: ['original', 'compressed'],
10
- sourceType: ['album', 'camera']
11
- }
12
-
13
- function getRes(images) {
14
- const tempFilePaths: string[] = []
15
- const tempFiles: any[] = []
16
- images.forEach((item: any) => {
17
- tempFilePaths.push(item.uri)
18
- tempFiles.push({
19
- path: item.uri,
20
- size: item.size
21
- })
22
- })
23
- return { tempFilePaths, tempFiles }
24
- }
25
-
26
- function openCamera(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
27
- const { success, fail, complete } = options
28
- return new Promise((resolve, reject) => {
29
- SYImagePicker.openCamera({
30
- compressFocusAlpha: true
31
- }, (err, photo: any) => {
32
- if (err) {
33
- const res = {
34
- errMsg: err
35
- }
36
- fail?.(res)
37
- complete?.(res)
38
- reject(res)
39
- } else {
40
- try {
41
- const data = Object.assign({}, getRes(photo), res)
42
- success?.(data)
43
- complete?.(data)
44
- resolve(data)
45
- } catch (error) {
46
- // 错误
47
- reject(error)
48
- }
49
- }
50
- })
51
- })
52
- }
53
-
54
- // NOTE: 调用此函数会改变图片的像素尺寸
55
- function openPicker(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
56
- const { count: imageCount, sizeType = [],success, complete, fail } = options
57
- return new Promise((resolve, reject) => {
58
- // NOTE:react-native-syan-image-picker 暂不支持 Android 端压缩
59
- SYImagePicker.showImagePicker({
60
- compressFocusAlpha: true,
61
- imageCount,
62
- quality: sizeType[0] === 'compressed' ? 70 : 90,
63
- }, (err, photos: any) => {
64
- if (err) {
65
- const res = {
66
- errMsg: err
67
- }
68
- fail?.(res)
69
- complete?.(res)
70
- reject(res)
71
- } else {
72
- try {
73
- const data = Object.assign({}, getRes(photos), res)
74
- success?.(data)
75
- complete?.(data)
76
- resolve(data)
77
- } catch (error) {
78
- reject(error)
79
- }
80
- }
81
- })
82
- })
83
- }
84
-
85
- /**
86
- * @description Display the image picker.
87
- * @param options
88
- * @returns {Promise}
89
- */
90
- function showImagePicker(options: Taro.chooseImage.Option):Promise<Taro.chooseImage.SuccessCallbackResult> {
91
- const { fail, complete } = options
92
- return new Promise((resolve, reject) => {
93
- showActionSheet({
94
- itemList: ['拍照', '从手机相册选择'],
95
- success(res) {
96
- console.log(res.tapIndex)
97
- if (res.tapIndex === 0) {
98
- // 不添加 setTimeout 会有一定概率卡死,肯能是与 sibling.destroy() 冲突
99
- setTimeout(() => {
100
- openCamera(options).then(res => {
101
- resolve(res)
102
- }).catch(e => {
103
- fail?.({ errMsg: `chooseImage:${e.message}` })
104
- complete?.({ errMsg: `chooseImage:${e.message}` })
105
- reject(new Error(`chooseImage:${e.message}`))
106
- })
107
- }, 100)
108
- }
109
- if (res.tapIndex === 1) {
110
- setTimeout(() => {
111
- openPicker(options).then(res => {
112
- resolve(res)
113
- }).catch(e => {
114
- fail?.({ errMsg: `chooseImage:${e.message}` })
115
- complete?.({ errMsg: `chooseImage:${e.message}` })
116
- reject(new Error(`chooseImage:${e.message}`))
117
- })
118
- }, 100)
119
- }
120
- },
121
- fail(res) {
122
- console.log('error: ', res.errMsg)
123
- }
124
- })
125
- })
126
- }
127
-
128
- /**
129
- * @deprecated
130
- * @description 从本地相册选择图片或使用相机拍照。
131
- * sizeType ❌
132
- * @param options
133
- * @returns {Promise<*>}
134
- */
135
- export function chooseImage(options: Taro.chooseImage.Option): Promise<Taro.chooseImage.SuccessCallbackResult> {
136
- // options must be an Object
137
- const isObject = shouldBeObject(options)
138
- if (!isObject.res) {
139
- const res = { errMsg: `chooseImage${isObject.msg}` }
140
- console.error(res.errMsg)
141
- return Promise.reject(res)
142
- }
143
-
144
- options = Object.assign({}, defaultOptions, options)
145
- const { sourceType } = options
146
-
147
- switch (JSON.stringify(sourceType)) {
148
- case '[\'camera\']':
149
- case '["camera"]':
150
- return openCamera(options)
151
- case '[\'album\']':
152
- case '["album"]':
153
- return openPicker(options)
154
- default:
155
- return showImagePicker(options)
156
- }
3
+ export function chooseImage(opts: Taro.chooseImage.Option): Promise<any> {
4
+ return chooseMedia(opts, MEDIA_TYPE.Images)
157
5
  }
@@ -0,0 +1,15 @@
1
+ import { chooseMedia as _chooseMedia, MEDIA_TYPE } from '../media'
2
+
3
+ export function chooseMedia (opts: Taro.chooseMedia.Option): Promise<any> {
4
+ if (opts.mediaType?.length === 1) {
5
+ if (opts.mediaType[0] === 'video') {
6
+ return _chooseMedia(opts, MEDIA_TYPE.Videos)
7
+ } else if (opts.mediaType[0] === 'image') {
8
+ return _chooseMedia(opts, MEDIA_TYPE.Images)
9
+ } else {
10
+ return _chooseMedia(opts, MEDIA_TYPE.All)
11
+ }
12
+ } else {
13
+ return _chooseMedia(opts, MEDIA_TYPE.All)
14
+ }
15
+ }
@@ -1,60 +1,5 @@
1
1
  import { chooseMedia, MEDIA_TYPE } from '../media'
2
- import { showActionSheet } from '../showActionSheet'
3
2
 
4
- /**
5
- * 拍摄视频或从手机相册中选视频。
6
- * @param {Object} opts
7
- * @param {Array} [opts.sourceType=['album', 'camera']] ✔
8
- * @param {boolean} [opts.compressed=true] ✔
9
- * @param {number} [opts.maxDuration=60] - 拍摄视频最长拍摄时间,单位秒 ✖
10
- * @param {string} [opts.camera='back'] - 默认拉起的是前置或者后置摄像头。✖
11
- * @returns {Promise<*>}
12
- */
13
3
  export function chooseVideo(opts: Taro.chooseVideo.Option): Promise<any> {
14
- const { sourceType, compressed } = opts
15
- opts = Object.assign(opts, { sizeType: compressed ? ['compressed'] : [] })
16
- switch (JSON.stringify(sourceType)) {
17
- case '[\'camera\']':
18
- case '["camera"]':
19
- return chooseMedia({...opts, sourceType: ['camera']}, MEDIA_TYPE.VIDEOS)
20
- case '[\'album\']':
21
- case '["album"]':
22
- return chooseMedia({...opts, sourceType: ['album']}, MEDIA_TYPE.VIDEOS)
23
- default:
24
- return showVideoPicker(opts)
25
- }
26
- }
27
-
28
- /**
29
- * 视频选择器
30
- * @param options
31
- * @returns {Promise}
32
- */
33
- function showVideoPicker(options: Taro.chooseVideo.Option):any {
34
- const { fail, complete } = options
35
- return new Promise((resolve, reject) => {
36
- showActionSheet({
37
- itemList: ['拍摄', '从手机相册选择'],
38
- success: function (res) {
39
- if (res.tapIndex === 0) {
40
- resolve(chooseMedia({...options, sourceType: ['camera']}, MEDIA_TYPE.VIDEOS))
41
- }
42
- if (res.tapIndex === 1) {
43
- resolve(chooseMedia({...options, sourceType: ['album']}, MEDIA_TYPE.VIDEOS))
44
- }
45
- },
46
- fail: function () {
47
- const res = { errMsg: 'chooseVideo:fail cancel' }
48
- reject(res)
49
- }
50
- }).catch(err => {
51
- console.log('error: ', err.errMsg)
52
- if (/showActionSheet:fail cancel/.test(err.errMsg)) {
53
- const res = { errMsg: 'chooseVideo:fail cancel' }
54
- fail?.(res)
55
- complete?.(res)
56
- reject(res)
57
- }
58
- })
59
- })
4
+ return chooseMedia(opts, MEDIA_TYPE.Videos)
60
5
  }
package/src/lib/file.ts CHANGED
@@ -2,7 +2,7 @@ import * as FileSystem from 'expo-file-system'
2
2
  import { Platform } from 'react-native'
3
3
  import { shouldBeObject, successHandler, errorHandler } from '../utils'
4
4
 
5
- interface Func{
5
+ interface Func {
6
6
  (arg: any): void
7
7
  }
8
8
 
package/src/lib/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from './authorize'
5
5
  export * from './base64ToArrayBuffer'
6
6
  export * from './canIUse'
7
7
  export * from './chooseImage'
8
+ export * from './chooseMedia'
8
9
  export * from './chooseVideo'
9
10
  export * from './clearStorage'
10
11
  export * from './clearStorageSync'
package/src/lib/media.ts CHANGED
@@ -1,16 +1,20 @@
1
1
  import { CameraRoll } from "@react-native-camera-roll/camera-roll"
2
2
  import { requestCameraPermissionsAsync } from 'expo-camera'
3
- import * as ImagePicker from 'expo-image-picker'
3
+ import {
4
+ requestMediaLibraryPermissionsAsync,
5
+ launchImageLibraryAsync,
6
+ launchCameraAsync,
7
+ MediaTypeOptions,
8
+ ImagePickerAsset,
9
+ } from 'expo-image-picker'
4
10
  import { successHandler, errorHandler } from '../utils'
11
+ import { showActionSheet } from "./showActionSheet"
5
12
 
6
- export const MEDIA_TYPE = {
7
- VIDEOS: 'Videos',
8
- IMAGES: 'Images'
9
- }
13
+ export const MEDIA_TYPE = MediaTypeOptions
10
14
 
11
15
  export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.saveVideoToPhotosAlbum.Option, type:string, API:string):Promise<TaroGeneral.CallbackResult> {
12
16
  const { filePath, success, fail, complete } = opts
13
- const { granted } = await ImagePicker.requestMediaLibraryPermissionsAsync()
17
+ const { granted } = await requestMediaLibraryPermissionsAsync()
14
18
  if (!granted) {
15
19
  const res = { errMsg: 'Permissions denied!' }
16
20
  return errorHandler(fail, complete)(res)
@@ -28,54 +32,99 @@ export async function saveMedia(opts: Taro.saveImageToPhotosAlbum.Option | Taro.
28
32
  }
29
33
  }
30
34
 
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 = {}
35
+ async function showPicker(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option | Taro.chooseMedia.Option, mediaTypes: MediaTypeOptions):Promise<any> {
36
+ const { fail, complete } = opts
37
+ try {
38
+ const res = await showActionSheet({
39
+ itemList: ['拍摄', '从手机相册选择'],
40
+ })
41
+ if (res.tapIndex === 0) {
42
+ return _chooseMedia({...opts, sourceType: ['camera']}, mediaTypes)
43
+ }
44
+ if (res.tapIndex === 1) {
45
+ return _chooseMedia({...opts, sourceType: ['album']}, mediaTypes)
46
+ }
47
+ } catch (err) {
48
+ const res = { errMsg: `choose${
49
+ mediaTypes === MediaTypeOptions.Images ? 'Image' : mediaTypes === MediaTypeOptions.Videos ? 'Video' : 'Media'
50
+ } fail` }
51
+ fail?.(res)
52
+ complete?.(res)
34
53
  }
35
- const { sizeType = [], sourceType = [], success, fail, complete, maxDuration } = opts as any
54
+ }
55
+
56
+ export async function chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option | Taro.chooseMedia.Option = {}, mediaTypes: MediaTypeOptions): Promise<TaroGeneral.CallbackResult> {
57
+ const {
58
+ sourceType = ['album', 'camera'],
59
+ } = opts
60
+ if(sourceType?.includes('camera') && sourceType?.includes('album')) {
61
+ return showPicker(opts, mediaTypes)
62
+ } else if (sourceType?.includes('camera')) {
63
+ return _chooseMedia({...opts, sourceType: ['camera']}, mediaTypes)
64
+ }
65
+ return _chooseMedia({...opts, sourceType: ['album']}, mediaTypes)
66
+ }
67
+
68
+ export async function _chooseMedia(opts: Taro.chooseImage.Option | Taro.chooseVideo.Option | Taro.chooseMedia.Option = {}, mediaTypes: MediaTypeOptions): Promise<TaroGeneral.CallbackResult> {
69
+ const {
70
+ sizeType = [],
71
+ sourceType = [],
72
+ success,
73
+ fail,
74
+ complete,
75
+ maxDuration,
76
+ count = (mediaTypes === MEDIA_TYPE.Videos ? 1 : 9),
77
+ compressed
78
+ } = opts as any
36
79
  const options = {
37
80
  mediaTypes,
38
- quality: sizeType[0] === 'compressed' ? 0.7 : 1,
39
- videoMaxDuration: maxDuration
81
+ quality: (sizeType[0] === 'compressed' || compressed) ? 0.7 : 1,
82
+ videoMaxDuration: maxDuration,
83
+ allowsMultipleSelection: count > 1,
84
+ selectionLimit: count,
40
85
  }
86
+ const messString = mediaTypes === MediaTypeOptions.Images ? 'Image' : mediaTypes === MediaTypeOptions.Videos ? 'Video' : 'Media'
41
87
  const isCamera = sourceType[0] === 'camera'
42
- const { granted } = isCamera ? await requestCameraPermissionsAsync() : await ImagePicker.requestMediaLibraryPermissionsAsync()
88
+ const { granted } = isCamera ? await requestCameraPermissionsAsync() : await requestMediaLibraryPermissionsAsync()
43
89
  if (!granted) {
44
90
  const res = { errMsg: 'Permissions denied!' }
45
91
  return errorHandler(fail, complete)(res)
46
92
  }
47
93
 
48
- let launchMediaAsync = isCamera ? ImagePicker.launchCameraAsync : ImagePicker.launchImageLibraryAsync
94
+ let launchMediaAsync = isCamera ? launchCameraAsync : launchImageLibraryAsync
49
95
  try {
50
- const resp: any = await launchMediaAsync(options as any)
51
- const { uri, duration, width, height } = resp
52
- resp.path = uri
53
-
96
+ const resp = await launchMediaAsync(options)
54
97
  let res: any = {}
55
- if (mediaTypes === MEDIA_TYPE.VIDEOS) {
98
+ if (mediaTypes === MEDIA_TYPE.Videos) {
99
+ const asset = resp.assets?.[0]
56
100
  res = {
57
- tempFilePath: uri,
58
- duration,
59
- width,
60
- height
101
+ ...asset,
102
+ tempFilePath: asset?.uri,
103
+ size: asset?.fileSize,
61
104
  }
62
105
  } else {
63
106
  res = {
64
- tempFilePaths: [uri],
65
- tempFiles: [resp]
107
+ tempFilePaths: resp.assets?.map((item) => item.uri),
108
+ tempFiles: resp.assets?.map((item: ImagePickerAsset) => ({
109
+ ...item,
110
+ path: item.uri,
111
+ size: item.fileSize,
112
+ type: item.mimeType,
113
+ fileType: item.mimeType?.startsWith('video') ? 'video' : 'image',
114
+ }))
66
115
  }
67
116
  }
68
117
  if (res.tempFilePath || (!!res.tempFilePaths && res.tempFilePaths.length > 0)) {
69
118
  return successHandler(success, complete)(res)
70
119
  } else {
71
120
  const res = {
72
- errMsg: mediaTypes === MEDIA_TYPE.VIDEOS ? 'chooseVideo:fail cancel' : 'chooseImage:fail cancel',
121
+ errMsg: `choose${messString}:fail cancel`
73
122
  }
74
123
  return errorHandler(fail, complete)(res)
75
124
  }
76
125
  } catch (err) {
77
126
  const res = {
78
- errMsg: mediaTypes === MEDIA_TYPE.VIDEOS ? 'chooseVideo fail' : 'chooseImage fail',
127
+ errMsg: `choose${messString}:fail`,
79
128
  err
80
129
  }
81
130
  return errorHandler(fail, complete)(res)
@@ -83,7 +83,7 @@ function _request<T = any>(options: Taro.request.Option): Taro.RequestTask<T> {
83
83
  controller?.abort()
84
84
  reject(Error('request:fail timeout'))
85
85
  clearTimeout?.(timer)
86
- }, options.timeout ?? 2000)
86
+ }, options.timeout ?? 60000)
87
87
  })
88
88
 
89
89
  const p: any = Promise.race([fetchPromise, timeoutPromise]).then(resData => {