@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.
- package/dist/components/AnimationModal/AnimationModal.js +151 -0
- package/dist/components/DottedLine/DottedLine.js +50 -0
- package/{lib/Echarts/EchartsView.tsx → dist/components/EchartsView/EchartsView.js} +74 -113
- package/{lib/Echarts/helper.tsx → dist/components/EchartsView/helper.js} +17 -24
- package/dist/components/Hud/AlertBottomView/AlertBottomView.js +174 -0
- package/dist/components/Hud/AlertSheetView/AlertSheetView.js +117 -0
- package/dist/components/Hud/AlertView/AlertView.js +184 -0
- package/dist/components/Hud/Hud.js +29 -0
- package/dist/components/Hud/Loading/Loading.js +66 -0
- package/dist/components/Hud/PopoverView/PopoverView.js +47 -0
- package/dist/components/Hud/Scanner/Scanner.js +301 -0
- package/dist/components/Hud/Toast/Toast.js +71 -0
- package/dist/components/MenuView/MenuView.js +184 -0
- package/{lib/Modal/Modal.tsx → dist/components/Modal/Modal.js} +1 -4
- package/dist/components/MutiPictureView/MutiPictureView.js +239 -0
- package/dist/components/PictureViewer/PictureViewer.js +54 -0
- package/dist/components/RefreshList/RefreshList.js +155 -0
- package/dist/components/RichText/RichText.js +56 -0
- package/dist/components/StickHeaderView/StickHeaderView.js +37 -0
- package/dist/components/TableCell/TableCell.js +97 -0
- package/dist/components/TextInputArea/TextInputArea.js +65 -0
- package/dist/components/WithLoadingContainer/WithLoadingContainer.js +77 -0
- package/dist/index.js +31 -0
- package/dist/jsbridge/RNEasyui.js +46 -0
- package/{jsbridge/UpgradeModule.ts → dist/jsbridge/UpgradeModule.js} +25 -23
- package/{jsbridge/index.ts → dist/jsbridge/index.js} +2 -2
- package/{screen/index.ts → dist/screen/index.js} +2 -2
- package/dist/screen/px2dp.js +45 -0
- package/{screen/px2sp.ts → dist/screen/px2sp.js} +13 -20
- package/{screen/text-fit.ts → dist/screen/text-fit.js} +10 -20
- package/{utils/index.ts → dist/utils/index.js} +2 -2
- package/{utils/lazy.ts → dist/utils/lazy.js} +164 -165
- package/dist/utils/mode.js +50 -0
- package/package.json +31 -19
- package/readme.md +3 -3
- package/types/components/AnimationModal/AnimationModal.d.ts +27 -0
- package/types/components/AnimationModal/AnimationModal.d.ts.map +1 -0
- package/types/components/DottedLine/DottedLine.d.ts +10 -0
- package/types/components/DottedLine/DottedLine.d.ts.map +1 -0
- package/types/components/EchartsView/EchartsView.d.ts +10 -0
- package/types/components/EchartsView/EchartsView.d.ts.map +1 -0
- package/types/components/EchartsView/helper.d.ts +10 -0
- package/types/components/EchartsView/helper.d.ts.map +1 -0
- package/types/components/Hud/AlertBottomView/AlertBottomView.d.ts +25 -0
- package/types/components/Hud/AlertBottomView/AlertBottomView.d.ts.map +1 -0
- package/types/components/Hud/AlertSheetView/AlertSheetView.d.ts +19 -0
- package/types/components/Hud/AlertSheetView/AlertSheetView.d.ts.map +1 -0
- package/types/components/Hud/AlertView/AlertView.d.ts +25 -0
- package/types/components/Hud/AlertView/AlertView.d.ts.map +1 -0
- package/types/components/Hud/Hud.d.ts +11 -0
- package/types/components/Hud/Hud.d.ts.map +1 -0
- package/types/components/Hud/Loading/Loading.d.ts +11 -0
- package/types/components/Hud/Loading/Loading.d.ts.map +1 -0
- package/types/components/Hud/PopoverView/PopoverView.d.ts +17 -0
- package/types/components/Hud/PopoverView/PopoverView.d.ts.map +1 -0
- package/types/components/Hud/Scanner/Scanner.d.ts +12 -0
- package/types/components/Hud/Scanner/Scanner.d.ts.map +1 -0
- package/types/components/Hud/Toast/Toast.d.ts +9 -0
- package/types/components/Hud/Toast/Toast.d.ts.map +1 -0
- package/types/components/MenuView/MenuView.d.ts +21 -0
- package/types/components/MenuView/MenuView.d.ts.map +1 -0
- package/types/components/Modal/Modal.d.ts +2 -0
- package/types/components/Modal/Modal.d.ts.map +1 -0
- package/{lib/MutiPictureView/index.ts → types/components/MutiPictureView/MutiPictureView.d.ts} +18 -31
- package/types/components/MutiPictureView/MutiPictureView.d.ts.map +1 -0
- package/types/components/PictureViewer/PictureViewer.d.ts +17 -0
- package/types/components/PictureViewer/PictureViewer.d.ts.map +1 -0
- package/types/components/RefreshList/RefreshList.d.ts +45 -0
- package/types/components/RefreshList/RefreshList.d.ts.map +1 -0
- package/types/components/RichText/RichText.d.ts +12 -0
- package/types/components/RichText/RichText.d.ts.map +1 -0
- package/types/components/StickHeaderView/StickHeaderView.d.ts +15 -0
- package/types/components/StickHeaderView/StickHeaderView.d.ts.map +1 -0
- package/{lib/TableCell/index.ts → types/components/TableCell/TableCell.d.ts} +8 -30
- package/types/components/TableCell/TableCell.d.ts.map +1 -0
- package/types/components/TextInputArea/TextInputArea.d.ts +17 -0
- package/types/components/TextInputArea/TextInputArea.d.ts.map +1 -0
- package/types/components/WithLoadingContainer/WithLoadingContainer.d.ts +23 -0
- package/types/components/WithLoadingContainer/WithLoadingContainer.d.ts.map +1 -0
- package/types/index.d.ts +22 -0
- package/types/index.d.ts.map +1 -0
- package/types/jsbridge/RNEasyui.d.ts +23 -0
- package/types/jsbridge/RNEasyui.d.ts.map +1 -0
- package/types/jsbridge/UpgradeModule.d.ts +26 -0
- package/types/jsbridge/UpgradeModule.d.ts.map +1 -0
- package/types/jsbridge/index.d.ts +3 -0
- package/types/jsbridge/index.d.ts.map +1 -0
- package/types/screen/index.d.ts +3 -0
- package/types/screen/index.d.ts.map +1 -0
- package/{screen/index.d.ts → types/screen/px2dp.d.ts} +6 -12
- package/types/screen/px2dp.d.ts.map +1 -0
- package/types/screen/px2sp.d.ts +2 -0
- package/types/screen/px2sp.d.ts.map +1 -0
- package/types/screen/text-fit.d.ts +5 -0
- package/types/screen/text-fit.d.ts.map +1 -0
- package/types/utils/index.d.ts +3 -0
- package/types/utils/index.d.ts.map +1 -0
- package/{utils/index.d.ts → types/utils/lazy.d.ts} +15 -53
- package/types/utils/lazy.d.ts.map +1 -0
- package/types/utils/mode.d.ts +24 -0
- package/types/utils/mode.d.ts.map +1 -0
- package/android/.DS_Store +0 -0
- package/android/src/.DS_Store +0 -0
- package/android/src/main/.DS_Store +0 -0
- package/android/src/main/java/.DS_Store +0 -0
- package/android/src/main/java/com/.DS_Store +0 -0
- package/android/src/main/java/com/easyui/.DS_Store +0 -0
- package/i.sh +0 -23
- package/ios/.DS_Store +0 -0
- package/ios/assets/.DS_Store +0 -0
- package/ios/views/.DS_Store +0 -0
- package/jsbridge/RNEasyui.ts +0 -42
- package/jsbridge/index.d.ts +0 -67
- package/lib/.DS_Store +0 -0
- package/lib/AnimationModal/AnimationModal.tsx +0 -201
- package/lib/AnimationModal/index.d.ts +0 -41
- package/lib/Badge/Badge.tsx +0 -40
- package/lib/Badge/index.ts +0 -21
- package/lib/DottedLine/DottedLine.tsx +0 -66
- package/lib/DottedLine/index.ts +0 -18
- package/lib/Echarts/demo.tsx +0 -235
- package/lib/Echarts/index.ts +0 -29
- package/lib/Hud/.DS_Store +0 -0
- package/lib/Hud/AlertBottomView/AlertBottomView.tsx +0 -228
- package/lib/Hud/AlertBottomView/index.d.ts +0 -42
- package/lib/Hud/AlertSheetView/AlertSheetView.tsx +0 -179
- package/lib/Hud/AlertSheetView/index.d.ts +0 -35
- package/lib/Hud/AlertView/AlertView.tsx +0 -234
- package/lib/Hud/AlertView/index.d.ts +0 -46
- package/lib/Hud/Hud.tsx +0 -67
- package/lib/Hud/Loading/Loading.tsx +0 -87
- package/lib/Hud/Loading/index.d.ts +0 -38
- package/lib/Hud/PopoverView/PopoverView.tsx +0 -66
- package/lib/Hud/PopoverView/index.d.ts +0 -39
- package/lib/Hud/Scanner/Scanner.tsx +0 -250
- package/lib/Hud/Scanner/index.d.ts +0 -42
- package/lib/Hud/Toast/Toast.tsx +0 -86
- package/lib/Hud/Toast/index.d.ts +0 -22
- package/lib/Hud/index.ts +0 -20
- package/lib/MenuView/MenuView.tsx +0 -252
- package/lib/MenuView/index.ts +0 -31
- package/lib/Modal/index.ts +0 -10
- package/lib/MutiPictureView/MutiPictureView.tsx +0 -259
- package/lib/PictureViewer/PictureViewer.tsx +0 -80
- package/lib/PictureViewer/index.ts +0 -26
- package/lib/RefreshList/RefreshList.tsx +0 -235
- package/lib/RefreshList/demo.tsx +0 -30
- package/lib/RefreshList/demo1.tsx +0 -60
- package/lib/RefreshList/demo2.tsx +0 -46
- package/lib/RefreshList/index.ts +0 -84
- package/lib/RichText/RichText.tsx +0 -82
- package/lib/RichText/index.ts +0 -21
- package/lib/StickHeaderView/StickHeaderView.tsx +0 -65
- package/lib/StickHeaderView/demo.tsx +0 -104
- package/lib/StickHeaderView/index.ts +0 -26
- package/lib/TableCell/TableCell.tsx +0 -118
- package/lib/TextInputArea/TextInputArea.tsx +0 -89
- package/lib/TextInputArea/index.d.ts +0 -33
- package/lib/WithLoadingContainer/WithLoadingContainer.tsx +0 -93
- package/lib/WithLoadingContainer/index.ts +0 -36
- package/screen/px2dp.ts +0 -51
- package/src/index.d.ts +0 -42
- package/src/index.ts +0 -54
- package/utils/mode.ts +0 -48
- /package/{lib/Hud/Scanner → dist/components/Hud/Scanner/assets}/flashlight-blue.png +0 -0
- /package/{lib/Hud/Scanner → dist/components/Hud/Scanner/assets}/flashlight-white.png +0 -0
- /package/{lib/Hud/Scanner → dist/components/Hud/Scanner/assets}/icon_back_white.png +0 -0
- /package/{lib/MutiPictureView → dist/components/MutiPictureView/assets}/icon_add_image.png +0 -0
- /package/{lib/MutiPictureView → dist/components/MutiPictureView/assets}/icon_del_image.png +0 -0
- /package/{lib/TableCell → dist/components/TableCell/assets}/back.png +0 -0
- /package/{lib/WithLoadingContainer → dist/components/WithLoadingContainer/assets}/loading.gif +0 -0
- /package/{lib/WithLoadingContainer → dist/components/WithLoadingContainer/assets}/loading3.gif +0 -0
- /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
|
+
};
|