@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.
- package/LICENSE +14 -0
- package/dist/lib/chooseImage/index.js +3 -151
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseMedia/index.js +19 -0
- package/dist/lib/chooseMedia/index.js.map +1 -0
- package/dist/lib/chooseVideo/index.js +1 -55
- package/dist/lib/chooseVideo/index.js.map +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/media.js +56 -27
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/request/index.js +1 -1
- package/dist/lib/request/index.js.map +1 -1
- package/dist/lib/scanCode/index.js +1 -1
- package/dist/lib/showActionSheet/index.js +10 -24
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/setup.js +13 -30
- package/dist/setup.js.map +1 -1
- package/libList.js +1 -0
- package/package.json +45 -48
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +3 -12
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +11 -16
- package/src/__tests__/clipboard.test.ts +2 -2
- package/src/lib/chooseImage/index.ts +3 -155
- package/src/lib/chooseMedia/index.ts +15 -0
- package/src/lib/chooseVideo/index.ts +1 -56
- package/src/lib/file.ts +1 -1
- package/src/lib/index.ts +1 -0
- package/src/lib/media.ts +76 -27
- package/src/lib/request/index.ts +1 -1
- package/src/lib/scanCode/index.tsx +1 -1
- package/src/lib/showActionSheet/index.tsx +10 -36
- package/src/setup.ts +13 -33
- package/types/runtime.d.ts +3 -0
- package/src/__tests__/__mock__/mockAsyncStorage.js +0 -47
- package/src/__tests__/__mock__/mockClipboard.js +0 -15
- package/src/__tests__/__mock__/mockNavigator.js +0 -20
- package/src/__tests__/__mock__/mockNetwork.js +0 -59
- package/src/__tests__/__mock__/mockVibrate.js +0 -6
|
@@ -143,7 +143,7 @@ function scanFromPhoto(callback, errorCallBack) {
|
|
|
143
143
|
})
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
}, MEDIA_TYPE.
|
|
146
|
+
}, MEDIA_TYPE.Images).catch(errorCallBack)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.scanCode.SuccessCallbackResult> {
|
|
@@ -20,9 +20,13 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
20
20
|
sibling && sibling.destroy()
|
|
21
21
|
sibling = undefined
|
|
22
22
|
const res = { tapIndex, errMsg: 'showActionSheet:ok' }
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// fix: iOS 无法打开相册
|
|
24
|
+
// https://github.com/expo/expo/issues/25705
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
success?.(res)
|
|
27
|
+
complete?.(res)
|
|
28
|
+
resolve(res)
|
|
29
|
+
}, 1)
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
function onFail () {
|
|
@@ -38,7 +42,7 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
38
42
|
<ActionSheet
|
|
39
43
|
autoDectect={autoDectect}
|
|
40
44
|
type={type}
|
|
41
|
-
visible={
|
|
45
|
+
visible={true}
|
|
42
46
|
onClose={onFail}
|
|
43
47
|
menus={
|
|
44
48
|
itemList.map((item, index) => {
|
|
@@ -46,7 +50,7 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
46
50
|
type: 'default',
|
|
47
51
|
label: item,
|
|
48
52
|
textStyle: { color: itemColor },
|
|
49
|
-
onPress: onSuccess
|
|
53
|
+
onPress: () => onSuccess(index)
|
|
50
54
|
}
|
|
51
55
|
}) as any
|
|
52
56
|
}
|
|
@@ -55,41 +59,11 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
55
59
|
type: 'default',
|
|
56
60
|
label: '取消',
|
|
57
61
|
textStyle: { color: itemColor },
|
|
58
|
-
onPress: onFail
|
|
62
|
+
onPress: onFail
|
|
59
63
|
}
|
|
60
64
|
] as any}
|
|
61
65
|
/>
|
|
62
66
|
)
|
|
63
|
-
|
|
64
|
-
// hack 的做法。不推荐
|
|
65
|
-
setTimeout(() => {
|
|
66
|
-
sibling.update(
|
|
67
|
-
<ActionSheet
|
|
68
|
-
autoDectect={autoDectect}
|
|
69
|
-
type={type}
|
|
70
|
-
visible
|
|
71
|
-
onClose={onFail}
|
|
72
|
-
menus={
|
|
73
|
-
itemList.map((item, index) => {
|
|
74
|
-
return {
|
|
75
|
-
type: 'default',
|
|
76
|
-
label: item,
|
|
77
|
-
textStyle: { color: itemColor },
|
|
78
|
-
onPress: onSuccess.bind(this, index)
|
|
79
|
-
}
|
|
80
|
-
}) as any
|
|
81
|
-
}
|
|
82
|
-
actions={[
|
|
83
|
-
{
|
|
84
|
-
type: 'default',
|
|
85
|
-
label: '取消',
|
|
86
|
-
textStyle: { color: itemColor },
|
|
87
|
-
onPress: onFail.bind(this)
|
|
88
|
-
}
|
|
89
|
-
] as any}
|
|
90
|
-
/>
|
|
91
|
-
)
|
|
92
|
-
}, 100)
|
|
93
67
|
})
|
|
94
68
|
}
|
|
95
69
|
|
package/src/setup.ts
CHANGED
|
@@ -1,44 +1,24 @@
|
|
|
1
|
-
import { jest } from '@jest/globals'
|
|
2
1
|
import '@testing-library/jest-native/extend-expect'
|
|
3
|
-
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock.js'
|
|
4
2
|
import { NetInfoStateType } from '@react-native-community/netinfo'
|
|
5
|
-
import
|
|
3
|
+
import mockRNCNetInfo from '@react-native-community/netinfo/jest/netinfo-mock'
|
|
4
|
+
import mockRNCAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'
|
|
6
5
|
import mockRNCDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock'
|
|
7
|
-
|
|
6
|
+
import mockRNCClipboard from '@react-native-clipboard/clipboard/jest/clipboard-mock'
|
|
7
|
+
import mockRNCGeolocation from './__tests__/__mock__/mockRNCGeolocation'
|
|
8
|
+
import mockRNCameraRoll from './__tests__/__mock__/mockRNCCameraRoll'
|
|
9
|
+
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter')
|
|
8
10
|
jest.doMock('@react-native-community/netinfo', () => ({ ...mockRNCNetInfo, NetInfoStateType }))
|
|
9
11
|
jest.doMock('@react-native-async-storage/async-storage', () => mockRNCAsyncStorage)
|
|
12
|
+
jest.doMock('@react-native-community/geolocation', () => mockRNCGeolocation)
|
|
13
|
+
jest.doMock('@react-native-clipboard/clipboard', () => mockRNCClipboard)
|
|
10
14
|
jest.doMock('react-native-device-info', () => mockRNCDeviceInfo)
|
|
15
|
+
jest.mock('@react-native-camera-roll/camera-roll', () => mockRNCameraRoll)
|
|
11
16
|
|
|
12
|
-
jest.
|
|
17
|
+
jest.mock('react-native', () => {
|
|
13
18
|
const ReactNative = jest.requireActual('react-native') as any
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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.RNCCameraRoll
|
|
29
|
-
ReactNative.NativeModules.RNCCameraRollPermissionModule = RNCCameraRoll.RNCCameraRollPermissionModule
|
|
30
|
-
ReactNative.NativeModules.RNCClipboard = new MockClipboard()
|
|
31
|
-
ReactNative.NativeModules.RNCGeolocation = RNCGeolocation
|
|
32
|
-
Object.defineProperty(ReactNative.NativeModules, 'ImageLoader', {
|
|
33
|
-
configurable: true,
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: () => ({
|
|
36
|
-
prefetchImage: jest.fn(),
|
|
37
|
-
getSize: jest.fn((_uri, success: any) => {
|
|
38
|
-
process.nextTick(() => success && success(320, 240))
|
|
39
|
-
return Promise.resolve([320, 240])
|
|
40
|
-
}),
|
|
41
|
-
}),
|
|
19
|
+
ReactNative.Image.getSize = jest.fn((_uri, success: any) => {
|
|
20
|
+
setTimeout(() => success && success(320, 240))
|
|
21
|
+
return Promise.resolve([320, 240])
|
|
42
22
|
})
|
|
43
23
|
return ReactNative
|
|
44
24
|
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
export default class MockStorage {
|
|
2
|
-
constructor (cache = {}) {
|
|
3
|
-
this.storageCache = cache
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
setItem = jest.fn((key, value) => {
|
|
7
|
-
return new Promise((resolve, reject) => {
|
|
8
|
-
return (typeof key !== 'string' || typeof value !== 'string')
|
|
9
|
-
? reject(new Error('key and value must be string'))
|
|
10
|
-
: resolve(this.storageCache[key] = value)
|
|
11
|
-
})
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
getItem = jest.fn((key) => {
|
|
15
|
-
return new Promise((resolve) => {
|
|
16
|
-
// eslint-disable-next-line
|
|
17
|
-
return this.storageCache.hasOwnProperty(key)
|
|
18
|
-
? resolve(this.storageCache[key])
|
|
19
|
-
: resolve(null)
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
removeItem = jest.fn((key) => {
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
return this.storageCache.hasOwnProperty(key)
|
|
26
|
-
? resolve(delete this.storageCache[key])
|
|
27
|
-
: reject(new Error('No such key!'))
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
clear = jest.fn(() => {
|
|
32
|
-
return new Promise((resolve) => resolve(this.storageCache = {}))
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
getAllKeys = jest.fn(() => {
|
|
36
|
-
return new Promise((resolve) => resolve(Object.keys(this.storageCache)))
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
multiRemove = jest.fn((keys) => {
|
|
40
|
-
return new Promise((resolve) => {
|
|
41
|
-
keys.forEach(key => {
|
|
42
|
-
this.removeItem(key)
|
|
43
|
-
})
|
|
44
|
-
resolve()
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const geolocation = {
|
|
2
|
-
getCurrentPosition (callback) {
|
|
3
|
-
const res = {}
|
|
4
|
-
const coords = {
|
|
5
|
-
latitude: 0,
|
|
6
|
-
longitude: 0,
|
|
7
|
-
speed: 0,
|
|
8
|
-
accuracy: 0,
|
|
9
|
-
altitude: 0
|
|
10
|
-
}
|
|
11
|
-
res.coords = coords
|
|
12
|
-
res.timestamp = Date.now()
|
|
13
|
-
callback && callback(res)
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const navigator = {}
|
|
18
|
-
navigator.geolocation = geolocation
|
|
19
|
-
|
|
20
|
-
export default navigator
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line
|
|
2
|
-
const noop = () => {}
|
|
3
|
-
|
|
4
|
-
export default class NetInfo {
|
|
5
|
-
constructor (connectionType = 'wifi', effectiveConnectionType = '4g') {
|
|
6
|
-
this.connectionType = connectionType
|
|
7
|
-
this.effectiveConnectionType = effectiveConnectionType
|
|
8
|
-
this.eventMaps = {}
|
|
9
|
-
this.connectedStatus = connectionType === 'wifi' || connectionType === 'cellular'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
isConnected = {
|
|
13
|
-
fetch: this.fetch.bind(this)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
fetch () {
|
|
17
|
-
return new Promise((resolve) => {
|
|
18
|
-
resolve({
|
|
19
|
-
type: this.connectionType,
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getConnectionInfo () {
|
|
25
|
-
return new Promise((resolve) => {
|
|
26
|
-
const res = {}
|
|
27
|
-
res.type = this.connectionType
|
|
28
|
-
res.effectiveType = this.effectiveConnectionType
|
|
29
|
-
resolve(res)
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
addEventListener (eventName, listener = noop) {
|
|
34
|
-
this.eventMaps[eventName] = listener
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
removeEventListener (eventName, listener = noop) {
|
|
38
|
-
if (this.eventMaps[eventName] === listener) {
|
|
39
|
-
delete this.eventMaps[eventName]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 纯粹为了模拟测试用,主动更改网络状态
|
|
44
|
-
changeNetworkType (connectionType, effectiveConnectionType = '4g') {
|
|
45
|
-
if (this.connectionType !== connectionType) {
|
|
46
|
-
this.connectionType = connectionType
|
|
47
|
-
if (connectionType === 'cellular') {
|
|
48
|
-
this.effectiveConnectionType = effectiveConnectionType
|
|
49
|
-
}
|
|
50
|
-
this.connectedStatus = connectionType === 'wifi' || connectionType === 'cellular'
|
|
51
|
-
|
|
52
|
-
const res = {}
|
|
53
|
-
res.type = this.connectionType
|
|
54
|
-
res.effectiveType = this.effectiveConnectionType
|
|
55
|
-
const fn = this.eventMaps.connectionChange
|
|
56
|
-
fn && fn(res)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|