From bb4f802456979e765f95547af86362d75bf34c05 Mon Sep 17 00:00:00 2001 From: Thomasdelecluse <81568452+Thomasdelecluse@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:54:55 +0200 Subject: [PATCH] feat: add modal when click on point --- apps/expo/src/component/CustomMarker.js | 16 +++ apps/expo/src/pages/EventScreen.js | 1 - apps/expo/src/pages/MapScreen.js | 144 ++++++++++++++++++++---- 3 files changed, 139 insertions(+), 22 deletions(-) create mode 100644 apps/expo/src/component/CustomMarker.js diff --git a/apps/expo/src/component/CustomMarker.js b/apps/expo/src/component/CustomMarker.js new file mode 100644 index 0000000..c3d8c81 --- /dev/null +++ b/apps/expo/src/component/CustomMarker.js @@ -0,0 +1,16 @@ +import React from 'react'; +import { Marker } from 'react-native-maps'; + +const CustomMarker = ({ coordinate, title, description, onPress, pinColor = "red" }) => { + return ( + + ); +}; + +export default CustomMarker; diff --git a/apps/expo/src/pages/EventScreen.js b/apps/expo/src/pages/EventScreen.js index a8ee580..388065d 100644 --- a/apps/expo/src/pages/EventScreen.js +++ b/apps/expo/src/pages/EventScreen.js @@ -13,7 +13,6 @@ const EventScreen = () => { showsVerticalScrollIndicator={false} > EVENEMENTS - {/* Génère plusieurs cartes d'événements */} {Array(7).fill(0).map((_, index) => ( { const [region, setRegion] = useState({ @@ -12,41 +16,41 @@ const MapScreen = () => { }); const [userLocation, setUserLocation] = useState(null); const [loading, setLoading] = useState(true); + const [selectedMarker, setSelectedMarker] = useState(null); // État pour gérer la sélection du marqueur useEffect(() => { const getLocation = async () => { - // Demander la permission const { status } = await Location.requestForegroundPermissionsAsync(); - if (status === 'granted') { - // Obtenir la position const location = await Location.getCurrentPositionAsync({ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000, }); - setUserLocation({ - latitude: location.coords.latitude, - longitude: location.coords.longitude, - }); - setRegion({ - ...region, - latitude: location.coords.latitude, - longitude: location.coords.longitude, - }); - setLoading(false); - } else { - // Permission refusée - setLoading(false); + const { latitude, longitude } = location.coords; + setUserLocation({ latitude, longitude }); + setRegion((prevRegion) => ({ + ...prevRegion, + latitude, + longitude, + })); } + setLoading(false); }; - getLocation(); }, []); + const handleMarkerPress = (markerData) => { + setSelectedMarker(markerData); // Mettre à jour l'état avec les informations du marqueur sélectionné + }; + + const closeModal = () => { + setSelectedMarker(null); // Fermer la modale + }; + if (loading) { return ( - + ); @@ -60,14 +64,70 @@ const MapScreen = () => { onRegionChangeComplete={setRegion} > {userLocation && ( - handleMarkerPress({ + title: "Votre position actuelle", + description: "Vous êtes ici", + image: null, + })} /> )} + + handleMarkerPress({ + title: "Exo", + description: "Heures : 17h", + image: PopupImage, + })} + /> + + handleMarkerPress({ + title: "Poab", + description: "Heures : 18h", + image: PopupImage, + })} + /> + + {selectedMarker && ( + + + + {/* Image au-dessus du titre */} + {selectedMarker.image && ( + + )} + {selectedMarker.title} + {selectedMarker.description} + + Fermer + + + + + )} ); }; @@ -81,4 +141,46 @@ const styles = StyleSheet.create({ map: { ...StyleSheet.absoluteFillObject, }, + loadingContainer: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + }, + modalContainer: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: 'rgba(0, 0, 0, 0.5)', + }, + modalContent: { + width: 300, + padding: 10, + backgroundColor: 'white', + borderRadius: 10, + alignItems: 'center', + }, + modalTitle: { + fontSize: 18, + fontWeight: 'bold', + marginBottom: 10, + }, + modalDescription: { + fontSize: 16, + marginBottom: 20, + }, + modalImage: { + width: 150, + height: 150, + marginBottom: 10, + resizeMode: 'contain', + }, + closeButton: { + backgroundColor: '#1B1464', + padding: 10, + borderRadius: 5, + }, + closeButtonText: { + color: 'white', + fontSize: 16, + }, });