Skip to main content

Predefined UI

The react native library can be easily integrated into your application by using the predefined UI. It utilizes a Native Module in React Native to start the capture interface and uses the event emitter to send results back to your application.

Usage

To start the capture interface in React Native simply import the launch function from the @mobaibio/mobai-biometric package and call the function.

import {
ErrorResult,
MBCaptureSessionResult,
EVENT_FAILURE,
EVENT_SUCCESS,
launch,
MobaiBiometric,
MobaiBiometricOptions,
} from "mobai-biometric";

mobaiBiometricEmmiter = new NativeEventEmitter(MobaiBiometric);

const onCaptureFinished = (result: MBCaptureSessionResult) => {
console.log("Capture Finished");
console.log(EVENT_SUCCESS + " image " + result.image.length);
console.log(EVENT_SUCCESS + " padData " + result.padData.length);
};

const onFailureWithErrorMessage = (result: ErrorResult) => {
console.log(EVENT_FAILURE + " error " + result.errorDescription);
};

mobaiBiometricEmmiter.addListener(EVENT_SUCCESS, onCaptureFinished);

mobaiBiometricEmmiter.addListener(EVENT_FAILURE, onFailureWithErrorMessage);

export const launchNativeModule = () => {
var myOptions: MobaiBiometricOptions = {
autoCaptureEnabled: true,
targetResolution: TargetResolution.HD_720
};
launch(myOptions);
};

Event Emitters

In order to receive data from the native library we use event emitter to send events that can be handled by a listener function:

Event NameDescription
EVENT_SUCCESSSent when the capture process has finished successfully and provides the captured data to the listener function
EVENT_FAILURESent when the capture process is not able to finish successfully and returns the failure reason to the listener function

Configuration

Some aspects of the capture process is configurable by providing options object to the launch function.

MobaiBiometricOptons

Variable NameTypeDefault ValueDescription
numberOfFramesBeforeCapturenumber0describes number of frame that library capture before starting the process of capturing.
numberOfFrameToCollectnumber3describes the number of frames to collect during the capture session.
frameIntervalnumber10after collected the first frame, is the number of frames to skip before collecting a frame.
timeBeforeAutomaticCapturenumber1number of seconds that user needs to wait in automatic capture.
isDebuggingbooleanfalseIf it is set to false will just display the overlay on the top of the camera. If it is set to true will display all components available ont the top of the camera(timer text, progress bar and face status text).
cameraPermissionAlertCameraPermissionAlertundefinedCamera permission object for showing alert when permission is denied from user
targetResolutionTargetResolutionundefinedTargetResolution is used to define the resolution in witch the frames are collected. TargetResolution.QHD represents (540x960)px, TargetResolution.HD_720 represents (720x1280)px, TargetResolution.HD_1080 rrepresents (1080x1920)px, TargetResolution.HD_4K represents (2160x3840)px.
faceStatusTextsFaceStatusTextsundefinedIs used to customize or localize the text displayed to the user indicating if the face is in correct position or not.
if no input is provided to faceStatusTexts default values are used.
previewScaleTypePreviewScaleTypefillThe mode used to scale the camera preview in the view. It can be set to either fit or fill. PreviewScaleType.fill will ensure the camera preview is taking up the whole view in both width and height. However, this means that some parts of the image will be cropped from the preview. This does not have any impact on the images captured from the camera. PreviewScaleType.fit will ensure that exactly what is captured from the camera is shown in the view.
showCountdownLabelbooleanfalse- Is used to show or hide the label displayed during countdown before capture starts.
- The text for the countdownLabel can be set using the countdownLabelText option.
countdownLabelTextstring'Hold Still'Is used to customize the text shown in the countdown label
showProgressBarbooleanfalseIs used to show or hide the progress bar. The progress bar indicates to the user how far in the capture process we are.
showFaceStatusLabelbooleanfalseIs used to show or hide the face status label. The face status label is used to indicate to the user if the face is in the correct position or not.
payloadOptimizationbooleanfalseEnable or disable the optimization of the payload you send to the backend, reduces the payload size.

CameraPermissionAlert Camera permission object for showing alert when permission is denied from user

| Member | Type | Default Value | Description | | title | string | | The title of the alert box | | message | string | | The message to show the user | | settingText | string | | The title of the button to go to the iOS settings page | | cancelText | string | | The title of the button to dismiss the alert |

FaceStatusTexts

FaceStatusTexts

MemberTypeDefault ValueDescription
faceTooFarAwaystringText to display when the face is too far away from the camera
faceTooFarUpstringText to display when the face i too far up in the camera
faceTooFarDownstringText to display when the face is too far down in the camera
faceTooFarLeftstringText to display when the face is too far left in the camera
faceTooFarRightstringText to display when the face is too far right in the camera
faceTooClosestringText to display when the face is too close to the camera
faceNotFoundstringText to display when no face is found
tooManyFacesstringText to display when too many faces are found in the camera
validFacestringText to display when the face is in a valid position in the camera