Tally UI

CameraScannerPanel

CameraScannerPanel is the inline, resizable camera barcode scanner, with a close button, status text and a flash on each accepted scan.

Import

import { CameraScannerPanel } from '@tallyui/components';
import type { CameraDecoder } from '@tallyui/pos';

Usage

<CameraScannerPanel
  onClose={() => setScannerOpen(false)}
  height={scannerHeight}
  onHeightChange={setScannerHeight}
  onDetected={camera.offer}
  onOpen={camera.reset}
  scanCount={camera.scanCount}
/>

The inline camera scanner, ported from WCPOS v2. It calls no POS hook: the app owns useCameraScan (and its ScanHubProvider) and passes its offer, reset and scanCount, so accepted decodes reach the app's useBarcodeScanner like any device scan. Mounting the panel calls onOpen once, and each change of scanCount after mount flashes a border around the view.

The camera view is ScannerViewfinder by default, which works on the web only. A native app passes its own viewfinder (for example one built on expo-camera) and a permission; while permission.granted is false the panel shows an "Allow camera" button that calls permission.request instead of the camera. On the web, leave permission out: the browser asks when the camera opens.

Status text from the viewfinder (starting, access denied, camera unavailable, decoding failing) and the readiness note are shown over the bottom of the view. A handle under the view resizes it: by pointer drag on the web, reported to onHeightChange once when the drag ends if the height changed, and by the accessibility increment and decrement actions, 16 points a step, reported on each step.

Props

PropTypeDefaultDescription
onClose() => voidrequiredCalled by the close button
heightnumberSCANNER_DEFAULT_HEIGHTHeight of the camera view, clamped to the min and max below
onHeightChange(height: number) => void—Called with the new height after a resize; the app persists it
permission{ granted: boolean; request: () => void }—Native permission flow; omit on web
viewfinderComponentType<ViewfinderProps>ScannerViewfinderThe camera view component
decoderCameraDecoder—Passed to the viewfinder
readinessstring—A note such as storage or sync starting; the app picks the copy
onDetected(code: string, symbology?: string) => voidrequiredEach decode, passed straight to the viewfinder
onOpen() => void—Called once on mount
scanCountnumber—Each change after mount flashes the panel

Constants

ConstantValueMeaning
SCANNER_MIN_HEIGHT96Smallest height of the camera view
SCANNER_MAX_HEIGHT480Largest height of the camera view
SCANNER_DEFAULT_HEIGHT176Height when height is not passed
FLASH_DURATION_MS350How long the scan flash stays on; a new scan restarts it