Skip to content

Commit

Permalink
Merge pull request Expensify#50770 from QichenZhu/fix/50083
Browse files Browse the repository at this point in the history
Fix errors after quickly tapping the shutter
  • Loading branch information
marcochavezf authored Oct 23, 2024
2 parents 41e8ef2 + 80bb24d commit ba29224
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/pages/iou/request/step/IOURequestStepScan/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ function IOURequestStepScan({
return;
}

setDidCapturePhoto(true);

camera?.current
?.takePhoto({
flash: flash && hasFlash ? 'on' : 'off',
Expand All @@ -490,26 +492,34 @@ function IOURequestStepScan({
const source = getPhotoSource(photo.path);
IOU.setMoneyRequestReceipt(transactionID, source, photo.path, !isEditing);

FileUtils.readFileAsync(source, photo.path, (file) => {
if (isEditing) {
updateScanAndNavigate(file, source);
return;
}
setDidCapturePhoto(true);
if (shouldSkipConfirmation) {
setFileResize(file);
setFileSource(source);
const gpsRequired = transaction?.amount === 0 && iouType !== CONST.IOU.TYPE.SPLIT && file;
if (gpsRequired) {
const shouldStartLocationPermissionFlow = IOUUtils.shouldStartLocationPermissionFlow();
if (shouldStartLocationPermissionFlow) {
setStartLocationPermissionFlow(true);
return;
FileUtils.readFileAsync(
source,
photo.path,
(file) => {
if (isEditing) {
updateScanAndNavigate(file, source);
return;
}
if (shouldSkipConfirmation) {
setFileResize(file);
setFileSource(source);
const gpsRequired = transaction?.amount === 0 && iouType !== CONST.IOU.TYPE.SPLIT && file;
if (gpsRequired) {
const shouldStartLocationPermissionFlow = IOUUtils.shouldStartLocationPermissionFlow();
if (shouldStartLocationPermissionFlow) {
setStartLocationPermissionFlow(true);
return;
}
}
}
}
navigateToConfirmationStep(file, source, false);
});
navigateToConfirmationStep(file, source, false);
},
() => {
setDidCapturePhoto(false);
showCameraAlert();
Log.warn('Error reading photo');
},
);
})
.catch((error: string) => {
setDidCapturePhoto(false);
Expand Down
4 changes: 4 additions & 0 deletions src/pages/iou/request/step/IOURequestStepScan/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ function IOURequestStepScan({

const imageBase64 = cameraRef.current.getScreenshot();

if (imageBase64 === null) {
return;
}

const filename = `receipt_${Date.now()}.png`;
const file = FileUtils.base64ToFile(imageBase64 ?? '', filename);
const source = URL.createObjectURL(file);
Expand Down

0 comments on commit ba29224

Please sign in to comment.