| sidebar_position | 4 |
|---|---|
| title | API Reference |
Scans an image for barcodes. The native module exposes a single method scan that takes one string argument (the image URL/path).
| Parameter | Type | Description |
|---|---|---|
imageURL |
string |
Local file URI (e.g. file:///...). On Android only, http:// or https:// URLs are also supported (image is downloaded then scanned). |
Returns: Promise<Barcode[]> — List of detected barcodes (empty array if none). Rejects with Barcode scanning failed (Android) or Barcode Scanning failed (iOS) on error.
interface Barcode {
format: BarcodeFormat;
/** @deprecated Use displayValue or rawValue instead. */
value: string;
rawValue: string;
displayValue: string;
}format: Barcode type (number; useBarcodeFormatenum for comparison).rawValue: Machine-readable string (from nativerawValue/getRawValue()).displayValue: Human-readable string when available (from nativedisplayValue/getDisplayValue()).value: Deprecated; usedisplayValueorrawValue. On Android it equalsrawValue; on iOS it equalsdisplayValue.
Enum of supported formats (values match the native ML Kit format codes):
enum BarcodeFormat {
UNKNOWN = -1,
ALL_FORMATS = 0,
CODE_128 = 1,
CODE_39 = 2,
CODE_93 = 4,
CODABAR = 8,
DATA_MATRIX = 16,
EAN_13 = 32,
EAN_8 = 64,
ITF = 128,
QR_CODE = 256,
UPC_A = 512,
UPC_E = 1024,
PDF417 = 2048,
AZTEC = 4096,
}Example: checking for QR codes only:
import BarcodeScanning, { BarcodeFormat } from '@react-native-ml-kit/barcode-scanning';
const barcodes = await BarcodeScanning.scan(uri);
const qrCodes = barcodes.filter((b) => b.format === BarcodeFormat.QR_CODE);