Closed jshtx closed 7 years ago
Hey @jshtx,
Not quite sure. I just did a clean test following my instructions, and it worked flawlessly.
Some ideas:
react-native link react-native-barcode-scanner-google
(basically, this command will add some Java/Android code within your app to link this module to the JS side) your output should look somewhat like this: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:
react-native run-android
.Hopefully there's something helpful in there.
same here can you please provide manual steps to link, some times it not linked
@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)
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}
/>
);
}
}
@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}
/>
)
I am getting still the same error in IOS scannerModule.BarcodeType is undefined In Android it works fine. please help me
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
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.