@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.
- package/LICENSE +8 -8
- package/apiList.js +31 -31
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/lib/Mask.js +2 -2
- package/dist/lib/Mask.js.map +1 -1
- package/dist/lib/Popup.js +13 -20
- package/dist/lib/Popup.js.map +1 -1
- package/dist/lib/StyleSheet.js +1 -1
- package/dist/lib/StyleSheet.js.map +1 -1
- package/dist/lib/accelerometer.js +1 -1
- package/dist/lib/accelerometer.js.map +1 -1
- package/dist/lib/chooseImage/index.js +151 -3
- package/dist/lib/chooseImage/index.js.map +1 -1
- package/dist/lib/chooseVideo/index.js +55 -1
- package/dist/lib/chooseVideo/index.js.map +1 -1
- package/dist/lib/clearStorage/index.js +2 -2
- package/dist/lib/clearStorage/index.js.map +1 -1
- package/dist/lib/compressImage/index.js +1 -1
- package/dist/lib/compressImage/index.js.map +1 -1
- package/dist/lib/connectSocket/index.js.map +1 -1
- package/dist/lib/connectSocket/socketTask.js +1 -1
- package/dist/lib/connectSocket/socketTask.js.map +1 -1
- package/dist/lib/createCameraContext/index.js +3 -3
- package/dist/lib/createCameraContext/index.js.map +1 -1
- package/dist/lib/createInnerAudioContext/index.js +2 -2
- package/dist/lib/createInnerAudioContext/index.js.map +1 -1
- package/dist/lib/createVideoContext/index.js +7 -7
- package/dist/lib/createVideoContext/index.js.map +1 -1
- package/dist/lib/deviceMotion.js +2 -2
- package/dist/lib/deviceMotion.js.map +1 -1
- package/dist/lib/file.js +4 -4
- package/dist/lib/file.js.map +1 -1
- package/dist/lib/getAppBaseInfo/index.js +2 -2
- package/dist/lib/getAppBaseInfo/index.js.map +1 -1
- package/dist/lib/getClipboardData/index.js.map +1 -1
- package/dist/lib/getImageInfo/index.js +2 -2
- package/dist/lib/getImageInfo/index.js.map +1 -1
- package/dist/lib/getLocation/index.js +4 -8
- package/dist/lib/getLocation/index.js.map +1 -1
- package/dist/lib/getRecorderManager/index.js +6 -11
- package/dist/lib/getRecorderManager/index.js.map +1 -1
- package/dist/lib/getStorage/index.js.map +1 -1
- package/dist/lib/getStorageInfo/index.js +2 -2
- package/dist/lib/getStorageInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfo/index.js +1 -1
- package/dist/lib/getSystemInfo/index.js.map +1 -1
- package/dist/lib/getSystemInfoSync/index.js +2 -2
- package/dist/lib/getSystemInfoSync/index.js.map +1 -1
- package/dist/lib/gyroscope.js +1 -1
- package/dist/lib/gyroscope.js.map +1 -1
- package/dist/lib/index.js +0 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/keyboard.js +3 -3
- package/dist/lib/keyboard.js.map +1 -1
- package/dist/lib/location.js.map +1 -1
- package/dist/lib/makePhoneCall/index.js +1 -1
- package/dist/lib/makePhoneCall/index.js.map +1 -1
- package/dist/lib/media.js +30 -61
- package/dist/lib/media.js.map +1 -1
- package/dist/lib/network.js +1 -1
- package/dist/lib/network.js.map +1 -1
- package/dist/lib/offWindowResize/index.js.map +1 -1
- package/dist/lib/onWindowResize/index.js +1 -1
- package/dist/lib/onWindowResize/index.js.map +1 -1
- package/dist/lib/openUrl/index.js +1 -1
- package/dist/lib/openUrl/index.js.map +1 -1
- package/dist/lib/permission.js +5 -6
- package/dist/lib/permission.js.map +1 -1
- package/dist/lib/previewImage/index.js +3 -3
- package/dist/lib/previewImage/index.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 +23 -23
- package/dist/lib/scanCode/index.js.map +1 -1
- package/dist/lib/screen.js +2 -2
- package/dist/lib/screen.js.map +1 -1
- package/dist/lib/setClipboardData/index.js +2 -2
- package/dist/lib/setClipboardData/index.js.map +1 -1
- package/dist/lib/setKeepScreenOn/index.js +1 -1
- package/dist/lib/setKeepScreenOn/index.js.map +1 -1
- package/dist/lib/setStorage/index.js.map +1 -1
- package/dist/lib/showActionSheet/ActionSheet.js +23 -11
- package/dist/lib/showActionSheet/ActionSheet.js.map +1 -1
- package/dist/lib/showActionSheet/index.js +24 -10
- package/dist/lib/showActionSheet/index.js.map +1 -1
- package/dist/lib/showModal/Dialog.js +36 -22
- package/dist/lib/showModal/Dialog.js.map +1 -1
- package/dist/lib/showModal/index.js.map +1 -1
- package/dist/lib/showModal/toast.js +6 -6
- package/dist/lib/showModal/toast.js.map +1 -1
- package/dist/lib/unsupportedApi.js +4 -2
- package/dist/lib/unsupportedApi.js.map +1 -1
- package/dist/lib/variable.js +1 -1
- package/dist/lib/variable.js.map +1 -1
- package/dist/lib/vibrate.js +1 -1
- package/dist/lib/vibrate.js.map +1 -1
- package/dist/lib/window.js.map +1 -1
- package/dist/setup.js +75 -0
- package/dist/setup.js.map +1 -0
- package/dist/utils/callbackManager.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/libList.js +0 -1
- package/package.json +69 -70
- package/src/__tests__/__mock__/mockAsyncStorage.js +47 -0
- package/src/__tests__/__mock__/mockClipboard.js +15 -0
- package/src/__tests__/__mock__/mockNavigator.js +20 -0
- package/src/__tests__/__mock__/mockNetwork.js +59 -0
- package/src/__tests__/__mock__/mockRNCCameraRoll.js +16 -0
- package/src/__tests__/__mock__/mockRNCGeolocation.js +13 -0
- package/src/__tests__/__mock__/mockVibrate.js +6 -0
- package/src/__tests__/__snapshots__/scanCode.test.tsx.snap +125 -0
- package/src/__tests__/clipboard.test.ts +88 -0
- package/src/__tests__/deviceMotion.test.ts +37 -0
- package/src/__tests__/geolocation.test.ts +60 -0
- package/src/__tests__/interactive.test.tsx +101 -0
- package/src/__tests__/keyboard.test.ts +46 -0
- package/src/__tests__/media.test.ts +104 -0
- package/src/__tests__/network.test.ts +57 -0
- package/src/__tests__/others.test.ts +25 -0
- package/src/__tests__/phone.test.ts +31 -0
- package/src/__tests__/request.test.ts +146 -0
- package/src/__tests__/scanCode.test.tsx +14 -0
- package/src/__tests__/storage.test.ts +202 -0
- package/src/__tests__/system.test.ts +69 -0
- package/src/__tests__/vibrate.test.ts +27 -0
- package/src/__tests__/websocket.test.ts +169 -0
- package/src/api/index.ts +31 -31
- package/src/lib/ENV_TYPE/index.ts +1 -1
- package/src/lib/Mask.tsx +2 -2
- package/src/lib/Popup.tsx +19 -26
- package/src/lib/StyleSheet.ts +1 -1
- package/src/lib/accelerometer.ts +1 -2
- package/src/lib/arrayBufferToBase64/index.ts +1 -1
- package/src/lib/base64ToArrayBuffer/index.ts +1 -1
- package/src/lib/chooseImage/index.ts +155 -3
- package/src/lib/chooseVideo/index.ts +56 -1
- package/src/lib/clearStorage/index.ts +0 -1
- package/src/lib/clearStorageSync/index.ts +1 -1
- package/src/lib/compressImage/index.ts +0 -1
- package/src/lib/connectSocket/socketTask.ts +9 -7
- package/src/lib/createCameraContext/index.ts +4 -6
- package/src/lib/createInnerAudioContext/index.ts +0 -1
- package/src/lib/createSelectorQuery/index.ts +1 -1
- package/src/lib/deviceMotion.ts +3 -4
- package/src/lib/file.ts +8 -9
- package/src/lib/getClipboardData/index.ts +0 -1
- package/src/lib/getEnv/index.ts +1 -1
- package/src/lib/getFileSystemManager/index.ts +1 -1
- package/src/lib/getLocation/index.ts +2 -7
- package/src/lib/getRecorderManager/index.ts +2 -7
- package/src/lib/getStorage/index.ts +0 -1
- package/src/lib/getStorageInfo/index.ts +0 -1
- package/src/lib/getStorageInfoSync/index.ts +1 -1
- package/src/lib/getStorageSync/index.ts +1 -1
- package/src/lib/getSystemInfo/index.ts +2 -2
- package/src/lib/getSystemInfoSync/index.ts +3 -3
- package/src/lib/gyroscope.ts +46 -47
- package/src/lib/index.ts +0 -1
- package/src/lib/keyboard.ts +4 -5
- package/src/lib/location.ts +5 -6
- package/src/lib/makePhoneCall/index.ts +1 -2
- package/src/lib/media.ts +31 -83
- package/src/lib/network.ts +5 -5
- package/src/lib/offLocationChange/index.ts +1 -1
- package/src/lib/offUserCaptureScreen/index.ts +1 -1
- package/src/lib/onLocationChange/index.ts +1 -1
- package/src/lib/onUserCaptureScreen/index.ts +1 -1
- package/src/lib/onWindowResize/index.ts +2 -2
- package/src/lib/openUrl/index.d.ts +22 -23
- package/src/lib/openUrl/index.ts +1 -2
- package/src/lib/permission.ts +25 -33
- package/src/lib/previewImage/index.tsx +3 -4
- package/src/lib/removeStorageSync/index.ts +1 -1
- package/src/lib/request/index.ts +2 -2
- package/src/lib/scanCode/index.tsx +16 -18
- package/src/lib/screen.ts +0 -1
- package/src/lib/setClipboardData/index.ts +2 -3
- package/src/lib/setKeepScreenOn/index.ts +1 -2
- package/src/lib/setStorage/index.ts +0 -1
- package/src/lib/setStorageSync/index.ts +1 -1
- package/src/lib/showActionSheet/ActionSheet.tsx +43 -34
- package/src/lib/showActionSheet/index.tsx +36 -11
- package/src/lib/showModal/Dialog.tsx +39 -34
- package/src/lib/showModal/index.tsx +0 -1
- package/src/lib/showModal/toast.tsx +13 -14
- package/src/lib/startGyroscope/index.ts +1 -1
- package/src/lib/startLocationUpdate/index.ts +1 -1
- package/src/lib/unsupportedApi.ts +5 -3
- package/src/lib/vibrate.ts +10 -11
- package/src/lib/window.ts +2 -3
- package/src/setup.ts +84 -0
- package/{types → src/types}/vue/index.d.ts +3 -2
- package/src/utils/callbackManager.ts +5 -5
- package/src/utils/index.ts +4 -4
- package/dist/lib/chooseMedia/index.js +0 -19
- package/dist/lib/chooseMedia/index.js.map +0 -1
- package/src/lib/chooseMedia/index.ts +0 -15
- /package/{types → src/types}/definition.d.ts +0 -0
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
1
|
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
4
3
|
import {
|
|
5
|
-
|
|
6
|
-
StyleSheet,
|
|
4
|
+
View,
|
|
7
5
|
Text,
|
|
8
6
|
TouchableHighlight,
|
|
9
|
-
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Platform
|
|
10
9
|
} from 'react-native'
|
|
11
|
-
import {
|
|
12
|
-
|
|
10
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types'
|
|
11
|
+
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
13
12
|
import { Popup } from '../Popup'
|
|
14
13
|
import V from '../variable'
|
|
15
14
|
|
|
16
15
|
const styles = StyleSheet.create({
|
|
17
|
-
|
|
16
|
+
iosActionsheet: {
|
|
18
17
|
backgroundColor: V.weuiBgColorDefault
|
|
19
18
|
},
|
|
20
19
|
androidActionsheetWrapper: {
|
|
@@ -22,6 +21,11 @@ const styles = StyleSheet.create({
|
|
|
22
21
|
alignItems: 'center',
|
|
23
22
|
justifyContent: 'center'
|
|
24
23
|
},
|
|
24
|
+
androidActionsheet: {
|
|
25
|
+
width: 274,
|
|
26
|
+
backgroundColor: V.weuiBgColorDefault,
|
|
27
|
+
borderRadius: V.weuiActionSheetAndroidBorderRadius
|
|
28
|
+
},
|
|
25
29
|
actionsheetMenu: {
|
|
26
30
|
backgroundColor: '#fff'
|
|
27
31
|
},
|
|
@@ -32,23 +36,29 @@ const styles = StyleSheet.create({
|
|
|
32
36
|
actionsheetCell: {
|
|
33
37
|
borderTopWidth: StyleSheet.hairlineWidth,
|
|
34
38
|
borderColor: V.weuiCellBorderColor,
|
|
35
|
-
borderStyle: 'solid'
|
|
39
|
+
borderStyle: 'solid'
|
|
40
|
+
},
|
|
41
|
+
iosActionsheetCell: {
|
|
36
42
|
paddingTop: 10,
|
|
37
|
-
paddingBottom: 10
|
|
43
|
+
paddingBottom: 10
|
|
44
|
+
},
|
|
45
|
+
androidActionsheetCell: {
|
|
46
|
+
paddingTop: 13,
|
|
47
|
+
paddingBottom: 13,
|
|
38
48
|
paddingLeft: 24,
|
|
39
49
|
paddingRight: 24
|
|
40
50
|
},
|
|
41
|
-
|
|
42
51
|
firstActionsheetCell: {
|
|
43
52
|
borderTopWidth: 0
|
|
44
53
|
},
|
|
45
|
-
|
|
54
|
+
iosActionsheetCellText: {
|
|
46
55
|
textAlign: 'center',
|
|
47
56
|
fontSize: 18,
|
|
48
57
|
marginTop: ((18 * V.baseLineHeight) - 18) / 2,
|
|
49
58
|
marginBottom: ((18 * V.baseLineHeight) - 18) / 2
|
|
50
59
|
},
|
|
51
60
|
androidActionsheetCellText: {
|
|
61
|
+
textAlign: 'center',
|
|
52
62
|
fontSize: 16,
|
|
53
63
|
marginTop: ((16 * 1.4) - 16) / 2,
|
|
54
64
|
marginBottom: ((16 * 1.4) - 16) / 2
|
|
@@ -95,6 +105,7 @@ const Index: React.FC<any> = ({
|
|
|
95
105
|
underlayColor={underlayColor}
|
|
96
106
|
style={[
|
|
97
107
|
styles.actionsheetCell,
|
|
108
|
+
styles[`${_type}ActionsheetCell`],
|
|
98
109
|
idx === 0 ? styles.firstActionsheetCell : {},
|
|
99
110
|
btnStyle
|
|
100
111
|
]}
|
|
@@ -102,8 +113,6 @@ const Index: React.FC<any> = ({
|
|
|
102
113
|
>
|
|
103
114
|
<Text
|
|
104
115
|
style={[
|
|
105
|
-
|
|
106
|
-
styles.actionSheetCellText,
|
|
107
116
|
styles[`${_type}ActionsheetCellText`],
|
|
108
117
|
styles[`${btnType}ActionsheetCellText`],
|
|
109
118
|
textStyle
|
|
@@ -119,6 +128,7 @@ const Index: React.FC<any> = ({
|
|
|
119
128
|
underlayColor={underlayColor}
|
|
120
129
|
style={[
|
|
121
130
|
styles.actionsheetCell,
|
|
131
|
+
styles[`${_type}ActionsheetCell`],
|
|
122
132
|
idx === 0 ? styles.firstActionsheetCell : {},
|
|
123
133
|
btnStyle
|
|
124
134
|
]}
|
|
@@ -126,7 +136,6 @@ const Index: React.FC<any> = ({
|
|
|
126
136
|
>
|
|
127
137
|
<Text
|
|
128
138
|
style={[
|
|
129
|
-
styles.actionSheetCellText,
|
|
130
139
|
styles[`${_type}ActionsheetCellText`],
|
|
131
140
|
styles[`${btnType}ActionsheetCellText`],
|
|
132
141
|
textStyle
|
|
@@ -136,29 +145,29 @@ const Index: React.FC<any> = ({
|
|
|
136
145
|
)
|
|
137
146
|
|
|
138
147
|
return <Popup
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
visible={visible}
|
|
149
|
+
style={[styles.iosActionsheet, style]}
|
|
150
|
+
maskStyle={maskStyle}
|
|
151
|
+
onShow={onShow}
|
|
152
|
+
onClose={onClose}
|
|
153
|
+
>
|
|
154
|
+
{menus.length
|
|
155
|
+
? <View style={[styles.actionsheetMenu]}>
|
|
156
|
+
{_renderMenuItems()}
|
|
157
|
+
</View>
|
|
158
|
+
: false}
|
|
159
|
+
{actions.length
|
|
160
|
+
? <View style={[styles.actionsheetAction]}>
|
|
161
|
+
{_renderActions()}
|
|
162
|
+
</View>
|
|
163
|
+
: false}
|
|
164
|
+
<View style={{paddingBottom: Math.max(initialWindowMetrics?.insets.bottom || 0, 16), backgroundColor: '#fff'}}></View>
|
|
165
|
+
</Popup>
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
Index.propTypes = {
|
|
160
169
|
autoDectect: PropTypes.bool,
|
|
161
|
-
type: PropTypes.oneOf(['ios', 'android'
|
|
170
|
+
type: PropTypes.oneOf(['ios', 'android']),
|
|
162
171
|
menus: PropTypes.any,
|
|
163
172
|
actions: PropTypes.any,
|
|
164
173
|
visible: PropTypes.bool,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import RootSiblings from 'react-native-root-siblings'
|
|
3
|
-
|
|
4
3
|
import ActionSheet from './ActionSheet'
|
|
5
4
|
|
|
6
5
|
function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showActionSheet.SuccessCallbackResult> {
|
|
@@ -21,13 +20,9 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
21
20
|
sibling && sibling.destroy()
|
|
22
21
|
sibling = undefined
|
|
23
22
|
const res = { tapIndex, errMsg: 'showActionSheet:ok' }
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
success?.(res)
|
|
28
|
-
complete?.(res)
|
|
29
|
-
resolve(res)
|
|
30
|
-
}, 1)
|
|
23
|
+
success?.(res)
|
|
24
|
+
complete?.(res)
|
|
25
|
+
resolve(res)
|
|
31
26
|
}
|
|
32
27
|
|
|
33
28
|
function onFail () {
|
|
@@ -43,7 +38,7 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
43
38
|
<ActionSheet
|
|
44
39
|
autoDectect={autoDectect}
|
|
45
40
|
type={type}
|
|
46
|
-
visible={
|
|
41
|
+
visible={false}
|
|
47
42
|
onClose={onFail}
|
|
48
43
|
menus={
|
|
49
44
|
itemList.map((item, index) => {
|
|
@@ -51,7 +46,7 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
51
46
|
type: 'default',
|
|
52
47
|
label: item,
|
|
53
48
|
textStyle: { color: itemColor },
|
|
54
|
-
onPress: (
|
|
49
|
+
onPress: onSuccess.bind(this, index)
|
|
55
50
|
}
|
|
56
51
|
}) as any
|
|
57
52
|
}
|
|
@@ -60,11 +55,41 @@ function showActionSheet (obj: Taro.showActionSheet.Option): Promise<Taro.showAc
|
|
|
60
55
|
type: 'default',
|
|
61
56
|
label: '取消',
|
|
62
57
|
textStyle: { color: itemColor },
|
|
63
|
-
onPress: onFail
|
|
58
|
+
onPress: onFail.bind(this)
|
|
64
59
|
}
|
|
65
60
|
] as any}
|
|
66
61
|
/>
|
|
67
62
|
)
|
|
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)
|
|
68
93
|
})
|
|
69
94
|
}
|
|
70
95
|
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { TextPropTypes, ViewPropTypes } from 'deprecated-react-native-prop-types'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
1
|
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
4
3
|
import {
|
|
5
|
-
|
|
6
|
-
Platform,
|
|
7
|
-
StyleSheet,
|
|
4
|
+
View,
|
|
8
5
|
Text,
|
|
9
6
|
TouchableHighlight,
|
|
10
|
-
|
|
7
|
+
Dimensions,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
Platform
|
|
11
10
|
} from 'react-native'
|
|
12
|
-
|
|
11
|
+
import { ViewPropTypes, TextPropTypes } from 'deprecated-react-native-prop-types'
|
|
13
12
|
import { Mask } from '../Mask'
|
|
14
13
|
import { create } from '../StyleSheet'
|
|
15
14
|
import V from '../variable'
|
|
@@ -34,42 +33,49 @@ const styles = create({
|
|
|
34
33
|
paddingRight: V.weuiDialogGapWidth
|
|
35
34
|
},
|
|
36
35
|
dialogTitle: {
|
|
37
|
-
fontWeight: '
|
|
38
|
-
|
|
36
|
+
fontWeight: '400'
|
|
37
|
+
},
|
|
38
|
+
iosDialogTitle: {
|
|
39
|
+
fontSize: 18,
|
|
39
40
|
textAlign: 'center'
|
|
40
41
|
},
|
|
41
|
-
|
|
42
42
|
androidDialogTitle: {
|
|
43
43
|
fontSize: 21,
|
|
44
44
|
textAlign: 'left'
|
|
45
45
|
},
|
|
46
|
-
|
|
47
46
|
dialogBody: {
|
|
48
47
|
paddingLeft: V.weuiDialogGapWidth,
|
|
49
|
-
paddingRight: V.weuiDialogGapWidth
|
|
50
|
-
|
|
48
|
+
paddingRight: V.weuiDialogGapWidth
|
|
49
|
+
},
|
|
50
|
+
iosDialogBody: {
|
|
51
|
+
paddingBottom: (0.8 * 15) + 20
|
|
52
|
+
},
|
|
53
|
+
androidDialogBody: {
|
|
54
|
+
paddingTop: 0.25 * 17,
|
|
55
|
+
paddingBottom: (17 * 2) + 20
|
|
51
56
|
},
|
|
52
|
-
|
|
53
57
|
dialogBodyText: {
|
|
54
58
|
color: V.weuiTextColorGray,
|
|
55
|
-
|
|
56
|
-
textAlign: 'center',
|
|
57
|
-
lineHeight: 17 * 1.4,
|
|
59
|
+
lineHeight: 15 * 1.3,
|
|
58
60
|
android: {
|
|
59
|
-
lineHeight: Math.round(
|
|
61
|
+
lineHeight: Math.round(15 * 1.3)
|
|
60
62
|
}
|
|
61
63
|
},
|
|
62
|
-
|
|
64
|
+
iosDialogBodyText: {
|
|
65
|
+
fontSize: 15,
|
|
66
|
+
textAlign: 'center'
|
|
67
|
+
},
|
|
63
68
|
androidDialogBodyText: {
|
|
69
|
+
fontSize: 17,
|
|
64
70
|
textAlign: 'left'
|
|
65
71
|
},
|
|
66
72
|
dialogFooter: {
|
|
67
|
-
flexDirection: 'row'
|
|
73
|
+
flexDirection: 'row'
|
|
74
|
+
},
|
|
75
|
+
iosDialogFooter: {
|
|
68
76
|
height: 48,
|
|
69
77
|
alignItems: 'center',
|
|
70
78
|
justifyContent: 'center',
|
|
71
|
-
},
|
|
72
|
-
dialogFooterBorder: {
|
|
73
79
|
borderTopWidth: StyleSheet.hairlineWidth,
|
|
74
80
|
borderColor: V.weuiDialogLineColor,
|
|
75
81
|
borderStyle: 'solid'
|
|
@@ -84,16 +90,17 @@ const styles = create({
|
|
|
84
90
|
},
|
|
85
91
|
dialogFooterOpr: {
|
|
86
92
|
alignItems: 'center',
|
|
87
|
-
justifyContent: 'center'
|
|
93
|
+
justifyContent: 'center'
|
|
94
|
+
},
|
|
95
|
+
iosDialogFooterOpr: {
|
|
88
96
|
height: 48,
|
|
89
|
-
flex: 1
|
|
97
|
+
flex: 1
|
|
90
98
|
},
|
|
91
99
|
androidDialogFooterOpr: {
|
|
92
100
|
height: 42,
|
|
93
101
|
paddingLeft: 16 * 0.8,
|
|
94
102
|
paddingRight: 16 * 0.8
|
|
95
103
|
},
|
|
96
|
-
|
|
97
104
|
dialogFooterOprWithNegativeMarginRight: {
|
|
98
105
|
marginRight: 0 - (16 * 0.8)
|
|
99
106
|
},
|
|
@@ -102,13 +109,12 @@ const styles = create({
|
|
|
102
109
|
borderColor: V.weuiDialogLineColor,
|
|
103
110
|
borderStyle: 'solid'
|
|
104
111
|
},
|
|
105
|
-
|
|
112
|
+
iosDialogFooterOprText: {
|
|
106
113
|
fontSize: 18
|
|
107
114
|
},
|
|
108
115
|
androidDialogFooterOprText: {
|
|
109
116
|
fontSize: 16
|
|
110
117
|
},
|
|
111
|
-
|
|
112
118
|
defaultDialogFooterOprText: {
|
|
113
119
|
color: '#353535'
|
|
114
120
|
},
|
|
@@ -164,15 +170,14 @@ const Index: React.FC<any> = (
|
|
|
164
170
|
style={[
|
|
165
171
|
styles.dialogFooterOpr,
|
|
166
172
|
styles[`${_type}DialogFooterOpr`],
|
|
167
|
-
_type === '
|
|
168
|
-
|
|
169
|
-
),
|
|
173
|
+
_type === 'ios' && idx > 0 ? styles.dialogFooterOprWithBorder : {},
|
|
174
|
+
_type === 'android' && idx === buttons.length - 1 ? styles.dialogFooterOprWithNegativeMarginRight : {}
|
|
170
175
|
]}
|
|
171
176
|
underlayColor={underlayColor}
|
|
172
177
|
{...others}
|
|
173
178
|
>
|
|
174
179
|
<Text
|
|
175
|
-
style={[styles
|
|
180
|
+
style={[styles[`${_type}DialogFooterOprText`], { color: btnType }]}
|
|
176
181
|
>{label}</Text>
|
|
177
182
|
</TouchableHighlight>
|
|
178
183
|
)
|
|
@@ -195,10 +200,10 @@ const Index: React.FC<any> = (
|
|
|
195
200
|
<View style={[styles.dialogHeader, headerStyle]}>
|
|
196
201
|
<Text style={[styles.dialogTitle, styles[`${_type}DialogTitle`], titleStyle]}>{title}</Text>
|
|
197
202
|
</View>
|
|
198
|
-
<View style={[styles.dialogBody, bodyStyle]}>
|
|
203
|
+
<View style={[styles.dialogBody, styles[`${_type}DialogBody`], bodyStyle]}>
|
|
199
204
|
{childrenWithProps}
|
|
200
205
|
</View>
|
|
201
|
-
<View style={[styles.dialogFooter, styles[`${_type}DialogFooter`],
|
|
206
|
+
<View style={[styles.dialogFooter, styles[`${_type}DialogFooter`], footerStyle]}>
|
|
202
207
|
{_renderButtons()}
|
|
203
208
|
</View>
|
|
204
209
|
</View>
|
|
@@ -209,7 +214,7 @@ const Index: React.FC<any> = (
|
|
|
209
214
|
|
|
210
215
|
Index.propTypes = {
|
|
211
216
|
autoDectect: PropTypes.bool,
|
|
212
|
-
type: PropTypes.oneOf(['ios', 'android'
|
|
217
|
+
type: PropTypes.oneOf(['ios', 'android']),
|
|
213
218
|
title: PropTypes.string,
|
|
214
219
|
buttons: PropTypes.arrayOf(PropTypes.object),
|
|
215
220
|
visible: PropTypes.bool,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
1
|
import React from 'react'
|
|
3
|
-
import
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { View, Text, Image, StyleSheet, ActivityIndicator } from 'react-native'
|
|
4
4
|
import RootSiblings from 'react-native-root-siblings'
|
|
5
|
-
|
|
6
|
-
import { errorHandler, shouldBeObject, successHandler } from '../../utils'
|
|
7
|
-
import errorPng from './error.png'
|
|
8
5
|
import successPng from './success.png'
|
|
6
|
+
import errorPng from './error.png'
|
|
7
|
+
import { errorHandler, shouldBeObject, successHandler } from '../../utils'
|
|
9
8
|
|
|
10
9
|
const globalAny: any = global
|
|
11
10
|
|
|
@@ -119,7 +118,7 @@ function showToast (options: Taro.showToast.Option): Promise<TaroGeneral.Callbac
|
|
|
119
118
|
return Promise.reject(res)
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
let {
|
|
121
|
+
let {title = '', icon = 'success', image, duration = 1500, mask = false, success, fail, complete} = options || {} // eslint-disable-line
|
|
123
122
|
|
|
124
123
|
const isLoading = (icon === 'loading')
|
|
125
124
|
|
|
@@ -139,7 +138,7 @@ function showToast (options: Taro.showToast.Option): Promise<TaroGeneral.Callbac
|
|
|
139
138
|
</View>
|
|
140
139
|
</View>
|
|
141
140
|
} else if (isLoading) {
|
|
142
|
-
ToastView = <WXLoading title={title} mask={mask}
|
|
141
|
+
ToastView = <WXLoading title={title} mask={mask}/>
|
|
143
142
|
} else if (icon === 'none') {
|
|
144
143
|
ToastView = <View style={maskStyle}>
|
|
145
144
|
<View style={styles.textGrayBlock}>
|
|
@@ -160,7 +159,7 @@ function showToast (options: Taro.showToast.Option): Promise<TaroGeneral.Callbac
|
|
|
160
159
|
try {
|
|
161
160
|
// setTimeout fires incorrectly when using chrome debug #4470
|
|
162
161
|
// https://github.com/facebook/react-native/issues/4470
|
|
163
|
-
globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy()
|
|
162
|
+
globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy();
|
|
164
163
|
|
|
165
164
|
globalAny.wxToastRootSiblings = new RootSiblings(ToastView)
|
|
166
165
|
setTimeout(() => {
|
|
@@ -178,7 +177,7 @@ function showToast (options: Taro.showToast.Option): Promise<TaroGeneral.Callbac
|
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
179
|
|
|
181
|
-
function showLoading (options: Taro.showLoading.Option
|
|
180
|
+
function showLoading (options: Taro.showLoading.Option): Promise<TaroGeneral.CallbackResult> {
|
|
182
181
|
const isObject = shouldBeObject(options)
|
|
183
182
|
if (!isObject.res) {
|
|
184
183
|
const res = { errMsg: `showLoading${isObject.msg}` }
|
|
@@ -203,7 +202,7 @@ function hideToast (opts: Taro.hideToast.Option = {}): void {
|
|
|
203
202
|
const { success, fail, complete } = opts
|
|
204
203
|
|
|
205
204
|
try {
|
|
206
|
-
globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy()
|
|
205
|
+
globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy();
|
|
207
206
|
globalAny.wxToastRootSiblings = undefined
|
|
208
207
|
const res = { errMsg: 'showToast:ok' }
|
|
209
208
|
success?.(res)
|
|
@@ -219,7 +218,7 @@ function hideLoading (opts: Taro.hideLoading.Option = {}): void {
|
|
|
219
218
|
const { success, fail, complete } = opts
|
|
220
219
|
|
|
221
220
|
try {
|
|
222
|
-
globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy()
|
|
221
|
+
globalAny.wxToastRootSiblings && globalAny.wxToastRootSiblings.destroy();
|
|
223
222
|
globalAny.wxToastRootSiblings = undefined
|
|
224
223
|
const res = { errMsg: 'showLoading:ok' }
|
|
225
224
|
success?.(res)
|
|
@@ -232,8 +231,8 @@ function hideLoading (opts: Taro.hideLoading.Option = {}): void {
|
|
|
232
231
|
}
|
|
233
232
|
|
|
234
233
|
export {
|
|
235
|
-
|
|
236
|
-
hideToast,
|
|
234
|
+
showToast,
|
|
237
235
|
showLoading,
|
|
238
|
-
|
|
236
|
+
hideToast,
|
|
237
|
+
hideLoading
|
|
239
238
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { startGyroscope } from '../gyroscope'
|
|
1
|
+
export { startGyroscope } from '../gyroscope'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { startLocationUpdate } from '../location'
|
|
1
|
+
export { startLocationUpdate } from '../location'
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
function temporarilyNotSupport(apiName:
|
|
1
|
+
function temporarilyNotSupport(apiName: String, recommended?: String, isSync = true) {
|
|
2
2
|
return () => {
|
|
3
3
|
let errMsg = `RN 端暂不支持 API ${apiName}`
|
|
4
|
-
if (recommended) {
|
|
4
|
+
if (!!recommended) {
|
|
5
5
|
errMsg += `, 请使用 ${recommended}`
|
|
6
6
|
}
|
|
7
7
|
console.error(errMsg)
|
|
8
8
|
if (!isSync) {
|
|
9
|
-
return Promise.reject(
|
|
9
|
+
return Promise.reject({
|
|
10
|
+
errMsg
|
|
11
|
+
})
|
|
10
12
|
} else {
|
|
11
13
|
return new Error(errMsg)
|
|
12
14
|
}
|
package/src/lib/vibrate.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { Vibration } from 'react-native'
|
|
2
|
-
|
|
3
2
|
import { errorHandler, successHandler } from '../utils'
|
|
4
3
|
|
|
5
4
|
function vibrate (DURATION, API, OPTS): Promise<TaroGeneral.CallbackResult> {
|
|
6
5
|
const res = { errMsg: `${API}:ok` }
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
const { success, fail, complete } = OPTS
|
|
7
|
+
try {
|
|
8
|
+
Vibration.vibrate(DURATION)
|
|
9
|
+
return successHandler(success, complete)(res)
|
|
10
|
+
} catch (err) {
|
|
11
|
+
res.errMsg = err.message
|
|
12
|
+
return errorHandler(fail, complete)(res)
|
|
13
|
+
}
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
function vibrateShort (opts: Taro.vibrateShort.Option = {}): Promise<TaroGeneral.CallbackResult> {
|
|
@@ -23,6 +22,6 @@ function vibrateLong (opts: Taro.vibrateLong.Option = {}): Promise<TaroGeneral.C
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
export {
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
vibrateShort,
|
|
26
|
+
vibrateLong
|
|
28
27
|
}
|
package/src/lib/window.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Dimensions, EmitterSubscription
|
|
2
|
-
|
|
1
|
+
import { ScaledSize, Dimensions, EmitterSubscription } from 'react-native'
|
|
3
2
|
import { createCallbackManager } from '../utils'
|
|
4
3
|
|
|
5
4
|
let listener: EmitterSubscription
|
|
@@ -19,4 +18,4 @@ export const addListener = () => {
|
|
|
19
18
|
|
|
20
19
|
export const removeListener = () => {
|
|
21
20
|
listener?.remove()
|
|
22
|
-
}
|
|
21
|
+
}
|
package/src/setup.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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.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
|
+
}),
|
|
42
|
+
})
|
|
43
|
+
return ReactNative
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
jest.doMock('expo-modules-core', () => {
|
|
47
|
+
const unimodules = jest.requireActual('expo-modules-core') as any
|
|
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
|
+
return unimodules
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const grantedPromise = jest.fn(() => Promise.resolve({
|
|
65
|
+
granted: true
|
|
66
|
+
}))
|
|
67
|
+
|
|
68
|
+
jest.doMock('expo-image-picker', () => {
|
|
69
|
+
const expoImagePicker = jest.requireActual('expo-image-picker') as any
|
|
70
|
+
expoImagePicker.requestMediaLibraryPermissionsAsync = grantedPromise
|
|
71
|
+
return expoImagePicker
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
jest.doMock('expo-location', () => {
|
|
75
|
+
const expoLocation = jest.requireActual('expo-location') as any
|
|
76
|
+
expoLocation.requestForegroundPermissionsAsync = grantedPromise
|
|
77
|
+
return expoLocation
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
jest.doMock('expo-barcode-scanner', () => {
|
|
81
|
+
const expoBarcodeSacnner = jest.requireActual('expo-barcode-scanner') as any
|
|
82
|
+
expoBarcodeSacnner.requestPermissionsAsync = grantedPromise
|
|
83
|
+
return expoBarcodeSacnner
|
|
84
|
+
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
interface CallbackManager {
|
|
2
|
-
add: (opt: any) => void
|
|
3
|
-
remove: (opt: any) => void
|
|
4
|
-
clear: () => void
|
|
5
|
-
count: () => number
|
|
6
|
-
trigger: (...args: any[]) => void
|
|
2
|
+
add: (opt: any) => void;
|
|
3
|
+
remove: (opt: any) => void;
|
|
4
|
+
clear: () => void;
|
|
5
|
+
count: () => number;
|
|
6
|
+
trigger: (...args: any[]) => void;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function createCallbackManager(): CallbackManager {
|