ScannerViewfinder
ScannerViewfinder is the web camera view that decodes barcodes from a live video stream and reports each code and its status.
Import
import { ScannerViewfinder } from '@tallyui/components';
import type { CameraDecoder, ViewfinderStatus } from '@tallyui/pos';Usage
<ScannerViewfinder
onDetected={(code, symbology) => offer(code, symbology)}
onStatus={(status) => setStatus(status)}
/>CameraScannerPanel renders it by default, so an app rarely uses it directly. On the web, where navigator.mediaDevices.getUserMedia exists, it opens the camera (the rear one where it can) into a muted, inline <video> that fills the view and decodes it with startDecodeLoop from @tallyui/pos. On unmount it stops the decode loop and the camera tracks, including a stream that arrives after unmount.
Anywhere else, including native, it reports 'camera-unavailable' and renders an empty view. A native app passes its own viewfinder with the same props to CameraScannerPanel (for example one built on expo-camera).
Props
| Prop | Type | Default | Description |
|---|---|---|---|
onDetected | (code: string, symbology?: string) => void | required | Called with each decoded code |
onStatus | (status: ViewfinderStatus) => void | required | Called as the camera state changes |
decoder | CameraDecoder | the BarcodeDetector global | An object with the same detect method, such as a ponyfill |
When no decoder is passed and the browser has no BarcodeDetector, the status becomes 'decoder-error' once the camera is open.
ViewfinderStatus
The props in the table above are exported as the type ViewfinderProps, the shape a replacement viewfinder takes. ViewfinderStatus is the union passed to onStatus:
type ViewfinderStatus = 'initializing' | 'scanning' | 'camera-denied' | 'camera-unavailable' | 'decoder-error';A camera error reports 'camera-denied' when access is refused (a NotAllowedError) and 'camera-unavailable' otherwise. 'decoder-error' also follows five decode failures in a row, and 'scanning' returns on the next successful decode.
CameraScannerPanel
CameraScannerPanel is the inline, resizable camera barcode scanner, with a close button, status text and a flash on each accepted scan.
SearchInput
SearchInput is a styled, controlled search field with an icon, change callback, and customizable placeholder for filtering product lists.