[](https://badge.fury.io/js/react-native-qrcode-scanner)
A QR code scanner component for React Native built on top of react-native-camera by Lochlan Wansbrough
Please note, this will also function as a generic barcode scanner by the virtue of the above module supporting barcode scanning, however, this module was initially built as a QR code scanner.
I wrote this module because I couldn't find one that could be simply plugged into a project without requiring too much setup.
Looking for active contributors (if you're interested, reach out to me at moaazsidat@gmail.com)
#### iOS 10
With iOS 10 and higher you need to add the "Privacy - Camera Usage Description" key to the info.plist of your project. This should be found in 'your_project/ios/your_project/Info.plist'. Add the following code:
``
`android/app/src/main/AndroidManifest.xml
#### Android 7
With Android 7 and higher you need to add the "Vibration" permission to your AndroidManifest.xml of your project. This should be found in your Add the following:
``
#### react-native-camera
react-native-camera is a dependency for this package that you'll need to add to your project. To install, run the following commands:
1. npm install react-native-camera --savereact-native link react-native-camera
2.
#### New Version/Migration
If using an older version of this module with RCTCamera you will need to follow the docs here to move from the old RCTCamera to the new RNCamera. You will then need to install it as above.
Versions of this library > 0.0.30 will not support react-native-camera versions less than 1.0.0.
npm install react-native-qrcode-scanner --save
`
`
react-native link react-native-qrcode-scanner
react-native link react-native-permissions
`Usage
To use react-native-qrcode-scanner, import the react-native-qrcode-scanner module and use the tag. More usage examples can be seen under the examples/ folder.Here is an example of basic usage:
`js
'use strict';import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TouchableOpacity,
Linking,
} from 'react-native';
import QRCodeScanner from 'react-native-qrcode-scanner';
class ScanScreen extends Component {
onSuccess(e) {
Linking
.openURL(e.data)
.catch(err => console.error('An error occured', err));
}
render() {
return (
onRead={this.onSuccess.bind(this)}
topContent={
Go to wikipedia.org/wiki/QR_code on your computer and scan the QR code.
}
bottomContent={
OK. Got it!
}
/>
);
}
}
const styles = StyleSheet.create({
centerText: {
flex: 1,
fontSize: 18,
padding: 32,
color: '#777',
},
textBold: {
fontWeight: '500',
color: '#000',
},
buttonText: {
fontSize: 21,
color: 'rgb(0,122,255)',
},
buttonTouchable: {
padding: 16,
},
});
AppRegistry.registerComponent('default', () => ScanScreen);
`Screenshot of the above:
!screenshot 2017-05-02 15 06 33
Please open an issue if something doesn't work or is not clear enough.
Methods
####
reactivate()Call this method to programmatically enabling scanning again. Use this by attaching a
ref like so and calling this.scanner.reactivate()Props
####
onRead (required)
propType: func.isRequired
default: (e) => (console.log('QR code scanned!', e))Will call this specified method when a QR code or a barcode is detected in the camera's view passing in the event emitted upon reading the code.
####
fadeIn
propType: bool
default: trueWhen set to
true this ensures that the camera view fades in after the initial load up instead of being rendered immediately.
Set this to false to prevent the animated fade in of the camera view.####
reactivate
propType: bool
default: falseWhen set to
false, when a QR code is scanned, the QRCodeScanner will not scan another code until it is re-rendered.
When set to true this will reactivate the scanning ability of the component.####
reactivateTimeout
propType: number
default: 0Use this to configure how long it should take before the
QRCodeScanner should reactivate.####
topContent
propType: oneOfType([Use this to render any additional content at the top of the camera view.
####
bottomContent
propType: oneOfType([Use this to render any additional content at the bottom of the camera view.
####
containerStyle
propType: anyUse this to pass styling for the outermost container. Useful for adding margin/padding to account for navigation bar.
####
cameraStyle
propType: anyUse this to pass or overwrite styling for the camera window rendered.
####
topViewStyle
propType: anyUse this to pass or overwrite styling for the
that contains the topContent prop.####
bottomViewStyle
propType: anyUse this to pass or overwrite styling for the
that contains the bottomContent prop.####
showMarker
propType: boolean
default: falseUse this to show marker on the camera scanning window
####
customMarker
propType: elementPass a RN element/component to use it as a custom marker.
####
notAuthorizedView
propType: elementPass a RN element/component to use it when no permissions given to the camera (iOS only).
####
cameraType
propType: oneOf(['front', 'back'])
default: 'back'Use this to control which camera to use for scanning QR codes, defaults to rear camera.
####
checkAndroid6Permissions
propType: bool
default: falseUse this to enable permission checking on Android 6
####
permissionDialogTitle
propType: string
default: 'Info'Use this to setting permission dialog title (Android only).
####
permissionDialogMessage
propType: string
default: 'Need camera permission'`Use this to setting permission dialog message (Android only).
This QR code scanner was inspired by the QR code scanner within Whatsapp.