@aks-dev/easyui 1.0.163 → 1.1.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 (173) hide show
  1. package/dist/components/AnimationModal/AnimationModal.js +151 -0
  2. package/dist/components/DottedLine/DottedLine.js +50 -0
  3. package/{lib/Echarts/EchartsView.tsx → dist/components/EchartsView/EchartsView.js} +74 -113
  4. package/{lib/Echarts/helper.tsx → dist/components/EchartsView/helper.js} +17 -24
  5. package/dist/components/Hud/AlertBottomView/AlertBottomView.js +174 -0
  6. package/dist/components/Hud/AlertSheetView/AlertSheetView.js +117 -0
  7. package/dist/components/Hud/AlertView/AlertView.js +184 -0
  8. package/dist/components/Hud/Hud.js +29 -0
  9. package/dist/components/Hud/Loading/Loading.js +66 -0
  10. package/dist/components/Hud/PopoverView/PopoverView.js +47 -0
  11. package/dist/components/Hud/Scanner/Scanner.js +301 -0
  12. package/dist/components/Hud/Toast/Toast.js +71 -0
  13. package/dist/components/MenuView/MenuView.js +184 -0
  14. package/{lib/Modal/Modal.tsx → dist/components/Modal/Modal.js} +1 -4
  15. package/dist/components/MutiPictureView/MutiPictureView.js +239 -0
  16. package/dist/components/PictureViewer/PictureViewer.js +54 -0
  17. package/dist/components/RefreshList/RefreshList.js +155 -0
  18. package/dist/components/RichText/RichText.js +56 -0
  19. package/dist/components/StickHeaderView/StickHeaderView.js +37 -0
  20. package/dist/components/TableCell/TableCell.js +97 -0
  21. package/dist/components/TextInputArea/TextInputArea.js +65 -0
  22. package/dist/components/WithLoadingContainer/WithLoadingContainer.js +77 -0
  23. package/dist/index.js +31 -0
  24. package/dist/jsbridge/RNEasyui.js +46 -0
  25. package/{jsbridge/UpgradeModule.ts → dist/jsbridge/UpgradeModule.js} +25 -23
  26. package/{jsbridge/index.ts → dist/jsbridge/index.js} +2 -2
  27. package/{screen/index.ts → dist/screen/index.js} +2 -2
  28. package/dist/screen/px2dp.js +45 -0
  29. package/{screen/px2sp.ts → dist/screen/px2sp.js} +13 -20
  30. package/{screen/text-fit.ts → dist/screen/text-fit.js} +10 -20
  31. package/{utils/index.ts → dist/utils/index.js} +2 -2
  32. package/{utils/lazy.ts → dist/utils/lazy.js} +164 -165
  33. package/dist/utils/mode.js +50 -0
  34. package/package.json +31 -19
  35. package/readme.md +3 -3
  36. package/types/components/AnimationModal/AnimationModal.d.ts +27 -0
  37. package/types/components/AnimationModal/AnimationModal.d.ts.map +1 -0
  38. package/types/components/DottedLine/DottedLine.d.ts +10 -0
  39. package/types/components/DottedLine/DottedLine.d.ts.map +1 -0
  40. package/types/components/EchartsView/EchartsView.d.ts +10 -0
  41. package/types/components/EchartsView/EchartsView.d.ts.map +1 -0
  42. package/types/components/EchartsView/helper.d.ts +10 -0
  43. package/types/components/EchartsView/helper.d.ts.map +1 -0
  44. package/types/components/Hud/AlertBottomView/AlertBottomView.d.ts +25 -0
  45. package/types/components/Hud/AlertBottomView/AlertBottomView.d.ts.map +1 -0
  46. package/types/components/Hud/AlertSheetView/AlertSheetView.d.ts +19 -0
  47. package/types/components/Hud/AlertSheetView/AlertSheetView.d.ts.map +1 -0
  48. package/types/components/Hud/AlertView/AlertView.d.ts +25 -0
  49. package/types/components/Hud/AlertView/AlertView.d.ts.map +1 -0
  50. package/types/components/Hud/Hud.d.ts +11 -0
  51. package/types/components/Hud/Hud.d.ts.map +1 -0
  52. package/types/components/Hud/Loading/Loading.d.ts +11 -0
  53. package/types/components/Hud/Loading/Loading.d.ts.map +1 -0
  54. package/types/components/Hud/PopoverView/PopoverView.d.ts +17 -0
  55. package/types/components/Hud/PopoverView/PopoverView.d.ts.map +1 -0
  56. package/types/components/Hud/Scanner/Scanner.d.ts +12 -0
  57. package/types/components/Hud/Scanner/Scanner.d.ts.map +1 -0
  58. package/types/components/Hud/Toast/Toast.d.ts +9 -0
  59. package/types/components/Hud/Toast/Toast.d.ts.map +1 -0
  60. package/types/components/MenuView/MenuView.d.ts +21 -0
  61. package/types/components/MenuView/MenuView.d.ts.map +1 -0
  62. package/types/components/Modal/Modal.d.ts +2 -0
  63. package/types/components/Modal/Modal.d.ts.map +1 -0
  64. package/{lib/MutiPictureView/index.ts → types/components/MutiPictureView/MutiPictureView.d.ts} +18 -31
  65. package/types/components/MutiPictureView/MutiPictureView.d.ts.map +1 -0
  66. package/types/components/PictureViewer/PictureViewer.d.ts +17 -0
  67. package/types/components/PictureViewer/PictureViewer.d.ts.map +1 -0
  68. package/types/components/RefreshList/RefreshList.d.ts +45 -0
  69. package/types/components/RefreshList/RefreshList.d.ts.map +1 -0
  70. package/types/components/RichText/RichText.d.ts +12 -0
  71. package/types/components/RichText/RichText.d.ts.map +1 -0
  72. package/types/components/StickHeaderView/StickHeaderView.d.ts +15 -0
  73. package/types/components/StickHeaderView/StickHeaderView.d.ts.map +1 -0
  74. package/{lib/TableCell/index.ts → types/components/TableCell/TableCell.d.ts} +8 -30
  75. package/types/components/TableCell/TableCell.d.ts.map +1 -0
  76. package/types/components/TextInputArea/TextInputArea.d.ts +17 -0
  77. package/types/components/TextInputArea/TextInputArea.d.ts.map +1 -0
  78. package/types/components/WithLoadingContainer/WithLoadingContainer.d.ts +23 -0
  79. package/types/components/WithLoadingContainer/WithLoadingContainer.d.ts.map +1 -0
  80. package/types/index.d.ts +22 -0
  81. package/types/index.d.ts.map +1 -0
  82. package/types/jsbridge/RNEasyui.d.ts +23 -0
  83. package/types/jsbridge/RNEasyui.d.ts.map +1 -0
  84. package/types/jsbridge/UpgradeModule.d.ts +26 -0
  85. package/types/jsbridge/UpgradeModule.d.ts.map +1 -0
  86. package/types/jsbridge/index.d.ts +3 -0
  87. package/types/jsbridge/index.d.ts.map +1 -0
  88. package/types/screen/index.d.ts +3 -0
  89. package/types/screen/index.d.ts.map +1 -0
  90. package/{screen/index.d.ts → types/screen/px2dp.d.ts} +6 -12
  91. package/types/screen/px2dp.d.ts.map +1 -0
  92. package/types/screen/px2sp.d.ts +2 -0
  93. package/types/screen/px2sp.d.ts.map +1 -0
  94. package/types/screen/text-fit.d.ts +5 -0
  95. package/types/screen/text-fit.d.ts.map +1 -0
  96. package/types/utils/index.d.ts +3 -0
  97. package/types/utils/index.d.ts.map +1 -0
  98. package/{utils/index.d.ts → types/utils/lazy.d.ts} +15 -53
  99. package/types/utils/lazy.d.ts.map +1 -0
  100. package/types/utils/mode.d.ts +24 -0
  101. package/types/utils/mode.d.ts.map +1 -0
  102. package/android/.DS_Store +0 -0
  103. package/android/src/.DS_Store +0 -0
  104. package/android/src/main/.DS_Store +0 -0
  105. package/android/src/main/java/.DS_Store +0 -0
  106. package/android/src/main/java/com/.DS_Store +0 -0
  107. package/android/src/main/java/com/easyui/.DS_Store +0 -0
  108. package/i.sh +0 -23
  109. package/ios/.DS_Store +0 -0
  110. package/ios/assets/.DS_Store +0 -0
  111. package/ios/views/.DS_Store +0 -0
  112. package/jsbridge/RNEasyui.ts +0 -42
  113. package/jsbridge/index.d.ts +0 -67
  114. package/lib/.DS_Store +0 -0
  115. package/lib/AnimationModal/AnimationModal.tsx +0 -201
  116. package/lib/AnimationModal/index.d.ts +0 -41
  117. package/lib/Badge/Badge.tsx +0 -40
  118. package/lib/Badge/index.ts +0 -21
  119. package/lib/DottedLine/DottedLine.tsx +0 -66
  120. package/lib/DottedLine/index.ts +0 -18
  121. package/lib/Echarts/demo.tsx +0 -235
  122. package/lib/Echarts/index.ts +0 -29
  123. package/lib/Hud/.DS_Store +0 -0
  124. package/lib/Hud/AlertBottomView/AlertBottomView.tsx +0 -228
  125. package/lib/Hud/AlertBottomView/index.d.ts +0 -42
  126. package/lib/Hud/AlertSheetView/AlertSheetView.tsx +0 -179
  127. package/lib/Hud/AlertSheetView/index.d.ts +0 -35
  128. package/lib/Hud/AlertView/AlertView.tsx +0 -234
  129. package/lib/Hud/AlertView/index.d.ts +0 -46
  130. package/lib/Hud/Hud.tsx +0 -67
  131. package/lib/Hud/Loading/Loading.tsx +0 -87
  132. package/lib/Hud/Loading/index.d.ts +0 -38
  133. package/lib/Hud/PopoverView/PopoverView.tsx +0 -66
  134. package/lib/Hud/PopoverView/index.d.ts +0 -39
  135. package/lib/Hud/Scanner/Scanner.tsx +0 -250
  136. package/lib/Hud/Scanner/index.d.ts +0 -42
  137. package/lib/Hud/Toast/Toast.tsx +0 -86
  138. package/lib/Hud/Toast/index.d.ts +0 -22
  139. package/lib/Hud/index.ts +0 -20
  140. package/lib/MenuView/MenuView.tsx +0 -252
  141. package/lib/MenuView/index.ts +0 -31
  142. package/lib/Modal/index.ts +0 -10
  143. package/lib/MutiPictureView/MutiPictureView.tsx +0 -259
  144. package/lib/PictureViewer/PictureViewer.tsx +0 -80
  145. package/lib/PictureViewer/index.ts +0 -26
  146. package/lib/RefreshList/RefreshList.tsx +0 -235
  147. package/lib/RefreshList/demo.tsx +0 -30
  148. package/lib/RefreshList/demo1.tsx +0 -60
  149. package/lib/RefreshList/demo2.tsx +0 -46
  150. package/lib/RefreshList/index.ts +0 -84
  151. package/lib/RichText/RichText.tsx +0 -82
  152. package/lib/RichText/index.ts +0 -21
  153. package/lib/StickHeaderView/StickHeaderView.tsx +0 -65
  154. package/lib/StickHeaderView/demo.tsx +0 -104
  155. package/lib/StickHeaderView/index.ts +0 -26
  156. package/lib/TableCell/TableCell.tsx +0 -118
  157. package/lib/TextInputArea/TextInputArea.tsx +0 -89
  158. package/lib/TextInputArea/index.d.ts +0 -33
  159. package/lib/WithLoadingContainer/WithLoadingContainer.tsx +0 -93
  160. package/lib/WithLoadingContainer/index.ts +0 -36
  161. package/screen/px2dp.ts +0 -51
  162. package/src/index.d.ts +0 -42
  163. package/src/index.ts +0 -54
  164. package/utils/mode.ts +0 -48
  165. /package/{lib/Hud/Scanner → dist/components/Hud/Scanner/assets}/flashlight-blue.png +0 -0
  166. /package/{lib/Hud/Scanner → dist/components/Hud/Scanner/assets}/flashlight-white.png +0 -0
  167. /package/{lib/Hud/Scanner → dist/components/Hud/Scanner/assets}/icon_back_white.png +0 -0
  168. /package/{lib/MutiPictureView → dist/components/MutiPictureView/assets}/icon_add_image.png +0 -0
  169. /package/{lib/MutiPictureView → dist/components/MutiPictureView/assets}/icon_del_image.png +0 -0
  170. /package/{lib/TableCell → dist/components/TableCell/assets}/back.png +0 -0
  171. /package/{lib/WithLoadingContainer → dist/components/WithLoadingContainer/assets}/loading.gif +0 -0
  172. /package/{lib/WithLoadingContainer → dist/components/WithLoadingContainer/assets}/loading3.gif +0 -0
  173. /package/{lib → dist/components}/index.md +0 -0
@@ -0,0 +1,301 @@
1
+ /*
2
+ * @Author: shiguo
3
+ * @Date: 2022-04-24 14:27:02
4
+ * @LastEditors: shiguo
5
+ * @LastEditTime: 2023-03-23 15:04:18
6
+ * @FilePath: /@aks-dev/easyui/lib/Hud/Scanner/Scanner.tsx
7
+ */
8
+ import React, { useImperativeHandle, useState } from "react";
9
+ import { Animated, BackHandler, Easing, Image, StyleSheet, Text, TouchableOpacity, View, } from "react-native";
10
+ import { Camera, useCameraDevice, useCameraPermission, useCodeScanner, } from "react-native-vision-camera";
11
+ import { PERMISSIONS, requestMultiple } from "react-native-permissions";
12
+ import { navigationBarHeight, px2dp, statusBarHeight, } from "../../../screen/px2dp";
13
+ import { px2sp } from "../../../screen/px2sp";
14
+ import * as utils from "../../../utils/lazy";
15
+ import { showToast } from "../Toast/Toast";
16
+ // enum SCANNER_TYPE {
17
+ // DENIED = -1,//没有开始权限
18
+ // START = 0,//没有扫描结果,继续扫描
19
+ // SUCCESS = 1,//已有扫描结果,停止扫描
20
+ // }
21
+ export const Scanner = React.forwardRef((_, ref) => {
22
+ const [show, setShow] = useState(false);
23
+ const moveAnim = React.useRef(new Animated.Value(0)).current;
24
+ const [pointStyle, setPointStyle] = React.useState();
25
+ const cameraRef = React.useRef(null);
26
+ const _cbRef = React.useRef(null);
27
+ const _scanerResultRef = React.useRef(null);
28
+ const device = useCameraDevice("back");
29
+ const { hasPermission } = useCameraPermission();
30
+ React.useEffect(() => {
31
+ const onBackPress = () => {
32
+ if (show) {
33
+ _hideScanner();
34
+ }
35
+ return true;
36
+ };
37
+ BackHandler.addEventListener("hardwareBackPress", onBackPress);
38
+ // return () => BackHandler.removeEventListener('hardwareBackPress', onBackPress);
39
+ }, [show]);
40
+ useImperativeHandle(ref, () => ({
41
+ showScanner: _showScanner,
42
+ hideScanner: _hideScanner,
43
+ }), [show]);
44
+ const _showScanner = async (cb) => {
45
+ let res = await requestMultiple([
46
+ PERMISSIONS.IOS.CAMERA,
47
+ PERMISSIONS.ANDROID.CAMERA,
48
+ ]);
49
+ if (res[PERMISSIONS.ANDROID.CAMERA] == "granted" ||
50
+ res[PERMISSIONS.IOS.CAMERA] == "granted") {
51
+ _scanerResultRef.current = null;
52
+ setShow(true);
53
+ setPointStyle({});
54
+ await utils.sleep();
55
+ animationStart();
56
+ _cbRef.current = cb;
57
+ }
58
+ else {
59
+ _hideScanner();
60
+ showToast("您未开启相机权限,暂不能使用此功能");
61
+ }
62
+ };
63
+ const _hideScanner = async () => {
64
+ animationStop();
65
+ await utils.sleep();
66
+ setShow(false);
67
+ };
68
+ const animation = Animated.loop(Animated.sequence([
69
+ Animated.timing(moveAnim, {
70
+ toValue: px2dp(222),
71
+ duration: 3000,
72
+ easing: Easing.linear,
73
+ useNativeDriver: true,
74
+ }),
75
+ Animated.timing(moveAnim, {
76
+ toValue: 0,
77
+ duration: 3000,
78
+ easing: Easing.linear,
79
+ useNativeDriver: true,
80
+ }),
81
+ ]));
82
+ const animationStart = async () => {
83
+ cameraRef.current?.resumePreview();
84
+ animation.start(({ finished }) => {
85
+ // console.log('animationStart finished', finished)
86
+ if (finished) {
87
+ animation.reset();
88
+ animation.start();
89
+ }
90
+ });
91
+ };
92
+ const animationStop = (result) => {
93
+ cameraRef.current?.pausePreview();
94
+ animation.stop();
95
+ };
96
+ const codeScanner = useCodeScanner({
97
+ codeTypes: ["qr", "ean-13"],
98
+ onCodeScanned: (codes) => {
99
+ console.log(`Scanned ${codes.length} codes!`);
100
+ let code = codes.find((i) => i.value);
101
+ if (code?.value && _scanerResultRef.current == undefined) {
102
+ _scanerResultRef.current = code.value;
103
+ _cbRef.current(code.value);
104
+ _hideScanner();
105
+ }
106
+ },
107
+ });
108
+ if (!show)
109
+ return null;
110
+ if (!hasPermission)
111
+ return <Text>PermissionsPage</Text>;
112
+ if (device == null)
113
+ return <Text>NoCameraDeviceError</Text>;
114
+ return (<TouchableOpacity disabled style={StyleSheet.absoluteFillObject}>
115
+ <Camera ref={cameraRef} style={styles.camera} device={device} codeScanner={codeScanner} isActive={true}>
116
+ {/* 导航栏 */}
117
+ <View style={{
118
+ display: "flex",
119
+ justifyContent: "center",
120
+ alignItems: "center",
121
+ height: navigationBarHeight,
122
+ marginTop: statusBarHeight,
123
+ position: "relative",
124
+ }}>
125
+ <TouchableOpacity onPress={() => _hideScanner()} style={{
126
+ height: navigationBarHeight,
127
+ width: px2dp(50),
128
+ paddingLeft: px2dp(15),
129
+ position: "absolute",
130
+ left: 0,
131
+ display: "flex",
132
+ justifyContent: "center",
133
+ }}>
134
+ <Image source={require("./assets/icon_back_white.png")} style={{ width: px2dp(20), height: px2dp(20) }} resizeMode="contain"/>
135
+ </TouchableOpacity>
136
+ <Text style={{
137
+ fontSize: px2sp(16),
138
+ color: "white",
139
+ fontWeight: "bold",
140
+ }}>
141
+ 扫一扫
142
+ </Text>
143
+ </View>
144
+
145
+ {/* 动画框 */}
146
+ <View style={styles.scanContainer}>
147
+ <View style={styles.rectangle}>
148
+ <View style={styles.rectangleLeft}/>
149
+ <View style={styles.cameraBackground}>
150
+ <Animated.View style={[
151
+ styles.scanLine,
152
+ { transform: [{ translateY: moveAnim }] },
153
+ ]}/>
154
+ <View style={styles.reactLineTopLeftX}/>
155
+ <View style={styles.reactLineTopLeftY}/>
156
+ <View style={styles.reactLineTopRightX}/>
157
+ <View style={styles.reactLineTopRightY}/>
158
+ <View style={styles.reactLineBottomLeftX}/>
159
+ <View style={styles.reactLineBottomLeftY}/>
160
+ <View style={styles.reactLineBottomRightX}/>
161
+ <View style={styles.reactLineBottomRightY}/>
162
+ </View>
163
+ <View style={styles.rectangleRight}/>
164
+ </View>
165
+
166
+ {/* <TouchableOpacity onPress={() => setTorchOn(!torchOn)}>
167
+ <Image
168
+ source={
169
+ torchOn
170
+ ? require("./assets/flashlight-blue.png")
171
+ : require("./assets/flashlight-white.png")
172
+ }
173
+ style={styles.flashlight}
174
+ />
175
+ </TouchableOpacity> */}
176
+ <Text style={styles.rectangleText}>
177
+ 将二维码/条码放入框内,即可自动扫描
178
+ </Text>
179
+ </View>
180
+ <View style={pointStyle}/>
181
+ </Camera>
182
+ </TouchableOpacity>);
183
+ });
184
+ const transparent = "#00000000";
185
+ const lineColor = "#6ab3ff";
186
+ const scanW = 225;
187
+ const scanCornerLineLength = 15;
188
+ const scanCornerLineHeight = 3;
189
+ const styles = StyleSheet.create({
190
+ camera: {
191
+ display: "flex",
192
+ flex: 1,
193
+ flexDirection: "column",
194
+ backgroundColor: "red",
195
+ },
196
+ cameraBackground: {
197
+ width: px2dp(scanW),
198
+ height: px2dp(scanW),
199
+ backgroundColor: transparent,
200
+ },
201
+ scanContainer: {
202
+ display: "flex",
203
+ flex: 1,
204
+ justifyContent: "center",
205
+ alignItems: "center",
206
+ },
207
+ rectangle: { flexDirection: "row", overflow: "hidden" },
208
+ rectangleLeft: {
209
+ backgroundColor: transparent,
210
+ height: px2dp(scanW),
211
+ width: px2dp(scanW),
212
+ },
213
+ rectangleRight: {
214
+ backgroundColor: transparent,
215
+ height: px2dp(scanW),
216
+ width: px2dp(scanW),
217
+ },
218
+ rectangleText: { color: "#fff", lineHeight: px2dp(15) },
219
+ scanLine: {
220
+ width: px2dp(scanW),
221
+ height: px2dp(scanCornerLineHeight),
222
+ borderRadius: px2dp(25),
223
+ backgroundColor: lineColor,
224
+ },
225
+ reactLineTopLeftX: {
226
+ position: "absolute",
227
+ top: 0,
228
+ left: 0,
229
+ width: px2dp(scanCornerLineLength),
230
+ height: px2dp(scanCornerLineHeight),
231
+ backgroundColor: lineColor,
232
+ },
233
+ reactLineTopLeftY: {
234
+ position: "absolute",
235
+ top: 0,
236
+ left: 0,
237
+ width: px2dp(scanCornerLineHeight),
238
+ height: px2dp(scanCornerLineLength),
239
+ backgroundColor: lineColor,
240
+ },
241
+ reactLineTopRightX: {
242
+ position: "absolute",
243
+ top: 0,
244
+ right: 0,
245
+ width: px2dp(scanCornerLineLength),
246
+ height: px2dp(scanCornerLineHeight),
247
+ backgroundColor: lineColor,
248
+ },
249
+ reactLineTopRightY: {
250
+ position: "absolute",
251
+ top: 0,
252
+ right: 0,
253
+ width: px2dp(scanCornerLineHeight),
254
+ height: px2dp(scanCornerLineLength),
255
+ backgroundColor: lineColor,
256
+ },
257
+ reactLineBottomLeftX: {
258
+ position: "absolute",
259
+ bottom: 0,
260
+ left: 0,
261
+ width: px2dp(scanCornerLineLength),
262
+ height: px2dp(scanCornerLineHeight),
263
+ backgroundColor: lineColor,
264
+ },
265
+ reactLineBottomLeftY: {
266
+ position: "absolute",
267
+ bottom: 0,
268
+ left: 0,
269
+ width: px2dp(scanCornerLineHeight),
270
+ height: px2dp(scanCornerLineLength),
271
+ backgroundColor: lineColor,
272
+ },
273
+ reactLineBottomRightX: {
274
+ position: "absolute",
275
+ bottom: 0,
276
+ right: 0,
277
+ width: px2dp(scanCornerLineLength),
278
+ height: px2dp(scanCornerLineHeight),
279
+ backgroundColor: lineColor,
280
+ },
281
+ reactLineBottomRightY: {
282
+ position: "absolute",
283
+ bottom: 0,
284
+ right: 0,
285
+ width: px2dp(scanCornerLineHeight),
286
+ height: px2dp(scanCornerLineLength),
287
+ backgroundColor: lineColor,
288
+ },
289
+ flashlight: {
290
+ width: px2dp(30),
291
+ height: px2dp(30),
292
+ resizeMode: "contain",
293
+ marginTop: px2dp(50),
294
+ marginBottom: px2dp(15),
295
+ marginHorizontal: px2dp(15),
296
+ },
297
+ grantedText: { lineHeight: px2dp(30), color: lineColor, fontWeight: "bold" },
298
+ });
299
+ export const scannerRef = React.createRef();
300
+ export const showScanner = (cb) => scannerRef.current?.showScanner(cb);
301
+ export const hideScanner = () => scannerRef.current?.hideScanner();
@@ -0,0 +1,71 @@
1
+ /*
2
+ * @Author: shiguo
3
+ * @Date: 2021-04-27 10:38:04
4
+ * @LastEditors: shiguo
5
+ * @LastEditTime: 2022-09-09 10:58:34
6
+ * @FilePath: /@aks-dev/easyui/lib/Hud/Toast/Toast.tsx
7
+ */
8
+ import React, { useImperativeHandle, useState, useRef } from "react";
9
+ import { View, StyleSheet, Text, Dimensions, Animated, Easing, } from "react-native";
10
+ const errorMsg = "(^_^)∠※ 送你一束小花";
11
+ export const Toast = React.forwardRef((_, ref) => {
12
+ const [tipText, setTipText] = useState(errorMsg);
13
+ const fade = useRef(new Animated.Value(0)).current;
14
+ const fadeAnimation = Animated.sequence([
15
+ Animated.timing(fade, {
16
+ toValue: 1,
17
+ duration: 750,
18
+ useNativeDriver: true,
19
+ easing: Easing.linear,
20
+ }),
21
+ Animated.delay(3000),
22
+ Animated.timing(fade, {
23
+ toValue: 0,
24
+ duration: 750,
25
+ useNativeDriver: true,
26
+ easing: Easing.linear,
27
+ }),
28
+ ]);
29
+ useImperativeHandle(ref, () => ({
30
+ showToast: (content) => {
31
+ setTipText(content || errorMsg);
32
+ fadeAnimation.reset();
33
+ fadeAnimation.start();
34
+ },
35
+ }));
36
+ return (<Animated.View style={{ ...styles.toastContainer, opacity: fade }}>
37
+ <View style={styles.toastTipsContainer}>
38
+ <Text numberOfLines={5} style={{ ...styles.toastTitle }}>
39
+ {tipText}{" "}
40
+ </Text>
41
+ </View>
42
+ </Animated.View>);
43
+ });
44
+ export const toastRef = React.createRef();
45
+ export const showToast = (content) => toastRef.current?.showToast(content);
46
+ const SCREEN_WIDTH = Dimensions.get("window").width;
47
+ const styles = StyleSheet.create({
48
+ toastContainer: {
49
+ position: "absolute",
50
+ bottom: 100,
51
+ width: "100%",
52
+ justifyContent: "center",
53
+ alignItems: "center",
54
+ },
55
+ toastTipsContainer: {
56
+ position: "absolute",
57
+ backgroundColor: "#00000088",
58
+ padding: 10,
59
+ // paddingVertical: 4,
60
+ borderRadius: 2,
61
+ justifyContent: "center",
62
+ alignItems: "center",
63
+ minWidth: 120,
64
+ },
65
+ toastTitle: {
66
+ fontSize: 13,
67
+ lineHeight: 20,
68
+ color: "white",
69
+ maxWidth: SCREEN_WIDTH * 0.8,
70
+ },
71
+ });
@@ -0,0 +1,184 @@
1
+ import React from "react";
2
+ import { Image, ScrollView, Text, TouchableOpacity, View, } from "react-native";
3
+ import { deviceHeight, deviceWidth } from "../../screen/px2dp";
4
+ // import * as utils from '../../utils/lazy';
5
+ import { hidePopoverView, showPopoverView } from "../Hud/Hud";
6
+ // type Reducer = (prevState: State, action: Partial<State>) => State
7
+ export default (props) => {
8
+ const { defaultAlignHorizontal = "left", defaultAlignVertical = "bottom" } = props;
9
+ const [state, dispatch] = React.useReducer((prevState, action) => Object.assign({}, prevState, action), {});
10
+ // const containerRef = React.useRef<{ measureInWindow: (callback: MeasureInWindowOnSuccessCallback) => void }>()
11
+ const containerRef = React.useRef(null);
12
+ const rootView = React.useRef({ pageX: 0, pageY: 0, width: 0, height: 0 });
13
+ const sc = React.useRef({ x: 0, y: 0, width: 0, height: 0 });
14
+ // React.useEffect(() => {
15
+ // ; (async () => {
16
+ // await utils.sleep()
17
+ // containerRef.current?.measure((...args) => {
18
+ // console.log('containerRef', args)
19
+ // if (args.length == 6) {
20
+ // _container.current = {
21
+ // x: args[4],
22
+ // y: args[5],
23
+ // width: args[2],
24
+ // height: args[3],
25
+ // }
26
+ // }
27
+ // })
28
+ // })()
29
+ // })
30
+ const getRootViewlayoutPromise = () => {
31
+ return new Promise((resovle, reject) => {
32
+ containerRef.current?.measure((...args) => {
33
+ if (args.length == 6) {
34
+ rootView.current = {
35
+ width: args[2],
36
+ height: args[3],
37
+ pageX: args[4],
38
+ pageY: args[5],
39
+ };
40
+ }
41
+ // console.log('RootView', rootView.current)
42
+ resovle(args);
43
+ });
44
+ });
45
+ };
46
+ const getLayoutInfos = () => {
47
+ let alignVertical = defaultAlignVertical;
48
+ let alignHorizontal = defaultAlignHorizontal;
49
+ let width = rootView.current.width;
50
+ let height = rootView.current.height;
51
+ let x = rootView.current.pageX;
52
+ // let y = (StatusBar.currentHeight || 0) + _container.current.y + height
53
+ let y = rootView.current.pageY + height;
54
+ if (x > Math.abs(deviceWidth - width - x)) {
55
+ alignHorizontal = "right";
56
+ }
57
+ if (y > deviceHeight * 0.5) {
58
+ alignVertical = "top";
59
+ }
60
+ /**todo: target_width的获取是延迟的,所以这里又问题 */
61
+ const target_width = sc.current.width;
62
+ const target_height = CELL_HEIGHT * (Math.min(props.data?.length || 0, 5) || 0);
63
+ return {
64
+ alignVertical,
65
+ alignHorizontal,
66
+ width,
67
+ height,
68
+ x,
69
+ y,
70
+ target_width,
71
+ target_height,
72
+ };
73
+ };
74
+ const reLayout = () => {
75
+ let { alignVertical, alignHorizontal, width, height, x, y, target_width, target_height, } = getLayoutInfos();
76
+ // console.log({ getLayoutInfos: getLayoutInfos() })
77
+ const layout = () => {
78
+ if (alignHorizontal == "left") {
79
+ if (target_width + x > deviceWidth) {
80
+ return {
81
+ left: Math.abs(deviceWidth - target_width) * 0.7,
82
+ top: y,
83
+ };
84
+ }
85
+ return {
86
+ left: Math.max(x, 15),
87
+ top: y,
88
+ };
89
+ }
90
+ else {
91
+ let _x = deviceWidth - x - width;
92
+ if (target_width + _x > deviceWidth) {
93
+ return {
94
+ right: Math.abs(deviceWidth - target_width) * 0.7,
95
+ top: y,
96
+ };
97
+ }
98
+ return {
99
+ right: Math.max(_x, 15),
100
+ top: y,
101
+ };
102
+ }
103
+ };
104
+ if (alignVertical == "bottom") {
105
+ y = y + PADDING;
106
+ return layout();
107
+ }
108
+ else {
109
+ y = rootView.current.pageY - target_height - PADDING * 2 - ARROW_HEIGHT;
110
+ return layout();
111
+ }
112
+ };
113
+ const PADDING = 10;
114
+ const ARROW_HEIGHT = 12;
115
+ const CELL_HEIGHT = 36;
116
+ const show = async () => {
117
+ props.onContainerClick && props.onContainerClick();
118
+ if (props.data == undefined || props.data?.length == 0)
119
+ return;
120
+ /**重新获取rootview的定位 */
121
+ await getRootViewlayoutPromise();
122
+ /**重新获取rootview的定位 */
123
+ showPopoverView({
124
+ content: (<TouchableOpacity activeOpacity={1} style={{
125
+ position: "absolute",
126
+ minWidth: deviceWidth * 0.36,
127
+ maxWidth: deviceWidth * 0.8,
128
+ minHeight: CELL_HEIGHT + PADDING * 2,
129
+ maxHeight: CELL_HEIGHT * 5 + PADDING * 2,
130
+ borderRadius: 6,
131
+ backgroundColor: "#000000ee",
132
+ // overflow: 'hidden' ,
133
+ padding: PADDING,
134
+ ...reLayout(),
135
+ }}>
136
+ <View style={{
137
+ width: ARROW_HEIGHT,
138
+ height: ARROW_HEIGHT,
139
+ backgroundColor: "#000000ee",
140
+ position: "absolute",
141
+ zIndex: 1,
142
+ transform: [{ rotateZ: "45deg" }],
143
+ ...(() => {
144
+ const { alignVertical, alignHorizontal } = getLayoutInfos();
145
+ if (alignVertical == "bottom" && alignHorizontal == "left")
146
+ return { left: "20%", top: -5 };
147
+ if (alignVertical == "bottom" && alignHorizontal == "right")
148
+ return { right: "20%", top: -5 };
149
+ if (alignVertical == "top" && alignHorizontal == "left")
150
+ return { left: "20%", bottom: -5 };
151
+ if (alignVertical == "top" && alignHorizontal == "right")
152
+ return { right: "20%", bottom: -5 };
153
+ return {};
154
+ })(),
155
+ }}/>
156
+
157
+ <ScrollView onLayout={(e) => {
158
+ // console.log('target onLayout', e.nativeEvent.layout)
159
+ let _sc = e.nativeEvent.layout;
160
+ sc.current = _sc;
161
+ }}>
162
+ {props.data?.map((i, idx) => {
163
+ return (<TouchableOpacity activeOpacity={0.7} key={`sg-memnu-${idx}`} style={{
164
+ height: CELL_HEIGHT,
165
+ display: "flex",
166
+ flexDirection: "row",
167
+ alignItems: "center",
168
+ // ,backgroundColor:utils.randomcolor()
169
+ }} onPress={(e) => {
170
+ props.onItemClick && props.onItemClick(idx, i.extra);
171
+ hidePopoverView();
172
+ }}>
173
+ {i.icon && (<Image style={{ width: 18, height: 18, marginRight: 4 }} source={i.icon}/>)}
174
+ <Text style={{ flexShrink: 1, fontSize: 14, color: "white" }}>
175
+ {i.text}
176
+ </Text>
177
+ </TouchableOpacity>);
178
+ })}
179
+ </ScrollView>
180
+ </TouchableOpacity>),
181
+ });
182
+ };
183
+ return (<TouchableOpacity ref={containerRef} onPress={(e) => show()} {...props}/>);
184
+ };
@@ -5,7 +5,4 @@
5
5
  * @LastEditTime: 2022-10-27 16:37:32
6
6
  * @FilePath: /@aks-dev/easyui/lib/Modal/Modal.tsx
7
7
  */
8
-
9
-
10
-
11
- export { default as Modal, ModalProps } from 'react-native-modal'
8
+ export { default as Modal } from 'react-native-modal';