ekreutz / react-native-barcode-scanner-google

Barcode scanner for react native, which implements barcode detection from Google's Vision API.
MIT License
113 stars 68 forks source link

scannerModule.BarcodeType is undefined #2

Closed jshtx closed 7 years ago

jshtx commented 7 years ago

Hey, I just started using react native and was trying to implement your barcode scanner on a small project and I keep getting an error that says "undefined is not an object (scannerModule.BarcodeType is undefined)". I'm just using your example code and haven't added anything to it, any idea why this might be happening?

thanks.

ekreutz commented 7 years ago

Hey @jshtx,

Not quite sure. I just did a clean test following my instructions, and it worked flawlessly.

Some ideas:

Scanning 558 folders for symlinks in /Users/<User>/Path/To/BarcodeApp/node_modules (5ms)
rnpm-install info Linking react-native-barcode-scanner-google android dependency
rnpm-install info Android module react-native-barcode-scanner-google has been successfully linked

Additionally:

Hopefully there's something helpful in there.

ShaileshPrajapati-BTC commented 6 years ago

same here can you please provide manual steps to link, some times it not linked

ducpt2 commented 6 years ago

@ShaileshPrajapati-BTC maybe it late, but when i delete ios build, clean xcode, remove derived data, reset cache... and re-run on xcode, it work. (i use this library with RN camera)

ognjetina commented 6 years ago

there is a workaround if this is breaking your ios build.


import React, { Component } from 'react';
import Camera from 'react-native-camera';
import PropTypes from 'prop-types';
import { Platform } from 'react-native';

const ScannerComponent = Platform.select({
  android: () => require('react-native-barcode-scanner-google').default,
  ios: () => require('react-native-camera').default
})();

export default class BarCodeScannerComponent extends Component {

  constructor(props) {
    super(props);

  }

  static propTypes = {
    //style: RNCamera.propTypes.style,
    onBarcodeRead: PropTypes.func,
    onPhoto: PropTypes.func,
    permissionDialogMessage: PropTypes.string,
    permissionDialogTitle: PropTypes.string,
    cameraType: PropTypes.string
  };

  render() {
    const {
      style,
      cameraType = Camera.constants.Type.back,
      permissionDialogTitle = 'Permission to use camera',
      permissionDialogMessage = 'We need your permission to use your camera',
      onBarcodeRead,
      onPhoto,
    } = this.props;

    return (
      Platform.OS === 'iso' ? <ScannerComponent
          ref={cam => this.cameraComponent = cam}
          style={style}
          type={cameraType}
          permissionDialogTitle={permissionDialogTitle}
          permissionDialogMessage={permissionDialogMessage}
          onBarCodeRead={onBarcodeRead}
          onPhoto={onPhoto}
          barCodeTypes={[Camera.constants.BarCodeType.code128]}>
          {this.props.children}
        </ScannerComponent>
        :
        <ScannerComponent
          style={style}
          onBarcodeRead={onBarcodeRead}
        />
    );
  }
}
Nualiian commented 5 years ago

@ognjetina your solution worked for me if I only used the component, but when I tried to use other attributes from the library, e.g. FocusMode, the iOS build was still broken as all the other stuff was required (imported) on iOS as well. I ended up doing something like this, which worked for me:

const Scanner = Platform.select({
  android: () => ({
    Component: require('react-native-barcode-scanner-google').default,
    attributes: {
      CameraFillMode: require('react-native-barcode-scanner-google').CameraFillMode,
      FocusMode: require('react-native-barcode-scanner-google').FocusMode,
      Exception: require('react-native-barcode-scanner-google').Exception
    }
  }),
  ios: () => ({
    Component: require('react-native-camera').default
  })
})()

and then in my render:

    if (IS_ANDROID) {
        return (
            <Scanner.Component
                focusMode={Scanner.attributes.FocusMode.TAP}
                {...otherProps}
            />
        )
    }
    return (
        <Scanner.Component
            aspect={Camera.constants.Aspect.fill}
            {...otherProps}
        />
    )
ppv94 commented 5 years ago

I am getting still the same error in IOS scannerModule.BarcodeType is undefined In Android it works fine. please help me

code-by commented 3 years ago

I have same problem try to run this module on Android, get null is not an object (evaluating 'scannerModule.BarcodeType') I have do react-native link react-native-barcode-scanner-google