Reads MRZ field for React Native
-
Install the Plugin:
npm install react-native-mrz-reader
-
Link Native Modules (if required for versions below React Native 0.60):
npx react-native link react-native-mrz-reader
-
iOS Additional Setup: Modify your Info.plist to include necessary Camera usage descriptions.
<key>NSCameraUsageDescription</key> <string>This app requires Camera access to verify your identity.</string>
-
Android Additional Setup: Add Camera permissions in your AndroidManifest.xml.
<uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-permission android:name="android.permission.CAMERA" />
Add the following code in your app to request camera permission at runtime:
import { PermissionsAndroid } from 'react-native'; async function requestCameraPermission() { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.CAMERA, { title: 'Camera Permission', message: 'This app needs access to your camera to scan MRZ.', buttonNeutral: 'Ask Me Later', buttonNegative: 'Cancel', buttonPositive: 'OK', } ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('You can use the camera'); } else { console.log('Camera permission denied'); } } catch (err) { console.warn(err); } }
Note: This plugin is currently only available for Android devices.
import MrzReader, { CameraSelector, DocType } from 'react-native-mrz-reader';
// ...
<MrzReader
style={{width: '100%', height: '100%'}}
docType={DocType.Passport}
cameraSelector={CameraType.Back}
onMRZRead={(mrz: string) => {
console.log(mrz)
}}
/>
For a detailed example of how to use the NFC Passport Reader, please see the Example App.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library