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:
parent
47a3030100
commit
39806791c4
1 changed files with 96 additions and 32 deletions
114
pro/app/scan.tsx
114
pro/app/scan.tsx
|
|
@ -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 } });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* Voile sombre autour du cadre de visée */}
|
||||||
|
<View style={StyleSheet.absoluteFill} pointerEvents="none">
|
||||||
|
<View style={{ flex: 1, backgroundColor: DIM }} />
|
||||||
|
<View style={{ flexDirection: 'row', height: FRAME }}>
|
||||||
|
<View style={{ flex: 1, backgroundColor: DIM }} />
|
||||||
|
<View style={{ width: FRAME, height: FRAME }}>
|
||||||
|
{corner({ top: 0, left: 0, borderTopWidth: 5, borderLeftWidth: 5, borderTopLeftRadius: 24 })}
|
||||||
|
{corner({ top: 0, right: 0, borderTopWidth: 5, borderRightWidth: 5, borderTopRightRadius: 24 })}
|
||||||
|
{corner({ bottom: 0, left: 0, borderBottomWidth: 5, borderLeftWidth: 5, borderBottomLeftRadius: 24 })}
|
||||||
|
{corner({ bottom: 0, right: 0, borderBottomWidth: 5, borderRightWidth: 5, borderBottomRightRadius: 24 })}
|
||||||
|
<Animated.View
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
left: 18,
|
||||||
|
right: 18,
|
||||||
|
height: 3,
|
||||||
|
borderRadius: 2,
|
||||||
|
backgroundColor: invalid ? '#F08A80' : '#F2B544',
|
||||||
|
transform: [{ translateY: line.interpolate({ inputRange: [0, 1], outputRange: [18, FRAME - 21] }) }],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<View style={{ flex: 1, backgroundColor: DIM }} />
|
||||||
|
</View>
|
||||||
|
<View style={{ flex: 1, backgroundColor: DIM }} />
|
||||||
|
</View>
|
||||||
|
|
||||||
<SafeAreaView style={{ flex: 1, justifyContent: 'space-between', padding: 20 }}>
|
<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>
|
{/* Barre du haut : fermer + consigne */}
|
||||||
<View style={styles.frame} accessibilityElementsHidden />
|
<View style={{ gap: 18 }}>
|
||||||
<View style={{ gap: 12 }}>
|
<Pressable accessibilityRole="button" accessibilityLabel="Fermer" onPress={() => router.back()} style={styles.round} hitSlop={8}>
|
||||||
{invalid && (
|
<T style={{ color: '#fff', fontSize: 22, lineHeight: 24 }}>✕</T>
|
||||||
<T style={{ color: '#fff', textAlign: 'center', backgroundColor: 'rgba(184,50,42,0.9)', padding: 10, borderRadius: 10, overflow: 'hidden' }}>
|
|
||||||
Ce QR code n'est pas une carte MonEspacePro.
|
|
||||||
</T>
|
|
||||||
)}
|
|
||||||
<View style={{ flexDirection: 'row', gap: 12 }}>
|
|
||||||
<Pressable accessibilityRole="button" onPress={() => router.back()} style={styles.chip}>
|
|
||||||
<T style={styles.chipText}>Annuler</T>
|
|
||||||
</Pressable>
|
</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
|
<Pressable
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={torch ? 'Éteindre la lampe' : 'Allumer la lampe'}
|
||||||
accessibilityState={{ selected: torch }}
|
accessibilityState={{ selected: torch }}
|
||||||
onPress={() => setTorch((t) => !t)}
|
onPress={() => setTorch((t) => !t)}
|
||||||
style={[styles.chip, torch && { backgroundColor: '#F2B544' }]}
|
style={[styles.round, { width: 64, height: 64, borderRadius: 32 }, torch && { backgroundColor: '#F2B544' }]}
|
||||||
>
|
>
|
||||||
<T style={[styles.chipText, torch && { color: '#1C1C19' }]}>{torch ? 'Lampe allumée' : 'Lampe'}</T>
|
<T style={{ fontSize: 26 }}>🔦</T>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
<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 },
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue