Skip to content

Commit

Permalink
[INJIMOB-1603]: fix camera blank screen issue (#1561)
Browse files Browse the repository at this point in the history
Signed-off-by: adityankannan-tw <[email protected]>
Co-authored-by: adityankannan-tw <[email protected]>
  • Loading branch information
adityankannan-tw and Adityankannan authored Jul 15, 2024
1 parent 0b11e0a commit 7a3c53e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
4 changes: 3 additions & 1 deletion components/FaceScanner/FaceCompare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import testIDProps from '../../shared/commonUtil';
const FaceCompare: React.FC<FaceCompareProps> = ({
whichCamera,
setCameraRef,
flipCamera,
isCapturing,
isVerifying,
service,
Expand Down Expand Up @@ -53,7 +54,7 @@ const FaceCompare: React.FC<FaceCompareProps> = ({
</Text>
</Centered>
<Centered>
<TouchableOpacity onPress={() => service.send('FLIP_CAMERA')}>
<TouchableOpacity onPress={flipCamera}>
{SvgImage.FlipCameraIcon()}
</TouchableOpacity>
<Text
Expand All @@ -74,6 +75,7 @@ export default FaceCompare;
interface FaceCompareProps {
whichCamera: CameraType;
setCameraRef: (node: Camera) => void;
flipCamera: () => void;
isCapturing: boolean;
isVerifying: boolean;
service: any;
Expand Down
16 changes: 12 additions & 4 deletions components/FaceScanner/FaceScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
selectIsValid,
selectIsPermissionDenied,
selectIsScanning,
selectWhichCamera,
createFaceScannerMachine,
selectIsInvalid,
selectIsCapturing,
Expand Down Expand Up @@ -45,7 +44,7 @@ export const FaceScanner: React.FC<FaceScannerProps> = props => {
const machine = useRef(createFaceScannerMachine(props.vcImage));
const service = useInterpret(machine.current);

const whichCamera = useSelector(service, selectWhichCamera);
const [cameraType, setCameraType] = useState(Camera.Constants.Type.front);
const cameraRef = useSelector(service, selectCameraRef);

const isPermissionDenied = useSelector(service, selectIsPermissionDenied);
Expand Down Expand Up @@ -77,6 +76,14 @@ export const FaceScanner: React.FC<FaceScannerProps> = props => {
[isScanning],
);

const flipCamera = () => {
setCameraType(prevType =>
prevType === Camera.Constants.Type.front
? Camera.Constants.Type.back
: Camera.Constants.Type.front,
);
};

function handleOnCancel() {
props.onCancel();
}
Expand Down Expand Up @@ -177,7 +184,7 @@ export const FaceScanner: React.FC<FaceScannerProps> = props => {
<LivenessDetection
screenColor={screenColor}
infoText={infoText}
whichCamera={whichCamera}
whichCamera={cameraType}
setCameraRef={setCameraRef}
handleFacesDetected={handleFacesDetected}
faceDetectorConfig={faceDetectorConfig}
Expand All @@ -190,8 +197,9 @@ export const FaceScanner: React.FC<FaceScannerProps> = props => {
} else {
return (
<FaceCompare
whichCamera={whichCamera}
whichCamera={cameraType}
setCameraRef={setCameraRef}
flipCamera={flipCamera}
isCapturing={isCapturing}
isVerifying={isVerifying}
service={service}
Expand Down
23 changes: 1 addition & 22 deletions machines/faceScanner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Camera, CameraCapturedPicture, PermissionResponse} from 'expo-camera';
import {CameraType, Face, ImageType} from 'expo-camera/build/Camera.types';
import {ImageType} from 'expo-camera/build/Camera.types';
import {Linking} from 'react-native';
import {assign, EventFrom, StateFrom} from 'xstate';
import {createModel} from 'xstate/lib/model';
Expand All @@ -13,14 +13,12 @@ const model = createModel(
minWidth: 280,
minHeight: 280,
},
whichCamera: Camera.Constants.Type.front as CameraType,
capturedImage: {} as CameraCapturedPicture,
captureError: '',
},
{
events: {
READY: (cameraRef: Camera) => ({cameraRef}),
FLIP_CAMERA: () => ({}),
CAPTURE: () => ({}),
DENIED: (response: PermissionResponse) => ({response}),
GRANTED: () => ({}),
Expand All @@ -32,11 +30,6 @@ const model = createModel(

export const FaceScannerEvents = model.events;

export interface FaceScanResult {
metadata: Face;
image: CameraCapturedPicture;
}

export const createFaceScannerMachine = (vcImage: string) =>
/** @xstate-layout N4IgpgJg5mDOIC5QDMCGBjMBldqB2eYATgHQCWeZALiegBZjoDWFUACsQLZmyxkD2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dM7gRNYEW3pGNDRjqsB6gam0EgdzJOcBLkeSE0odIO-go3B-lFTorqWCYc2RA4yxBAY6PvXsgOk20MIjdCY2TJNDPIrN4TBpB0puOY3P4YRlCcU+ZF8+JjMzbYjhcjW7TmHyQTCjYM2yehMojjpKIKxGSvEZgEj8FQPF7SJgFA5l2aonK4Rgk43mmAF2awmVmGVa5zpwjbUUPvq6sDTY9rZVhoH5UbRVOHYpXRNmZgebMXOvXhTacKgMDUqgChUFq6quxaolA+0YoxAjbgjrYRjCuhUlmO0Osophzq1usb3KvHLRtKYIODsLoGi5O4w6Ms9rwYYyxGL0ha1XEQA */
model.createMachine(
Expand Down Expand Up @@ -118,9 +111,6 @@ export const createFaceScannerMachine = (vcImage: string) =>
CAPTURE: {
target: 'capturing',
},
FLIP_CAMERA: {
actions: 'flipWhichCamera',
},
},
},
capturing: {
Expand Down Expand Up @@ -175,13 +165,6 @@ export const createFaceScannerMachine = (vcImage: string) =>
capturedImage: (_context, event) => event.data,
}),

flipWhichCamera: model.assign({
whichCamera: context =>
context.whichCamera === Camera.Constants.Type.front
? Camera.Constants.Type.back
: Camera.Constants.Type.front,
}),

setCaptureError: assign({
captureError: '',
}),
Expand Down Expand Up @@ -236,10 +219,6 @@ export const createFaceScannerMachine = (vcImage: string) =>

type State = StateFrom<ReturnType<typeof createFaceScannerMachine>>;

export function selectWhichCamera(state: State) {
return state.context.whichCamera;
}

export function selectCameraRef(state: State) {
return state.context.cameraRef;
}
Expand Down

0 comments on commit 7a3c53e

Please sign in to comment.