@unif/react-native-hms-scan 0.2.2 → 0.3.1
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 +29 -12
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +11 -1
- package/src/index.tsx +1 -0
package/README.md
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@unif/react-native-hms-scan)
|
|
4
4
|
[](https://github.com/unif-design/react-native-hms-scan/actions/workflows/ci.yml)
|
|
5
|
-
[](
|
|
5
|
+
[](LICENSE)
|
|
6
6
|
[](https://unif-design.github.io/react-native-hms-scan/)
|
|
7
7
|
|
|
8
|
-
华为 **HMS
|
|
8
|
+
华为 **HMS 统一扫码(HUAWEI Scan Kit)** 的 React Native 封装,面向 RN 0.85 新架构(Fabric + TurboModule):成品扫一扫页、headless 自定义扫码 UI、从图片识别条码 / 二维码。
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
## 特性
|
|
11
|
+
|
|
12
|
+
- **三种用法** — 成品 `<Scanner>` 扫一扫页(自带权限流 / 状态机 / 主题)、headless `<HmsScanView>` 相机组件(自定义 UI)、`decodeImage(uri)` 从本地图片识别。
|
|
13
|
+
- **Android 内置引擎** — 用 Scan SDK-Plus,**非华为机型可用**,不依赖设备装 HMS Core APK;华为 maven 与依赖已内置在库里,宿主无需改 gradle。
|
|
14
|
+
- **零云端配置** — 两端**都不需要 AppGallery Connect / agconnect / API Key**。
|
|
15
|
+
- **14 种码制** — `QR_CODE` / `EAN_13` / `CODE_128` / `PDF417` / `DATA_MATRIX` 等,默认识别全部。
|
|
16
|
+
- 仅支持 **RN 新架构**;`@unif/react-native-design` 风格统一。
|
|
12
17
|
|
|
13
18
|
## 安装
|
|
14
19
|
|
|
@@ -17,9 +22,11 @@ yarn add @unif/react-native-hms-scan react-native-svg
|
|
|
17
22
|
cd ios && pod install
|
|
18
23
|
```
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
`react-native-svg` 是 peer 依赖(`<Scanner>` 图标用它绘制);`<Scanner>` 还依赖 peer `@unif/react-native-design`。宿主需开启新架构。Android 权限、iOS `NSCameraUsageDescription` 等见[文档站 · 安装](https://unif-design.github.io/react-native-hms-scan/docs/getting-started/installation)。
|
|
26
|
+
|
|
27
|
+
## 快速开始
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
成品「扫一扫」页 —— 扫到条码后由宿主解析商品、确认带回:
|
|
23
30
|
|
|
24
31
|
```tsx
|
|
25
32
|
import { Scanner, type ScanResult, type ScanProduct } from '@unif/react-native-hms-scan';
|
|
@@ -30,18 +37,28 @@ function ScanScreen({ navigation }) {
|
|
|
30
37
|
title="扫一扫"
|
|
31
38
|
onClose={() => navigation.goBack()}
|
|
32
39
|
resolveProduct={async (r: ScanResult): Promise<ScanProduct | null> => {
|
|
33
|
-
const p = await api.lookupByBarcode(r.value);
|
|
34
|
-
return p
|
|
35
|
-
? { name: p.name, brand: p.brand, price: `¥${p.price}`, barcode: r.value }
|
|
36
|
-
: null;
|
|
40
|
+
const p = await api.lookupByBarcode(r.value); // 你来解析;返回 null = 未识别
|
|
41
|
+
return p ? { name: p.name, brand: p.brand, price: `¥${p.price}`, barcode: r.value } : null;
|
|
37
42
|
}}
|
|
38
|
-
onConfirm={(product, result) => navigation.navigate('Order', { product })}
|
|
43
|
+
onConfirm={(product, result) => navigation.navigate('Order', { product, barcode: result.value })}
|
|
39
44
|
/>
|
|
40
45
|
);
|
|
41
46
|
}
|
|
42
47
|
```
|
|
43
48
|
|
|
44
|
-
headless `<HmsScanView
|
|
49
|
+
headless `<HmsScanView>`(完全自定义 UI)、图片识别 `decodeImage`、权限、平台差异 —— 见[文档站](https://unif-design.github.io/react-native-hms-scan/)。
|
|
50
|
+
|
|
51
|
+
## 文档
|
|
52
|
+
|
|
53
|
+
- **完整文档**(安装 · 平台配置 · API · 平台差异 · 故障排查):https://unif-design.github.io/react-native-hms-scan/
|
|
54
|
+
- **AI / Agent**(按需 fetch,别凭记忆猜 API):[llms.txt](https://unif-design.github.io/react-native-hms-scan/llms.txt) · [llms-full.txt](https://unif-design.github.io/react-native-hms-scan/llms-full.txt)
|
|
55
|
+
- **Agent Skill** `using-unif-hms-scan`(`unif-react-native` plugin):`/plugin marketplace add unif-design/react-native-skills` → `/plugin install unif-react-native@unif-react-native-skills`
|
|
56
|
+
|
|
57
|
+
## 兼容性
|
|
58
|
+
|
|
59
|
+
- **React Native** 新架构(Fabric + TurboModule)**必须开启**;在 RN 0.85 上开发与验证。
|
|
60
|
+
- **Android** minSdkVersion ≥ 24(Android 7.0)。
|
|
61
|
+
- **iOS** `ScanKitFrameWork` 扫码功能**仅真机**(模拟器可编译,相机要真机)。
|
|
45
62
|
|
|
46
63
|
## 许可
|
|
47
64
|
|
package/lib/module/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// @unif/react-native-hms-scan —— 华为 HMS 统一扫码服务 RN bridge(Fabric 新架构)
|
|
4
4
|
// 能力:定制视图扫码(底层 <HmsScanView> + 成品 <Scanner> 扫一扫页)+ 图片识别(decodeImage)+ 相机权限。
|
|
5
5
|
// 0.2.1:package.json#files 补 scripts/,修 pod install 缺 prepare-scankit-xcframework.sh(podspec prepare_command 调用)。
|
|
6
|
+
// 文档站:https://unif-design.github.io/react-native-hms-scan/(版本随发版自动部署)。
|
|
6
7
|
|
|
7
8
|
// ── 类型与常量 ──
|
|
8
9
|
export { ALL_BARCODE_FORMATS, HmsScanError } from "./types.js";
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ALL_BARCODE_FORMATS","HmsScanError","coerceFormat","coerceContentType","formatsToCsv","HmsScanView","decodeImage","getCameraPermissionStatus","requestCameraPermission","Scanner"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA;AACA;AACA;;AAEA;AACA,SACEA,mBAAmB,EACnBC,YAAY,QACP,YAAS;AAYhB;AACA,SAASC,YAAY,EAAEC,iBAAiB,EAAEC,YAAY,QAAQ,aAAU;;AAExE;AACA,SAASC,WAAW,QAAQ,kBAAe;AAG3C;AACA,SAASC,WAAW,QAAQ,kBAAe;;AAE3C;AACA,SAASC,yBAAyB,EAAEC,uBAAuB,QAAQ,kBAAe;;AAElF;AACA,SAASC,OAAO,QAAQ,sBAAmB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["ALL_BARCODE_FORMATS","HmsScanError","coerceFormat","coerceContentType","formatsToCsv","HmsScanView","decodeImage","getCameraPermissionStatus","requestCameraPermission","Scanner"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA;AACA,SACEA,mBAAmB,EACnBC,YAAY,QACP,YAAS;AAYhB;AACA,SAASC,YAAY,EAAEC,iBAAiB,EAAEC,YAAY,QAAQ,aAAU;;AAExE;AACA,SAASC,WAAW,QAAQ,kBAAe;AAG3C;AACA,SAASC,WAAW,QAAQ,kBAAe;;AAE3C;AACA,SAASC,yBAAyB,EAAEC,uBAAuB,QAAQ,kBAAe;;AAElF;AACA,SAASC,OAAO,QAAQ,sBAAmB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAMA,OAAO,EACL,mBAAmB,EACnB,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,WAAW,GACZ,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGzE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAGnF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unif/react-native-hms-scan",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "华为 HMS 统一扫码服务 React Native bridge:定制视图扫码 + 图片识别 (Scan SDK-Plus / ScanKitFrameWork,@unif 私有)",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -127,6 +127,11 @@
|
|
|
127
127
|
"name": "ReactNativeHmsScanSpec",
|
|
128
128
|
"type": "all",
|
|
129
129
|
"jsSrcsDir": "src",
|
|
130
|
+
"ios": {
|
|
131
|
+
"componentProvider": {
|
|
132
|
+
"HmsScanView": "HmsScanView"
|
|
133
|
+
}
|
|
134
|
+
},
|
|
130
135
|
"android": {
|
|
131
136
|
"javaPackageName": "com.unif.reactnativehmsscan"
|
|
132
137
|
}
|
|
@@ -184,6 +189,11 @@
|
|
|
184
189
|
],
|
|
185
190
|
"setupFiles": [
|
|
186
191
|
"./jest.setup.ts"
|
|
192
|
+
],
|
|
193
|
+
"testPathIgnorePatterns": [
|
|
194
|
+
"<rootDir>/node_modules/",
|
|
195
|
+
"<rootDir>/website/",
|
|
196
|
+
"<rootDir>/lib/"
|
|
187
197
|
]
|
|
188
198
|
},
|
|
189
199
|
"prettier": {
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @unif/react-native-hms-scan —— 华为 HMS 统一扫码服务 RN bridge(Fabric 新架构)
|
|
2
2
|
// 能力:定制视图扫码(底层 <HmsScanView> + 成品 <Scanner> 扫一扫页)+ 图片识别(decodeImage)+ 相机权限。
|
|
3
3
|
// 0.2.1:package.json#files 补 scripts/,修 pod install 缺 prepare-scankit-xcframework.sh(podspec prepare_command 调用)。
|
|
4
|
+
// 文档站:https://unif-design.github.io/react-native-hms-scan/(版本随发版自动部署)。
|
|
4
5
|
|
|
5
6
|
// ── 类型与常量 ──
|
|
6
7
|
export {
|