BNA

BNA UI
26

A powerful camera component with advanced features like zoom, timer, torch, and video recording.

Installation

pnpm dlx bna-ui add camera

Usage

import { Camera } from '@/components/ui/camera';
<Camera
  onCapture={({ uri, type }) => {
    console.log('Captured:', uri, type);
  }}
  onVideoCapture={({ uri, type }) => {
    console.log('Video captured:', uri, type);
  }}
  onClose={() => {
    // Handle camera close
  }}
/>

Examples

Default

With Custom Controls

Picture Only Mode

Video Recording

Timer Features

Zoom Controls

Settings Panel

API Reference

Camera

The main camera component with comprehensive controls and features.

PropTypeDefaultDescription
styleViewStyle-Additional styles to apply to the camera container.
facing'front' | 'back''back'The initial camera facing direction.
enableTorchbooleantrueWhether to show the torch/flash control.
showControlsbooleantrueWhether to show the camera controls overlay.
timerOptionsnumber[][0, 3, 10]Available timer options in seconds.
enableVideobooleantrueWhether to enable video recording mode.
maxVideoDurationnumber60Maximum video duration in seconds.
onClose() => void-Callback when the close button is pressed.
onCapture({ type, uri, cameraHeight }) => void-Callback when a picture is captured.
onVideoCapture({ type, uri, cameraHeight }) => void-Callback when a video is captured.

CameraRef

The camera component exposes these methods via ref:

MethodTypeDescription
switchCamera() => voidSwitch between front and back camera.
toggleTorch() => voidToggle the torch/flash on and off.
takePicture() => Promise<void>Programmatically take a picture.
startRecording() => Promise<void>Start video recording.
stopRecording() => Promise<void>Stop video recording.

CaptureSuccess

The callback data structure for successful captures:

PropertyTypeDescription
type'picture' | 'video'The type of media captured.
uristringThe local URI of the captured media.
cameraHeightnumberThe height of the camera view when captured.

Features

Camera Controls

  • Capture Button: Large, prominent button for taking pictures or starting/stopping video recording
  • Mode Toggle: Switch between picture and video modes
  • Camera Flip: Switch between front and back cameras
  • Torch/Flash: Toggle flashlight for back camera
  • Zoom: Pinch-to-zoom gestures and tap-to-zoom controls

Advanced Features

  • Timer: Set delays of 0, 3, or 10 seconds before capture
  • Grid Lines: Rule of thirds overlay for better composition
  • Aspect Ratios: Support for 16:9, 4:3, and 1:1 ratios
  • Sound Control: Enable/disable camera sounds
  • Settings Panel: Collapsible panel with advanced options

Gestures

  • Pinch to Zoom: Smooth zoom in/out with gesture controls
  • Double Tap: Quick zoom toggle between 1x and 2.5x
  • Tap Controls: Tap zoom button to cycle through zoom levels

Video Recording

  • Recording Timer: Shows elapsed recording time
  • Duration Limit: Configurable maximum recording duration
  • Visual Feedback: Recording indicator with red dot animation

Permissions

The Camera component requires camera and microphone permissions. The component will:

  1. Check for existing permissions
  2. Show a permission request screen if not granted
  3. Provide a clear call-to-action to grant permissions
  4. Handle permission denial gracefully

Accessibility

The Camera component includes accessibility features:

  • Screen Reader Support: All controls have appropriate labels
  • High Contrast: Clear visual distinction between active/inactive states
  • Touch Targets: All interactive elements meet minimum size requirements
  • Keyboard Navigation: Focus management for external keyboard users
  • Reduced Motion: Respects system animation preferences

Performance

  • Optimized Rendering: Minimal re-renders using React.memo and useCallback
  • Gesture Handling: Efficient native gesture recognition
  • Memory Management: Proper cleanup of timers and resources
  • Battery Optimization: Automatic torch disable when switching cameras

Error Handling

The component handles various error scenarios:

  • Permission Denied: Shows clear permission request screen
  • Camera Unavailable: Graceful fallback with error messages
  • Recording Failures: User-friendly error alerts
  • Memory Issues: Automatic cleanup and error recovery

Customization

The Camera component can be customized through:

  • Theme Integration: Uses theme colors and design tokens
  • Custom Styles: Style prop for container customization
  • Control Visibility: Toggle individual control elements
  • Timer Options: Configure available timer durations
  • Aspect Ratios: Support for multiple aspect ratios