I've created an app named BarcodeApp exactly same as in the doc and copied every line of codes in the doc. But I've not installed 1.2.0 version (called the latest version in the doc, actually the latest version was 1.4.2). But I've installed 1.4.2 by npm install --save react-native-barcode-scanner-google. And the app launched OK. But seems like onBarcodeRead could not triggered just showing the camera only. Here is my package.json:
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View, Alert } from 'react-native';
import BarcodeScanner, { Exception, FocusMode, CameraFillMode, BarcodeType, pauseScanner, resumeScanner } from 'react-native-barcode-scanner-google';
export default class BarcodeApp extends Component {
render() {
return (
<View style={{ flex: 1 }}>
<BarcodeScanner
style={{ flex: 1 }}
onBarcodeRead={({ data, type }) => {
alert('HEY');
// handle your scanned barcodes here!
// as an example, we show an alert:
// Alert.alert(`Barcode '${data}' of type '${type}' was scanned.`);
// alert(`Barcode '${data}' of type '${type}' was scanned.`);
}}
onException={exceptionKey => {
// check instructions on Github for a more detailed overview of these exceptions.
switch (exceptionKey) {
case Exception.NO_PLAY_SERVICES:
// tell the user they need to update Google Play Services
case Exception.LOW_STORAGE:
// tell the user their device doesn't have enough storage to fit the barcode scanning magic
case Exception.NOT_OPERATIONAL:
// Google's barcode magic is being downloaded, but is not yet operational.
default: break;
}
}}
focusMode={FocusMode.TAP /* could also be TAP or FIXED */}
cameraFillMode={CameraFillMode.COVER /* could also be FIT */}
barcodeType={BarcodeType.ALL /* replace with ALL for all alternatives */}
/>
</View>
);
}
}
AppRegistry.registerComponent('BarcodeApp', () => BarcodeApp);
I've created an app named BarcodeApp exactly same as in the doc and copied every line of codes in the doc. But I've not installed 1.2.0 version (called the latest version in the doc, actually the latest version was 1.4.2). But I've installed 1.4.2 by npm install --save react-native-barcode-scanner-google. And the app launched OK. But seems like onBarcodeRead could not triggered just showing the camera only. Here is my package.json:
Here is my index.js: