expo: [expo-camera] [iOS] onBarcodeScanned is never called on iOS with Expo Go

Minimal reproducible example

https://github.com/jcxldn/expo-sdk50-cam-qr-repro

Summary

When using Expo Go (client version 1017593) on my iOS 17.2.1 device with this minimal reproduction project, the camera loads up and appears to work as normal but onBarcodeScanned is never called even if a valid QR code is in focus and in frame. I have not been able to test this on a production build.

Environment

  expo-env-info 1.2.0 environment info:
    System:
      OS: Linux 6.6 Manjaro Linux
      Shell: 5.2.21 - /bin/bash
    Binaries:
      Node: 21.5.0 - /usr/bin/node
      Yarn: 1.22.21 - /usr/bin/yarn
      npm: 10.3.0 - /usr/bin/npm
    npmPackages:
      expo: ~50.0.3 => 50.0.3 
      react: 18.2.0 => 18.2.0 
      react-native: 0.73.2 => 0.73.2 
    npmGlobalPackages:
      eas-cli: 7.0.0
    Expo Workflow: managed

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 2
  • Comments: 17 (1 by maintainers)

Most upvoted comments

I think they changed the prop name It’s now onBarcodeScanned instead of onBarCodeScanned (no uppercase ‘C’ on ‘code’)

Also, barCodeScannerSettings becomes barcodeScannerSettings

But barCodeTypes remains the same

Has anyone solved this issue? Same with me for

import { CameraView, useCameraPermissions } from 'expo-camera/next';

<CameraView
    style={styles.camera}
    type="back"
    barcodeScannerSettings={{
      barCodeTypes: ["qr"],
    }}
    onBarcodeScanned={handleBarcodeScanned}
  >

onBarcodeScanned doesn’t fire anything…

This solution worked for me! 😃

import { CameraView, BarcodeScanningResult, useCameraPermissions } from "expo-camera/next";

const handleQrcodeScanner = (scanningResult: BarcodeScanningResult) => {
    console.log("Qrcode:", scanningResult.data);
};

<CameraView
    style={StyleSheet.absoluteFillObject}
    facing="back"
    onBarcodeScanned={handleQrcodeScanner}
    barcodeScannerSettings={{
      barcodeTypes: ["qr"],
    }}
/>

I think they changed the prop name It’s now onBarcodeScanned instead of onBarCodeScanned (no uppercase ‘C’ on ‘code’)

According to the doc, the prop remains as onBarCodeScanned

@obviouswhy Thanks! Indeed it was due to that barCodeTypes enum not working properly.

FYI to anyone with the same issue, since I’m using typescript I had to handle the type within the callback function:

  const handleBarcodeScanned = (result: BarcodeScanningResult) => {
    if (result) {
      const { type, data } = result;
      if (type === "org.iso.QRCode") {
        console.log(data);
      }
    }
  };

  <CameraView
    style={styles.camera}
    type="back"
    onBarcodeScanned={handleBarcodeScanned}
  >

Seems like for iOS the barCodeTypes: ["qr"] part is not recognizing the enum of the type for iOS correctly. I was able to trigger onBarcodeScanned by setting barCodeTypes to BarCodeScanner.Constants.BarCodeType.qr or "org.iso.QRCode" (which is the value of BarCodeScanner.Constants.BarCodeType.qr).

It would look something like:

<CameraView
    style={styles.camera}
    barcodeScannerSettings={{
      barCodeTypes: [BarCodeScanner.Constants.BarCodeType.qr],
      // barCodeTypes: ["org.iso.QRCode"], <--- this also works
    }}
    onBarcodeScanned={handleBarcodeScanned}
  >

Has anyone solved this issue? Same with me for

import { CameraView, useCameraPermissions } from 'expo-camera/next';

<CameraView
    style={styles.camera}
    type="back"
    barcodeScannerSettings={{
      barCodeTypes: ["qr"],
    }}
    onBarcodeScanned={handleBarcodeScanned}
  >

onBarcodeScanned doesn’t fire anything…

It’s especially confusing as TS insists it’s onBarcodeScanned while the docs say onBarCodeScanned. As I recall I tried both on my project but neither worked. I will try it with this reproduction later today and report back for you all. I will also try barCodeScannerSettings/barcodeScannerSettings.

Thanks,

James

My apologies, I got a little mixed up here. It seems to be onBarcodeScanned for expo-camera/next and onBarCodeScanned for expo-camera. I tried both expo-camera and expo-camera/next on my own and had the same issue, but this minimal repro is for expo-camera.