diff --git a/App.tsx b/App.tsx index 54b6e2e..42c16d8 100644 --- a/App.tsx +++ b/App.tsx @@ -5,11 +5,9 @@ import { Provider } from 'react-redux'; import QRScannerScreen from './screens/QRScannerScreen'; import HistoryScreen from './screens/HistoryScreen'; import EmailScreen from './screens/EmailScreen'; // Import the Email screen -import SettingsScreen from './screens/SettingsScreen'; // Import the Settings screen import { QRCodeContext } from './types'; import CustomTabBar from './components/CustomTabBar'; import store from './store'; - import { withAuthenticator } from '@aws-amplify/ui-react-native'; import { Amplify } from 'aws-amplify'; import config from './src/aws-exports'; @@ -21,7 +19,6 @@ Amplify.configure(config); const Tab = createBottomTabNavigator(); - const App: React.FC = () => { const [scannedData, setScannedData] = useState(''); diff --git a/components/CustomTabBar.tsx b/components/CustomTabBar.tsx index febad38..4f7cc9f 100644 --- a/components/CustomTabBar.tsx +++ b/components/CustomTabBar.tsx @@ -15,9 +15,7 @@ const CustomTabBar: React.FC = ({ state, descriptors, navigat {state.routes.map((route, index) => { const { options } = descriptors[route.key]; const label = - route.name === 'Email' - ? 'Gmail' - : options.tabBarLabel !== undefined + options.tabBarLabel !== undefined ? options.tabBarLabel : options.title !== undefined ? options.title diff --git a/package-lock.json b/package-lock.json index 71ef542..34eb7af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "react-native-gesture-handler": "^2.17.1", "react-native-get-random-values": "^1.11.0", "react-native-qrcode-svg": "^6.3.1", + "react-native-reanimated": "^3.14.0", "react-native-safe-area-context": "^4.10.4", "react-native-screens": "3.31.1", "react-native-svg": "15.2.0", @@ -2977,7 +2978,6 @@ "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.24.7.tgz", "integrity": "sha512-Ts7xQVk1OEocqzm8rHMXHlxvsfZ0cEF2yomUqpKENHWMF4zKk175Y4q8H5knJes6PgYad50uuRmt3UJuhBw8pQ==", - "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.24.7", "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3" @@ -3058,7 +3058,6 @@ "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-optional-chaining/-/plugin-transform-optional-chaining-7.24.7.tgz", "integrity": "sha512-tK+0N9yd4j+x/4hxF3F0e0fu/VdcxU18y5SevtyM/PCFlQvXbR0Zmlo2eBrKtVipGNFzpq56o8WsIIKcJFUCRQ==", - "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.24.7", "@babel/helper-skip-transparent-expression-wrappers": "^7.24.7", @@ -3320,7 +3319,6 @@ "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.24.7.tgz", "integrity": "sha512-AfDTQmClklHCOLxtGoP7HkeMw56k1/bTQjwsfhL6pppo/M4TOBSq+jjBUBLmV/4oeFg4GWMavIl44ZeCtmmZTw==", - "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.24.7" }, @@ -16369,7 +16367,6 @@ "version": "3.14.0", "resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-3.14.0.tgz", "integrity": "sha512-TAxLtCfRyC/nOLeWoX/8MhdIF+Fi1e1NbLhIgEm5Kv9/gioAwSNaqLUYxjIClU1RaLwSTE8iaiHNVhTU4TS9DA==", - "peer": true, "dependencies": { "@babel/plugin-transform-arrow-functions": "^7.0.0-0", "@babel/plugin-transform-nullish-coalescing-operator": "^7.0.0-0", diff --git a/package.json b/package.json index 36068f7..e577ddb 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "react-native-gesture-handler": "^2.17.1", "react-native-get-random-values": "^1.11.0", "react-native-qrcode-svg": "^6.3.1", + "react-native-reanimated": "^3.14.0", "react-native-safe-area-context": "^4.10.4", "react-native-screens": "3.31.1", "react-native-svg": "15.2.0", diff --git a/screens/QRScannerScreen.tsx b/screens/QRScannerScreen.tsx index 3987793..10cff52 100644 --- a/screens/QRScannerScreen.tsx +++ b/screens/QRScannerScreen.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useContext, useCallback } from 'react'; -import { View, Text, StyleSheet, ActivityIndicator, TouchableOpacity, Alert, Image } from 'react-native'; +import { View, Text, StyleSheet, ActivityIndicator, TouchableOpacity, Alert, Modal } from 'react-native'; import { Camera, CameraView, scanFromURLAsync } from 'expo-camera'; import { QRCodeContext } from '../types'; import axios from 'axios'; // For URL calls @@ -11,8 +11,8 @@ import { useDispatch } from 'react-redux'; import { RootState, AppDispatch } from '../store'; import { addQRCode } from '../reducers/qrCodesReducer'; // Assuming you have actions defined for Redux import { detectQRCodeType, verifyURL, checkRedirects } from '../api/qrCodeAPI'; // Import utility functions +import SettingsScreen from './SettingsScreen'; // Import the Settings screen -// Main Function const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanData }) => { const navigation = useNavigation(); // call Navigation bar const dispatch = useDispatch(); // Use dispatch for Redux actions @@ -28,6 +28,9 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat const [enableTorch, setEnableTorch] = useState(false); // State for torch const [cameraVisible, setCameraVisible] = useState(true); // State to control camera visibility + // State to control the visibility of the modal + const [isSettingsModalVisible, setIsSettingsModalVisible] = useState(false); + // Add state variables for scan results const [secureConnection, setSecureConnection] = useState(null); const [virusTotalCheck, setVirusTotalCheck] = useState(null); @@ -53,17 +56,6 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat console.log("Scan data cleared"); }; - useEffect(() => { - navigation.setOptions({ - headerRight: () => ( - navigation.navigate('Settings')}> - - - ), - }); - }, [navigation]); - - // Handle QR Code Payload const handlePayload = async (payload: string) => { setScanned(true); console.log("Scanning Completed. Payload is:", payload); @@ -95,7 +87,6 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat console.log("QR code data added to history"); }; - // Send QR Code Data to Backend Server const sendToAPIServer = async (payload: string): Promise => { console.log('Sending QR code data to backend:', payload); @@ -115,19 +106,16 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat } }; - // Toggle Torch (Flashlight) const toggleTorch = () => { setEnableTorch((prev) => !prev); console.log("Torch toggled:", enableTorch ? "off" : "on"); }; - // Handle Test Scan const handleTestScan = () => { handlePayload('TEST123'); console.log("Test scan executed"); }; - // Read QR Code from Image const readQRFromImage = async () => { clearScanDataInternal(); console.log("Reading QR code from image"); @@ -143,11 +131,9 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat const scannedResult = await scanFromURLAsync(result.assets[0].uri); if (scannedResult && scannedResult[0] && scannedResult[0].data) { handlePayload(scannedResult[0].data); - // Not sure why scannedResult.data is undefined but access as array work, KIV console.log('QR code data from image:', scannedResult[0].data); } else { setScannedData("No QR Code Found"); - //setTimeout(() => setScannedData(""), 4000); console.log("No QR code found in the selected image"); Alert.alert('No QR code found in the selected image.'); } @@ -158,7 +144,6 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat } }; - // Clear scan data when screen is focused useFocusEffect( useCallback(() => { setCameraVisible(true); @@ -206,9 +191,6 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat - {/* - - */} @@ -228,6 +210,28 @@ const QRScannerScreen: React.FC<{ clearScanData: () => void }> = ({ clearScanDat /> )} + + {/* Settings Icon */} + setIsSettingsModalVisible(true)} style={styles.settingsButton}> + + + + {/* Settings Modal */} + setIsSettingsModalVisible(false)} + > + + + + setIsSettingsModalVisible(false)} style={styles.closeButton}> + Close + + + + ); }; @@ -275,14 +279,6 @@ const styles = StyleSheet.create({ backgroundColor: '#000', borderRadius: 25, }, - testButton: { - position: 'absolute', - bottom: 1, - alignSelf: 'stretch', - backgroundColor: '#000', - padding: 10, - borderRadius: 5, - }, galleryButton: { position: 'absolute', bottom: 20, @@ -307,6 +303,36 @@ const styles = StyleSheet.create({ marginVertical: 10, color: 'black', }, + settingsButton: { + position: 'absolute', + top: 40, + right: 20, + zIndex: 2, + }, + modalContainer: { + flex: 1, + justifyContent: 'center', + height: '90%', + alignItems: 'center', + backgroundColor: 'rgba(0, 0, 0, 0.5)', + }, + modalContent: { + width: '100%', // Adjust the width to cover more space + height: '90%', // Adjust the height to cover more space + backgroundColor: 'white', + padding: 20, // Reduce the padding + borderRadius: 10, + alignItems: 'center', + }, + closeButton: { + marginTop: 10, + padding: 10, + backgroundColor: '#ff69b4', + borderRadius: 5, + }, + closeButtonText: { + color: 'white', + fontWeight: 'bold', + }, }); - export default QRScannerScreen; diff --git a/screens/SettingsScreen.tsx b/screens/SettingsScreen.tsx index 82923e6..885b120 100644 --- a/screens/SettingsScreen.tsx +++ b/screens/SettingsScreen.tsx @@ -1,142 +1,199 @@ -import React from 'react'; -import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; -import { BottomTabBarProps } from '@react-navigation/bottom-tabs'; -import { Ionicons, MaterialIcons } from '@expo/vector-icons'; +import { View, Text, StyleSheet, TouchableOpacity, Linking, Button } from 'react-native'; +import { useAuthenticator } from '@aws-amplify/ui-react-native'; +import useFetchUserAttributes from '../hooks/useFetchUserAttributes'; +import { fetchAuthSession, getCurrentUser, signInWithRedirect } from 'aws-amplify/auth'; +import { useEffect, useState } from 'react'; +import { Buffer } from 'buffer'; -// Define custom props for CustomTabBar -interface CustomTabBarProps extends BottomTabBarProps { - clearScanData: () => void; + +function SignOutButton() { + const { signOut } = useAuthenticator(); + return