UNPKG

@nstudio/nativescript-barcodescanner

Version:
139 lines (138 loc) 4.96 kB
import { ContentView, Property } from '@nativescript/core'; export declare type BarcodeFormat = 'QR_CODE' | 'PDF_417' | 'AZTEC' | 'UPC_E' | 'CODE_39' | 'CODE_39_MOD_43' | 'CODE_93' | 'CODE_128' | 'DATA_MATRIX' | 'EAN_8' | 'ITF' | 'EAN_13' | 'UPC_A' | 'CODABAR' | 'MAXICODE' | 'RSS_14' | 'INTERLEAVED_2_OF_5'; export interface ScanResult { text: string; format: BarcodeFormat; } export interface CommonScanOptions { /** * A comma sep. string of barcode types: "QR_CODE,PDF_417" * Default: empty, so all types of codes can be scanned. */ formats?: string; /** * By default the scanned object is returned in the Promise, * but if you want to scan continuously (until you call 'stop'), * you can provide a callback function that receives the same object * as the Promise would, but every time something is scanned. * * This function doesn't report duplicates in the same scanning session, * unless reportDuplicates is set to true. */ continuousScanCallback?: (scanResult: ScanResult) => void; /** * Called when the user stopped/cancelled scanning, or in single scan mode when the scan was successful. */ closeCallback?: () => void; /** * Wheter or not to report duplicate scan results during continuous scanning. * Default false. */ reportDuplicates?: boolean; /** * Start the scanner with the front camera? * Default: false, so the back camera is used. */ preferFrontCamera?: boolean; /** * While scanning for a barcode show a button to flip to the other camera (front or back). * Default: false */ showFlipCameraButton?: boolean; /** * Default: false */ showTorchButton?: boolean; /** * Currently only used on iOS; with iOS 13 modals are no longer shown fullScreen by default, * which may be actually preferred. But to use the old fullScreen appearance, set this to 'true'. * Default: false */ fullScreen?: boolean; /** * Launch the scanner with the flashlight turned on. */ torchOn?: boolean; /** * Play a sound when a code was scanned. * Default: true */ beepOnScan?: boolean; } export interface IOS extends CommonScanOptions { /** * The label of the button used to close the scanner. * Default: "Close". */ cancelLabel?: string; /** * The background color of the button the label is drawn upon. * Default: "#000000" (black) */ cancelLabelBackgroundColor?: string; /** * You can send the user to the settings app if access was previously denied. * Default: false */ openSettingsIfPermissionWasPreviouslyDenied?: boolean; /** * If you're sure you're not presenting the (non embedded) scanner in a modal, * or are experiencing issues with fi. the navigationbar, please set this to 'true'. * Default: false */ presentInRootViewController?: boolean; } export interface Android extends CommonScanOptions { /** * The message shown when looking for something to scan. * Default: "Place a barcode inside the viewfinder rectangle to scan it." */ message?: string; /** * Optionally lock the orientation to 'portrait' or 'landscape'. * Default: "sensor", which follows the current device rotation. */ orientation?: string; /** * Default is 1500, set to 0 o suppress the scanner echoing the scanned text. */ resultDisplayDuration?: number; } export interface ScanOptions extends IOS, Android { IOS?: IOS; Android?: Android; } export declare class BarcodeScanner { private _observer; private _observerActive; private _currentVolume; private _scanner; constructor(); private _hasCameraPermission; private _hasDeniedCameraPermission; private _addVolumeObserver; private _removeVolumeObserver; private _enableTorch; private _disableTorch; available(): Promise<boolean>; hasCameraPermission(): Promise<boolean>; requestCameraPermission(): Promise<void>; stop(): Promise<void>; scan(arg: ScanOptions): Promise<ScanResult>; } /**** View-related stuff below ****/ export declare const formatsProperty: any; export declare const preferFrontCameraProperty: Property<BarcodeScannerView, boolean>; export declare const beepOnScanProperty: Property<BarcodeScannerView, boolean>; export declare const reportDuplicatesProperty: Property<BarcodeScannerView, boolean>; export declare const pauseProperty: Property<BarcodeScannerView, boolean>; export declare abstract class BarcodeScannerView extends ContentView { static scanResultEvent: string; protected formats: string; protected preferFrontCamera: boolean; protected beepOnScan: boolean; protected reportDuplicates: boolean; protected pause: boolean; protected pauseScanning(): void; protected resumeScanning(): void; }