Scan Region

Limit barcode detection to a specific area on screen with a customizable viewfinder overlay.

What is a scan region?

A scan region lets you define a rectangular area on the camera preview. Only barcodes that are fully inside that area will be detected — anything outside gets ignored.

This is useful when your UI has other things on screen and you want to guide the user to a specific spot. Think of it like a viewfinder box, similar to what you'd see in banking apps or parcel delivery apps.

Scan region with dimmed overlay outside the frame

Basic example

import { Scanner } from 'react-native-scanner-pro';
import { StyleSheet } from 'react-native';

<Scanner
  style={StyleSheet.absoluteFill}
  onCodeScanned={(result) => console.log(result.data)}
  scanRegion={{
    enabled: true,
    width: 280,
    height: 280,
  }}
/>

This draws a 280×280 centered viewfinder on the screen. The dim mask covers everything outside of it.


How the filtering works

The library checks whether the entire bounding box of a detected barcode is inside the scan region. If any part of the code sticks outside the region, it won't trigger.

This means the user has to line up the code properly before a scan fires — which actually feels more natural and intentional.


Customizing the appearance

You can control almost everything about how the region looks:

<Scanner
  style={StyleSheet.absoluteFill}
  onCodeScanned={(result) => console.log(result.data)}
  scanRegion={{
    enabled: true,
    width: 300,
    height: 200,

    // Move the box up or down from center
    offsetY: -60,

    // Border
    borderColor: '#00AAFF',
    borderWidth: 2,
    cornerRadius: 16,

    // Corner brackets
    showCorners: true,
    cornerLength: 36,
    cornerWidth: 5,

    // Dim overlay behind the region
    dimColor: '#000000',
    dimAlpha: 160,

    // Hint text shown below the box
    showHint: true,
    hintText: 'Point camera at the barcode',
    hintTextColor: '#FFFFFF',
    hintTextSize: 14,
  }}
/>

Moving the region off-center

By default the region is centered. You can shift it using offsetX and offsetY:

scanRegion={{
  enabled: true,
  width: 300,
  height: 300,
  offsetX: 0,    // Positive moves right, negative moves left
  offsetY: -80,  // Negative moves up, positive moves down
}}

This is handy when you have a result card at the bottom of the screen and want the scanner box to sit in the upper-center area.


All options

OptionTypeDefaultDescription
enabledbooleanRequired. Set to true to activate the region
widthnumber300Width of the scan area
heightnumber300Height of the scan area
offsetXnumber0Horizontal offset from center
offsetYnumber0Vertical offset from center
cornerRadiusnumber12Rounded corners on the cutout
borderColorstring#FFFFFFBorder color (#RRGGBB or #RRGGBBAA)
borderWidthnumber3Border thickness in points/dp
showBorderbooleantrueShow the border around the cutout
dimColorstring#000000Color of the dim mask
dimAlphanumber180Opacity of the dim mask (0–255)
showCornersbooleantrueShow corner bracket decorations
cornerLengthnumber30Length of each corner bracket
cornerWidthnumber4Line width of corner brackets
showHintbooleantrueShow hint text below the frame
hintTextstring"Align code within frame"The hint message
hintTextColorstring#FFFFFFHint text color
hintTextSizenumber14Hint font size

Units

  • On Android, sizes (width, height, offsetX, offsetY) are in dp (density-independent pixels). The library converts them to actual pixels internally.
  • On iOS, sizes are in points.

In practice, you can use the same values on both platforms and they'll look roughly the same.


Full example with hint and custom style

<Scanner
  style={StyleSheet.absoluteFill}
  onCodeScanned={(result) => {
    console.log('Scanned inside region:', result.data);
  }}
  scanRegion={{
    enabled: true,
    width: 260,
    height: 260,
    cornerRadius: 20,
    borderColor: '#4CAF50',
    borderWidth: 2,
    showCorners: true,
    cornerLength: 32,
    cornerWidth: 4,
    dimColor: '#000000',
    dimAlpha: 200,
    showHint: true,
    hintText: 'Scan a QR code to continue',
    hintTextColor: '#EEEEEE',
    hintTextSize: 13,
  }}
/>