Document Reading Integration Guide
The React Native Document Reader module exposes the native Mobai Document Reader SDKs through a Native Module and event emitter.
Native Module API
Module and Launch Function
import { MobaiDocumentReaderModule } from '@mobaibio/mobai-document-reader';
launch signature:
MobaiDocumentReaderModule.launch(license: string)
Events
The module provides two event constants from getConstants():
| Constant | Native Event | Description |
|---|---|---|
EVENT_SUCCESS | onScanningFinished | Emits MrzResult when reading completes |
EVENT_FAILURE | onFailureWithErrorMessage | Emits error payload on failure |
Data Models
MrzResult
export interface MrzResult {
firstName: string;
lastName: string;
gender: string;
birthDate: string;
nationality: string;
dateOfExpiry: string;
issuingStateOrOrganization: string;
documentNumber: string;
}
Full React Native Flow Example
import React, { useEffect } from 'react';
import { NativeEventEmitter } from 'react-native';
import {
MobaiDocumentReaderModule,
EVENT_SUCCESS,
EVENT_FAILURE,
type MrzResult,
} from '@mobaibio/mobai-document-reader';
export function DocumentReaderScreen({ license, onResult }: any) {
useEffect(() => {
const eventEmitter = new NativeEventEmitter(MobaiDocumentReaderModule);
const successListener = eventEmitter.addListener(
EVENT_SUCCESS,
(event: MrzResult) => {
onResult(event);
}
);
const errorListener = eventEmitter.addListener(EVENT_FAILURE, (event) => {
console.log('Document reading error', event.onFailureWithErrorMessage);
});
return () => {
successListener.remove();
errorListener.remove();
};
}, [onResult]);
const startReading = () => {
MobaiDocumentReaderModule.launch(license);
};
return null;
}
Best Practices
- Always remove listeners on unmount to avoid memory leaks.
- Surface permission errors to users if camera access is denied.
- Handle failure events via
EVENT_FAILUREto show readable errors.