react-native-barcode-mask: useBarcodeRead hook is not working

Hi there,

I am trying to use the useBarcodeRead hook, but it is not triggering anything. I have created a pretty simple camera component.

import React from 'react';
import { StyleSheet, View } from 'react-native';
import { RNCamera } from 'react-native-camera';
import {
  BarcodeMaskWithOuterLayout,
  useBarcodeRead,
} from '@nartc/react-native-barcode-mask';

import { getColor } from '../assets/style/style.constants';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column',
  },
  preview: {
    flex: 1,
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
});
export const Camera = () => {
  const {
    barcodeRead,
    onBarcodeRead,
    onBarcodeFinderLayoutChange,
  } = useBarcodeRead(
    true,
    barcodeData => {
      console.log(barcodeData);
      return barcodeData;
    },
    processedBarcodeData => {
      console.log(processedBarcodeData);
      return processedBarcodeData;
    },
  );
  console.log(1, barcodeRead);
  console.log(2, onBarcodeRead);
  console.log(3, onBarcodeFinderLayoutChange);

  return (
    <View style={styles.container}>
      <RNCamera
        barCodeTypes={barcodeRead ? [] : [RNCamera.Constants.BarCodeType.qr]}
        onBarCodeRead={onBarcodeRead}
        captureAudio={false}
        style={styles.preview}
        type={RNCamera.Constants.Type.back}
      >
        <BarcodeMaskWithOuterLayout
          edgeColor={getColor().PRIMARY}
          animatedLineColor={getColor().PRIMARY}
          maskOpacity={0.7}
          height="80%"
          width="80%"
          showAnimatedLine
          onLayoutChange={onBarcodeFinderLayoutChange}
        />
      </RNCamera>
    </View>
  );
};

The console.log are not being triggered. Am I doing something wrong or is there something wrong with the lib?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 31 (16 by maintainers)

Most upvoted comments

Hi @nartc Sorry due sickness I wasn’t able to test it yet. I’m back at the office today, I’ll try to test it this week ASAP and will get back to you.

Thanks for the information