Expo BarCodeScanner - datamatrix issues on android OS

Please provide the following:

  1. SDK Version: 48
  2. Platforms(Android/iOS/web/all): Android
  3. Add the appropriate “Tag” based on what Expo library you have a question on. #expo-barcodescanner

Hi, I’m new to this forum.
I have issue regarding expo barcodescanner package. More precisely, it’s datamatrix scanning abilities. Since, on your documentation is says it scans datamatrix code on both Android and iOS, but in my case it works only on iOS.
I’ve tested it on Android 11, and iOS 16.2. Expo BarCodeScanner version is 12.3.2
Expected behaviour from code below is to show alert message after successfully scanning code.
Best regards

My code:

import React, { useState, useEffect } from "react";
import { Text, View, StyleSheet, Button } from "react-native";
import { BarCodeScanner } from "expo-barcode-scanner";

export default function App() {
  const [hasPermission, setHasPermission] = useState(null);
  const [scanned, setScanned] = useState(false);

  useEffect(() => {
    const getBarCodeScannerPermissions = async () => {
      const { status } = await BarCodeScanner.requestPermissionsAsync();
      setHasPermission(status === "granted");
    };

    getBarCodeScannerPermissions();
  }, []);

  const handleBarCodeScanned = ({ type, data }) => {
    setScanned(true);
    alert(`Bar code with type ${type} and data ${data} has been scanned!`);
  };

  if (hasPermission === null) {
    return <Text>Requesting for camera permission</Text>;
  }
  if (hasPermission === false) {
    return <Text>No access to camera</Text>;
  }

  return (
    <View style={styles.container}>
      <BarCodeScanner
        barCodeTypes={[BarCodeScanner.Constants.BarCodeType.datamatrix]}
        onBarCodeScanned={scanned ? undefined : handleBarCodeScanned}
        style={StyleSheet.absoluteFillObject}
      />
      {scanned && (
        <Button title={"Tap to Scan Again"} onPress={() => setScanned(false)} />
      )}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});

Hi @ivan1996

I have just copied your code to a Snack: forums-72193 - Snack

It works for me on my Android phone.

I have found that it doesn’t scan datamatrix codes as reliably as QR codes. I think this might be because datamatrix codes are not as easy to identify as QR codes. QR codes have the three large squares that are easier to detect.

I forgot to mention in my initial post that I need to scan 6x6 datamatrix barcodes. Smaller ones are working fine

OK, I see what you mean.

I think Expo’s BarCodeScanner is built on ZXing. ZXing seems to be able to scan 6x6 datamatrix codes (it worked for me with https://play.google.com/store/apps/details?id=com.google.zxing.client.android) So I’m not sure why Expo’s BarCodeScanner doesn’t seem to support 6x6 datamatrix barcodes.

ML Kit supposedly supports datamatrix barcodes although I don’t know if it supports 6x6 ones. There is @react-native-firebase/ml, which gives access to some ML Kit functionality. Unfortunately it doesn’t look like it currently supports barcode scanning.

Another option would be to write an Expo Module that calls into ML Kit. This is a lot easier than it used to be. See: Expo Modules API: Overview - Expo Documentation

There’s also a channel on Expo’s Discord to get help if you are writing an Expo module.

Here are some other libraries that could also be wrapped in an Expo Module: Android Barcode Scanner Library | Top 11 Curated List - Android Dvlpr

If none of the above work for you, there are also commercial options. I am not aware of any with React Native support, but again you could wrap them in an Expo Module:

Good luck

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.