Use the module in App.js
.
import {NativeModules} from 'react-native';
import { RNCamera } from 'rn-mobile-barcode-scanner';
import Canvas from 'react-native-canvas';
state = {
license: '-- put your license here -- ',
barcodeFormat: RNCamera.Constants.DynamsoftBarcodeFormats.BarcodeFormat.ALL,
barcodeFormat2: RNCamera.Constants.DynamsoftBarcodeFormats.BarcodeFormat2.NULL,
type: 'back',
canDetectBarcode: false,
barcodes: [{
type: '',
data: '',
localizationResult: []
}]
};
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={{
flex: 1,
justifyContent: 'space-between',
}}
type={this.state.type}
license={this.state.license}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}
onDynamsoftBarcodesReader={canDetectBarcode ? this.barcodeRecognized : null}
barcodeFormat={this.state.barcodeFormat}
barcodeFormat2={this.state.barcodeFormat2}
>
<View style={{height:'100%'}}>
<View style={{height:'90%'}}>
{!!canDetectBarcode && this.renderBarcodes()}
</View>
<View style={{ flexDirection: 'row', alignSelf: 'center' }}>
<TouchableOpacity
onPress={this.toggle('canDetectBarcode')}
style={[styles.flipButton, { flex: 0.5, alignSelf: 'center' }]}
>
<Text style={styles.flipText}>{!canDetectBarcode ? 'Decode' : 'Decoding'}</Text>
</TouchableOpacity>
</View>
</View>
</RNCamera>