React Native
The React Native plugin has been completely reworked in release 8.4, resulting in changes to the public interfaces. This section provides a side-by-side comparison of the basic features between releases 8.3 and 8.4
Plugin Installation
The plugin's name has been changed. The previous plugin version is deprecated and will be supported for one more release (8.5), so it's strongly recommended to migrate to the new plugin version.
npm install @regulaforensics/document-reader
npm install @regulaforensics/document-reader-core-fullauthrfid
npm install @regulaforensics/react-native-document-reader-api
npm install @regulaforensics/react-native-document-reader-core-fullauthrfid
Accessing DocumentReader
DocumentReader.instance.
var documentReader = DocumentReader.instance
documentReader.
DocumentReader.
Preparing Database
await documentReader.prepareDatabase("Full", showProgress)
onDatabasePrepared()
const eventManager = new NativeEventEmitter(RNRegulaDocumentReader)
eventManager.addListener('prepareDatabaseProgressChangeEvent', e => console.log("Downloading database: " + e["msg"] + "%" ))
DocumentReader.prepareDatabase("Full", (respond) => {
onDatabasePrepared()
}, error => console.log(error))
Initialization
var [success, error] = await documentReader.initialize(new InitConfig(license))
if (success) console.log("Init complete")
else console.log(error.code + ": " + error.message)
var config = new DocReaderConfig()
config.license = license
config.delayedNNLoad = true
DocumentReader.initializeReader(config, (message) => {
result = JSON.parse(message)
if (!result.success) {
console.log("Init error: " + result.error.message)
} else {
console.log("Init complete")
}
}, _ => { })
Accessing Fields
var tag = documentReader.tag
documentReader.tag = "new tag"
DocumentReader.getTag((value) => {
console.log("Tag: " + value)
}, _ => { })
DocumentReader.setTag(value, (m) => {
console.log("Tag set: " + value)
}, _ => { })
Accessing Available Scenarios
var scenarios = documentReader.availableScenarios
DocumentReader.getAvailableScenarios((scenariosString) => {
var scenariosJson = JSON.parse(scenariosString)
var scenarios = []
for (var index in scenariosJson) {
var scenarioJson = scenariosJson[index]
var scenario = DocumentReaderScenario.fromJson(typeof scenarioJson === "string" ? JSON.parse(scenarioJson) : scenarioJson)
scenarios.add(scenario)
}
}, _ => { })
Changing Configuration
documentReader.functionality.showCaptureButton = true
var functionality = new Functionality()
functionality.showCaptureButton = true
DocumentReader.setFunctionality(functionality, _ => { }, _ => { })
Scanning Document
documentReader.startScanner(
ScannerConfig.withScenario(Scenario.MRZ),
handleCompletion,
)
var eventManager = new NativeEventEmitter(RNRegulaDocumentReader)
eventManager.addListener('completion', (e) => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))!))
var config = new ScannerConfig()
config.scenario = Enum.ScenarioIdentifier.SCENARIO_MRZ
DocumentReader.startScanner(config, _ => { }, _ => { })
Reading RFID
documentReader.rfid(new RFIDConfig(handleCompletion))
var eventManager = new NativeEventEmitter(RNRegulaDocumentReader)
eventManager.addListener('completion', (e) => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))!))
DocumentReader.startRFIDReader(false, false, false, _ => { }, _ => { })