@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.
Files changed (168) hide show
  1. package/README.md +24 -72
  2. package/android/src/main/AndroidManifest.xml +0 -9
  3. package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanImage.kt +135 -0
  4. package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanModule.kt +163 -147
  5. package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanResultMapper.kt +17 -9
  6. package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanView.kt +57 -19
  7. package/android/src/main/java/com/unif/reactnativehmsscan/HmsScanViewManager.kt +1 -1
  8. package/ios/HmsScanModule.mm +13 -37
  9. package/ios/HmsScanResultMapper.h +4 -3
  10. package/ios/HmsScanResultMapper.mm +31 -19
  11. package/ios/HmsScanView.h +1 -1
  12. package/ios/HmsScanView.mm +140 -25
  13. package/lib/module/HmsScanView/HmsScanView.js +66 -0
  14. package/lib/module/HmsScanView/HmsScanView.js.map +1 -0
  15. package/lib/module/HmsScanView/HmsScanView.web.js +26 -0
  16. package/lib/module/HmsScanView/HmsScanView.web.js.map +1 -0
  17. package/lib/module/HmsScanView/types.js +4 -0
  18. package/lib/module/HmsScanView/types.js.map +1 -0
  19. package/lib/module/HmsScanViewNativeComponent.ts +7 -5
  20. package/lib/module/NativeHmsScan.js +1 -1
  21. package/lib/module/NativeHmsScan.js.map +1 -1
  22. package/lib/module/ScanError.js +12 -0
  23. package/lib/module/ScanError.js.map +1 -0
  24. package/lib/module/Scanner/DeniedOverlay.js +1 -1
  25. package/lib/module/Scanner/DeniedOverlay.js.map +1 -1
  26. package/lib/module/Scanner/ResultFail.js +3 -2
  27. package/lib/module/Scanner/ResultFail.js.map +1 -1
  28. package/lib/module/Scanner/ResultFocus/ResultFocus.js +56 -0
  29. package/lib/module/Scanner/ResultFocus/ResultFocus.js.map +1 -0
  30. package/lib/module/Scanner/ResultFocus/styles.js +39 -0
  31. package/lib/module/Scanner/ResultFocus/styles.js.map +1 -0
  32. package/lib/module/Scanner/ResultFocus/types.js +4 -0
  33. package/lib/module/Scanner/ResultFocus/types.js.map +1 -0
  34. package/lib/module/Scanner/ScanHint.js +6 -3
  35. package/lib/module/Scanner/ScanHint.js.map +1 -1
  36. package/lib/module/Scanner/ScanToolbar.js +6 -3
  37. package/lib/module/Scanner/ScanToolbar.js.map +1 -1
  38. package/lib/module/Scanner/ScanTopBar.js +6 -3
  39. package/lib/module/Scanner/ScanTopBar.js.map +1 -1
  40. package/lib/module/Scanner/Scanner.js +9 -311
  41. package/lib/module/Scanner/Scanner.js.map +1 -1
  42. package/lib/module/Scanner/Scanner.web.js +29 -0
  43. package/lib/module/Scanner/Scanner.web.js.map +1 -0
  44. package/lib/module/Scanner/ScannerInner.js +310 -0
  45. package/lib/module/Scanner/ScannerInner.js.map +1 -0
  46. package/lib/module/Scanner/styles.js +11 -0
  47. package/lib/module/Scanner/styles.js.map +1 -0
  48. package/lib/module/Scanner/types.js +4 -0
  49. package/lib/module/Scanner/types.js.map +1 -0
  50. package/lib/module/constants.js +20 -0
  51. package/lib/module/constants.js.map +1 -0
  52. package/lib/module/decodeImage.js +29 -24
  53. package/lib/module/decodeImage.js.map +1 -1
  54. package/lib/module/decodeImage.web.js +7 -0
  55. package/lib/module/decodeImage.web.js.map +1 -0
  56. package/lib/module/errors.js +24 -0
  57. package/lib/module/errors.js.map +1 -0
  58. package/lib/module/format.js +53 -47
  59. package/lib/module/format.js.map +1 -1
  60. package/lib/module/index.js +5 -19
  61. package/lib/module/index.js.map +1 -1
  62. package/lib/module/index.web.js +8 -0
  63. package/lib/module/index.web.js.map +1 -0
  64. package/lib/module/mock.js +2 -23
  65. package/lib/module/mock.js.map +1 -1
  66. package/lib/module/permissions.js +24 -20
  67. package/lib/module/permissions.js.map +1 -1
  68. package/lib/module/permissions.web.js +10 -0
  69. package/lib/module/permissions.web.js.map +1 -0
  70. package/lib/module/types.js +1 -45
  71. package/lib/module/types.js.map +1 -1
  72. package/lib/typescript/src/HmsScanView/HmsScanView.d.ts +3 -0
  73. package/lib/typescript/src/HmsScanView/HmsScanView.d.ts.map +1 -0
  74. package/lib/typescript/src/HmsScanView/HmsScanView.web.d.ts +3 -0
  75. package/lib/typescript/src/HmsScanView/HmsScanView.web.d.ts.map +1 -0
  76. package/lib/typescript/src/HmsScanView/types.d.ts +12 -0
  77. package/lib/typescript/src/HmsScanView/types.d.ts.map +1 -0
  78. package/lib/typescript/src/HmsScanViewNativeComponent.d.ts +6 -4
  79. package/lib/typescript/src/HmsScanViewNativeComponent.d.ts.map +1 -1
  80. package/lib/typescript/src/NativeHmsScan.d.ts +3 -5
  81. package/lib/typescript/src/NativeHmsScan.d.ts.map +1 -1
  82. package/lib/typescript/src/ScanError.d.ts +7 -0
  83. package/lib/typescript/src/ScanError.d.ts.map +1 -0
  84. package/lib/typescript/src/Scanner/DeniedOverlay.d.ts.map +1 -1
  85. package/lib/typescript/src/Scanner/ResultFail.d.ts +2 -1
  86. package/lib/typescript/src/Scanner/ResultFail.d.ts.map +1 -1
  87. package/lib/typescript/src/Scanner/ResultFocus/ResultFocus.d.ts +4 -0
  88. package/lib/typescript/src/Scanner/ResultFocus/ResultFocus.d.ts.map +1 -0
  89. package/lib/typescript/src/Scanner/ResultFocus/styles.d.ts +36 -0
  90. package/lib/typescript/src/Scanner/ResultFocus/styles.d.ts.map +1 -0
  91. package/lib/typescript/src/Scanner/ResultFocus/types.d.ts +8 -0
  92. package/lib/typescript/src/Scanner/ResultFocus/types.d.ts.map +1 -0
  93. package/lib/typescript/src/Scanner/ScanHint.d.ts.map +1 -1
  94. package/lib/typescript/src/Scanner/ScanToolbar.d.ts.map +1 -1
  95. package/lib/typescript/src/Scanner/ScanTopBar.d.ts.map +1 -1
  96. package/lib/typescript/src/Scanner/Scanner.d.ts +2 -45
  97. package/lib/typescript/src/Scanner/Scanner.d.ts.map +1 -1
  98. package/lib/typescript/src/Scanner/Scanner.web.d.ts +3 -0
  99. package/lib/typescript/src/Scanner/Scanner.web.d.ts.map +1 -0
  100. package/lib/typescript/src/Scanner/ScannerInner.d.ts +3 -0
  101. package/lib/typescript/src/Scanner/ScannerInner.d.ts.map +1 -0
  102. package/lib/typescript/src/Scanner/styles.d.ts +7 -0
  103. package/lib/typescript/src/Scanner/styles.d.ts.map +1 -0
  104. package/lib/typescript/src/Scanner/types.d.ts +20 -0
  105. package/lib/typescript/src/Scanner/types.d.ts.map +1 -0
  106. package/lib/typescript/src/constants.d.ts +8 -0
  107. package/lib/typescript/src/constants.d.ts.map +1 -0
  108. package/lib/typescript/src/decodeImage.d.ts +2 -12
  109. package/lib/typescript/src/decodeImage.d.ts.map +1 -1
  110. package/lib/typescript/src/decodeImage.web.d.ts +3 -0
  111. package/lib/typescript/src/decodeImage.web.d.ts.map +1 -0
  112. package/lib/typescript/src/errors.d.ts +6 -0
  113. package/lib/typescript/src/errors.d.ts.map +1 -0
  114. package/lib/typescript/src/format.d.ts +15 -12
  115. package/lib/typescript/src/format.d.ts.map +1 -1
  116. package/lib/typescript/src/index.d.ts +6 -7
  117. package/lib/typescript/src/index.d.ts.map +1 -1
  118. package/lib/typescript/src/index.web.d.ts +9 -0
  119. package/lib/typescript/src/index.web.d.ts.map +1 -0
  120. package/lib/typescript/src/mock.d.ts +9 -8
  121. package/lib/typescript/src/mock.d.ts.map +1 -1
  122. package/lib/typescript/src/permissions.d.ts +4 -8
  123. package/lib/typescript/src/permissions.d.ts.map +1 -1
  124. package/lib/typescript/src/permissions.web.d.ts +4 -0
  125. package/lib/typescript/src/permissions.web.d.ts.map +1 -0
  126. package/lib/typescript/src/types.d.ts +31 -56
  127. package/lib/typescript/src/types.d.ts.map +1 -1
  128. package/package.json +9 -2
  129. package/src/HmsScanView/HmsScanView.tsx +67 -0
  130. package/src/HmsScanView/HmsScanView.web.tsx +22 -0
  131. package/src/HmsScanView/types.ts +17 -0
  132. package/src/HmsScanViewNativeComponent.ts +7 -5
  133. package/src/NativeHmsScan.ts +3 -5
  134. package/src/ScanError.ts +13 -0
  135. package/src/Scanner/DeniedOverlay.tsx +4 -2
  136. package/src/Scanner/ResultFail.tsx +23 -5
  137. package/src/Scanner/ResultFocus/ResultFocus.tsx +43 -0
  138. package/src/Scanner/ResultFocus/styles.ts +25 -0
  139. package/src/Scanner/ResultFocus/types.ts +8 -0
  140. package/src/Scanner/ScanHint.tsx +16 -11
  141. package/src/Scanner/ScanToolbar.tsx +35 -13
  142. package/src/Scanner/ScanTopBar.tsx +20 -12
  143. package/src/Scanner/Scanner.tsx +13 -436
  144. package/src/Scanner/Scanner.web.tsx +26 -0
  145. package/src/Scanner/ScannerInner.tsx +391 -0
  146. package/src/Scanner/styles.ts +6 -0
  147. package/src/Scanner/types.ts +36 -0
  148. package/src/constants.ts +55 -0
  149. package/src/decodeImage.ts +35 -29
  150. package/src/decodeImage.web.ts +8 -0
  151. package/src/errors.ts +26 -0
  152. package/src/format.ts +77 -76
  153. package/src/index.tsx +17 -32
  154. package/src/index.web.tsx +22 -0
  155. package/src/mock.ts +21 -29
  156. package/src/permissions.ts +33 -20
  157. package/src/permissions.web.ts +9 -0
  158. package/src/types.ts +38 -126
  159. package/lib/module/HmsScanView.js +0 -43
  160. package/lib/module/HmsScanView.js.map +0 -1
  161. package/lib/module/Scanner/ResultFocus.js +0 -171
  162. package/lib/module/Scanner/ResultFocus.js.map +0 -1
  163. package/lib/typescript/src/HmsScanView.d.ts +0 -33
  164. package/lib/typescript/src/HmsScanView.d.ts.map +0 -1
  165. package/lib/typescript/src/Scanner/ResultFocus.d.ts +0 -14
  166. package/lib/typescript/src/Scanner/ResultFocus.d.ts.map +0 -1
  167. package/src/HmsScanView.tsx +0 -87
  168. 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
+ });
@@ -0,0 +1,8 @@
1
+ import type { ScanResult } from '../../types';
2
+
3
+ export interface ResultFocusProps {
4
+ result: Readonly<ScanResult>;
5
+ bottomInset: number;
6
+ onRescan(): void;
7
+ onConfirm(): void;
8
+ }
@@ -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={styles.text}>{detecting ? '识别中…' : text}</Text>
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 { Icon, useColors, r, rf, fw, type IconName } from '@unif/react-native-design';
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 style={[styles.bar, { bottom: bottomInset + r(50) }]} pointerEvents="box-none">
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
- ? { backgroundColor: activeColor, borderColor: scanChrome.glassBorderActive }
66
- : { backgroundColor: scanChrome.glassDisc2, borderColor: scanChrome.glassBorder },
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={styles.label}>{label}</Text>
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 style={[styles.bar, { paddingTop: topInset }]} pointerEvents="box-none">
15
- <Text style={styles.title}>{title}</Text>
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
+ });