import {Platform, Pressable, StyleSheet, Text, View} from 'react-native'; import React, {useEffect} from 'react'; import {styles} from './styles'; import Header from '../header/header.component'; import Footer from '../footer/footer.component'; import CaptureButton from '../../design-system/capture-button/capture-button.component'; import FlipButton from '../../design-system/flip-button/flip-button.component'; import {globalStyles} from '../../../globalStyles'; import {getBranding} from '../../branding'; import Icon from 'react-native-vector-icons/Ionicons'; import { Camera, useCameraDevice, useCameraDevices, } from 'react-native-vision-camera'; import {useMyStepsVerification} from '../../provider/verification.context'; import Toast from 'react-native-toast-message'; type props = { webcamRef: React.MutableRefObject; userStep: number; findOutStepContent: () => { step: number; heading: string; subHeading: string; }; goBackUserSteps: (index?: number) => void; handlerUserSteps: () => void; buttonText: (userStep: number) => any; handleSingleCapturePhoto: (step: number) => void; skipGuidanceScreens?: boolean; }; /** * A component for capturing a selfie using the device's camera. * * @param {Object} props - The component props. * @param {Object} props.webcamRef - A mutable ref object for accessing the camera component. * @param {string} props.cameraMode - The type of camera to use (front or back). * @param {number} props.userStep - The current step in the user verification process. * @param {Function} props.findOutStepContent - A function that returns an object with the heading and subheading text for the current verification step. * @param {Function} props.goBackUserSteps - A function that allows the user to go back to the previous verification step. * @param {Function} props.handlerUserSteps - A function that handles the user's progress through the verification steps. * @param {Function} props.buttonText - A function that returns the text to display on the footer button based on the current verification step. * @param {Function} props.handleSingleCapturePhoto - A function that handles capturing a single photo for the current verification step. * @param {Function} props.flipCamera - A function that switches between the front and back camera. * @returns {JSX.Element} - The rendered component as a JSX element. */ const CaptureSelfie = ({ webcamRef, userStep, findOutStepContent, goBackUserSteps, handlerUserSteps, buttonText, handleSingleCapturePhoto, skipGuidanceScreens, }: props) => { const device = useCameraDevice('front'); const flipCamera = () => {}; let context = useMyStepsVerification(); const { t } = context; useEffect(() => { if (!device || !webcamRef?.current) return; let cancelled = false; const checkRes = async () => { try { const probe = await webcamRef.current?.takePhoto?.({ enableShutterSound: false, qualityPrioritization: 'speed', }); if (cancelled || !probe?.width || !probe?.height) return; const w = Math.max(probe.width, probe.height); const h = Math.min(probe.width, probe.height); if (w < 1920 && h < 1080) { Toast.show({ type: 'info', text1: t.lowCameraResolution, text2: t.frontCameraMsg.replace('{w}', String(w)).replace('{h}', String(h)), visibilityTime: 5000, }); } } catch (_) {} }; const timer = setTimeout(checkRes, Platform.OS === 'android' ? 500 : 1500); return () => { cancelled = true; clearTimeout(timer); }; }, [device]); return ( {/* Camera Screen */} {device && ( )} {/* Oval Screen */} {/* Content Screen */} { context.skipGuidanceScreens ?(context.allowSingle && context.selectedOption == "Passport") ? goBackUserSteps(4) : goBackUserSteps(2) : goBackUserSteps(); }}> {findOutStepContent()?.heading} {findOutStepContent()?.subHeading} {context.onCancel ? ( pressed && styles.opacity}> ) : ( )}