vision-camera-code-scanner icon indicating copy to clipboard operation
vision-camera-code-scanner copied to clipboard

Latest RN 0.69 on iOS: (0,_.scanBarcodes) is not a function

Open netzwerg opened this issue 2 years ago • 13 comments

Using the latest RN 0.69, I get the following error on iOS:

Frame Processor threw an error: (0,_.scanBarcodes) is not a function. (In '(0,_.scanBarcodes)(frame,types,options)', '(0,_.scanBarcodes)' is undefined)
In: _f@/Users/xxx/node_modules/vision-camera-code-scanner/lib/commonjs/hook.js (18:73):1:137
    @[native code]
    _f@/Users/xxx/node_modules/react-native-vision-camera/lib/commonjs/hooks/useFrameProcessor.js (31:33):1:425
    @[native code]

package.json

"react-native-reanimated": "^2.8.0",
"react-native-vision-camera": "^2.13.5",
"vision-camera-code-scanner": "^0.2.0"

I get the same error if I don't use the useScanBarcodes hook, but invoke useFrameProcessor myself:

const frameProcessor = useFrameProcessor((frame) => {
    'worklet';
    const detectedBarcodes = scanBarcodes(frame, types, options);
    runOnJS(setBarcodes)(detectedBarcodes);
  }, []);

netzwerg avatar Jun 29 '22 06:06 netzwerg

I'm also have the same issue, I have created a private package so it can be used across the companies multiple projects.

From my example build it works fine, but when I try to integrate it with the company's project it gives me this error.

rajjsajnani avatar Jul 01 '22 11:07 rajjsajnani

Any solution regarding this issue so far guys.

saidybarry avatar Jul 02 '22 18:07 saidybarry

I'm also experiencing this issue

kierancrown avatar Jul 06 '22 15:07 kierancrown

Same problem on Android, haven't tested iOS.

vidkreca-inova avatar Jul 07 '22 12:07 vidkreca-inova

Same on react-native 0.69.1, this is the last library I can't update 😿

whalemare avatar Jul 12 '22 08:07 whalemare

Hello, have you found any solution for the problem?

thelastwizardOC avatar Aug 11 '22 09:08 thelastwizardOC

Hello, have you found any solution for the problem?

Unfortunately not. I don’t see much if any progress being made in this matter either. I think I’m going to have to use the deprecated rn-camera package instead :(

kierancrown avatar Aug 11 '22 09:08 kierancrown

the same issue, any update?

taduyde avatar Aug 26 '22 02:08 taduyde

I use this way, it's worked // Alternatively you can use the underlying function: // const frameProcessor = useFrameProcessor((frame) => { 'worklet'; const detectedBarcodes = scanBarcodes(frame, [BarcodeFormat.QR_CODE], { checkInverted: true }); runOnJS(setBarcodes)(detectedBarcodes); }, []);

taduyde avatar Aug 26 '22 03:08 taduyde

I use this way, it's worked // Alternatively you can use the underlying function: // const frameProcessor = useFrameProcessor((frame) => { 'worklet'; const detectedBarcodes = scanBarcodes(frame, [BarcodeFormat.QR_CODE], { checkInverted: true }); runOnJS(setBarcodes)(detectedBarcodes); }, []);

RN Version?

kierancrown avatar Aug 26 '22 08:08 kierancrown

Aynı sorun, herhangi bir güncelleme var mı?

cemocanon avatar Sep 29 '22 14:09 cemocanon

Getting the same issue. Any update?

waweru-kamau avatar Oct 13 '22 05:10 waweru-kamau

I was able to get around this issue by recreating scanBarcodes in my component. The whole thing looks something like this:

import 'react-native-reanimated';
import React, { FunctionComponent, useEffect, useCallback, useRef, useState } from 'react';
import { StyleSheet, Text } from 'react-native';
import { Camera, useCameraDevices, useFrameProcessor } from 'react-native-vision-camera';
import type { Frame } from 'react-native-vision-camera';
import { BarcodeFormat } from 'vision-camera-code-scanner';
import type { CodeScannerOptions, Barcode } from 'vision-camera-code-scanner';
import { runOnJS } from 'react-native-reanimated';

interface Props {
  children: React.ReactNode;
  torch: boolean;
}

export const ScannerCamera: FunctionComponent<Props> = ({ children, torch }) => {
  const devices = useCameraDevices();
  const device = devices.back;
  const camera = useRef<Camera>(null);
  const [barcodes, setBc] = useState<Barcode[]>([]);

  function scanBarcodes(frame: Frame, types: BarcodeFormat[], options?: CodeScannerOptions): Barcode[] {
    'worklet';
    // @ts-ignore
    // eslint-disable-next-line no-undef
    return __scanCodes(frame, types, options);
  }

  const frameProcessor = useFrameProcessor((frame) => {
    'worklet';
    const detectedBarcodes = scanBarcodes(frame, [BarcodeFormat.QR_CODE], { checkInverted: true });
    runOnJS(setBc)(detectedBarcodes);
  }, []);

  const [hasPerms, setPerms] = React.useState(false);
  const [permsGotten, setPermsGotten] = React.useState(false);

  const requestPermissions = useCallback(async () => {
    const permission = await Camera.requestCameraPermission();
    setPerms(permission === 'authorized');
    setPermsGotten(true);
  }, []);

  useEffect(() => {
    void requestPermissions();
  }, [requestPermissions]);

  if (!permsGotten) return <Text>loading</Text>;
  if (device === undefined || !hasPerms) return <Text>no perms</Text>;
  return (
    <>
      <Camera
        ref={camera}
        style={StyleSheet.absoluteFill}
        device={device}
        isActive={true}
        torch={torch ? 'on' : 'off'}
        frameProcessor={frameProcessor}
        frameProcessorFps={5}
      >
        {children}
      </Camera>
      {barcodes.map((barcode, idx) => (
        <Text key={idx} style={styles.barcodeTextURL}>
          {barcode.displayValue}
        </Text>
      ))}
    </>
  );
};

const styles = StyleSheet.create({
  barcodeTextURL: {
    fontSize: 20,
    color: 'white',
    fontWeight: 'bold',
  },
});

sepeterson avatar Dec 28 '22 17:12 sepeterson