Open ShaoGongBra opened 2 months ago
这是一个patch其中对BarCodeType的定义,我也不确定对不对,我是复制了types的定义
diff --git a/node_modules/@tarojs/taro-rn/dist/lib/scanCode/index.js b/node_modules/@tarojs/taro-rn/dist/lib/scanCode/index.js
index 715d9a9..5a947f9 100644
--- a/node_modules/@tarojs/taro-rn/dist/lib/scanCode/index.js
+++ b/node_modules/@tarojs/taro-rn/dist/lib/scanCode/index.js
@@ -7,8 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
-import { BarCodeScanner, requestPermissionsAsync } from 'expo-barcode-scanner';
-import { CameraView } from 'expo-camera';
+import { CameraView, Camera } from 'expo-camera';
import React from 'react';
import { BackHandler, Dimensions, Image, Platform, StatusBar, StyleSheet, TouchableOpacity, View } from 'react-native';
import RootSiblings from 'react-native-root-siblings';
@@ -44,7 +43,23 @@ const typeMap = {
datamatrix: ['datamatrix'],
pdf417: ['pdf417']
};
-const BarCodeType = BarCodeScanner.Constants.BarCodeType;
+
+const BarCodeType = {
+ aztec: 'aztec' ,
+ ean13: 'ean13',
+ ean8: 'ean8',
+ qr: 'qr',
+ pdf417: 'pdf417' ,
+ upc_e: 'upc_e',
+ datamatrix: 'datamatrix',
+ code39: 'code39',
+ code93: 'code93',
+ itf14: 'itf14',
+ codabar: 'codabar',
+ code128: 'code128',
+ upc_a: 'upc_a'
+};
+
function findKey(value, data, compare = (a, b) => a === b) {
return Object.keys(data).find(k => compare(data[k], value)) || '';
}
@@ -133,7 +148,7 @@ function scanFromPhoto(callback, errorCallBack) {
success: function (res) {
const imageUrl = res.tempFilePaths[0];
if (imageUrl) {
- BarCodeScanner.scanFromURLAsync(imageUrl).then(res => {
+ Camera.scanFromURLAsync(imageUrl).then(res => {
res && res.length > 0 && callback(res[0].data, res[0].type);
});
}
@@ -143,7 +158,7 @@ function scanFromPhoto(callback, errorCallBack) {
export function scanCode() {
return __awaiter(this, arguments, void 0, function* (option = {}) {
const { success, fail, complete, onlyFromCamera, scanType = ['barCode', 'qrCode'] } = option;
- const { granted } = yield requestPermissionsAsync();
+ const { granted } = yield Camera.requestCameraPermissionsAsync();
if (!granted) {
const res = { errMsg: 'Permissions denied!' };
fail === null || fail === void 0 ? void 0 : fail(res);
相关平台
React Native
使用框架: React
复现步骤
Deprecated: This library will no longer be available from SDK 51. We recommend using expo-camera which has barcode scanning built-in instead.
扫码的方法在 expo-camera 中提供了 scanFromURLAsync
期望结果
修改api
实际结果
api
环境信息