From 7618532d7ad73034ff0fc5f8cd88f6a5fcd96019 Mon Sep 17 00:00:00 2001 From: Isky Date: Thu, 15 Aug 2024 16:22:13 +0800 Subject: [PATCH] Fixed ClearScanData not being called when closing ScannedData Modal --- App.tsx | 1 + screens/QRScannerScreen.tsx | 62 +++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/App.tsx b/App.tsx index 97c506b..3a38e52 100644 --- a/App.tsx +++ b/App.tsx @@ -26,6 +26,7 @@ const App: React.FC = () => { const clearScanData = () => { setScannedData(''); + console.log('ClearScanedDATa'); }; useEffect(() => { diff --git a/screens/QRScannerScreen.tsx b/screens/QRScannerScreen.tsx index 6b9c33a..f8f190b 100644 --- a/screens/QRScannerScreen.tsx +++ b/screens/QRScannerScreen.tsx @@ -11,7 +11,7 @@ import NetInfo from '@react-native-community/netinfo'; const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); -const QRScannerScreen: React.FC = () => { +const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanData }) => { // State management const [isSettingsModalVisible, setIsSettingsModalVisible] = useState(false); const [enableTorch, setEnableTorch] = useState(false); @@ -79,7 +79,14 @@ const QRScannerScreen: React.FC = () => { setIsScannedDataBoxVisible(false); }); }; - + const clearSelectedQrCodeData = () => { + console.log("!!!!!clearSelectedQrCodeData"); + setQRCodeId(null); + hideScannedDataBox(); + setScanned(false); // Reset the scanned state so the camera can scan again + clearScanData(); // Call the clearScanData passed from App.tsx + }; + // Show an offline banner const showBanner = () => { Animated.timing(bannerOpacity, { @@ -174,12 +181,13 @@ const QRScannerScreen: React.FC = () => { {device && ( + style={StyleSheet.absoluteFill} + device={device} + isActive={!isSettingsModalVisible && !isScannedDataBoxVisible} // Disable the camera when settings modal or ScannedDataBox is open + torch={enableTorch ? 'on' : 'off'} + codeScanner={codeScanner} + /> + )} {/* Torch Button */} @@ -210,24 +218,26 @@ const QRScannerScreen: React.FC = () => { {/* Scanned Data Box as a modal with sliding animation */} - - - - { - setScanned(false); - hideScannedDataBox(); - }} - /> - - - + + + + + + + + {/* Settings Icon */} setIsSettingsModalVisible(true)} style={styles.settingsButton}>