App : page de scan retravaillée

Voile autour du cadre de visée, coins arrondis, ligne de balayage animée,
bouton fermer en haut, lampe en bouton rond, message d'erreur temporaire
avec vibration ; écran d'autorisation de la caméra plus clair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tony AVERTY 2026-10-07 14:34:40 +02:00
parent 47a3030100
commit 39806791c4

View file

@ -1,37 +1,67 @@
import { useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { Pressable, StyleSheet, View } from 'react-native'; import { Animated, Easing, Pressable, StyleSheet, View } from 'react-native';
import { CameraView, useCameraPermissions } from 'expo-camera'; import { CameraView, useCameraPermissions } from 'expo-camera';
import { router } from 'expo-router'; import { router } from 'expo-router';
import * as Haptics from 'expo-haptics'; import * as Haptics from 'expo-haptics';
import { SafeAreaView } from 'react-native-safe-area-context'; import { SafeAreaView } from 'react-native-safe-area-context';
import { Button, Screen, T } from '../src/ui'; import { Button, Screen, T } from '../src/ui';
import { font } from '../src/theme'; import { font, useColors } from '../src/theme';
/** Les numéros de carte commencent par « MEP » (voir le back-end). */ /** Les numéros de carte commencent par « MEP » (voir le back-end). */
const SERIAL = /^MEP[A-Z2-9]{16}$/; const SERIAL = /^MEP[A-Z2-9]{16}$/;
const FRAME = 260;
const DIM = 'rgba(0,0,0,0.55)';
export default function Scan() { export default function Scan() {
const c = useColors();
const [permission, requestPermission] = useCameraPermissions(); const [permission, requestPermission] = useCameraPermissions();
const [torch, setTorch] = useState(false); const [torch, setTorch] = useState(false);
const [invalid, setInvalid] = useState(false); const [invalid, setInvalid] = useState(false);
const handled = useRef(false); const handled = useRef(false);
const line = useRef(new Animated.Value(0)).current;
// Ligne de balayage : montre que la lecture est en cours.
useEffect(() => {
const anim = Animated.loop(
Animated.sequence([
Animated.timing(line, { toValue: 1, duration: 1600, easing: Easing.inOut(Easing.quad), useNativeDriver: true }),
Animated.timing(line, { toValue: 0, duration: 1600, easing: Easing.inOut(Easing.quad), useNativeDriver: true }),
]),
);
anim.start();
return () => anim.stop();
}, [line]);
// Le message « QR code inconnu » disparaît tout seul.
useEffect(() => {
if (!invalid) return;
const t = setTimeout(() => setInvalid(false), 2500);
return () => clearTimeout(t);
}, [invalid]);
if (!permission) return null; if (!permission) return null;
if (!permission.granted) { if (!permission.granted) {
return ( return (
<Screen noHeader style={{ justifyContent: 'center' }}> <Screen noHeader style={{ justifyContent: 'center', alignItems: 'stretch' }}>
<T v="h1">Accès à la caméra</T> <View style={{ alignItems: 'center', gap: 14 }}>
<T v="muted">La caméra sert uniquement à lire le QR code de la carte de fidélité du client.</T> <View style={{ width: 96, height: 96, borderRadius: 48, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
<T style={{ fontSize: 44 }}>📷</T>
</View>
<T v="h1" style={{ textAlign: 'center' }}>Accès à la caméra</T>
<T v="muted" style={{ textAlign: 'center' }}>La caméra sert uniquement à lire le QR code de la carte de fidélité du client.</T>
</View>
{permission.canAskAgain ? ( {permission.canAskAgain ? (
<Button label="Autoriser la caméra" onPress={requestPermission} /> <Button large label="Autoriser la caméra" onPress={requestPermission} />
) : ( ) : (
<T>Autorisez la caméra pour MonEspacePro dans les réglages du téléphone.</T> <T style={{ textAlign: 'center' }}>Autorisez la caméra pour MonEspacePro dans les réglages du téléphone.</T>
)} )}
<Button label="Retour" variant="secondary" onPress={() => router.back()} /> <Button label="Retour" variant="secondary" onPress={() => router.back()} />
</Screen> </Screen>
); );
} }
const corner = (pos: object) => <View style={[styles.corner, pos]} />;
return ( return (
<View style={{ flex: 1, backgroundColor: '#000' }}> <View style={{ flex: 1, backgroundColor: '#000' }}>
<CameraView <CameraView
@ -43,6 +73,7 @@ export default function Scan() {
if (handled.current) return; if (handled.current) return;
const serial = data.trim().toUpperCase(); const serial = data.trim().toUpperCase();
if (!SERIAL.test(serial)) { if (!SERIAL.test(serial)) {
if (!invalid) Haptics.notificationAsync(Haptics.NotificationFeedbackType.Warning);
setInvalid(true); setInvalid(true);
return; return;
} }
@ -51,28 +82,62 @@ export default function Scan() {
router.replace({ pathname: '/client/[serial]', params: { serial } }); router.replace({ pathname: '/client/[serial]', params: { serial } });
}} }}
/> />
<SafeAreaView style={{ flex: 1, justifyContent: 'space-between', padding: 20 }}>
<T style={{ color: '#fff', fontFamily: font.bold, fontSize: 22, textAlign: 'center' }}>Visez le QR code de la carte</T> {/* Voile sombre autour du cadre de visée */}
<View style={styles.frame} accessibilityElementsHidden /> <View style={StyleSheet.absoluteFill} pointerEvents="none">
<View style={{ gap: 12 }}> <View style={{ flex: 1, backgroundColor: DIM }} />
{invalid && ( <View style={{ flexDirection: 'row', height: FRAME }}>
<T style={{ color: '#fff', textAlign: 'center', backgroundColor: 'rgba(184,50,42,0.9)', padding: 10, borderRadius: 10, overflow: 'hidden' }}> <View style={{ flex: 1, backgroundColor: DIM }} />
Ce QR code n'est pas une carte MonEspacePro. <View style={{ width: FRAME, height: FRAME }}>
</T> {corner({ top: 0, left: 0, borderTopWidth: 5, borderLeftWidth: 5, borderTopLeftRadius: 24 })}
)} {corner({ top: 0, right: 0, borderTopWidth: 5, borderRightWidth: 5, borderTopRightRadius: 24 })}
<View style={{ flexDirection: 'row', gap: 12 }}> {corner({ bottom: 0, left: 0, borderBottomWidth: 5, borderLeftWidth: 5, borderBottomLeftRadius: 24 })}
<Pressable accessibilityRole="button" onPress={() => router.back()} style={styles.chip}> {corner({ bottom: 0, right: 0, borderBottomWidth: 5, borderRightWidth: 5, borderBottomRightRadius: 24 })}
<T style={styles.chipText}>Annuler</T> <Animated.View
</Pressable> style={{
<Pressable position: 'absolute',
accessibilityRole="button" left: 18,
accessibilityState={{ selected: torch }} right: 18,
onPress={() => setTorch((t) => !t)} height: 3,
style={[styles.chip, torch && { backgroundColor: '#F2B544' }]} borderRadius: 2,
> backgroundColor: invalid ? '#F08A80' : '#F2B544',
<T style={[styles.chipText, torch && { color: '#1C1C19' }]}>{torch ? 'Lampe allumée' : 'Lampe'}</T> transform: [{ translateY: line.interpolate({ inputRange: [0, 1], outputRange: [18, FRAME - 21] }) }],
</Pressable> }}
/>
</View> </View>
<View style={{ flex: 1, backgroundColor: DIM }} />
</View>
<View style={{ flex: 1, backgroundColor: DIM }} />
</View>
<SafeAreaView style={{ flex: 1, justifyContent: 'space-between', padding: 20 }}>
{/* Barre du haut : fermer + consigne */}
<View style={{ gap: 18 }}>
<Pressable accessibilityRole="button" accessibilityLabel="Fermer" onPress={() => router.back()} style={styles.round} hitSlop={8}>
<T style={{ color: '#fff', fontSize: 22, lineHeight: 24 }}>✕</T>
</Pressable>
<View style={{ alignItems: 'center', gap: 4 }}>
<T style={{ color: '#fff', fontFamily: font.bold, fontSize: 22, textAlign: 'center' }}>Scannez la carte du client</T>
<T style={{ color: 'rgba(255,255,255,0.8)', fontSize: 15, textAlign: 'center' }}>QR code affiché dans son Wallet</T>
</View>
</View>
<View style={{ alignItems: 'center', gap: 16 }}>
{invalid && (
<View style={{ backgroundColor: 'rgba(184,50,42,0.92)', paddingVertical: 10, paddingHorizontal: 16, borderRadius: 999 }}>
<T style={{ color: '#fff', fontFamily: font.semibold, fontSize: 15 }}>Ce QR code n'est pas une carte MonEspacePro</T>
</View>
)}
<Pressable
accessibilityRole="button"
accessibilityLabel={torch ? 'Éteindre la lampe' : 'Allumer la lampe'}
accessibilityState={{ selected: torch }}
onPress={() => setTorch((t) => !t)}
style={[styles.round, { width: 64, height: 64, borderRadius: 32 }, torch && { backgroundColor: '#F2B544' }]}
>
<T style={{ fontSize: 26 }}>🔦</T>
</Pressable>
<T style={{ color: 'rgba(255,255,255,0.8)', fontSize: 13 }}>{torch ? 'Lampe allumée' : 'Lampe'}</T>
</View> </View>
</SafeAreaView> </SafeAreaView>
</View> </View>
@ -80,7 +145,6 @@ export default function Scan() {
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
frame: { alignSelf: 'center', width: 260, height: 260, borderRadius: 24, borderWidth: 4, borderColor: '#FFFFFF' }, corner: { position: 'absolute', width: 44, height: 44, borderColor: '#FFFFFF' },
chip: { flex: 1, height: 56, borderRadius: 14, backgroundColor: 'rgba(255,255,255,0.2)', alignItems: 'center', justifyContent: 'center' }, round: { width: 44, height: 44, borderRadius: 22, backgroundColor: 'rgba(255,255,255,0.2)', alignItems: 'center', justifyContent: 'center' },
chipText: { color: '#fff', fontFamily: font.bold, fontSize: 17 },
}); });