Updated sliding animation for ScannedDatabox on all 3 screens
This commit is contained in:
17053
package-lock.json
generated
Normal file
17053
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -469,7 +469,7 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
deleteButtonText: {
|
deleteButtonText: {
|
||||||
marginRight: screenWidth * 0.02,
|
marginRight: screenWidth * 0.02,
|
||||||
color: '#ff69b4',
|
color: '#f41c87',
|
||||||
fontSize: screenWidth * 0.035,
|
fontSize: screenWidth * 0.035,
|
||||||
},
|
},
|
||||||
modalOverlay: {
|
modalOverlay: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useCallback, useState, useEffect } from 'react';
|
import React, { useCallback, useState, useEffect } from 'react';
|
||||||
import { View, Text, StyleSheet, FlatList, TouchableOpacity, Image, Modal, ActivityIndicator, Dimensions } from 'react-native';
|
import { View, Text, StyleSheet, FlatList, TouchableOpacity, Image, Modal, ActivityIndicator, Dimensions, Animated } from 'react-native';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import ScannedDataBox from '../components/ScannedDataBox';
|
import ScannedDataBox from '../components/ScannedDataBox';
|
||||||
import { Ionicons } from '@expo/vector-icons';
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
@@ -19,10 +19,11 @@ const HistoryScreen: React.FC = () => {
|
|||||||
|
|
||||||
const [qrCodeToDelete, setQrCodeToDelete] = useState<string | null>(null);
|
const [qrCodeToDelete, setQrCodeToDelete] = useState<string | null>(null);
|
||||||
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState<boolean>(false);
|
const [isDeleteModalVisible, setIsDeleteModalVisible] = useState<boolean>(false);
|
||||||
const [isScannedDataModalVisible, setIsScannedDataModalVisible] = useState<boolean>(false);
|
|
||||||
const [historiesLoading, setHistoriesLoading] = useState(false);
|
const [historiesLoading, setHistoriesLoading] = useState(false);
|
||||||
const [historiesError, setHistoriesError] = useState<string | null>(null);
|
const [historiesError, setHistoriesError] = useState<string | null>(null);
|
||||||
const [selectedQrCodeId, setSelectedQrCodeId] = useState<string | null>(null);
|
const [selectedQrCodeId, setSelectedQrCodeId] = useState<string | null>(null);
|
||||||
|
const [isModalVisible, setIsModalVisible] = useState<boolean>(false); // Modal for ScannedDataBox
|
||||||
|
|
||||||
|
|
||||||
const fetchHistories = useCallback(async () => {
|
const fetchHistories = useCallback(async () => {
|
||||||
if (!userAttributes?.sub) return;
|
if (!userAttributes?.sub) return;
|
||||||
@@ -51,20 +52,21 @@ const HistoryScreen: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [dispatch, userAttributes]);
|
}, [dispatch, userAttributes]);
|
||||||
|
|
||||||
|
|
||||||
const handleSelectQrCodeForView = (item: QRCodeType) => {
|
const handleSelectQrCodeForView = (item: QRCodeType) => {
|
||||||
setSelectedQrCodeId(item.data.id || null);
|
setSelectedQrCodeId(item.data.id || null);
|
||||||
setIsScannedDataModalVisible(true);
|
setIsModalVisible(true); // Show ScannedDataBox Modal
|
||||||
};
|
};
|
||||||
|
|
||||||
const clearSelectedQrCodeData = () => {
|
const clearSelectedQrCodeData = () => {
|
||||||
setSelectedQrCodeId(null);
|
setSelectedQrCodeId(null);
|
||||||
setIsScannedDataModalVisible(false);
|
setIsModalVisible(false); // Close ScannedDataBox Modal
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredQrCodes = showBookmarks
|
const filteredQrCodes = showBookmarks
|
||||||
? histories.filter((qr) => qr.bookmarked)
|
? histories.filter((qr) => qr.bookmarked)
|
||||||
: histories;
|
: histories;
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<View style={styles.headerContainer}>
|
<View style={styles.headerContainer}>
|
||||||
@@ -116,22 +118,29 @@ const HistoryScreen: React.FC = () => {
|
|||||||
contentContainerStyle={styles.flatListContent}
|
contentContainerStyle={styles.flatListContent}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Modal for ScannedDataBox */}
|
{/* Modal for ScannedDataBox */}
|
||||||
<Modal
|
<Modal
|
||||||
visible={isScannedDataModalVisible}
|
visible={isModalVisible}
|
||||||
transparent={true}
|
transparent={true}
|
||||||
animationType="fade"
|
animationType="slide"
|
||||||
onRequestClose={clearSelectedQrCodeData}
|
onRequestClose={clearSelectedQrCodeData}
|
||||||
>
|
>
|
||||||
<View style={styles.modalOverlay}>
|
{/* The greyspace outside, made clickable to close the modal */}
|
||||||
<TouchableOpacity style={styles.modalOverlayTouchable} onPress={clearSelectedQrCodeData} activeOpacity={1}>
|
<TouchableOpacity
|
||||||
<View style={styles.modalContainer}>
|
style={styles.scannedDataBoxModalOverlay}
|
||||||
<ScannedDataBox qrCodeId={selectedQrCodeId} clearScanData={clearSelectedQrCodeData} />
|
activeOpacity={1}
|
||||||
</View>
|
onPressOut={clearSelectedQrCodeData}
|
||||||
</TouchableOpacity>
|
>
|
||||||
</View>
|
{/* Ensure ScannedDataBox does not render another modal */}
|
||||||
|
<View style={styles.scannedDataBoxModalContainer}>
|
||||||
|
<ScannedDataBox qrCodeId={selectedQrCodeId} clearScanData={clearSelectedQrCodeData} />
|
||||||
|
</View>
|
||||||
|
</TouchableOpacity>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{/* Modal to confirm deletion */}
|
{/* Modal to confirm deletion */}
|
||||||
<Modal
|
<Modal
|
||||||
transparent={true}
|
transparent={true}
|
||||||
@@ -276,6 +285,18 @@ const styles = StyleSheet.create({
|
|||||||
fontSize: screenWidth * 0.04,
|
fontSize: screenWidth * 0.04,
|
||||||
color: '#000',
|
color: '#000',
|
||||||
},
|
},
|
||||||
|
scannedDataBoxModalOverlay: {
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: 'center',
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
|
},
|
||||||
|
scannedDataBoxModalContainer: {
|
||||||
|
marginHorizontal: '5%',
|
||||||
|
borderRadius: screenWidth * 0.025,
|
||||||
|
backgroundColor: 'white',
|
||||||
|
padding: screenWidth * 0.025,
|
||||||
|
elevation: 5,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default HistoryScreen;
|
export default HistoryScreen;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
const [bannerOpacity] = useState(new Animated.Value(0));
|
const [bannerOpacity] = useState(new Animated.Value(0));
|
||||||
const [isConnected, setIsConnected] = useState<boolean>(true);
|
const [isConnected, setIsConnected] = useState<boolean>(true);
|
||||||
const [qrTip, setQrTip] = useState<string>('Always scan QR codes from trusted sources');
|
const [qrTip, setQrTip] = useState<string>('Always scan QR codes from trusted sources');
|
||||||
|
const [scannedDataBoxY] = useState(new Animated.Value(screenHeight)); // Start off-screen
|
||||||
|
|
||||||
// Camera permissions and device management
|
// Camera permissions and device management
|
||||||
const { hasPermission, requestPermission } = useCameraPermission();
|
const { hasPermission, requestPermission } = useCameraPermission();
|
||||||
@@ -37,7 +38,6 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
requestPermission(); // Request camera permission on component mount
|
requestPermission(); // Request camera permission on component mount
|
||||||
|
|
||||||
// Initial fetch for QR tips
|
// Initial fetch for QR tips
|
||||||
@@ -61,6 +61,25 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const showScannedDataBox = () => {
|
||||||
|
setIsScannedDataBoxVisible(true);
|
||||||
|
Animated.timing(scannedDataBoxY, {
|
||||||
|
toValue: 0, // Slide the modal to the top of the screen
|
||||||
|
duration: 500,
|
||||||
|
useNativeDriver: true,
|
||||||
|
}).start();
|
||||||
|
};
|
||||||
|
|
||||||
|
const hideScannedDataBox = () => {
|
||||||
|
Animated.timing(scannedDataBoxY, {
|
||||||
|
toValue: screenHeight, // Move it back off-screen
|
||||||
|
duration: 500,
|
||||||
|
useNativeDriver: true,
|
||||||
|
}).start(() => {
|
||||||
|
setIsScannedDataBoxVisible(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Show an offline banner
|
// Show an offline banner
|
||||||
const showBanner = () => {
|
const showBanner = () => {
|
||||||
Animated.timing(bannerOpacity, {
|
Animated.timing(bannerOpacity, {
|
||||||
@@ -78,7 +97,6 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle payload after scanning QR code
|
|
||||||
const handlePayload = async (payload: string) => {
|
const handlePayload = async (payload: string) => {
|
||||||
setScanned(true);
|
setScanned(true);
|
||||||
console.info("Decoded QR Code, Payload is: ", payload);
|
console.info("Decoded QR Code, Payload is: ", payload);
|
||||||
@@ -86,8 +104,8 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
const response = await scanQRCode(payload);
|
const response = await scanQRCode(payload);
|
||||||
const qrCodeId = response.qrcode.data.id;
|
const qrCodeId = response.qrcode.data.id;
|
||||||
setQRCodeId(qrCodeId); // Store QR code ID
|
setQRCodeId(qrCodeId);
|
||||||
setIsScannedDataBoxVisible(true); // Show the ScannedDataBox pop-up
|
showScannedDataBox(); // Show the ScannedDataBox pop-up with animation
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error scanning QR code:", error);
|
console.error("Error scanning QR code:", error);
|
||||||
}
|
}
|
||||||
@@ -191,18 +209,25 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{/* Scanned Data Box as a pop-up */}
|
{/* Scanned Data Box as a modal with sliding animation */}
|
||||||
{isScannedDataBoxVisible && (
|
<Modal
|
||||||
<View style={styles.scannedDataBoxPopup}>
|
transparent={true}
|
||||||
<ScannedDataBox
|
visible={isScannedDataBoxVisible}
|
||||||
qrCodeId={qrCodeId!}
|
animationType="none"
|
||||||
clearScanData={() => {
|
onRequestClose={hideScannedDataBox}
|
||||||
setScanned(false);
|
>
|
||||||
setIsScannedDataBoxVisible(false);
|
<TouchableOpacity style={styles.modalOverlay} activeOpacity={1} onPress={hideScannedDataBox}>
|
||||||
}}
|
<Animated.View style={[styles.modalContainer, { transform: [{ translateY: scannedDataBoxY }] }]}>
|
||||||
/>
|
<ScannedDataBox
|
||||||
</View>
|
qrCodeId={qrCodeId!}
|
||||||
)}
|
clearScanData={() => {
|
||||||
|
setScanned(false);
|
||||||
|
hideScannedDataBox();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Animated.View>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
{/* Settings Icon */}
|
{/* Settings Icon */}
|
||||||
<TouchableOpacity onPress={() => setIsSettingsModalVisible(true)} style={styles.settingsButton}>
|
<TouchableOpacity onPress={() => setIsSettingsModalVisible(true)} style={styles.settingsButton}>
|
||||||
@@ -257,17 +282,15 @@ const styles = StyleSheet.create({
|
|||||||
color: 'black',
|
color: 'black',
|
||||||
},
|
},
|
||||||
cameraContainer: {
|
cameraContainer: {
|
||||||
width: '100%', // Adjust the width as needed
|
width: '100%',
|
||||||
height: '45%', // Adjust the height as needed
|
height: '45%',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
alignSelf: 'center', // Center the container horizontally
|
alignSelf: 'center',
|
||||||
marginTop: '10%', // Adjust the top margin to position it vertically in the middle
|
marginTop: '10%',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
settingsButton: {
|
settingsButton: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: screenHeight * 0.05,
|
top: screenHeight * 0.05,
|
||||||
@@ -295,14 +318,15 @@ const styles = StyleSheet.create({
|
|||||||
backgroundColor: '#000',
|
backgroundColor: '#000',
|
||||||
borderRadius: screenWidth * 0.0625,
|
borderRadius: screenWidth * 0.0625,
|
||||||
},
|
},
|
||||||
scannedDataBoxPopup: {
|
modalOverlay: {
|
||||||
position: 'absolute',
|
flex: 1,
|
||||||
top: '20%',
|
justifyContent: 'center', // Aligns the modal to the bottom by default
|
||||||
left: '5%',
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
right: '5%',
|
},
|
||||||
zIndex: 2,
|
modalContainer: {
|
||||||
backgroundColor: 'white',
|
marginHorizontal: '5%',
|
||||||
borderRadius: screenWidth * 0.025,
|
borderRadius: screenWidth * 0.025,
|
||||||
|
backgroundColor: 'white',
|
||||||
padding: screenWidth * 0.025,
|
padding: screenWidth * 0.025,
|
||||||
elevation: 5,
|
elevation: 5,
|
||||||
},
|
},
|
||||||
@@ -312,15 +336,14 @@ const styles = StyleSheet.create({
|
|||||||
settingsModalContainer: {
|
settingsModalContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
backgroundColor: '#f8f0fc', // Full pink background to match the app's theme
|
backgroundColor: '#f8f0fc',
|
||||||
},
|
},
|
||||||
|
|
||||||
settingsModalContent: {
|
settingsModalContent: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
backgroundColor: '#f8f0fc', // Full pink background for the content as well
|
backgroundColor: '#f8f0fc',
|
||||||
padding: screenWidth * 0.05,
|
padding: screenWidth * 0.05,
|
||||||
borderTopLeftRadius: 0, // Remove border radius to avoid white edges
|
borderTopLeftRadius: 0,
|
||||||
borderTopRightRadius: 0, // Remove border radius to avoid white edges
|
borderTopRightRadius: 0,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
closeButton: {
|
closeButton: {
|
||||||
@@ -353,24 +376,23 @@ const styles = StyleSheet.create({
|
|||||||
fontSize: screenWidth * 0.04,
|
fontSize: screenWidth * 0.04,
|
||||||
},
|
},
|
||||||
tipsContainer: {
|
tipsContainer: {
|
||||||
backgroundColor: '#fff', // Make sure the container background matches the white box
|
backgroundColor: '#fff',
|
||||||
padding: 10,
|
padding: 10,
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
marginTop: 10, // Space from the camera container
|
marginTop: 10,
|
||||||
},
|
},
|
||||||
iconTextRow: {
|
iconTextRow: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
alignItems: 'center', // This will align the icon and text vertically
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
tipsText: {
|
tipsText: {
|
||||||
color: '#f41c87', // Adjusted color to match the pink theme
|
color: '#f41c87',
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
marginLeft: 5, // Add some spacing between the icon and the text
|
marginLeft: 5,
|
||||||
paddingHorizontal: 10, // Add horizontal padding to ensure text isn't too close to the edges
|
paddingHorizontal: 10,
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default QRScannerScreen;
|
export default QRScannerScreen;
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ const SettingsScreen: React.FC = () => {
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<Text style={styles.versionText}>Version 1.2</Text>
|
<Text style={styles.versionText}>Version 1.0</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -292,7 +292,7 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
deleteAllButton: {
|
deleteAllButton: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
backgroundColor: '#ff5941',
|
backgroundColor: '#f41c87',
|
||||||
borderRadius: 25,
|
borderRadius: 25,
|
||||||
paddingVertical: 10,
|
paddingVertical: 10,
|
||||||
paddingHorizontal: 20,
|
paddingHorizontal: 20,
|
||||||
|
|||||||
Reference in New Issue
Block a user