Skip to content

Commit f332cfd

Browse files
authored
Merge pull request #85642 from samranahm/83380/IOURequestStepScan-phase-4
[No QA] refactor: `IOURequestStepScan` clean-up, phase 4: fix react-hooks/exhaustive-deps warning
2 parents 4343ec1 + a9fbe1e commit f332cfd

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

src/pages/iou/request/step/IOURequestStepScan/index.native.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ function IOURequestStepScan({
368368

369369
const path = getReceiptsUploadFolderPath();
370370

371-
camera?.current
372-
?.takePhoto({
371+
camera.current
372+
.takePhoto({
373373
flash: flash && hasFlash ? 'on' : 'off',
374374
enableShutterSound: !isPlatformMuted,
375375
path,
@@ -422,7 +422,6 @@ function IOURequestStepScan({
422422
showCameraAlert();
423423
Log.warn('Error taking photo', error);
424424
});
425-
// eslint-disable-next-line react-hooks/exhaustive-deps -- askForPermissions is not needed
426425
}, [
427426
cameraPermissionStatus,
428427
isMultiScanEnabled,
@@ -437,9 +436,11 @@ function IOURequestStepScan({
437436
initialTransactionID,
438437
isEditing,
439438
receiptFiles,
439+
setReceiptFiles,
440440
submitReceipts,
441441
updateScanAndNavigate,
442442
askForPermissions,
443+
maybeCancelShutterSpan,
443444
]);
444445

445446
const cameraLoadingReasonAttributes: SkeletonSpanReasonAttributes = {
@@ -522,7 +523,7 @@ function IOURequestStepScan({
522523
<Animated.View style={[styles.cameraFocusIndicator, cameraFocusIndicatorAnimatedStyle]} />
523524
<Animated.View
524525
pointerEvents="none"
525-
style={[StyleSheet.absoluteFillObject, StyleUtils.getBackgroundColorStyle(theme.appBG), blinkStyle, styles.zIndex10]}
526+
style={[StyleSheet.absoluteFill, StyleUtils.getBackgroundColorStyle(theme.appBG), blinkStyle, styles.zIndex10]}
526527
/>
527528
</View>
528529
</GestureDetector>

src/pages/iou/request/step/IOURequestStepScan/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback, useEffect} from 'react';
1+
import React, {useCallback, useEffect, useRef} from 'react';
22
import {RESULTS} from 'react-native-permissions';
33
import LocationPermissionModal from '@components/LocationPermissionModal';
44
import withCurrentUserPersonalDetails from '@components/withCurrentUserPersonalDetails';
@@ -95,10 +95,17 @@ function IOURequestStepScan({
9595
onLayout?.(setTestReceiptAndNavigate);
9696
}, [onLayout, setTestReceiptAndNavigate]);
9797

98-
// 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.
98+
const hasValidatedInitialScanFiles = useRef(false);
99+
100+
// 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.
99101
// 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
100102
// 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.
101103
useEffect(() => {
104+
if (hasValidatedInitialScanFiles.current) {
105+
return;
106+
}
107+
hasValidatedInitialScanFiles.current = true;
108+
102109
let isAllScanFilesCanBeRead = true;
103110

104111
Promise.all(
@@ -124,9 +131,7 @@ function IOURequestStepScan({
124131
removeTransactionReceipt(CONST.IOU.OPTIMISTIC_TRANSACTION_ID);
125132
removeDraftTransactionsByIDs(draftTransactionIDs, true);
126133
});
127-
// We want this hook to run on mounting only
128-
// eslint-disable-next-line react-hooks/exhaustive-deps
129-
}, []);
134+
}, [setIsMultiScanEnabled, transactions, draftTransactionIDs]);
130135

131136
// this effect will pre-fetch location in web if the location permission is already granted to optimize the flow
132137
useEffect(() => {

0 commit comments

Comments
 (0)