ScannerView - Advanced Android Barcode Scanner

Advanced Android-only React Native barcode scanner component with zoom, focus control, HDR, and performance tuning.

Overview

ScannerView is an Android-only component that gives you fine-grained control over the camera and scanning pipeline. It's built on top of CameraX and ML Kit, with a C++ layer for frame math and smoothing.

You probably don't need this unless you're building something specialized — like a warehouse inventory app that needs to scan codes from 5 meters away, or an app that needs to handle poor lighting or fast-moving barcodes.

If you're building a regular app, use Scanner instead.

iOS is not supported. If you render ScannerView on iOS, nothing will appear.


Import

import { ScannerView } from 'react-native-scanner-pro';

Basic usage

<ScannerView
  style={StyleSheet.absoluteFill}
  onCodeScanned={(result) => console.log(result.data)}
  barcodeFormats={['QR_CODE', 'CODE_128', 'EAN_13']}
/>

Ref methods

const ref = useRef(null);
<ScannerView ref={ref} ... />
MethodDescription
resumeScanning()Resume after freeze frame
getMetrics()Returns current performance metrics
focusAt(x, y)Focus the camera at a specific screen coordinate

Camera props

PropTypeDefaultDescription
cameraPosition'front' | 'back''back'Which camera to use
resolution'low' | 'medium' | 'high' | 'ultra''high'Camera resolution
autoFocusbooleantrueEnable autofocus
focusMode'auto' | 'continuous' | 'manual''continuous'Focus mode
tapToFocusbooleantrueTap to focus on tap location
exposurenumber0Exposure compensation (-2 to +2)
zoomnumber1Zoom level
minZoomnumber1Minimum zoom
maxZoomnumber10Maximum zoom
pinchToZoombooleantrueEnable pinch-to-zoom gesture
torchbooleanfalseFlashlight

Detection props

PropTypeDefaultDescription
barcodeFormatsBarcodeFormat[]['QR_CODE']Which barcode types to detect
scanRegionScanRegionRestrict detection to an area
enableStabilizationbooleantrueRequire multiple consistent frames before firing
stabilizationFramesnumber3Number of consistent frames required
stabilizationThresholdnumber0.8Similarity threshold (0–1)

BarcodeFormat values: QR_CODE, CODE_128, CODE_39, CODE_93, CODABAR, DATA_MATRIX, EAN_13, EAN_8, ITF, UPC_A, UPC_E, PDF417, AZTEC


Performance props

PropTypeDefaultDescription
targetFpsnumber30Target frames per second for analysis
enableFrameGatingbooleanfalseSkip frames to reduce CPU usage
frameGateIntervalnumber2Analyze every Nth frame when gating is on
enableSmoothingbooleanfalseSmooth bounding box movement
smoothingAlphanumber0.5Smoothing factor (0 = very smooth, 1 = no smoothing)
enableMetricsbooleanfalseCollect performance data
mode'default' | 'performance' | 'quality' | 'battery''default'Overall performance preset

Performance presets

Use the performanceModes helper or set mode directly:

import { performanceModes } from 'react-native-scanner-pro';

<ScannerView
  {...performanceModes.performance}
  onCodeScanned={...}
/>
ModeDescription
defaultBalanced settings
performanceHigher FPS, more CPU
qualityBetter detection accuracy
batteryLower FPS, frame gating on

Overlay props

PropTypeDefaultDescription
showOverlaybooleantrueShow any overlay
overlayMode'none' | 'standard' | 'professional' | 'minimal''standard'Overlay style
overlayColorstring#000000Overlay background color
overlayOpacitynumber0.5Overlay background opacity (0–1)

Freeze frame props

PropTypeDefaultDescription
enableFreezeFramebooleanfalsePause camera after scan
freezeFrameDurationnumber600How long to stay frozen (ms)
autoResumebooleantrueAutomatically resume after freeze
autoResumeDurationnumber1500Delay before auto-resume (ms)

Advanced camera props

PropTypeDefaultDescription
enableHdrbooleanfalseEnable HDR capture (helps in mixed lighting)
enableLowLightbooleanfalseEnable low-light enhancement
videoStabilizationbooleanfalseEnable video stabilization

Events

EventPayloadDescription
onCodeScannedScanResultFired when a stable code is detected
onCameraReadyCameraReadyEventCamera is initialized and ready
onErrorErrorEventAn error occurred
onMetricsCameraMetricsPerformance data (requires enableMetrics: true)

defaultScanRegion helper

The library exports a defaultScanRegion constant that gives you a sensible centered region config to start from:

import { ScannerView, defaultScanRegion } from 'react-native-scanner-pro';

<ScannerView
  style={StyleSheet.absoluteFill}
  scanRegion={defaultScanRegion}
  onCodeScanned={(result) => console.log(result.data)}
/>

You can spread it and override specific values:

scanRegion={{
  ...defaultScanRegion,
  width: 320,
  height: 200,
}}

Full example

import React, { useRef } from 'react';
import { View, StyleSheet } from 'react-native';
import { ScannerView } from 'react-native-scanner-pro';

export default function AdvancedScanner() {
  const ref = useRef(null);

  return (
    <View style={{ flex: 1 }}>
      <ScannerView
        ref={ref}
        style={StyleSheet.absoluteFill}
        cameraPosition="back"
        resolution="high"
        barcodeFormats={['QR_CODE', 'CODE_128', 'EAN_13']}
        enableStabilization={true}
        stabilizationFrames={3}
        mode="quality"
        enableFreezeFrame={true}
        freezeFrameDuration={500}
        autoResume={true}
        autoResumeDuration={2000}
        overlayMode="professional"
        onCodeScanned={(result) => {
          console.log('Code:', result.data, 'Type:', result.type);
        }}
        onError={(e) => {
          console.error('Scanner error:', e.nativeEvent);
        }}
      />
    </View>
  );
}