@unif/react-native-hms-scan 0.6.1 → 1.0.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/README.md +24 -72
- package/android/src/main/AndroidManifest.xml +0 -9
- package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanImage.kt +135 -0
- package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanModule.kt +163 -147
- package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanResultMapper.kt +17 -9
- package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanView.kt +57 -19
- package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanViewManager.kt +1 -1
- package/ios/HmsScanModule.mm +13 -37
- package/ios/HmsScanResultMapper.h +4 -3
- package/ios/HmsScanResultMapper.mm +31 -19
- package/ios/HmsScanView.h +1 -1
- package/ios/HmsScanView.mm +140 -25
- package/lib/module/HmsScanView/HmsScanView.js +66 -0
- package/lib/module/HmsScanView/HmsScanView.js.map +1 -0
- package/lib/module/HmsScanView/HmsScanView.web.js +26 -0
- package/lib/module/HmsScanView/HmsScanView.web.js.map +1 -0
- package/lib/module/HmsScanView/types.js +4 -0
- package/lib/module/HmsScanView/types.js.map +1 -0
- package/lib/module/HmsScanViewNativeComponent.ts +7 -5
- package/lib/module/NativeHmsScan.js +1 -1
- package/lib/module/NativeHmsScan.js.map +1 -1
- package/lib/module/ScanError.js +12 -0
- package/lib/module/ScanError.js.map +1 -0
- package/lib/module/Scanner/DeniedOverlay.js +1 -1
- package/lib/module/Scanner/DeniedOverlay.js.map +1 -1
- package/lib/module/Scanner/ResultFail.js +3 -2
- package/lib/module/Scanner/ResultFail.js.map +1 -1
- package/lib/module/Scanner/ResultFocus/ResultFocus.js +56 -0
- package/lib/module/Scanner/ResultFocus/ResultFocus.js.map +1 -0
- package/lib/module/Scanner/ResultFocus/styles.js +39 -0
- package/lib/module/Scanner/ResultFocus/styles.js.map +1 -0
- package/lib/module/Scanner/ResultFocus/types.js +4 -0
- package/lib/module/Scanner/ResultFocus/types.js.map +1 -0
- package/lib/module/Scanner/ScanHint.js +6 -3
- package/lib/module/Scanner/ScanHint.js.map +1 -1
- package/lib/module/Scanner/ScanToolbar.js +6 -3
- package/lib/module/Scanner/ScanToolbar.js.map +1 -1
- package/lib/module/Scanner/ScanTopBar.js +6 -3
- package/lib/module/Scanner/ScanTopBar.js.map +1 -1
- package/lib/module/Scanner/Scanner.js +9 -311
- package/lib/module/Scanner/Scanner.js.map +1 -1
- package/lib/module/Scanner/Scanner.web.js +29 -0
- package/lib/module/Scanner/Scanner.web.js.map +1 -0
- package/lib/module/Scanner/ScannerInner.js +310 -0
- package/lib/module/Scanner/ScannerInner.js.map +1 -0
- package/lib/module/Scanner/styles.js +11 -0
- package/lib/module/Scanner/styles.js.map +1 -0
- package/lib/module/Scanner/types.js +4 -0
- package/lib/module/Scanner/types.js.map +1 -0
- package/lib/module/constants.js +20 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/decodeImage.js +29 -24
- package/lib/module/decodeImage.js.map +1 -1
- package/lib/module/decodeImage.web.js +7 -0
- package/lib/module/decodeImage.web.js.map +1 -0
- package/lib/module/errors.js +24 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/format.js +53 -47
- package/lib/module/format.js.map +1 -1
- package/lib/module/index.js +5 -19
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +8 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/module/mock.js +2 -23
- package/lib/module/mock.js.map +1 -1
- package/lib/module/permissions.js +24 -20
- package/lib/module/permissions.js.map +1 -1
- package/lib/module/permissions.web.js +10 -0
- package/lib/module/permissions.web.js.map +1 -0
- package/lib/module/types.js +1 -45
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/src/HmsScanView/HmsScanView.d.ts +3 -0
- package/lib/typescript/src/HmsScanView/HmsScanView.d.ts.map +1 -0
- package/lib/typescript/src/HmsScanView/HmsScanView.web.d.ts +3 -0
- package/lib/typescript/src/HmsScanView/HmsScanView.web.d.ts.map +1 -0
- package/lib/typescript/src/HmsScanView/types.d.ts +12 -0
- package/lib/typescript/src/HmsScanView/types.d.ts.map +1 -0
- package/lib/typescript/src/HmsScanViewNativeComponent.d.ts +6 -4
- package/lib/typescript/src/HmsScanViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/NativeHmsScan.d.ts +3 -5
- package/lib/typescript/src/NativeHmsScan.d.ts.map +1 -1
- package/lib/typescript/src/ScanError.d.ts +7 -0
- package/lib/typescript/src/ScanError.d.ts.map +1 -0
- package/lib/typescript/src/Scanner/DeniedOverlay.d.ts.map +1 -1
- package/lib/typescript/src/Scanner/ResultFail.d.ts +2 -1
- package/lib/typescript/src/Scanner/ResultFail.d.ts.map +1 -1
- package/lib/typescript/src/Scanner/ResultFocus/ResultFocus.d.ts +4 -0
- package/lib/typescript/src/Scanner/ResultFocus/ResultFocus.d.ts.map +1 -0
- package/lib/typescript/src/Scanner/ResultFocus/styles.d.ts +36 -0
- package/lib/typescript/src/Scanner/ResultFocus/styles.d.ts.map +1 -0
- package/lib/typescript/src/Scanner/ResultFocus/types.d.ts +8 -0
- package/lib/typescript/src/Scanner/ResultFocus/types.d.ts.map +1 -0
- package/lib/typescript/src/Scanner/ScanHint.d.ts.map +1 -1
- package/lib/typescript/src/Scanner/ScanToolbar.d.ts.map +1 -1
- package/lib/typescript/src/Scanner/ScanTopBar.d.ts.map +1 -1
- package/lib/typescript/src/Scanner/Scanner.d.ts +2 -45
- package/lib/typescript/src/Scanner/Scanner.d.ts.map +1 -1
- package/lib/typescript/src/Scanner/Scanner.web.d.ts +3 -0
- package/lib/typescript/src/Scanner/Scanner.web.d.ts.map +1 -0
- package/lib/typescript/src/Scanner/ScannerInner.d.ts +3 -0
- package/lib/typescript/src/Scanner/ScannerInner.d.ts.map +1 -0
- package/lib/typescript/src/Scanner/styles.d.ts +7 -0
- package/lib/typescript/src/Scanner/styles.d.ts.map +1 -0
- package/lib/typescript/src/Scanner/types.d.ts +20 -0
- package/lib/typescript/src/Scanner/types.d.ts.map +1 -0
- package/lib/typescript/src/constants.d.ts +8 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/decodeImage.d.ts +2 -12
- package/lib/typescript/src/decodeImage.d.ts.map +1 -1
- package/lib/typescript/src/decodeImage.web.d.ts +3 -0
- package/lib/typescript/src/decodeImage.web.d.ts.map +1 -0
- package/lib/typescript/src/errors.d.ts +6 -0
- package/lib/typescript/src/errors.d.ts.map +1 -0
- package/lib/typescript/src/format.d.ts +15 -12
- package/lib/typescript/src/format.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +6 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.web.d.ts +9 -0
- package/lib/typescript/src/index.web.d.ts.map +1 -0
- package/lib/typescript/src/mock.d.ts +9 -8
- package/lib/typescript/src/mock.d.ts.map +1 -1
- package/lib/typescript/src/permissions.d.ts +4 -8
- package/lib/typescript/src/permissions.d.ts.map +1 -1
- package/lib/typescript/src/permissions.web.d.ts +4 -0
- package/lib/typescript/src/permissions.web.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +31 -56
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +9 -2
- package/src/HmsScanView/HmsScanView.tsx +67 -0
- package/src/HmsScanView/HmsScanView.web.tsx +22 -0
- package/src/HmsScanView/types.ts +17 -0
- package/src/HmsScanViewNativeComponent.ts +7 -5
- package/src/NativeHmsScan.ts +3 -5
- package/src/ScanError.ts +13 -0
- package/src/Scanner/DeniedOverlay.tsx +4 -2
- package/src/Scanner/ResultFail.tsx +23 -5
- package/src/Scanner/ResultFocus/ResultFocus.tsx +43 -0
- package/src/Scanner/ResultFocus/styles.ts +25 -0
- package/src/Scanner/ResultFocus/types.ts +8 -0
- package/src/Scanner/ScanHint.tsx +16 -11
- package/src/Scanner/ScanToolbar.tsx +35 -13
- package/src/Scanner/ScanTopBar.tsx +20 -12
- package/src/Scanner/Scanner.tsx +13 -436
- package/src/Scanner/Scanner.web.tsx +26 -0
- package/src/Scanner/ScannerInner.tsx +391 -0
- package/src/Scanner/styles.ts +6 -0
- package/src/Scanner/types.ts +36 -0
- package/src/constants.ts +55 -0
- package/src/decodeImage.ts +35 -29
- package/src/decodeImage.web.ts +8 -0
- package/src/errors.ts +26 -0
- package/src/format.ts +77 -76
- package/src/index.tsx +17 -32
- package/src/index.web.tsx +22 -0
- package/src/mock.ts +21 -29
- package/src/permissions.ts +33 -20
- package/src/permissions.web.ts +9 -0
- package/src/types.ts +38 -126
- package/lib/module/HmsScanView.js +0 -43
- package/lib/module/HmsScanView.js.map +0 -1
- package/lib/module/Scanner/ResultFocus.js +0 -171
- package/lib/module/Scanner/ResultFocus.js.map +0 -1
- package/lib/typescript/src/HmsScanView.d.ts +0 -33
- package/lib/typescript/src/HmsScanView.d.ts.map +0 -1
- package/lib/typescript/src/Scanner/ResultFocus.d.ts +0 -14
- package/lib/typescript/src/Scanner/ResultFocus.d.ts.map +0 -1
- package/src/HmsScanView.tsx +0 -87
- package/src/Scanner/ResultFocus.tsx +0 -122
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ScrollView, Text, View } from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
Card,
|
|
5
|
+
useColors,
|
|
6
|
+
useThemedStyles,
|
|
7
|
+
r,
|
|
8
|
+
} from '@unif/react-native-design';
|
|
9
|
+
import type { ResultFocusProps } from './types';
|
|
10
|
+
import { styles, makeStyles } from './styles';
|
|
11
|
+
|
|
12
|
+
/** A raw result is selected here; interpreting it belongs to the consumer. */
|
|
13
|
+
export function ResultFocus({
|
|
14
|
+
result,
|
|
15
|
+
bottomInset,
|
|
16
|
+
onRescan,
|
|
17
|
+
onConfirm,
|
|
18
|
+
}: ResultFocusProps) {
|
|
19
|
+
const colors = useColors();
|
|
20
|
+
const themed = useThemedStyles(makeStyles);
|
|
21
|
+
return (
|
|
22
|
+
<View style={[styles.wrap, { bottom: bottomInset + r(18) }]}>
|
|
23
|
+
<Card
|
|
24
|
+
borderColor={colors.primary}
|
|
25
|
+
borderWidth={2}
|
|
26
|
+
borderRadius={r(16)}
|
|
27
|
+
padding={r(14)}
|
|
28
|
+
>
|
|
29
|
+
<Text style={themed.badge}>已识别</Text>
|
|
30
|
+
<Text style={themed.format}>{result.format}</Text>
|
|
31
|
+
<ScrollView style={styles.content}>
|
|
32
|
+
<Text selectable style={themed.value}>
|
|
33
|
+
{result.value}
|
|
34
|
+
</Text>
|
|
35
|
+
</ScrollView>
|
|
36
|
+
<View style={styles.actions}>
|
|
37
|
+
<Button label="重扫" variant="secondary" block onPress={onRescan} />
|
|
38
|
+
<Button label="选用" variant="primary" block onPress={onConfirm} />
|
|
39
|
+
</View>
|
|
40
|
+
</Card>
|
|
41
|
+
</View>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import {
|
|
3
|
+
r,
|
|
4
|
+
rf,
|
|
5
|
+
fw,
|
|
6
|
+
fontMono,
|
|
7
|
+
type ColorTokens,
|
|
8
|
+
} from '@unif/react-native-design';
|
|
9
|
+
|
|
10
|
+
export const styles = StyleSheet.create({
|
|
11
|
+
wrap: { position: 'absolute', left: r(16), right: r(16), zIndex: 50 },
|
|
12
|
+
content: { maxHeight: r(220), marginVertical: r(14) },
|
|
13
|
+
actions: { flexDirection: 'row', columnGap: r(10) },
|
|
14
|
+
});
|
|
15
|
+
export const makeStyles = (colors: ColorTokens) =>
|
|
16
|
+
StyleSheet.create({
|
|
17
|
+
badge: { fontSize: rf(13), fontWeight: fw.semi, color: colors.foreground },
|
|
18
|
+
format: {
|
|
19
|
+
fontSize: rf(12),
|
|
20
|
+
color: colors.foregroundMuted,
|
|
21
|
+
fontFamily: fontMono,
|
|
22
|
+
marginTop: r(4),
|
|
23
|
+
},
|
|
24
|
+
value: { fontSize: rf(16), lineHeight: rf(21), color: colors.foreground },
|
|
25
|
+
});
|
package/src/Scanner/ScanHint.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StyleSheet, Text, View } from 'react-native';
|
|
2
|
-
import { Spinner, r, rf, fw } from '@unif/react-native-design';
|
|
2
|
+
import { Spinner, r, rf, useThemedStyles, fw } from '@unif/react-native-design';
|
|
3
3
|
import { scanChrome } from './scanChrome';
|
|
4
4
|
|
|
5
5
|
interface ScanHintProps {
|
|
@@ -10,10 +10,11 @@ interface ScanHintProps {
|
|
|
10
10
|
|
|
11
11
|
// 取景框下方提示。识别中显示 design 的 Spinner(白)+ "识别中…"。
|
|
12
12
|
export function ScanHint({ detecting, text }: ScanHintProps) {
|
|
13
|
+
const s = useThemedStyles(makeTextStyles);
|
|
13
14
|
return (
|
|
14
15
|
<View style={styles.row}>
|
|
15
16
|
{detecting && <Spinner size={r(15)} color={scanChrome.white} />}
|
|
16
|
-
<Text style={
|
|
17
|
+
<Text style={s.text}>{detecting ? '识别中…' : text}</Text>
|
|
17
18
|
</View>
|
|
18
19
|
);
|
|
19
20
|
}
|
|
@@ -26,13 +27,17 @@ const styles = StyleSheet.create({
|
|
|
26
27
|
justifyContent: 'center',
|
|
27
28
|
columnGap: r(7),
|
|
28
29
|
},
|
|
29
|
-
text: {
|
|
30
|
-
color: scanChrome.hintText,
|
|
31
|
-
fontSize: rf(13.5),
|
|
32
|
-
fontWeight: fw.medium,
|
|
33
|
-
letterSpacing: 0.2,
|
|
34
|
-
textShadowColor: scanChrome.textShadow,
|
|
35
|
-
textShadowOffset: { width: 0, height: 1 },
|
|
36
|
-
textShadowRadius: 6,
|
|
37
|
-
},
|
|
38
30
|
});
|
|
31
|
+
|
|
32
|
+
const makeTextStyles = () =>
|
|
33
|
+
StyleSheet.create({
|
|
34
|
+
text: {
|
|
35
|
+
color: scanChrome.hintText,
|
|
36
|
+
fontSize: rf(13.5),
|
|
37
|
+
fontWeight: fw.medium,
|
|
38
|
+
letterSpacing: 0.2,
|
|
39
|
+
textShadowColor: scanChrome.textShadow,
|
|
40
|
+
textShadowOffset: { width: 0, height: 1 },
|
|
41
|
+
textShadowRadius: 6,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Icon,
|
|
4
|
+
useColors,
|
|
5
|
+
r,
|
|
6
|
+
rf,
|
|
7
|
+
useThemedStyles,
|
|
8
|
+
fw,
|
|
9
|
+
type IconName,
|
|
10
|
+
} from '@unif/react-native-design';
|
|
3
11
|
import { scanChrome } from './scanChrome';
|
|
4
12
|
|
|
5
13
|
interface ScanToolbarProps {
|
|
@@ -23,7 +31,10 @@ export function ScanToolbar({
|
|
|
23
31
|
}: ScanToolbarProps) {
|
|
24
32
|
const c = useColors();
|
|
25
33
|
return (
|
|
26
|
-
<View
|
|
34
|
+
<View
|
|
35
|
+
style={[styles.bar, { bottom: bottomInset + r(50) }]}
|
|
36
|
+
pointerEvents="box-none"
|
|
37
|
+
>
|
|
27
38
|
{onClose && <ToolbarItem icon="undo" label="返回" onPress={onClose} />}
|
|
28
39
|
{onFlash && (
|
|
29
40
|
<ToolbarItem
|
|
@@ -49,6 +60,7 @@ function ToolbarItem({
|
|
|
49
60
|
activeColor?: string;
|
|
50
61
|
onPress: () => void;
|
|
51
62
|
}) {
|
|
63
|
+
const s = useThemedStyles(makeTextStyles);
|
|
52
64
|
return (
|
|
53
65
|
<Pressable
|
|
54
66
|
onPress={onPress}
|
|
@@ -62,14 +74,20 @@ function ToolbarItem({
|
|
|
62
74
|
style={[
|
|
63
75
|
styles.circle,
|
|
64
76
|
activeColor
|
|
65
|
-
? {
|
|
66
|
-
|
|
77
|
+
? {
|
|
78
|
+
backgroundColor: activeColor,
|
|
79
|
+
borderColor: scanChrome.glassBorderActive,
|
|
80
|
+
}
|
|
81
|
+
: {
|
|
82
|
+
backgroundColor: scanChrome.glassDisc2,
|
|
83
|
+
borderColor: scanChrome.glassBorder,
|
|
84
|
+
},
|
|
67
85
|
pressed && { opacity: 0.7 },
|
|
68
86
|
]}
|
|
69
87
|
>
|
|
70
88
|
<Icon name={icon} size={r(23)} color={scanChrome.white} />
|
|
71
89
|
</View>
|
|
72
|
-
<Text style={
|
|
90
|
+
<Text style={s.label}>{label}</Text>
|
|
73
91
|
</>
|
|
74
92
|
)}
|
|
75
93
|
</Pressable>
|
|
@@ -95,12 +113,16 @@ const styles = StyleSheet.create({
|
|
|
95
113
|
justifyContent: 'center',
|
|
96
114
|
borderWidth: StyleSheet.hairlineWidth,
|
|
97
115
|
},
|
|
98
|
-
label: {
|
|
99
|
-
fontSize: rf(12),
|
|
100
|
-
fontWeight: fw.medium,
|
|
101
|
-
color: scanChrome.toolbarLabel,
|
|
102
|
-
textShadowColor: 'rgba(0,0,0,0.4)',
|
|
103
|
-
textShadowOffset: { width: 0, height: 1 },
|
|
104
|
-
textShadowRadius: 4,
|
|
105
|
-
},
|
|
106
116
|
});
|
|
117
|
+
|
|
118
|
+
const makeTextStyles = () =>
|
|
119
|
+
StyleSheet.create({
|
|
120
|
+
label: {
|
|
121
|
+
fontSize: rf(12),
|
|
122
|
+
fontWeight: fw.medium,
|
|
123
|
+
color: scanChrome.toolbarLabel,
|
|
124
|
+
textShadowColor: 'rgba(0,0,0,0.4)',
|
|
125
|
+
textShadowOffset: { width: 0, height: 1 },
|
|
126
|
+
textShadowRadius: 4,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StyleSheet, Text, View } from 'react-native';
|
|
2
|
-
import { r, rf, fw } from '@unif/react-native-design';
|
|
2
|
+
import { r, rf, useThemedStyles, fw } from '@unif/react-native-design';
|
|
3
3
|
import { scanChrome } from './scanChrome';
|
|
4
4
|
|
|
5
5
|
interface ScanTopBarProps {
|
|
@@ -10,9 +10,13 @@ interface ScanTopBarProps {
|
|
|
10
10
|
// 顶栏:仅居中标题。关闭键已移到底部工具栏,与手电筒并排(见 ScanToolbar)。
|
|
11
11
|
// 叠在深色相机预览之上,故文字恒为白(不随主题)。
|
|
12
12
|
export function ScanTopBar({ title, topInset }: ScanTopBarProps) {
|
|
13
|
+
const s = useThemedStyles(makeTextStyles);
|
|
13
14
|
return (
|
|
14
|
-
<View
|
|
15
|
-
|
|
15
|
+
<View
|
|
16
|
+
style={[styles.bar, { paddingTop: topInset }]}
|
|
17
|
+
pointerEvents="box-none"
|
|
18
|
+
>
|
|
19
|
+
<Text style={s.title}>{title}</Text>
|
|
16
20
|
</View>
|
|
17
21
|
);
|
|
18
22
|
}
|
|
@@ -30,13 +34,17 @@ const styles = StyleSheet.create({
|
|
|
30
34
|
alignItems: 'center',
|
|
31
35
|
justifyContent: 'center',
|
|
32
36
|
},
|
|
33
|
-
title: {
|
|
34
|
-
color: scanChrome.white,
|
|
35
|
-
fontSize: rf(16),
|
|
36
|
-
fontWeight: fw.semi,
|
|
37
|
-
letterSpacing: 0.2,
|
|
38
|
-
textShadowColor: scanChrome.textShadow,
|
|
39
|
-
textShadowOffset: { width: 0, height: 1 },
|
|
40
|
-
textShadowRadius: 6,
|
|
41
|
-
},
|
|
42
37
|
});
|
|
38
|
+
|
|
39
|
+
const makeTextStyles = () =>
|
|
40
|
+
StyleSheet.create({
|
|
41
|
+
title: {
|
|
42
|
+
color: scanChrome.white,
|
|
43
|
+
fontSize: rf(16),
|
|
44
|
+
fontWeight: fw.semi,
|
|
45
|
+
letterSpacing: 0.2,
|
|
46
|
+
textShadowColor: scanChrome.textShadow,
|
|
47
|
+
textShadowOffset: { width: 0, height: 1 },
|
|
48
|
+
textShadowRadius: 6,
|
|
49
|
+
},
|
|
50
|
+
});
|