diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx index 00ddc69ff1c83..7c1b645f0fc0f 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.tsx @@ -422,7 +422,6 @@ function IOURequestStepScan({ showCameraAlert(); Log.warn('Error taking photo', error); }); - // eslint-disable-next-line react-hooks/exhaustive-deps -- askForPermissions is not needed }, [ cameraPermissionStatus, isMultiScanEnabled, @@ -437,9 +436,11 @@ function IOURequestStepScan({ initialTransactionID, isEditing, receiptFiles, + setReceiptFiles, submitReceipts, updateScanAndNavigate, askForPermissions, + maybeCancelShutterSpan, ]); const cameraLoadingReasonAttributes: SkeletonSpanReasonAttributes = { diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.tsx b/src/pages/iou/request/step/IOURequestStepScan/index.tsx index 2824febeae81a..3891b287019fb 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.tsx +++ b/src/pages/iou/request/step/IOURequestStepScan/index.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect} from 'react'; +import React, {useCallback, useEffect, useRef} from 'react'; import {RESULTS} from 'react-native-permissions'; import LocationPermissionModal from '@components/LocationPermissionModal'; import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails'; @@ -93,10 +93,17 @@ function IOURequestStepScan({ onLayout?.(setTestReceiptAndNavigate); }, [onLayout, setTestReceiptAndNavigate]); - // When the component mounts, if there is a receipt, see if the image can be read from the disk. If not, make the user star scanning flow from scratch. + const hasValidatedInitialScanFiles = useRef(false); + + // When the component mounts, if there is a receipt, see if the image can be read from the disk. If not, make the user start scanning flow from scratch. // This is because until the request is saved, the receipt file is only stored in the browsers memory as a blob:// and if the browser is refreshed, then // the image ceases to exist. The best way for the user to recover from this is to start over from the start of the request process. useEffect(() => { + if (hasValidatedInitialScanFiles.current) { + return; + } + hasValidatedInitialScanFiles.current = true; + let isAllScanFilesCanBeRead = true; Promise.all( @@ -122,9 +129,7 @@ function IOURequestStepScan({ removeTransactionReceipt(CONST.IOU.OPTIMISTIC_TRANSACTION_ID); removeDraftTransactions(true); }); - // We want this hook to run on mounting only - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [setIsMultiScanEnabled, transactions]); // this effect will pre-fetch location in web if the location permission is already granted to optimize the flow useEffect(() => {