import React, { useEffect, useRef } from 'react'; import { Modal, Text, TouchableOpacity, View, Animated, Easing, Vibration, Alert } from 'react-native'; import { X, Radio, SmartphoneNfc } from 'lucide-react-native'; import NfcManager, { NfcTech } from 'react-native-nfc-manager'; interface NfcScanModalProps { visible: boolean; onClose: () => void; onScan: (data: string) => void; } export default function NfcScanModal({ visible, onClose, onScan }: NfcScanModalProps) { // Animazione per l'effetto "pulsante" (Breathing) const scaleAnim = useRef(new Animated.Value(1)).current; const opacityAnim = useRef(new Animated.Value(0.3)).current; const readNfcTag = async () => { const supported = await NfcManager.isSupported(); const nfcScanning = await NfcManager.isEnabled(); if (!supported || !nfcScanning) { onClose(); return; } NfcManager.start(); try { await NfcManager.requestTechnology(NfcTech.Ndef); const tag = await NfcManager.getTag(); if (tag) { console.log('NFC Tag Found:', tag); Vibration.vibrate(); // onScan(tag.id || JSON.stringify(tag)); onClose(); } else { console.warn('Tag NFC vuoto o non formattato NDEF'); } } catch (error) { console.warn('Error reading NFC tag', error); } finally { NfcManager.cancelTechnologyRequest(); } }; // Loop infinito di espansione e contrazione const animationLoop = () => { Animated.loop( Animated.parallel([ Animated.sequence([ Animated.timing(scaleAnim, { toValue: 1.2, duration: 1500, easing: Easing.inOut(Easing.ease), useNativeDriver: true, }), Animated.timing(scaleAnim, { toValue: 1, duration: 1500, easing: Easing.inOut(Easing.ease), useNativeDriver: true, }), ]), Animated.sequence([ Animated.timing(opacityAnim, { toValue: 0.1, duration: 1500, useNativeDriver: true, }), Animated.timing(opacityAnim, { toValue: 0.3, duration: 1500, useNativeDriver: true, }), ]) ]) ).start(); } useEffect(() => { if (visible) { animationLoop(); readNfcTag(); } else { scaleAnim.setValue(1); opacityAnim.setValue(0.3); } }, [visible]); return ( {/* Card Principale */} {/* Bottone Chiudi (Alto Destra) */} {/* Area Animata NFC */} {/* Cerchio Pulsante (Sfondo) */} {/* Cerchio Fisso (Primo piano) */} {/* Testi */} Pronto alla scansione Avvicina il retro del tuo smartphone al Tag NFC per registrare la presenza. {/* Indicatore Visivo (Simulazione onde) */} Ricerca in corso... {/* Footer Button */} Annulla ); }