1. Add the module with typing the following command in the terminal (skip if previously executed) :
$cd Project/Dir
$yarn add react-native-mrzscannerlib
1. Add the following code with flatDir in pathToYourApp/android/build.gradle:
allprojects {
repositories {
flatDir { dirs "$rootDir/../node_modules/react-native-mrzscannerlib/android/mrzlibs" }
}
}
1. Disable bitcode. Your app will immediately generate an error if you try and run with an Enable Bitcode.
2. The scanner uses your phone camera, automatically requires a permission to access your camera.
-key: NSCameraUsageDescription.
-value: value: MRZ Scanner requires using camera.
1.In order to interact with module, first thing is to import it into your App.js file and create a reference to it:
import {NativeModules} from 'react-native' ;
const MrzScanner = NativeModules.RNMrzScanner;
2. To receive results from the scanner , you have to import “NativeEventEmitter” as followed :
const EventEmitter = new NativeEventEmitter(MrzScanner);
'successfulScanEmittedEvent' - for MRZ scan
'successfulDocumentScanEmittedEvent' - for document image scan
‘scannerWasDismissedEmittedEvent’ - for dismissed scanner
’permissionsWereDeniedEmittedEvent’ - for denied permission
‘scanImageFailedEmittedEvent’- for a failed image scan
JavaScript can then receive the registered event by “add ListenerOn” using the “Subscribe” mixin.
(Use of the eventEmitter can be found in the provided sample project ”Sample.js”.)
3. To receive results you need to embed an EventListener in the componentDidMount() life cycle method.
-The way the listener works is that it waits for an event to happen under the key "successfulScanEmittedEvent", in this case, we're getting the results for "body".
-In this case we're using type SCANNER_TYPE.MRZ,
the results for "body" will also include the following if found :
- body.raw_result (raw String of the scanner MRZ)
- body.portrait (base64 String)
- body.signature (base64 String)
- body.full_image (base64 String)
componentDidMount(){
subscription=EventEmitter.addListener
('successfulScanEmittedEvent',
(body) =>
console.log("Results" + body.surname,
body.document_type_readable,
body.issuing_country,
body.surname,
body.document_number,
body.nationality,
body.dob_raw,
body.dob_readable,
body.sex, )
);}
To get access to the new functionalities from JavaScript you have to pull them off of NativeModules each time :
const MrzScanner= NativeModules.RNMrzScanner;
MrzScanner.startScanner()
Activates the scanner, with a default SCANNER_TYPE.MRZ if not specified.
MrzScanner.startScanner()
Stop and close the MRZ Scanner
MrzScanner.closeScanner()
Specify which scanner type you want to use. There are two options: "MRZ Scanner" and "Document Image scanner".
The "MRZ Scanner" option is used to scan for MRZ.
The "Document image scanner" is used for capturing the front and back image of the ID documents.
@param int [SCANNER_TYPE.MRZ, SCANNER_TYPE.DOCUMENT_IMAGE_ID, SCANNER_TYPE.DOCUMENT_IMAGE_PASSPORT, SCANNER_TYPE.DRIVING_LICENCE, SCANNER_TYPE.DOCUMENT_IMAGE_ID_FRONT, SCANNER_TYPE.ID_SESSION]. The default value is SCANNER_TYPE.MRZ
MrzScanner.setScannerType(ScannerType int)
Resume scanning after the scanner has been paused/stopped. Usually after a successful scan.
MrzScanner.resumeScanning()
Set the date format in which the parsed dates are formatted.
@return the currently set date format in which the parsed dates are formatted.
@param dateFormat the pattern describing the date format. Example: "dd.MM.yyyy"
MrzScanner.setDateFormat(String dateFormat)
@return the current SDK Version.
MrzScanner.getSdkVersion()
Specify whether the scanner should detect and return results for IDs.
@param isIDActive [true, false]. The default value is true.
MrzScanner.setIDActive(isIDActive: Boolean)
Specify whether the scanner should detect and return results for passports.
@param isPassportActive [true, false]. The default value is true.
MrzScanner.setPassportActive(isPassportActive: Boolean)
Specify whether the scanner should detect and return results for *visas.
@param activate [true, false]. Default value is true.
MrzScanner.setVisaActive(isVisaActive: Boolean)
Specify the maximum number of CPU threads that the scanner can use during the scanning process.
@param int [MAX_THREADS.ONE, MAX_THREADS.TWO, MAX_THREADS.THREE, MAX_THREADS.FOUR, MAX_THREADS.FIVE,
MAX_THREADS.SIX]. The default value is MAX_THREADS.TWO
MrzScanner.setMaxThreads(maxThreads: Int)
Specify the effort level for the scanner to use during the scanning process.
@param int [EFFORT_LEVEL.CASUAL, EFFORT_LEVEL.TRY_HARDER, EFFORT_LEVEL.SWEATY]. The default value is EFFORT_LEVEL.TRY_HARDER
MrzScanner.setEffortLevel(effortLevel: Int)
Set the zoom factor for the camera preview.
@param number. Default value is 1.0
MrzScanner.setZoomFactor(zoomFactor: number)
Register with the license key provided to remove the asterisks (*) from the result.
@param key the provided license key.
@return 0 for success, -1 if registration failed.
MrzScanner.registerWithLicenseKey(key: String)
To get your evaluation key today, register an account on https://mrzscanner.com/register
Customize the overlay of the finder in the scanner
@param base64String takes a base64 type string
MrzScanner.startScannerWithCustomOverlay(base64String : String)
Trigger flashlight.
MrzScanner.toggleFlash(active : Boolean)
Trigger an image picker.
MrzScanner.scanFromGallery()
Initiates the scanner view with continuous scanning enabled.
After a successful scan, the scanner will not be dismissed or paused.
To close the scanner call closeScanner()
See setIgnoreDuplicatesEnabled for further continuous scanning behavior changes.
@param boolean: activate.
MrzScanner.setContinuousScanningEnabled(active : Boolean)
Ignores duplicate is used to specify whether the scanner should ignore *the successful scan if the document number is identical to the previous *successful scan.
@param boolean: activate.
MrzScanner.setIgnoreDuplicatesEnabled(activete : Boolean)
Enables vibrate on a successful scan option.
@param boolean: activate.
MrzScanner.setVibrateOnSuccessfulScan(activete : Boolean)
Enable automatically extracting portrait image on successful scan; Default value: false.
@param:activated.
MrzScanner.setExtractPortraitEnabled(activated);
Enable automatically extracting signature image on successful scan; Default value: false.
@param:activated.
MrzScanner.setExtractSignatureEnabled(activated);
Enable automatically extracting passport image on successful scan; Default value: false.
@param:activated.
MrzScanner.setExtractFullPassportImageEnabled(activated);
Enable automatically extracting ID(back) image on successful scan; Default value: false.
@param:activated.
MrzScanner.setExtractIdBackImageEnabled(activated);
Set the scanning rectangle to limit the scanning area.The parameters' values are representing percentages of the scanning preview.
@param x the top-left point of the scanning rectangle. [0,...,100]Default value: 5.
@param y the top-left point of the scanning rectangle. [0,...,100]Default value: 20.
@param width the width of the scanning rectangle. [0,...,100]Default value: 90.
@param height the height of the scanning rectangle. [0,...,100]Default value: 60.
MrzScanner.startPartialViewScanner(Int : x, Int : y, Int : width, Int : height)
Download link: https://mrzscanner.com/download.