import { View, StyleSheet, Button, Text } from 'react-native'; import React, { memo, useCallback, useEffect, useState } from 'react'; import HintMessage from './HintMessage'; import { type GetIdSdk } from '@get-id/react-native-sdk'; import type { InitialiseLivenessScanResult } from '../../../src/types/sdkTypes'; type FaceScanProps = { sdk: GetIdSdk; onComplete?: () => void; onError?: (error: any) => void; }; type FaceScanFunctions = Omit; const GetidLivenessScanWrapper = ({ sdk, onComplete, onError, }: FaceScanProps) => { const [captureClicked, setCaptureClicked] = useState(false); const [hintMessage, setHintMessage] = useState(''); const [sdkFunctions, setSdkFunctions] = useState({ capture: () => Promise.resolve(), stopCapture: () => {}, }); const [error, setError] = useState(null); const [faceComponent, setFaceComponent] = useState(); const [isCameraReady, setIsCameraReady] = useState(false); const onCameraReady = useCallback(() => { setIsCameraReady(true); }, []); const onUserHintChange = useCallback((hint: any) => { console.log(`onUserHintChange: ${hint}`); setHintMessage(hint.value); }, []); const onServerValidationStarted = useCallback(() => { console.log( 'onDocumentScanServerValidationStarted: Document scan server validation started' ); }, []); useEffect(() => { const initDocScan = async () => { const initialiseFaceScan = sdk.initialiseLivenessScan; try { const { component, ...functions } = await initialiseFaceScan({ onServerValidationStarted, onCameraReady, onUserHintChange, }); setFaceComponent(component); setSdkFunctions(functions); } catch (e: any) { console.error('Error initialising face scan', e); onError?.(e); } }; initDocScan(); }, [ sdk, onServerValidationStarted, onUserHintChange, onError, onCameraReady, ]); return ( <> {!isCameraReady && ( Loading... )} {faceComponent} Time for selfie {error && Error: {error}} {hintMessage && }