updates UI and testing Hisory page
This commit is contained in:
132
App.tsx
132
App.tsx
@@ -1,13 +1,17 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, createContext, useContext } from 'react';
|
||||||
import { Text, View, StyleSheet, Button, ActivityIndicator } from 'react-native';
|
import { Text, View, StyleSheet, ActivityIndicator, TouchableOpacity, FlatList } from 'react-native';
|
||||||
import { NavigationContainer } from '@react-navigation/native';
|
import { NavigationContainer } from '@react-navigation/native';
|
||||||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||||
import { CameraView, Camera } from 'expo-camera';
|
import { CameraView, Camera } from 'expo-camera';
|
||||||
import { Ionicons } from '@expo/vector-icons';
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
|
|
||||||
|
// Create a Context for QR code data
|
||||||
|
const QRCodeContext = createContext();
|
||||||
|
|
||||||
const Tab = createBottomTabNavigator();
|
const Tab = createBottomTabNavigator();
|
||||||
|
|
||||||
function QRScannerScreen() {
|
function QRScannerScreen() {
|
||||||
|
const { qrCodes, setQrCodes } = useContext(QRCodeContext); // Access context
|
||||||
const [hasPermission, setHasPermission] = useState(null);
|
const [hasPermission, setHasPermission] = useState(null);
|
||||||
const [scanned, setScanned] = useState(false);
|
const [scanned, setScanned] = useState(false);
|
||||||
const [showSplash, setShowSplash] = useState(true);
|
const [showSplash, setShowSplash] = useState(true);
|
||||||
@@ -17,16 +21,18 @@ function QRScannerScreen() {
|
|||||||
const initializeApp = async () => {
|
const initializeApp = async () => {
|
||||||
const { status } = await Camera.requestCameraPermissionsAsync();
|
const { status } = await Camera.requestCameraPermissionsAsync();
|
||||||
setHasPermission(status === 'granted');
|
setHasPermission(status === 'granted');
|
||||||
setShowSplash(false);
|
setShowSplash(false); // Hide splash screen after initializing
|
||||||
};
|
};
|
||||||
|
|
||||||
initializeApp();
|
initializeApp();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleBarCodeScanned = ({ type, data }) => {
|
const handleBarCodeScanned = ({ type, data }) => {
|
||||||
setScanned(true);
|
setScanned(true); // Mark as scanned
|
||||||
setScannedData(`Type: ${type}\nData: ${data}`);
|
const newScannedData = `Type: ${type}\nData: ${data}`;
|
||||||
alert(`Bar code with type ${type} and data ${data} has been scanned!`);
|
setScannedData(newScannedData); // Save scanned data
|
||||||
|
setQrCodes([...qrCodes, newScannedData]); // Add scanned data to history
|
||||||
|
alert(`Bar code with type ${type} and data ${data} has been scanned!`); // Show an alert
|
||||||
};
|
};
|
||||||
|
|
||||||
if (showSplash) {
|
if (showSplash) {
|
||||||
@@ -40,31 +46,43 @@ function QRScannerScreen() {
|
|||||||
if (hasPermission === null) {
|
if (hasPermission === null) {
|
||||||
return <Text>Requesting for camera permission</Text>;
|
return <Text>Requesting for camera permission</Text>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPermission === false) {
|
if (hasPermission === false) {
|
||||||
return <Text>No access to camera</Text>;
|
return <Text>No access to camera</Text>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
{/* Header banner */}
|
||||||
<View style={styles.banner}>
|
<View style={styles.banner}>
|
||||||
<Text style={styles.headerText}>SafeQR</Text>
|
<Text style={styles.headerText}>SafeQR</Text>
|
||||||
</View>
|
</View>
|
||||||
|
{/* Welcome message */}
|
||||||
<Text style={styles.welcomeText}>Welcome to SafeQR code Scanner</Text>
|
<Text style={styles.welcomeText}>Welcome to SafeQR code Scanner</Text>
|
||||||
|
{/* Camera view container */}
|
||||||
<View style={styles.cameraContainer}>
|
<View style={styles.cameraContainer}>
|
||||||
<CameraView
|
<CameraView
|
||||||
onBarcodeScanned={scanned ? undefined : handleBarCodeScanned}
|
onBarcodeScanned={scanned ? undefined : handleBarCodeScanned} // Disable scanner if already scanned
|
||||||
barcodeScannerSettings={{ barcodeTypes: ['qr', 'pdf417'] }}
|
barcodeScannerSettings={{ barcodeTypes: ['qr', 'pdf417'] }} // Scanner settings
|
||||||
style={styles.camera}
|
style={styles.camera} // Apply styles
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{/* Display scanned data */}
|
||||||
{scannedData !== '' && (
|
{scannedData !== '' && (
|
||||||
<View style={styles.dataBox}>
|
<View style={styles.dataBox}>
|
||||||
<Text style={styles.dataText}>{scannedData}</Text>
|
<Text style={styles.dataText}>{scannedData}</Text>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Button to scan again */}
|
||||||
{scanned && (
|
{scanned && (
|
||||||
<Button title={"Tap to Scan Again"} onPress={() => setScanned(false)} />
|
<TouchableOpacity style={styles.button} onPress={() => setScanned(false)}>
|
||||||
|
<Text style={styles.buttonText}>Tap to Scan Again</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Menu (Placeholder for additional menu items) */}
|
||||||
<View style={styles.menu}>
|
<View style={styles.menu}>
|
||||||
{/* Your existing menu items */}
|
{/* Your existing menu items */}
|
||||||
</View>
|
</View>
|
||||||
@@ -73,9 +91,20 @@ function QRScannerScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function HistoryScreen() {
|
function HistoryScreen() {
|
||||||
|
const { qrCodes } = useContext(QRCodeContext); // Access context
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<Text style={styles.welcomeText}>History Screen</Text>
|
<Text style={styles.welcomeText}>History Screen</Text>
|
||||||
|
<FlatList
|
||||||
|
data={qrCodes}
|
||||||
|
renderItem={({ item }) => (
|
||||||
|
<View style={styles.dataBox}>
|
||||||
|
<Text style={styles.dataText}>{item}</Text>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
keyExtractor={(item, index) => index.toString()}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -96,45 +125,53 @@ function ProfileScreen() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main App component with bottom tab navigation
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
const [qrCodes, setQrCodes] = useState([]); // State to hold QR codes
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavigationContainer>
|
<QRCodeContext.Provider value={{ qrCodes, setQrCodes }}>
|
||||||
<Tab.Navigator
|
<NavigationContainer>
|
||||||
screenOptions={({ route }) => ({
|
<Tab.Navigator
|
||||||
tabBarIcon: ({ color, size }) => {
|
screenOptions={({ route }) => ({
|
||||||
let iconName;
|
tabBarIcon: ({ color, size }) => {
|
||||||
|
let iconName;
|
||||||
|
|
||||||
if (route.name === 'QR Scanner') {
|
// Set different icons for each tab
|
||||||
iconName = 'qr-code-outline';
|
if (route.name === 'QR Scanner') {
|
||||||
} else if (route.name === 'History') {
|
iconName = 'qr-code-outline';
|
||||||
iconName = 'time-outline';
|
} else if (route.name === 'History') {
|
||||||
} else if (route.name === 'Settings') {
|
iconName = 'time-outline';
|
||||||
iconName = 'settings-outline';
|
} else if (route.name === 'Settings') {
|
||||||
} else if (route.name === 'Profile') {
|
iconName = 'settings-outline';
|
||||||
iconName = 'person-outline';
|
} else if (route.name === 'Profile') {
|
||||||
}
|
iconName = 'person-outline';
|
||||||
|
}
|
||||||
|
|
||||||
return <Ionicons name={iconName} size={size} color={color} />;
|
// Return the appropriate icon
|
||||||
},
|
return <Ionicons name={iconName} size={size} color={color} />;
|
||||||
})}
|
},
|
||||||
tabBarOptions={{
|
})}
|
||||||
activeTintColor: 'tomato',
|
tabBarOptions={{
|
||||||
inactiveTintColor: 'gray',
|
activeTintColor: 'tomato', // Active tab color
|
||||||
}}
|
inactiveTintColor: 'gray', // Inactive tab color
|
||||||
>
|
}}
|
||||||
<Tab.Screen name="QR Scanner" component={QRScannerScreen} />
|
>
|
||||||
<Tab.Screen name="History" component={HistoryScreen} />
|
<Tab.Screen name="QR Scanner" component={QRScannerScreen} />
|
||||||
<Tab.Screen name="Settings" component={SettingsScreen} />
|
<Tab.Screen name="History" component={HistoryScreen} />
|
||||||
<Tab.Screen name="Profile" component={ProfileScreen} />
|
<Tab.Screen name="Settings" component={SettingsScreen} />
|
||||||
</Tab.Navigator>
|
<Tab.Screen name="Profile" component={ProfileScreen} />
|
||||||
</NavigationContainer>
|
</Tab.Navigator>
|
||||||
|
</NavigationContainer>
|
||||||
|
</QRCodeContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StyleSheet for styling components
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: "#f8f0fc", // light purple background
|
backgroundColor: '#fa5da2',
|
||||||
},
|
},
|
||||||
splashContainer: {
|
splashContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@@ -143,7 +180,7 @@ const styles = StyleSheet.create({
|
|||||||
backgroundColor: "#f8f0fc", // light purple background
|
backgroundColor: "#f8f0fc", // light purple background
|
||||||
},
|
},
|
||||||
banner: {
|
banner: {
|
||||||
backgroundColor: "#ff69b4", // pink background
|
backgroundColor: "#333", // dark background
|
||||||
paddingVertical: 10,
|
paddingVertical: 10,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
@@ -155,7 +192,7 @@ const styles = StyleSheet.create({
|
|||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
marginVertical: 10, // Adjusted margin
|
marginVertical: 10, // Adjusted margin
|
||||||
color: "#ff69b4", // pink color
|
color: "white",
|
||||||
},
|
},
|
||||||
cameraContainer: {
|
cameraContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@@ -166,6 +203,19 @@ const styles = StyleSheet.create({
|
|||||||
width: 300,
|
width: 300,
|
||||||
height: 300,
|
height: 300,
|
||||||
},
|
},
|
||||||
|
button: {
|
||||||
|
backgroundColor: '#333',
|
||||||
|
paddingHorizontal: 20,
|
||||||
|
paddingVertical: 10,
|
||||||
|
borderRadius: 30,
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
marginVertical: 10,
|
||||||
|
},
|
||||||
|
buttonText: {
|
||||||
|
color: 'white',
|
||||||
|
fontSize: 16,
|
||||||
|
},
|
||||||
dataBox: {
|
dataBox: {
|
||||||
marginVertical: 10,
|
marginVertical: 10,
|
||||||
padding: 10,
|
padding: 10,
|
||||||
|
|||||||
Reference in New Issue
Block a user