NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.66k stars 4.8k forks source link

expo-barcode-scanner 在expo51中已经移除 #16484

Open ShaoGongBra opened 2 months ago

ShaoGongBra commented 2 months ago

相关平台

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

环境信息

Taro CLI 4.0.5 environment info:
    System:
      OS: macOS 14.5
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 18.20.3 - /var/folders/rf/gd60z12164z72bny7z_0d4f80000gn/T/yarn--1725710583904-0.7793732353786511/node
      Yarn: 1.22.22 - /var/folders/rf/gd60z12164z72bny7z_0d4f80000gn/T/yarn--1725710583904-0.7793732353786511/yarn
      npm: 10.7.0 - ~/.nvm/versions/node/v18.20.3/bin/npm
    npmPackages:
      @tarojs/cli: 4.0.5 => 4.0.5 
      @tarojs/components: 4.0.5 => 4.0.5 
      @tarojs/helper: 4.0.5 => 4.0.5 
      @tarojs/plugin-framework-react: 4.0.5 => 4.0.5 
      @tarojs/plugin-platform-alipay: 4.0.5 => 4.0.5 
      @tarojs/plugin-platform-h5: 4.0.5 => 4.0.5 
      @tarojs/plugin-platform-jd: 4.0.5 => 4.0.5 
      @tarojs/plugin-platform-qq: 4.0.5 => 4.0.5 
      @tarojs/plugin-platform-swan: 4.0.5 => 4.0.5 
      @tarojs/plugin-platform-tt: 4.0.5 => 4.0.5 
      @tarojs/plugin-platform-weapp: 4.0.5 => 4.0.5 
      @tarojs/react: 4.0.5 => 4.0.5 
      @tarojs/rn-runner: 4.0.5 => 4.0.5 
      @tarojs/rn-supporter: 4.0.5 => 4.0.5 
      @tarojs/runtime: 4.0.5 => 4.0.5 
      @tarojs/shared: 4.0.5 => 4.0.5 
      @tarojs/taro: 4.0.5 => 4.0.5 
      @tarojs/taro-loader: 4.0.5 => 4.0.5 
      @tarojs/taro-rn: 4.0.5 => 4.0.5 
      @tarojs/webpack5-runner: 4.0.5 => 4.0.5 
      babel-preset-taro: 4.0.5 => 4.0.5 
      eslint-config-taro: 4.0.5 => 4.0.5 
      expo: ~51.0.32 => 51.0.32 
      react: ^18.2.0 => 18.3.1 
      react-native: ~0.75.2 => 0.75.2
ShaoGongBra commented 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);