Skip to main content

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():

ConstantNative EventDescription
EVENT_SUCCESSonScanningFinishedEmits MrzResult when reading completes
EVENT_FAILUREonFailureWithErrorMessageEmits 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

  1. Always remove listeners on unmount to avoid memory leaks.
  2. Surface permission errors to users if camera access is denied.
  3. Handle failure events via EVENT_FAILURE to show readable errors.