NativeScript MLKit Barcode Scanner module
npm install @nativescript/mlkit-barcode-scanningThis plugin is used with @nativescript/mlkit-core. It enables barcode scanning and provides the BarcodeResult type for the barcode-scanned data.
* Installation
* Use @nativescript/mlkit-barcode-scanning
* Demo app
* API
* BarcodeResult
``shell`
npm install @nativescript/mlkit-barcode-scanning
Follow these steps to scan a barcode:
1. Add MLKitView to your page and set the detectionType property to "barcode".
`xml`
detection="{{ onDetection }}"
/>
detection
2. To receive the scanned barcode data, handle the event and get the data if the event's type is "barcode".
`ts
import { Observable } from "@nativescript/core"
import { DetectionEvent, DetectionType } from "@nativescript/mlkit-core";
import { BarcodeResult } from "@nativescript/mlkit-barcode-scanning";
export class BarcodeScannerViewModel extends Observable {
barcode = ""
...
onDetection(event: DetectionEvent){
if(event.type == DetectionType.Barcode){
const barcodeData: BarcodeResult = event.data[0] as BarcodeResult;
this.set("barcode", barcodeData?.rawValue)
}
}
}
`
#### Demo app
You can try a demo app at StackBlitz with the NativeScript Preview app.
#### BarcodeResult
The scanned barcode data object has the following properties:
| Property | Type | Optional
|:---------|:-----|:------------------
| format | BarcodeFormats | _No_calendarEvent
| | CalenderEvent | _Yes_contactInfo
| | ContactInfo | _Yes_bounds
| | Bounds | _Yes_points
| | Point[] | _Yes_displayValue
| | string | _Yes_driverLicense
| | DriverLicense | _Yes_email
| | Email | _Yes_geoPoint
| | GeoPoint | _Yes_phone
| | Phone | _Yes_rawBytes
| | any[] | _Yes_rawValue
| | string | _Yes_sms
| | Sms | _Yes_url
| | UrlBookmark | _Yes_valueType
| | [ValueType]() | _Yes_wifi
| | WiFi | _Yes_
#### WiFi
| Property | Type | Optional
|:---------|:-----|:-------
| encryptionType | string | _No_password
| | string | _No_ssid
| | string | _No_
#### UrlBookmark
| Property | Type | Optional
|:---------|:-----|:-------
| title | string | _Yes_url
| | string | _Yes_
#### Sms
| Property | Type | Optional
|:---------|:-----|:-------
| message | string | _No_honeNumber
| | string | _No_
#### Phone
| Property | Type | Optional
|:---------|:-----|:-------
| number | string | _No_type
| | PhoneType | _No_
#### Email
| Property | Type | Optional
|:---------|:-----|:-------
| address | string | _No_subject
| | string | _No_body
| | string | _No_type
| | EmailType
#### DriverLicense
| Property | Type | Optional
|:---------|:-----|:-------
| documentType| string | _No_firstName
| | string | _No_middleName
| | string | _No_lastName
| | string | _No_gender
| | string | _No_addressStreet
| | string | _No_addressCity
| | string | _No_addressState
| | string | _No_addressZip
| | string | _No_licenseNumber
| | string | _No_issueDate
| | string | _No_expiryDate
| | string | _No_birthDate
| | string | _No_issuingCountry
| | string | _No_
#### CalenderEvent
| Property | Type | Optional
|:---------|:-----|:-------
| description| string | _Yes_location
| | string | _Yes_organizer
| | string | _Yes_status
| | string | _Yes_summary
| | string | _Yes_start
| | string | _Yes_end
| | string | _Yes_
#### Address
| Property | Type | Optional
|:---------|:-----|:-------
| addressLines| string[]| _No_ type
| | AddressType | _No_
#### ContactInfo
| Property | Type | Optional
|:---------|:-----|:-------
| addresses| Address[] | _No_
#### Origin
| Property | Type | Optional
|:---------|:-----|:-------
| x| number | _No_y
| | number | _No_
#### Size
| Property | Type | Optional
|:---------|:-----|:-------
| width| number | _No_height
| | number | _No_
#### Bounds
| Property | Type | Optional
|:---------|:-----|:-------
| origin | Origin | _No_size
| | Size | _No_
#### Point
| Property | Type | Optional
|:---------|:-----|:-------
| x| number | _No_y
| | number | _No_
#### GeoPoint
| Property | Type | Optional
|:---------|:-----|:-------
| lat| number | _No_lng
| | number | _No_
#### EncryptionType
- Open = 'open'WPA
- = 'wpa'WEP
- = 'wep'Unknown
- = 'unknown'
#### PhoneType
- Unknown = "unknown"Home
- = "home"Work
- = "work"Fax
- = "fax"Mobile
- = "mobile"
#### EmailType
- Unknown = "unknown"Home
- = "home"Work
- = "work"
#### AddressType
- Unknown = "unknown"Home
- = "home"Work
- = "work"
#### ValueType
- ContactInfo= "contactInfo"
- = "email"ISBN
- = "isbn"Phone
- = "phone"Product
- = "product"Text
- = "text"Sms
- = "sms"URL
- = "url"WiFi
- = "wifi"Geo
- = "geo"CalenderEvent
- = "calender"DriverLicense
- = "driverLicense"Unknown
- = "unknown"
#### BarcodeFormats
- ALL = 'all'CODE_128
- = 'code_128'CODE_39
- = 'code_39'CODE_93
- = 'code_93'CODABAR
- = 'codabar'DATA_MATRIX
- = 'data_matrix'EAN_13
- = 'ean_13'EAN_8
- = 'ean_8'ITF
- = 'itf'QR_CODE
- = 'qr_code'UPC_A
- = 'upc_a'UPC_E
- = 'upc_e'PDF417
- = 'pdf417'AZTEC
- = 'aztec'UNKOWN
- = 'unknown'`
Apache License Version 2.0