Scanzy barcode scanner plugin for React Native platform
sh
npm install react-native-scanzy-barcode-scanner-plugin
`
For ios project, in order to get camera permission, please add below configs to the Info.plist of the Project Targets.
`xml
NSCameraUsageDescription
camera description.
`
For android project, add the following config in the same build.gradle(Android/app/build.gradle) file to avoid conflicts with the lib filename libc++_shared.so, which is used by React Native as well as by many other 3rd-party modules:
`
android {
...
packagingOptions {
pickFirst '**/libc++_shared.so'
}
}
`
Usage
`js
import ScanzyBarcodeManager, {ScanzyBarcodeFormat, ScanzyBarcodeOptions} from 'react-native-scanzy-barcode-scanner-plugin';
//set lisense in your app init function
ScanzyBarcodeManager.setLicense('YOUR LICENSE KEY');
//set scan formats and options
const formats = [ScanzyBarcodeFormat.Code128, ScanzyBarcodeFormat.Code93, ScanzyBarcodeFormat.EAN13, ScanzyBarcodeFormat.QRCode];
const options: ScanzyBarcodeOptions = {
enableVibration: true,
enableBeep: true,
enableAutoZoom: false,
enableScanCropRectOnly: false,
formats: formats
}
// scan
ScanzyBarcodeManager.scan(options).then((result: ScanzyBarcodeScanResult)=>{
//get the scan result
console.log('Scan Result:', result.barcode, result.barcodeType)
})
`
API Specification
Below gives you more details about the parameters:
The definition of ScanzyBarcodeFormat:
`typescript
const ScanzyBarcodeFormat = {
Code128:"Code128",
Code39:"Code39",
Code93:"Code93",
CodaBar:"CodaBar",
DataMatrix:"DataMatrix",
EAN13:"EAN13",
EAN8:"EAN8",
ITF:"ITF",
QRCode:"QRCode",
UPCA:"UPCA",
UPCE:"UPCE",
PDF417:"PDF417",
Aztec:"Aztec",
MaxiCode:"MaxiCode"
}
`
Note: to set the formats you only interested, although you can add ALL formats, it definitely would impact the performance.
The ScanzyBarcodeOptions is defined as:
`typescript
interface ScanzyBarcodeOptions {
enableVibration?: boolean;
enableBeep?: boolean;
enableAutoZoom?: boolean;
enableScanCropRectOnly?: boolean;
formats?: string[];
}
`
enableVibration: vibrate your phone when barcode detected.
enableBeep: play the beep sound when barcode detected.
enableAutoZoom: the library will zoom in/out automatcially to scan the barcode.
enableScanCropRectOnly: only scan the view finder area.
formats: the barcode formats.
The ScanzyBarcodeScanResult is defined as:
`typescript
interface ScanzyBarcodeScanResult {
barcode: string;
barcodeType: string;
}
``