From f44142deaae113814ef6792086b1e9a701abdb07 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Wed, 13 Mar 2024 23:36:20 +0300 Subject: [PATCH 1/6] lock capturePhoto --- .../step/IOURequestStepScan/index.native.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.js b/src/pages/iou/request/step/IOURequestStepScan/index.native.js index 338444d473c6..eec79d969ce5 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.js +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.js @@ -30,6 +30,7 @@ import reportPropTypes from '@pages/reportPropTypes'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; +import {useNavigation} from "@react-navigation/native"; import * as CameraPermission from './CameraPermission'; import NavigationAwareCamera from './NavigationAwareCamera'; @@ -61,12 +62,24 @@ function IOURequestStepScan({ const styles = useThemeStyles(); const devices = useCameraDevices('wide-angle-camera'); const device = devices.back; + const navigation = useNavigation(); const camera = useRef(null); const [flash, setFlash] = useState(false); const [cameraPermissionStatus, setCameraPermissionStatus] = useState(undefined); const askedForPermission = useRef(false); + const [didCapturePhoto, setDidCapturePhoto] = useState(false); + useEffect(() => { + const unsubscribe = navigation.addListener('focus', () => { + setDidCapturePhoto(false); + }); + + return () => { + unsubscribe(); + } + }, [navigation]); + const {translate} = useLocalize(); const askForPermissions = (showPermissionsAlert = true) => { @@ -238,6 +251,10 @@ function IOURequestStepScan({ return; } + if (didCapturePhoto) { + return; + } + return camera.current .takePhoto({ qualityPrioritization: 'speed', @@ -255,13 +272,15 @@ function IOURequestStepScan({ return; } + setDidCapturePhoto(true); navigateToConfirmationStep(); }) .catch((error) => { + setDidCapturePhoto(false); showCameraAlert(); Log.warn('Error taking photo', error); }); - }, [flash, action, translate, transactionID, updateScanAndNavigate, navigateToConfirmationStep, cameraPermissionStatus]); + }, [flash, action, translate, transactionID, updateScanAndNavigate, navigateToConfirmationStep, cameraPermissionStatus, didCapturePhoto]); // Wait for camera permission status to render if (cameraPermissionStatus == null) { From 0b0847d863c8e2e43ed4d564f197f13080b07620 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Thu, 14 Mar 2024 18:37:46 +0300 Subject: [PATCH 2/6] prettier --- src/pages/iou/request/step/IOURequestStepScan/index.native.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.js b/src/pages/iou/request/step/IOURequestStepScan/index.native.js index eec79d969ce5..22b54b1247ef 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.js +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.js @@ -1,3 +1,4 @@ +import {useNavigation} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import React, {useCallback, useEffect, useRef, useState} from 'react'; import {ActivityIndicator, Alert, AppState, View} from 'react-native'; @@ -30,7 +31,6 @@ import reportPropTypes from '@pages/reportPropTypes'; import * as IOU from '@userActions/IOU'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -import {useNavigation} from "@react-navigation/native"; import * as CameraPermission from './CameraPermission'; import NavigationAwareCamera from './NavigationAwareCamera'; @@ -77,7 +77,7 @@ function IOURequestStepScan({ return () => { unsubscribe(); - } + }; }, [navigation]); const {translate} = useLocalize(); From 2eaad6f31c061b53af666a2f7f4951063181966a Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Mon, 18 Mar 2024 17:27:08 +0300 Subject: [PATCH 3/6] useFocusEffect --- .../step/IOURequestStepScan/index.native.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.js b/src/pages/iou/request/step/IOURequestStepScan/index.native.js index 22b54b1247ef..b52a71e30de6 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.js +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.js @@ -1,4 +1,4 @@ -import {useNavigation} from '@react-navigation/native'; +import {useFocusEffect} from '@react-navigation/native'; import lodashGet from 'lodash/get'; import React, {useCallback, useEffect, useRef, useState} from 'react'; import {ActivityIndicator, Alert, AppState, View} from 'react-native'; @@ -62,7 +62,6 @@ function IOURequestStepScan({ const styles = useThemeStyles(); const devices = useCameraDevices('wide-angle-camera'); const device = devices.back; - const navigation = useNavigation(); const camera = useRef(null); const [flash, setFlash] = useState(false); @@ -70,15 +69,11 @@ function IOURequestStepScan({ const askedForPermission = useRef(false); const [didCapturePhoto, setDidCapturePhoto] = useState(false); - useEffect(() => { - const unsubscribe = navigation.addListener('focus', () => { + useFocusEffect( + useCallback(() => { setDidCapturePhoto(false); - }); - - return () => { - unsubscribe(); - }; - }, [navigation]); + }, []), + ); const {translate} = useLocalize(); From 1075405a20179d457ed544f11fe5480bd85d0629 Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Wed, 20 Mar 2024 17:27:30 +0300 Subject: [PATCH 4/6] cleanup --- .../iou/request/step/IOURequestStepScan/index.native.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.js b/src/pages/iou/request/step/IOURequestStepScan/index.native.js index 4503cdf10c61..d02d4874b67d 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.js +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.js @@ -67,13 +67,7 @@ function IOURequestStepScan({ const [flash, setFlash] = useState(false); const [cameraPermissionStatus, setCameraPermissionStatus] = useState(undefined); const askedForPermission = useRef(false); - const [didCapturePhoto, setDidCapturePhoto] = useState(false); - useFocusEffect( - useCallback(() => { - setDidCapturePhoto(false); - }, []), - ); const {translate} = useLocalize(); @@ -130,6 +124,8 @@ function IOURequestStepScan({ useFocusEffect( useCallback(() => { + setDidCapturePhoto(false); + const refreshCameraPermissionStatus = (shouldAskForPermission = false) => { CameraPermission.getCameraPermissionStatus() .then((res) => { From 80d2d261c2080386d6f84431aeaf24c7561b5d8a Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Mon, 1 Apr 2024 16:19:58 +0300 Subject: [PATCH 5/6] cleanup --- src/pages/iou/request/step/IOURequestStepScan/index.native.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.js b/src/pages/iou/request/step/IOURequestStepScan/index.native.js index 2501c0494287..17c834a7909f 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.js +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.js @@ -127,7 +127,6 @@ function IOURequestStepScan({ useCallback(() => { setDidCapturePhoto(false); const refreshCameraPermissionStatus = () => { - const refreshCameraPermissionStatus = (shouldAskForPermission = false) => { CameraPermission.getCameraPermissionStatus() .then(setCameraPermissionStatus) .catch(() => setCameraPermissionStatus(RESULTS.UNAVAILABLE)); From 8f820e1695555b53b3cc7b3205d2c5f5aaffa30f Mon Sep 17 00:00:00 2001 From: Abdullah Alsigar Date: Tue, 2 Apr 2024 16:12:41 +0300 Subject: [PATCH 6/6] cleanup --- src/pages/iou/request/step/IOURequestStepScan/index.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepScan/index.native.js b/src/pages/iou/request/step/IOURequestStepScan/index.native.js index b9c80be5a78f..738fbb00167d 100644 --- a/src/pages/iou/request/step/IOURequestStepScan/index.native.js +++ b/src/pages/iou/request/step/IOURequestStepScan/index.native.js @@ -5,7 +5,7 @@ import {ActivityIndicator, Alert, AppState, InteractionManager, View} from 'reac import {Gesture, GestureDetector} from 'react-native-gesture-handler'; import {RESULTS} from 'react-native-permissions'; import Animated, {runOnJS, useAnimatedStyle, useSharedValue, withDelay, withSequence, withSpring, withTiming} from 'react-native-reanimated'; -import {useCameraDevices} from 'react-native-vision-camera'; +import {useCameraDevice} from 'react-native-vision-camera'; import Hand from '@assets/images/hand.svg'; import Shutter from '@assets/images/shutter.svg'; import AttachmentPicker from '@components/AttachmentPicker';