fixed warning in all tsx file except for CameraView.tsx

This commit is contained in:
2024-06-10 21:54:22 +08:00
parent 4dfbbe7cbd
commit 7e0e9ec1bb
4 changed files with 41 additions and 25 deletions

View File

@@ -1,12 +1,12 @@
import React from 'react'; import React from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import { BottomTabBarProps } from '@react-navigation/bottom-tabs';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
// Custom tab bar component // Custom tab bar component with typings
const CustomTabBar = ({ state, descriptors, navigation }) => { const CustomTabBar: React.FC<BottomTabBarProps> = ({ state, descriptors, navigation }) => {
return ( return (
<View style={styles.tabBar}> <View style={styles.tabBar}>
{/* Iterate through each route in the state to render tab buttons */}
{state.routes.map((route, index) => { {state.routes.map((route, index) => {
const { options } = descriptors[route.key]; const { options } = descriptors[route.key];
const label = options.tabBarLabel !== undefined const label = options.tabBarLabel !== undefined
@@ -15,14 +15,14 @@ const CustomTabBar = ({ state, descriptors, navigation }) => {
? options.title ? options.title
: route.name; : route.name;
// Check if the current route is focused
const isFocused = state.index === index; const isFocused = state.index === index;
// Define the onPress behavior for each tab button // Event handler for tab press
const onPress = () => { const onPress = () => {
const event = navigation.emit({ const event = navigation.emit({
type: 'tabPress', type: 'tabPress',
target: route.key, target: route.key,
canPreventDefault: true
}); });
if (!isFocused && !event.defaultPrevented) { if (!isFocused && !event.defaultPrevented) {
@@ -30,7 +30,7 @@ const CustomTabBar = ({ state, descriptors, navigation }) => {
} }
}; };
// Define the onLongPress behavior for each tab button // Event handler for tab long press
const onLongPress = () => { const onLongPress = () => {
navigation.emit({ navigation.emit({
type: 'tabLongPress', type: 'tabLongPress',
@@ -38,7 +38,6 @@ const CustomTabBar = ({ state, descriptors, navigation }) => {
}); });
}; };
// Determine the icon name based on the route name
const iconName = route.name === 'QR Scanner' ? 'camera' : route.name === 'History' ? 'time' : route.name === 'Settings' ? 'settings' : 'person'; const iconName = route.name === 'QR Scanner' ? 'camera' : route.name === 'History' ? 'time' : route.name === 'Settings' ? 'settings' : 'person';
return ( return (
@@ -52,17 +51,18 @@ const CustomTabBar = ({ state, descriptors, navigation }) => {
onLongPress={onLongPress} onLongPress={onLongPress}
style={styles.tabButton} style={styles.tabButton}
> >
{/* Render the icon and label for each tab */}
<Ionicons name={iconName} size={24} color={isFocused ? '#673ab7' : '#222'} /> <Ionicons name={iconName} size={24} color={isFocused ? '#673ab7' : '#222'} />
{/* Check if label is a string before rendering */}
{typeof label === 'string' ? (
<Text style={{ color: isFocused ? '#673ab7' : '#222' }}> <Text style={{ color: isFocused ? '#673ab7' : '#222' }}>
{label} {label}
</Text> </Text>
) : null}
</TouchableOpacity> </TouchableOpacity>
); );
})} })}
{/* Floating button to navigate directly to QR Scanner */} <View style={styles.floatingButtonContainer}>
<View style={styles.floatingButton}> <TouchableOpacity style={styles.floatingButton} onPress={() => { navigation.navigate('QR Scanner'); }}>
<TouchableOpacity onPress={() => { navigation.navigate('QR Scanner'); }}>
<Ionicons name="camera" size={28} color="#fff" /> <Ionicons name="camera" size={28} color="#fff" />
</TouchableOpacity> </TouchableOpacity>
</View> </View>
@@ -93,22 +93,32 @@ const styles = StyleSheet.create({
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}, },
floatingButton: { floatingButtonContainer: {
position: 'absolute', position: 'absolute',
bottom: 30, top: -30,
left: '50%', left: '50%',
marginLeft: -30, marginLeft: -35,
width: 70,
height: 70,
borderRadius: 35,
backgroundColor: '#fff',
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#000',
shadowOpacity: 0.2,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 5,
elevation: 3,
borderWidth: 3,
borderColor: '#673ab7',
},
floatingButton: {
width: 60, width: 60,
height: 60, height: 60,
borderRadius: 30, borderRadius: 30,
backgroundColor: '#673ab7', backgroundColor: '#673ab7',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
shadowColor: '#000',
shadowOpacity: 0.1,
shadowOffset: { width: 0, height: 2 },
shadowRadius: 5,
elevation: 3,
}, },
}); });

View File

@@ -3,8 +3,10 @@ import { View, Text, StyleSheet, FlatList } from 'react-native';
import { QRCodeContext } from '../types'; import { QRCodeContext } from '../types';
const HistoryScreen: React.FC = () => { const HistoryScreen: React.FC = () => {
const { qrCodes } = useContext(QRCodeContext); const qrCodeContext = useContext(QRCodeContext);
// Safely access qrCodes and handle the case when the context is null
const qrCodes = qrCodeContext ? qrCodeContext.qrCodes : [];
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.welcomeText}>History Screen</Text> <Text style={styles.welcomeText}>History Screen</Text>

View File

@@ -109,7 +109,7 @@ const QRScannerScreen: React.FC = () => {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.banner}> <View style={styles.banner}>
<Text style={styles.headerText}>SafeQR</Text> <Text style={styles.headerText}>SafeQR v0.16</Text>
</View> </View>
<Text style={styles.welcomeText}>Welcome to SafeQR code Scanner</Text> <Text style={styles.welcomeText}>Welcome to SafeQR code Scanner</Text>
<View style={styles.cameraContainer}> <View style={styles.cameraContainer}>

View File

@@ -3,7 +3,11 @@ import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import { QRCodeContext } from '../types'; import { QRCodeContext } from '../types';
const SettingsScreen: React.FC = () => { const SettingsScreen: React.FC = () => {
const { setQrCodes } = useContext(QRCodeContext); const qrCodeContext = useContext(QRCodeContext);
// Safely access setQrCodes and handle the case when the context is null
const setQrCodes = qrCodeContext ? qrCodeContext.setQrCodes : () => {};
const clearHistory = () => { const clearHistory = () => {
setQrCodes([]); setQrCodes([]);