Document Detector
Install and launch Document Detector for React Native. Learn configuration options, UI setup, customization paths, hook events, and result handling.
Prerequisites
Before proceeding, ensure the Certta SDK is properly installed. If you haven't done this yet, please refer to our Installation Guide.
Enable documentDetector (and documentDetectorUI if you want the built-in UI) in caf-modules-config.json.
Starting Document Detector
Use useCafDocumentDetector and call open() with a CerttaDocumentDetectorConfiguration object. Read results from the hook event state.
import { useEffect } from 'react';
import {
useCafDocumentDetector,
CafDocument,
} from '@caf.io/react-native-sdk';
function DocumentCapture() {
const { open, event } = useCafDocumentDetector();
useEffect(() => {
if (event.success) {
// Handle success — event.success.response is a JWT
} else if (event.error) {
// Handle error
}
}, [event]);
const startCapture = async () => {
try {
await open({
flow: [
{ document: CafDocument.RG_FRONT },
{ document: CafDocument.RG_BACK },
],
});
} catch {
// Handle BRIDGE_EXCEPTION
}
};
// ...
}open() rejects with CerttaPlatformException and code BRIDGE_EXCEPTION when the native mapper rejects the configuration.
CerttaDocumentDetectorConfiguration parameters
flow
None
Ordered list of capture steps. Required.
uploadSettings
null
Settings for uploading document images.
showPreview
true
Shows a preview screen for user confirmation when true.
requestTimeout
60
Maximum time (in seconds) for network requests.
showPopup
false
Displays a guidance popup during capture when true.
maxRetryAttempts
3
Maximum retries after a failed capture. Use 0 to disable retries.
messageCustomization
null
In-flow capture messages.
previewCustomization
null
Preview screen copy.
uploadCustomization
null
Upload dialog copy.
uploadMessagesCustomization
null
Messages shown while the document is sent and processed.
retryCustomization
null
Retry screen copy.
Starting Document Detector UI
Use useCafDocumentDetectorUI and call open() with a CerttaDocumentDetectorUIConfiguration.
CerttaDocumentDetectorUIConfiguration parameters
Inherits every field from CerttaDocumentDetectorConfiguration, plus:
instructionScreen
null
Instructions shown before camera or file gallery.
documentSelectionScreen
null
Title and description of the document picker. Documents come from flow.
Deep dive into customizations
UI CustomizationsSupported documents
RG_FRONT
Front side of the RG document, where the photo is located.
RG_BACK
Back side of the RG document.
RG_FULL
Open RG document, displaying both the front and back sides together.
CNH_FRONT
Front side of the CNH document, where the photo is located.
CNH_BACK
Back side of the CNH document.
CNH_FULL
Open CNH document, displaying both the front and back sides together.
CRLV
CRLV document.
RNE_FRONT
Front side of the RNE or RNM document.
RNE_BACK
Back side of the RNE or RNM document.
PASSPORT
Passport document, displaying the photo and personal data.
CTPS_FRONT
Front side of the CTPS document, where the photo is located.
CTPS_BACK
Back side of the CTPS document.
ANY
Allows submission of any type of document, including all those listed above or any other unclassified document.
In TypeScript, use the CafDocument enum (CafDocument.RG_FRONT, CafDocument.CNH_BACK, CafDocument.PASSPORT, and so on).
Supported file formats (CafFileFormat)
Used by CafDocumentDetectorUploadSettings.fileFormats.
PNG
image/png
JPG
image/jpg
JPEG
image/jpeg
PDF
application/pdf
HEIF
image/heif
HEIC
image/heic
Understanding Document Detector events and results
success (CerttaSuccess)
Triggered when the document is captured and processed successfully.
response: a JWT with the result data from the Document Detector flow.
error (CerttaError)
Triggered when capture fails (network issues, user cancellation, camera permission denials, or configuration errors).
type: error identifier mapped from the native SDK.cause: additional context, when present.
InitializationError
configure not called, empty token or user ID, or invalid maxRetryAttempts.
PermissionError
Camera (or related) permission denied.
NetworkError
Connectivity or server-side issues surfaced as network class errors.
SecurityError
Security checks failed.
UnknownError
Other failures not mapped to a specific case.
Cancelled
Occurs when the user abandons the flow before completion, such as by pressing the back button or sending the app to the background.
Atualizado

