@tarojs/taro-rn 4.0.7-canary.6 → 4.0.8-alpha.0
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/lib/compressImage/index.js +5 -19
- package/dist/lib/compressImage/index.js.map +1 -1
- package/dist/lib/scanCode/index.js +78 -104
- package/dist/lib/scanCode/index.js.map +1 -1
- package/package.json +38 -36
- package/src/lib/compressImage/index.ts +12 -21
- package/src/lib/scanCode/index.tsx +103 -157
|
@@ -30,25 +30,11 @@ export function compressImage(opt) {
|
|
|
30
30
|
return errorHandler(fail, complete)(res);
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
reject(error);
|
|
41
|
-
}
|
|
42
|
-
}), () => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
try {
|
|
44
|
-
const resizedImage = yield _createResizedImage();
|
|
45
|
-
resolve(resizedImage);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
reject(error);
|
|
49
|
-
}
|
|
50
|
-
}));
|
|
51
|
-
});
|
|
33
|
+
return Image.getSize(src, (width, height) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return yield _createResizedImage(width, height);
|
|
35
|
+
}), () => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return yield _createResizedImage();
|
|
37
|
+
}));
|
|
52
38
|
});
|
|
53
39
|
}
|
|
54
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/compressImage/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,YAA8B,MAAM,sCAAsC,CAAA;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,cAAc,E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,GAAG,CAAC,CAAA;YAC1C,CAAC;QACH,CAAC,CAAA,CAAA;QAED,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAO,KAAK,EAAE,MAAM,EAAE,EAAE;YAChD,OAAO,MAAM,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QACjD,CAAC,CAAA,EAAE,GAAS,EAAE;YACZ,OAAO,MAAM,mBAAmB,EAAE,CAAA;QACpC,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;CAAA"}
|
|
@@ -7,8 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
10
|
+
import { BarCodeScanner, requestPermissionsAsync } from 'expo-barcode-scanner';
|
|
11
|
+
import { Camera } from 'expo-camera';
|
|
12
|
+
import React from 'react';
|
|
12
13
|
import { BackHandler, Dimensions, Image, Platform, StatusBar, StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
13
14
|
import RootSiblings from 'react-native-root-siblings';
|
|
14
15
|
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
@@ -35,47 +36,36 @@ const codeMap = {
|
|
|
35
36
|
upc_a: 'UPC_A',
|
|
36
37
|
upc_e: 'UPC_E',
|
|
37
38
|
upc_ean: 'UPC_EAN_EXTENSION',
|
|
38
|
-
qr: 'QR_CODE'
|
|
39
|
+
qr: 'QR_CODE'
|
|
39
40
|
};
|
|
40
41
|
const typeMap = {
|
|
41
|
-
barCode: [
|
|
42
|
-
'aztec',
|
|
43
|
-
'codabar',
|
|
44
|
-
'code39',
|
|
45
|
-
'code93',
|
|
46
|
-
'code128',
|
|
47
|
-
'code39mod43',
|
|
48
|
-
'ean13',
|
|
49
|
-
'ean8',
|
|
50
|
-
'interleaved2of5',
|
|
51
|
-
'itf14',
|
|
52
|
-
'maxicode',
|
|
53
|
-
'rss14',
|
|
54
|
-
'rssexpanded',
|
|
55
|
-
'upc_a',
|
|
56
|
-
'upc_e',
|
|
57
|
-
'upc_ean',
|
|
58
|
-
],
|
|
42
|
+
barCode: ['aztec', 'codabar', 'code39', 'code93', 'code128', 'code39mod43', 'ean13', 'ean8', 'interleaved2of5', 'itf14', 'maxicode', 'rss14', 'rssexpanded', 'upc_a', 'upc_e', 'upc_ean'],
|
|
59
43
|
qrCode: ['qr'],
|
|
60
44
|
datamatrix: ['datamatrix'],
|
|
61
|
-
pdf417: ['pdf417']
|
|
45
|
+
pdf417: ['pdf417']
|
|
62
46
|
};
|
|
47
|
+
const BarCodeType = BarCodeScanner.Constants.BarCodeType;
|
|
48
|
+
function findKey(value, data, compare = (a, b) => a === b) {
|
|
49
|
+
return Object.keys(data).find(k => compare(data[k], value)) || '';
|
|
50
|
+
}
|
|
63
51
|
const { width, height } = Dimensions.get('screen');
|
|
64
52
|
function getBarCodeTypes(types) {
|
|
65
53
|
const result = [];
|
|
66
54
|
for (const t of types) {
|
|
67
|
-
result.push(...typeMap[t]
|
|
55
|
+
result.push(...typeMap[t].map(type => {
|
|
56
|
+
return BarCodeType[type];
|
|
57
|
+
}));
|
|
68
58
|
}
|
|
69
|
-
return result.filter(
|
|
59
|
+
return result.filter(r => !!r);
|
|
70
60
|
}
|
|
71
61
|
function formatCodeType(type) {
|
|
72
|
-
return codeMap[type];
|
|
62
|
+
return codeMap[findKey(type, BarCodeType)];
|
|
73
63
|
}
|
|
74
64
|
function safeViewWrapper(element) {
|
|
75
65
|
if (Platform.OS === 'ios') {
|
|
76
|
-
return
|
|
66
|
+
return React.createElement(View, { style: {
|
|
77
67
|
paddingTop: Math.max((initialWindowMetrics === null || initialWindowMetrics === void 0 ? void 0 : initialWindowMetrics.insets.top) || 0, 20),
|
|
78
|
-
} }, element)
|
|
68
|
+
} }, element);
|
|
79
69
|
}
|
|
80
70
|
return element;
|
|
81
71
|
}
|
|
@@ -98,12 +88,12 @@ const styles = StyleSheet.create({
|
|
|
98
88
|
justifyContent: 'center',
|
|
99
89
|
alignItems: 'center',
|
|
100
90
|
flex: 1,
|
|
101
|
-
zIndex: 1000
|
|
91
|
+
zIndex: 1000
|
|
102
92
|
},
|
|
103
93
|
closeIcon: {
|
|
104
94
|
position: 'absolute',
|
|
105
95
|
left: 20,
|
|
106
|
-
top: 10
|
|
96
|
+
top: 10
|
|
107
97
|
},
|
|
108
98
|
closeImg: {
|
|
109
99
|
width: 25,
|
|
@@ -115,12 +105,12 @@ const styles = StyleSheet.create({
|
|
|
115
105
|
height: 40,
|
|
116
106
|
borderRadius: 20,
|
|
117
107
|
justifyContent: 'center',
|
|
118
|
-
alignItems: 'center'
|
|
108
|
+
alignItems: 'center'
|
|
119
109
|
},
|
|
120
110
|
albumIcon: {
|
|
121
111
|
position: 'absolute',
|
|
122
112
|
right: 20,
|
|
123
|
-
bottom: 40
|
|
113
|
+
bottom: 40
|
|
124
114
|
},
|
|
125
115
|
albumImg: {
|
|
126
116
|
width: 20,
|
|
@@ -132,8 +122,8 @@ const styles = StyleSheet.create({
|
|
|
132
122
|
height: 40,
|
|
133
123
|
borderRadius: 20,
|
|
134
124
|
justifyContent: 'center',
|
|
135
|
-
alignItems: 'center'
|
|
136
|
-
}
|
|
125
|
+
alignItems: 'center'
|
|
126
|
+
}
|
|
137
127
|
});
|
|
138
128
|
function scanFromPhoto(callback, errorCallBack) {
|
|
139
129
|
chooseMedia({
|
|
@@ -143,87 +133,71 @@ function scanFromPhoto(callback, errorCallBack) {
|
|
|
143
133
|
success: function (res) {
|
|
144
134
|
const imageUrl = res.tempFilePaths[0];
|
|
145
135
|
if (imageUrl) {
|
|
146
|
-
scanFromURLAsync(imageUrl).then(
|
|
136
|
+
BarCodeScanner.scanFromURLAsync(imageUrl).then(res => {
|
|
147
137
|
res && res.length > 0 && callback(res[0].data, res[0].type);
|
|
148
138
|
});
|
|
149
139
|
}
|
|
150
|
-
}
|
|
140
|
+
}
|
|
151
141
|
}, MEDIA_TYPE.Images).catch(errorCallBack);
|
|
152
142
|
}
|
|
153
143
|
export function scanCode() {
|
|
154
144
|
return __awaiter(this, arguments, void 0, function* (option = {}) {
|
|
145
|
+
const { success, fail, complete, onlyFromCamera, scanType = ['barCode', 'qrCode'] } = option;
|
|
146
|
+
const { granted } = yield requestPermissionsAsync();
|
|
147
|
+
if (!granted) {
|
|
148
|
+
const res = { errMsg: 'Permissions denied!' };
|
|
149
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
150
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
151
|
+
return Promise.reject(res);
|
|
152
|
+
}
|
|
153
|
+
const barCodeTypes = getBarCodeTypes(scanType);
|
|
155
154
|
return new Promise((resolve, reject) => {
|
|
156
|
-
scannerView = new RootSiblings(React.createElement(
|
|
155
|
+
scannerView = new RootSiblings((React.createElement(View, { style: [styles.container] },
|
|
156
|
+
React.createElement(StatusBar, { backgroundColor: "rgba(0, 0, 0, 0)", translucent: true, hidden: Platform.OS === 'ios' }),
|
|
157
|
+
React.createElement(Camera, { onBarCodeScanned: ({ type, data }) => {
|
|
158
|
+
const res = {
|
|
159
|
+
charSet: 'UTF-8', // todo
|
|
160
|
+
path: '', // todo
|
|
161
|
+
rawData: '', // todo
|
|
162
|
+
errMsg: 'scanCode:ok',
|
|
163
|
+
result: data,
|
|
164
|
+
scanType: formatCodeType(type),
|
|
165
|
+
};
|
|
166
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
167
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
168
|
+
hide(scannerView);
|
|
169
|
+
resolve(res);
|
|
170
|
+
}, barCodeScannerSettings: {
|
|
171
|
+
barCodeTypes,
|
|
172
|
+
}, style: { width, height } }),
|
|
173
|
+
React.createElement(TouchableOpacity, { accessibilityLabel: "Close", style: styles.closeIcon, onPress: () => hide(scannerView) }, safeViewWrapper(React.createElement(Image, { source: iconClose, style: styles.closeImg }))),
|
|
174
|
+
!onlyFromCamera && (React.createElement(TouchableOpacity, { style: styles.albumIcon, onPress: () => {
|
|
175
|
+
scanFromPhoto((data, type) => {
|
|
176
|
+
const res = {
|
|
177
|
+
charSet: 'UTF-8', // todo
|
|
178
|
+
path: '', // todo
|
|
179
|
+
rawData: '', // todo
|
|
180
|
+
errMsg: 'scanCode:ok',
|
|
181
|
+
result: data,
|
|
182
|
+
scanType: formatCodeType(type),
|
|
183
|
+
};
|
|
184
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
185
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
186
|
+
hide(scannerView);
|
|
187
|
+
resolve(res);
|
|
188
|
+
}, (err) => {
|
|
189
|
+
const res = {
|
|
190
|
+
errMsg: 'scanCode fail',
|
|
191
|
+
err
|
|
192
|
+
};
|
|
193
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
194
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
195
|
+
hide(scannerView);
|
|
196
|
+
reject(res);
|
|
197
|
+
});
|
|
198
|
+
} }, safeViewWrapper(React.createElement(Image, { source: iconPic, style: styles.albumImg })))))));
|
|
157
199
|
BackHandler.addEventListener('hardwareBackPress', backAction);
|
|
158
200
|
});
|
|
159
201
|
});
|
|
160
202
|
}
|
|
161
|
-
function CameraEmpty() {
|
|
162
|
-
return (React.createElement(View, { style: [styles.container] },
|
|
163
|
-
React.createElement(TouchableOpacity, { accessibilityLabel: "Close", style: styles.closeIcon, onPress: () => hide(scannerView) }, safeViewWrapper(React.createElement(Image, { source: iconClose, style: styles.closeImg })))));
|
|
164
|
-
}
|
|
165
|
-
function CameraScan({ option, resolve, reject }) {
|
|
166
|
-
const { success, fail, complete, onlyFromCamera, scanType = ['barCode', 'qrCode'] } = option;
|
|
167
|
-
const [status, requestPermission] = useCameraPermissions();
|
|
168
|
-
useEffect(() => {
|
|
169
|
-
if (!(status === null || status === void 0 ? void 0 : status.granted)) {
|
|
170
|
-
requestPermission();
|
|
171
|
-
}
|
|
172
|
-
}, [status, requestPermission]);
|
|
173
|
-
if (!status) {
|
|
174
|
-
return React.createElement(CameraEmpty, null);
|
|
175
|
-
}
|
|
176
|
-
if (!status.granted) {
|
|
177
|
-
const res = { errMsg: 'Permissions denied!' };
|
|
178
|
-
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
179
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
180
|
-
reject(res);
|
|
181
|
-
return React.createElement(CameraEmpty, null);
|
|
182
|
-
}
|
|
183
|
-
const barcodeTypes = getBarCodeTypes(scanType);
|
|
184
|
-
return (React.createElement(View, { style: [styles.container] },
|
|
185
|
-
React.createElement(StatusBar, { backgroundColor: "rgba(0, 0, 0, 0)", translucent: true, hidden: Platform.OS === 'ios' }),
|
|
186
|
-
React.createElement(CameraView, { onBarcodeScanned: ({ type, data }) => {
|
|
187
|
-
const res = {
|
|
188
|
-
charSet: 'UTF-8', // todo
|
|
189
|
-
path: '', // todo
|
|
190
|
-
rawData: '', // todo
|
|
191
|
-
errMsg: 'scanCode:ok',
|
|
192
|
-
result: data,
|
|
193
|
-
scanType: formatCodeType(type),
|
|
194
|
-
};
|
|
195
|
-
success === null || success === void 0 ? void 0 : success(res);
|
|
196
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
197
|
-
hide(scannerView);
|
|
198
|
-
resolve(res);
|
|
199
|
-
}, barcodeScannerSettings: {
|
|
200
|
-
barcodeTypes,
|
|
201
|
-
}, style: { width, height } }),
|
|
202
|
-
React.createElement(TouchableOpacity, { accessibilityLabel: "Close", style: styles.closeIcon, onPress: () => hide(scannerView) }, safeViewWrapper(React.createElement(Image, { source: iconClose, style: styles.closeImg }))),
|
|
203
|
-
!onlyFromCamera && (React.createElement(TouchableOpacity, { style: styles.albumIcon, onPress: () => {
|
|
204
|
-
scanFromPhoto((data, type) => {
|
|
205
|
-
const res = {
|
|
206
|
-
charSet: 'UTF-8', // todo
|
|
207
|
-
path: '', // todo
|
|
208
|
-
rawData: '', // todo
|
|
209
|
-
errMsg: 'scanCode:ok',
|
|
210
|
-
result: data,
|
|
211
|
-
scanType: formatCodeType(type),
|
|
212
|
-
};
|
|
213
|
-
success === null || success === void 0 ? void 0 : success(res);
|
|
214
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
215
|
-
hide(scannerView);
|
|
216
|
-
resolve(res);
|
|
217
|
-
}, (err) => {
|
|
218
|
-
const res = {
|
|
219
|
-
errMsg: 'scanCode fail',
|
|
220
|
-
err,
|
|
221
|
-
};
|
|
222
|
-
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
223
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
224
|
-
hide(scannerView);
|
|
225
|
-
reject(res);
|
|
226
|
-
});
|
|
227
|
-
} }, safeViewWrapper(React.createElement(Image, { source: iconPic, style: styles.albumImg }))))));
|
|
228
|
-
}
|
|
229
203
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/scanCode/index.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/scanCode/index.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACtH,OAAO,YAAY,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AAErE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,SAAS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
5
|
"author": "O2Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,65 +27,67 @@
|
|
|
27
27
|
"base64-js": "^1.5.1",
|
|
28
28
|
"deprecated-react-native-prop-types": "^5.0.0",
|
|
29
29
|
"prop-types": "^15.8.1",
|
|
30
|
-
"@tarojs/
|
|
31
|
-
"@tarojs/
|
|
30
|
+
"@tarojs/runtime-rn": "4.0.8-alpha.0",
|
|
31
|
+
"@tarojs/taro": "4.0.8-alpha.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/core": "^7.24.4",
|
|
35
35
|
"@babel/parser": "^7.24.4",
|
|
36
36
|
"@babel/preset-env": "^7.24.4",
|
|
37
37
|
"@babel/traverse": "^7.24.4",
|
|
38
|
-
"@react-native/babel-preset": "^0.
|
|
38
|
+
"@react-native/babel-preset": "^0.73.18",
|
|
39
39
|
"@testing-library/jest-native": "^5.4.2",
|
|
40
|
-
"@testing-library/react-native": "^12.
|
|
40
|
+
"@testing-library/react-native": "^12.4.1",
|
|
41
41
|
"@bam.tech/react-native-image-resizer": "^3.0.10",
|
|
42
|
-
"@react-native-async-storage/async-storage": "1.
|
|
42
|
+
"@react-native-async-storage/async-storage": "1.21.0",
|
|
43
43
|
"@react-native-camera-roll/camera-roll": "^7.8.3",
|
|
44
|
-
"@react-native-clipboard/clipboard": "^1.
|
|
44
|
+
"@react-native-clipboard/clipboard": "^1.14.3",
|
|
45
45
|
"@react-native-community/geolocation": "^3.4.0",
|
|
46
|
-
"@react-native-community/netinfo": "11.
|
|
46
|
+
"@react-native-community/netinfo": "11.1.0",
|
|
47
47
|
"cpy-cli": "^5.0.0",
|
|
48
48
|
"dpdm": "^3.14.0",
|
|
49
|
-
"expo": "~
|
|
50
|
-
"expo-av": "~
|
|
51
|
-
"expo-
|
|
52
|
-
"expo-
|
|
53
|
-
"expo-
|
|
54
|
-
"expo-
|
|
55
|
-
"expo-
|
|
56
|
-
"expo-
|
|
57
|
-
"expo-
|
|
58
|
-
"
|
|
49
|
+
"expo": "~50.0.0",
|
|
50
|
+
"expo-av": "~13.10.6",
|
|
51
|
+
"expo-barcode-scanner": "~12.9.3",
|
|
52
|
+
"expo-brightness": "~11.8.0",
|
|
53
|
+
"expo-camera": "~14.1.3",
|
|
54
|
+
"expo-file-system": "~16.0.9",
|
|
55
|
+
"expo-image-picker": "~14.7.1",
|
|
56
|
+
"expo-keep-awake": "~12.8.2",
|
|
57
|
+
"expo-location": "~16.5.5",
|
|
58
|
+
"expo-sensors": "~12.9.1",
|
|
59
|
+
"jest-expo": "~50.0.3",
|
|
59
60
|
"mock-socket": "^7.1.0",
|
|
60
|
-
"react": "^18.
|
|
61
|
-
"react-native": "^0.
|
|
61
|
+
"react": "^18.2.0",
|
|
62
|
+
"react-native": "^0.73.1",
|
|
62
63
|
"react-native-device-info": "^14.0.0",
|
|
63
64
|
"react-native-image-zoom-viewer": "^3.0.1",
|
|
64
65
|
"react-native-root-siblings": "^5.0.1",
|
|
65
|
-
"react-native-safe-area-context": "4.
|
|
66
|
+
"react-native-safe-area-context": "4.8.2"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
69
|
"@bam.tech/react-native-image-resizer": "^3.0.10",
|
|
69
|
-
"@react-native-async-storage/async-storage": "1.
|
|
70
|
+
"@react-native-async-storage/async-storage": "1.21.0",
|
|
70
71
|
"@react-native-camera-roll/camera-roll": "^7.8.3",
|
|
71
|
-
"@react-native-clipboard/clipboard": "^1.
|
|
72
|
+
"@react-native-clipboard/clipboard": "^1.14.3",
|
|
72
73
|
"@react-native-community/geolocation": "^3.4.0",
|
|
73
|
-
"@react-native-community/netinfo": "11.
|
|
74
|
-
"expo": "~
|
|
75
|
-
"expo-av": "~
|
|
76
|
-
"expo-
|
|
77
|
-
"expo-
|
|
78
|
-
"expo-
|
|
79
|
-
"expo-
|
|
80
|
-
"expo-
|
|
81
|
-
"expo-
|
|
82
|
-
"expo-
|
|
83
|
-
"
|
|
84
|
-
"react
|
|
74
|
+
"@react-native-community/netinfo": "11.1.0",
|
|
75
|
+
"expo": "~50.0.0",
|
|
76
|
+
"expo-av": "~13.10.6",
|
|
77
|
+
"expo-barcode-scanner": "~12.9.3",
|
|
78
|
+
"expo-brightness": "~11.8.0",
|
|
79
|
+
"expo-camera": "~14.1.3",
|
|
80
|
+
"expo-file-system": "~16.0.9",
|
|
81
|
+
"expo-image-picker": "~14.7.1",
|
|
82
|
+
"expo-keep-awake": "~12.8.2",
|
|
83
|
+
"expo-location": "~16.5.5",
|
|
84
|
+
"expo-sensors": "~12.9.1",
|
|
85
|
+
"react": "^18.2.0",
|
|
86
|
+
"react-native": "^0.73.1",
|
|
85
87
|
"react-native-device-info": "^14.0.0",
|
|
86
88
|
"react-native-image-zoom-viewer": "^3.0.1",
|
|
87
89
|
"react-native-root-siblings": "^5.0.1",
|
|
88
|
-
"react-native-safe-area-context": "4.
|
|
90
|
+
"react-native-safe-area-context": "4.8.2"
|
|
89
91
|
},
|
|
90
92
|
"scripts": {
|
|
91
93
|
"prod": "pnpm run build",
|
|
@@ -8,7 +8,13 @@ import { errorHandler, successHandler } from '../../utils'
|
|
|
8
8
|
* @param opts
|
|
9
9
|
*/
|
|
10
10
|
export async function compressImage(opt: Taro.compressImage.Option): Promise<Taro.compressImage.SuccessCallbackResult> {
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
src,
|
|
13
|
+
quality = 80,
|
|
14
|
+
success,
|
|
15
|
+
fail,
|
|
16
|
+
complete
|
|
17
|
+
} = opt
|
|
12
18
|
|
|
13
19
|
const res = { errMsg: 'compressImage:ok', tempFilePath: '' }
|
|
14
20
|
|
|
@@ -23,25 +29,10 @@ export async function compressImage(opt: Taro.compressImage.Option): Promise<Tar
|
|
|
23
29
|
return errorHandler(fail, complete)(res)
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const resizedImage = await _createResizedImage(width, height)
|
|
32
|
-
resolve(resizedImage)
|
|
33
|
-
} catch (error) {
|
|
34
|
-
reject(error)
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
async () => {
|
|
38
|
-
try {
|
|
39
|
-
const resizedImage = await _createResizedImage()
|
|
40
|
-
resolve(resizedImage)
|
|
41
|
-
} catch (error) {
|
|
42
|
-
reject(error)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
)
|
|
32
|
+
|
|
33
|
+
return Image.getSize(src, async (width, height) => {
|
|
34
|
+
return await _createResizedImage(width, height)
|
|
35
|
+
}, async () => {
|
|
36
|
+
return await _createResizedImage()
|
|
46
37
|
})
|
|
47
38
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { BarCodeScanner, requestPermissionsAsync } from 'expo-barcode-scanner'
|
|
2
|
+
import { Camera } from 'expo-camera'
|
|
3
|
+
import React from 'react'
|
|
3
4
|
import { BackHandler, Dimensions, Image, Platform, StatusBar, StyleSheet, TouchableOpacity, View } from 'react-native'
|
|
4
5
|
import RootSiblings from 'react-native-root-siblings'
|
|
5
6
|
import { initialWindowMetrics } from 'react-native-safe-area-context'
|
|
@@ -29,60 +30,45 @@ const codeMap = {
|
|
|
29
30
|
upc_a: 'UPC_A',
|
|
30
31
|
upc_e: 'UPC_E',
|
|
31
32
|
upc_ean: 'UPC_EAN_EXTENSION',
|
|
32
|
-
qr: 'QR_CODE'
|
|
33
|
+
qr: 'QR_CODE'
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
const typeMap = {
|
|
36
|
-
barCode: [
|
|
37
|
-
'aztec',
|
|
38
|
-
'codabar',
|
|
39
|
-
'code39',
|
|
40
|
-
'code93',
|
|
41
|
-
'code128',
|
|
42
|
-
'code39mod43',
|
|
43
|
-
'ean13',
|
|
44
|
-
'ean8',
|
|
45
|
-
'interleaved2of5',
|
|
46
|
-
'itf14',
|
|
47
|
-
'maxicode',
|
|
48
|
-
'rss14',
|
|
49
|
-
'rssexpanded',
|
|
50
|
-
'upc_a',
|
|
51
|
-
'upc_e',
|
|
52
|
-
'upc_ean',
|
|
53
|
-
],
|
|
37
|
+
barCode: ['aztec', 'codabar', 'code39', 'code93', 'code128', 'code39mod43', 'ean13', 'ean8', 'interleaved2of5', 'itf14', 'maxicode', 'rss14', 'rssexpanded', 'upc_a', 'upc_e', 'upc_ean'],
|
|
54
38
|
qrCode: ['qr'],
|
|
55
39
|
datamatrix: ['datamatrix'],
|
|
56
|
-
pdf417: ['pdf417']
|
|
40
|
+
pdf417: ['pdf417']
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const BarCodeType = BarCodeScanner.Constants.BarCodeType
|
|
44
|
+
|
|
45
|
+
function findKey (value:string, data, compare = (a, b) => a === b):string {
|
|
46
|
+
return Object.keys(data).find(k => compare(data[k], value)) || ''
|
|
57
47
|
}
|
|
58
48
|
|
|
59
49
|
const { width, height } = Dimensions.get('screen')
|
|
60
50
|
|
|
61
|
-
function getBarCodeTypes(types:
|
|
62
|
-
const result:
|
|
51
|
+
function getBarCodeTypes(types:string[]): string[] {
|
|
52
|
+
const result: string[] = []
|
|
63
53
|
|
|
64
54
|
for (const t of types) {
|
|
65
|
-
result.push(...typeMap[t]
|
|
55
|
+
result.push(...typeMap[t].map(type => {
|
|
56
|
+
return BarCodeType[type]
|
|
57
|
+
}))
|
|
66
58
|
}
|
|
67
59
|
|
|
68
|
-
return result.filter(
|
|
60
|
+
return result.filter(r => !!r)
|
|
69
61
|
}
|
|
70
62
|
|
|
71
|
-
function formatCodeType(type:
|
|
72
|
-
return codeMap[type]
|
|
63
|
+
function formatCodeType(type:string):keyof Taro.scanCode.QRType {
|
|
64
|
+
return codeMap[findKey(type, BarCodeType)]
|
|
73
65
|
}
|
|
74
66
|
|
|
75
|
-
function safeViewWrapper(element:
|
|
67
|
+
function safeViewWrapper(element:any) {
|
|
76
68
|
if (Platform.OS === 'ios') {
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
paddingTop: Math.max(initialWindowMetrics?.insets.top || 0, 20),
|
|
81
|
-
}}
|
|
82
|
-
>
|
|
83
|
-
{element}
|
|
84
|
-
</View>
|
|
85
|
-
)
|
|
69
|
+
return <View style={{
|
|
70
|
+
paddingTop: Math.max(initialWindowMetrics?.insets.top || 0, 20),
|
|
71
|
+
}}>{element}</View>
|
|
86
72
|
}
|
|
87
73
|
return element
|
|
88
74
|
}
|
|
@@ -109,12 +95,12 @@ const styles = StyleSheet.create({
|
|
|
109
95
|
justifyContent: 'center',
|
|
110
96
|
alignItems: 'center',
|
|
111
97
|
flex: 1,
|
|
112
|
-
zIndex: 1000
|
|
98
|
+
zIndex: 1000
|
|
113
99
|
},
|
|
114
100
|
closeIcon: {
|
|
115
101
|
position: 'absolute',
|
|
116
102
|
left: 20,
|
|
117
|
-
top: 10
|
|
103
|
+
top: 10
|
|
118
104
|
},
|
|
119
105
|
closeImg: {
|
|
120
106
|
width: 25,
|
|
@@ -126,12 +112,12 @@ const styles = StyleSheet.create({
|
|
|
126
112
|
height: 40,
|
|
127
113
|
borderRadius: 20,
|
|
128
114
|
justifyContent: 'center',
|
|
129
|
-
alignItems: 'center'
|
|
115
|
+
alignItems: 'center'
|
|
130
116
|
},
|
|
131
117
|
albumIcon: {
|
|
132
118
|
position: 'absolute',
|
|
133
119
|
right: 20,
|
|
134
|
-
bottom: 40
|
|
120
|
+
bottom: 40
|
|
135
121
|
},
|
|
136
122
|
albumImg: {
|
|
137
123
|
width: 20,
|
|
@@ -143,132 +129,92 @@ const styles = StyleSheet.create({
|
|
|
143
129
|
height: 40,
|
|
144
130
|
borderRadius: 20,
|
|
145
131
|
justifyContent: 'center',
|
|
146
|
-
alignItems: 'center'
|
|
147
|
-
}
|
|
132
|
+
alignItems: 'center'
|
|
133
|
+
}
|
|
148
134
|
})
|
|
149
135
|
|
|
150
136
|
function scanFromPhoto(callback, errorCallBack) {
|
|
151
|
-
chooseMedia(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
},
|
|
165
|
-
MEDIA_TYPE.Images
|
|
166
|
-
).catch(errorCallBack)
|
|
137
|
+
chooseMedia({
|
|
138
|
+
sourceType: ['album'],
|
|
139
|
+
maxDuration: 60,
|
|
140
|
+
camera: 'back',
|
|
141
|
+
success: function (res) {
|
|
142
|
+
const imageUrl = res.tempFilePaths[0]
|
|
143
|
+
if (imageUrl) {
|
|
144
|
+
BarCodeScanner.scanFromURLAsync(imageUrl).then(res => {
|
|
145
|
+
res && res.length > 0 && callback(res[0].data, res[0].type)
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}, MEDIA_TYPE.Images).catch(errorCallBack)
|
|
167
150
|
}
|
|
168
151
|
|
|
169
152
|
export async function scanCode(option: Taro.scanCode.Option = {}): Promise<Taro.scanCode.SuccessCallbackResult> {
|
|
170
|
-
return new Promise((resolve, reject) => {
|
|
171
|
-
scannerView = new RootSiblings(<CameraScan option={option} reject={reject} resolve={resolve} />)
|
|
172
|
-
BackHandler.addEventListener('hardwareBackPress', backAction)
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
interface CameraScanOption {
|
|
177
|
-
option: Taro.scanCode.Option
|
|
178
|
-
resolve: (value?: Taro.scanCode.SuccessCallbackResult | PromiseLike<Taro.scanCode.SuccessCallbackResult>) => void
|
|
179
|
-
reject: (reason?: any) => void
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function CameraEmpty() {
|
|
183
|
-
return (
|
|
184
|
-
<View style={[styles.container]}>
|
|
185
|
-
<TouchableOpacity accessibilityLabel="Close" style={styles.closeIcon} onPress={() => hide(scannerView)}>
|
|
186
|
-
{safeViewWrapper(<Image source={iconClose} style={styles.closeImg} />)}
|
|
187
|
-
</TouchableOpacity>
|
|
188
|
-
</View>
|
|
189
|
-
)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function CameraScan({ option, resolve, reject }: CameraScanOption) {
|
|
193
153
|
const { success, fail, complete, onlyFromCamera, scanType = ['barCode', 'qrCode'] } = option
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
if (!status?.granted) {
|
|
197
|
-
requestPermission()
|
|
198
|
-
}
|
|
199
|
-
}, [status, requestPermission])
|
|
200
|
-
if (!status) {
|
|
201
|
-
return <CameraEmpty />
|
|
202
|
-
}
|
|
203
|
-
if (!status.granted) {
|
|
154
|
+
const { granted } = await requestPermissionsAsync()
|
|
155
|
+
if (!granted) {
|
|
204
156
|
const res = { errMsg: 'Permissions denied!' }
|
|
205
157
|
fail?.(res)
|
|
206
158
|
complete?.(res)
|
|
207
|
-
reject(res)
|
|
208
|
-
return <CameraEmpty />
|
|
159
|
+
return Promise.reject(res)
|
|
209
160
|
}
|
|
210
|
-
const
|
|
211
|
-
return (
|
|
212
|
-
|
|
213
|
-
<
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
style={{ width, height }}
|
|
233
|
-
/>
|
|
234
|
-
<TouchableOpacity accessibilityLabel="Close" style={styles.closeIcon} onPress={() => hide(scannerView)}>
|
|
235
|
-
{safeViewWrapper(<Image source={iconClose} style={styles.closeImg} />)}
|
|
236
|
-
</TouchableOpacity>
|
|
237
|
-
{!onlyFromCamera && (
|
|
238
|
-
<TouchableOpacity
|
|
239
|
-
style={styles.albumIcon}
|
|
240
|
-
onPress={() => {
|
|
241
|
-
scanFromPhoto(
|
|
242
|
-
(data, type) => {
|
|
243
|
-
const res = {
|
|
244
|
-
charSet: 'UTF-8', // todo
|
|
245
|
-
path: '', // todo
|
|
246
|
-
rawData: '', // todo
|
|
247
|
-
errMsg: 'scanCode:ok',
|
|
248
|
-
result: data,
|
|
249
|
-
scanType: formatCodeType(type),
|
|
250
|
-
}
|
|
251
|
-
success?.(res)
|
|
252
|
-
complete?.(res)
|
|
253
|
-
hide(scannerView)
|
|
254
|
-
resolve(res)
|
|
255
|
-
},
|
|
256
|
-
(err) => {
|
|
257
|
-
const res = {
|
|
258
|
-
errMsg: 'scanCode fail',
|
|
259
|
-
err,
|
|
260
|
-
}
|
|
261
|
-
fail?.(res)
|
|
262
|
-
complete?.(res)
|
|
263
|
-
hide(scannerView)
|
|
264
|
-
reject(res)
|
|
265
|
-
}
|
|
266
|
-
)
|
|
161
|
+
const barCodeTypes = getBarCodeTypes(scanType)
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
scannerView = new RootSiblings(
|
|
164
|
+
(<View style={[styles.container]}>
|
|
165
|
+
<StatusBar backgroundColor="rgba(0, 0, 0, 0)" translucent hidden={Platform.OS === 'ios'} />
|
|
166
|
+
<Camera
|
|
167
|
+
onBarCodeScanned={({ type, data }: {type: string, data: string}) => {
|
|
168
|
+
const res = {
|
|
169
|
+
charSet: 'UTF-8', // todo
|
|
170
|
+
path: '', // todo
|
|
171
|
+
rawData: '', // todo
|
|
172
|
+
errMsg: 'scanCode:ok',
|
|
173
|
+
result: data,
|
|
174
|
+
scanType: formatCodeType(type),
|
|
175
|
+
}
|
|
176
|
+
success?.(res)
|
|
177
|
+
complete?.(res)
|
|
178
|
+
hide(scannerView)
|
|
179
|
+
resolve(res)
|
|
180
|
+
}}
|
|
181
|
+
barCodeScannerSettings={{
|
|
182
|
+
barCodeTypes,
|
|
267
183
|
}}
|
|
268
|
-
|
|
269
|
-
|
|
184
|
+
style={{ width, height }}
|
|
185
|
+
/>
|
|
186
|
+
<TouchableOpacity accessibilityLabel="Close" style={styles.closeIcon} onPress={() => hide(scannerView)}>
|
|
187
|
+
{safeViewWrapper(<Image source={iconClose} style={styles.closeImg}/>)}
|
|
270
188
|
</TouchableOpacity>
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
189
|
+
{!onlyFromCamera && (<TouchableOpacity style={styles.albumIcon} onPress={() => {
|
|
190
|
+
scanFromPhoto((data, type) => {
|
|
191
|
+
const res = {
|
|
192
|
+
charSet: 'UTF-8', // todo
|
|
193
|
+
path: '', // todo
|
|
194
|
+
rawData: '', // todo
|
|
195
|
+
errMsg: 'scanCode:ok',
|
|
196
|
+
result: data,
|
|
197
|
+
scanType: formatCodeType(type),
|
|
198
|
+
}
|
|
199
|
+
success?.(res)
|
|
200
|
+
complete?.(res)
|
|
201
|
+
hide(scannerView)
|
|
202
|
+
resolve(res)
|
|
203
|
+
}, (err) => {
|
|
204
|
+
const res = {
|
|
205
|
+
errMsg: 'scanCode fail',
|
|
206
|
+
err
|
|
207
|
+
}
|
|
208
|
+
fail?.(res)
|
|
209
|
+
complete?.(res)
|
|
210
|
+
hide(scannerView)
|
|
211
|
+
reject(res)
|
|
212
|
+
})
|
|
213
|
+
}}>
|
|
214
|
+
{safeViewWrapper(<Image source={iconPic} style={styles.albumImg}/>)}
|
|
215
|
+
</TouchableOpacity>)}
|
|
216
|
+
</View>)
|
|
217
|
+
)
|
|
218
|
+
BackHandler.addEventListener('hardwareBackPress', backAction)
|
|
219
|
+
})
|
|
274
220
|
}
|