CameraScanner component provides a full-screen QR code scanner interface with visual feedback states, haptic responses, and sound effects. It validates scanned QR codes against known table data and handles navigation to the menu or displays error states.
Component overview
Located at/src/components/scanner/CameraScanner.tsx, this component:
- Manages camera permissions with a graceful error state
- Scans QR codes and validates them against table data
- Provides visual feedback (success/error states) with animated scan frames
- Offers haptic and audio feedback for successful and failed scans
- Prevents double-scan processing with idempotency guards
- Displays permission denied states with actionable recovery options
Props
TheCameraScanner component does not accept any props. It’s a standalone component that manages its own state and integrates with the app’s routing and store systems.
Usage
Permission states
The component handles three permission states:Loading state
Displays an activity indicator while checking camera permissions:Permission denied
Shows anErrorState component with options to grant permission:
Camera active
Renders the full camera view with overlay and scan frame.Scan validation
The component validates scanned QR codes againstTABLES_DATA from the mock data:
Scan states
TheScanFrame component displays different visual states:
Default neutral state while waiting for a scan
Green animated frame shown when a valid QR code is detected
Red frame displayed when an invalid QR code is scanned
Multimodal feedback
The scanner provides feedback through multiple channels:Visual feedback
- Animated scan frame that changes color based on scan state
- Darkened overlay with transparent scan area
- Toast message for invalid QR codes
Haptic feedback
- Success: Heavy impact haptic (
Haptics.ImpactFeedbackStyle.Heavy) - Error: Warning notification haptic (
Haptics.NotificationFeedbackType.Warning)
Audio feedback
- Beep sound plays on successful scan via
playBeep()fromSoundService
Idempotency guard
The component prevents double-scan processing using a ref-based guard:onToastHide callback).
Error messages
The component shows context-specific error messages:Dependencies
expo-camera: Camera access and QR code scanningexpo-haptics: Haptic feedbackexpo-router: Navigation after successful scanlucide-react-native: Icons for UI states@/src/stores/useTableStore: Table state management@/src/lib/core/sound/SoundService: Audio feedback@/src/components/scanner/ScanFrame: Animated scan frame overlay@/src/components/ui/ErrorState: Permission denied UI@/src/components/ui/ToastMessage: Error toast notifications