Files
inji-wallet/components/FaceScanner.tsx
dhivya0413 769ed54bcf [INJI-195] Upgrade React native version to 0.71.8 (#824)
* chore(INJI-195): upgrade react native version and dependencies

* chore(INJI-195): upgrade expo version and dependencies

* chore(INJI-195): modify associated files on version upgrade

* chore(INJI-295): fixed react native flipper and patch packages

* chore(INJI-195): fix for expo prebuild

* chore(INJI-195): expo linked to android/ios projects

* chore(INJI-195): update metro config

* chore(INJI-195): fix ios build with mmkv storage patch

* chore(INJI-195): gradle version modified

* chore(INJI-195): fixed rn version 0.71.8 due to mmkv library issue

* chore(INJI-195): removed files in android

* chore(INJI-195): fix 0.71.8 for iOS project through pods with expo linking

* chore(INJI-195): fix for custom fonts added through pods due to rn linkage

* chore(INJI-195): fix for removing assets.car generated from pods

* Modify Node version in pipeline (#806)

* chore(INJI-195): fix for android splash screen not shown up

* chore(INJI-195): upgraded to node 18 in pipeline

* chore(INJI-195): add the pod install twice to remove duplicates via script workaround (#807)

Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com>

* INJI-195 Set the signing team for iOS  (#810)

* chore(INJI-195): add the pod install twice to remove duplicates via script workaround

* chore(INJI-195): set the signing team for ios build

---------

Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com>

* Modify github runner to self hosted runner (#811)

* chore(INJI-195): add the pod install twice to remove duplicates via script workaround

* chore(INJI-195): set the signing team for ios build

* chore(INJI-195): set the self hosted runner for ios build

---------

Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com>

* Modify self hosted runner to github hosted runner  (#813)

* chore(INJI-195): add the pod install twice to remove duplicates via script workaround

* chore(INJI-195): set the signing team for ios build

* chore(INJI-195): set the self hosted runner for ios build

* chore(INJI-195): modify the self hosted to github hosted runner

---------

Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com>

* chore(INJI-195): modify the self hosted to github hosted runner

* chore(INJI-195): set the code signing identity for ios build

* chore(INJI-195): assigned app icon files to asset

---------

Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com>
Signed-off-by: Swati Goel <meet2swati@gmail.com>
Co-authored-by: Swati Goel <meet2swati@gmail.com>
2023-09-13 11:53:59 +05:30

148 lines
4.3 KiB
TypeScript

import React, {useCallback, useContext, useEffect, useRef} from 'react';
import {Camera} from 'expo-camera';
import {
Platform,
StyleSheet,
TouchableOpacity,
View,
Image,
} from 'react-native';
import {Button, Centered, Column, Row, Text} from './ui';
import {useInterpret, useSelector} from '@xstate/react';
import {useTranslation} from 'react-i18next';
import {
FaceScannerEvents,
selectIsCheckingPermission,
selectIsValid,
selectIsPermissionDenied,
selectIsScanning,
selectWhichCamera,
createFaceScannerMachine,
selectIsInvalid,
selectIsCapturing,
selectIsVerifying,
} from '../machines/faceScanner';
import {GlobalContext} from '../shared/GlobalContext';
import {selectIsActive} from '../machines/app';
import {RotatingIcon} from './RotatingIcon';
import {Theme} from './ui/styleUtils';
export const FaceScanner: React.FC<FaceScannerProps> = props => {
const {t} = useTranslation('FaceScanner');
const {appService} = useContext(GlobalContext);
const isActive = useSelector(appService, selectIsActive);
const machine = useRef(createFaceScannerMachine(props.vcImage));
const service = useInterpret(machine.current);
const whichCamera = useSelector(service, selectWhichCamera);
const isPermissionDenied = useSelector(service, selectIsPermissionDenied);
const isValid = useSelector(service, selectIsValid);
const isInvalid = useSelector(service, selectIsInvalid);
const isCheckingPermission = useSelector(service, selectIsCheckingPermission);
const isScanning = useSelector(service, selectIsScanning);
const isCapturing = useSelector(service, selectIsCapturing);
const isVerifying = useSelector(service, selectIsVerifying);
const setCameraRef = useCallback(
(node: Camera) => {
if (node != null && !isScanning) {
service.send(FaceScannerEvents.READY(node));
}
},
[isScanning],
);
useEffect(() => {
if (isValid) {
props.onValid();
} else if (isInvalid) {
props.onInvalid();
}
}, [isValid, isInvalid]);
useEffect(() => {
if (isActive) {
service.send(FaceScannerEvents.APP_FOCUSED());
}
}, [isActive]);
if (isCheckingPermission) {
return <Column></Column>;
} else if (isPermissionDenied) {
return (
<Column padding="24" fill align="space-between">
<Text align="center" color={Theme.Colors.errorMessage}>
{t('missingPermissionText')}
</Text>
<Button
title={t('allowCameraButton')}
onPress={() => service.send(FaceScannerEvents.OPEN_SETTINGS())}
/>
</Column>
);
}
return (
<View>
<View style={Theme.Styles.scannerContainer}>
<Camera
style={Theme.Styles.scanner}
type={whichCamera}
ref={setCameraRef}
/>
</View>
<Text
align="center"
weight="semibold"
style={Theme.TextStyles.base}
margin="50 57 0 57">
{t('imageCaptureGuide')}
</Text>
<Centered margin="24 0">
{isCapturing || isVerifying ? (
<RotatingIcon name="sync" size={64} />
) : (
<Row align="center" style={{marginTop: 42}}>
<Centered style={Theme.Styles.imageCaptureButton}>
<TouchableOpacity
onPress={() => service.send(FaceScannerEvents.CAPTURE())}>
<Image source={Theme.ImageCaptureButton} />
</TouchableOpacity>
<Text size="small" weight="semibold" margin="8">
{t('capture')}
</Text>
</Centered>
<Centered>
<TouchableOpacity
onPress={() => service.send(FaceScannerEvents.FLIP_CAMERA())}>
<Image
source={Theme.CameraFlipIcon}
style={Theme.Styles.cameraFlipIcon}
/>
</TouchableOpacity>
<Text size="smaller" weight="semibold" margin="8">
{t('flipCamera')}
</Text>
</Centered>
</Row>
)}
{/* TODO: remove warning when iOS SDK is ready */}
{Platform.OS === 'ios' && (
<Text size="smaller" color={Theme.Colors.textLabel} align="center">
(face-matching in iOS is mocked)
</Text>
)}
</Centered>
</View>
);
};
interface FaceScannerProps {
vcImage: string;
onValid: () => void;
onInvalid: () => void;
}