import { useEffect, useRef, useState } from 'react'; import { Animated, Easing, KeyboardAvoidingView, Platform, Pressable, StyleSheet, TextInput, View } from 'react-native'; import { CameraView, useCameraPermissions } from 'expo-camera'; import { router } from 'expo-router'; import * as Haptics from 'expo-haptics'; import { SafeAreaView } from 'react-native-safe-area-context'; import { Button, Screen, T } from '../src/ui'; import { font, useColors } from '../src/theme'; /** Les numéros de carte commencent par « MEP » (voir le back-end). */ const SERIAL = /^MEP[A-Z2-9]{16}$/; const FRAME = 260; const DIM = 'rgba(0,0,0,0.55)'; /** Saisie manuelle : espaces et tirets ignorés (« MEP ABCD EFGH… » est affiché sous le QR de la carte). */ const normalize = (v: string) => v.toUpperCase().replace(/[s-]/g, ''); export default function Scan() { const c = useColors(); const [permission, requestPermission] = useCameraPermissions(); const [torch, setTorch] = useState(false); const [invalid, setInvalid] = useState(false); const handled = useRef(false); const [manual, setManual] = useState(false); const [typed, setTyped] = useState(''); const typedOk = SERIAL.test(normalize(typed)); function openCard(serial: string) { handled.current = true; Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success); router.replace({ pathname: '/client/[serial]', params: { serial } }); } /** Panneau de saisie du numéro de carte (si le scan échoue ou sans caméra). */ const manualPanel = ( setManual(false)} accessibilityLabel="Fermer la saisie" /> Numéro de la carte Inscrit sous le QR code de la carte du client : MEP suivi de 16 caractères. typedOk && openCard(normalize(typed))} accessibilityLabel="Numéro de la carte" style={{ borderWidth: 1, borderColor: c.border, borderRadius: 14, padding: 14, fontSize: 18, letterSpacing: 1, color: c.text, backgroundColor: c.bg, fontFamily: font.semibold }} /> {typed.length > 0 && !typedOk && {normalize(typed).length} / 19 caractères}