Skip to content

Commit f936037

Browse files
authored
Merge pull request #37 from Ombuweb/readme/mlkit-barcode-scanning
chore(mlkit-barcode-scanning): README improvements
2 parents 5374cdf + f8940b4 commit f936037

File tree

1 file changed

+254
-3
lines changed

1 file changed

+254
-3
lines changed

packages/mlkit-barcode-scanning/README.md

Lines changed: 254 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,263 @@
11
# @nativescript/mlkit-barcode-scanning
22

3-
```javascript
3+
This plugin is used with [@nativescript/mlkit-core](../mlkit-core/). It enables barcode scanning and provides the [BarcodeResult](#barcoderesult) type for the barcode-scanned data.
4+
5+
## Contents
6+
7+
* [Installation](#installation)
8+
* [Use @nativescript/mlkit-barcode-scanning](#use-nativescriptmlkit-barcode-scanning)
9+
* [Demo app](#demo-app)
10+
* [API](#api)
11+
* [BarcodeResult](#barcoderesult)
12+
13+
14+
## Installation
15+
16+
```shell
417
npm install @nativescript/mlkit-barcode-scanning
518
```
619

7-
## Usage
20+
## Use @nativescript/mlkit-barcode-scanning
21+
22+
Follow these steps to scan a barcode:
23+
24+
1. Add [MLKitView](../mlkit-core/) to your page and set the `detectionType` property to `"barcode"`.
25+
26+
```xml
27+
<StackLayout>
28+
<MLKitView
29+
detectionType="barcode"
30+
detection="{{ onDetection }}"
31+
/>
32+
<Label row="6">
33+
<FormattedString>
34+
<Span text="Barcode: "/>
35+
<Span text="{{ barcode }}" class="text-green-500"/>
36+
</FormattedString>
37+
</Label>
38+
</StackLayout>
39+
```
40+
2. To receive the scanned barcode data, handle the `detection` event and get the data if the event's type is `"barcode"`.
41+
42+
```ts
43+
import { Observable } from "@nativescript/core"
44+
import { DetectionEvent, DetectionType } from "@nativescript/mlkit-core";
45+
import { BarcodeResult } from "@nativescript/mlkit-barcode-scanning";
46+
47+
export class BarcodeScannerViewModel extends Observable {
48+
barcode = ""
49+
...
50+
onDetection(event: DetectionEvent){
51+
52+
if(event.type == DetectionType.Barcode){
53+
const barcodeData: BarcodeResult = event.data[0] as BarcodeResult;
54+
this.set("barcode", barcodeData?.rawValue)
55+
}
56+
}
57+
}
58+
59+
```
60+
#### Demo app
61+
You can try a demo app at [StackBlitz](https://stackblitz.com/edit/nativescript-stackblitz-templates-svbcbz?file=app/main-page.xml) with the [NativeScript Preview app](https://preview.nativescript.org/).
62+
63+
## API
64+
65+
### Interfaces
66+
67+
#### BarcodeResult
68+
69+
The scanned barcode data object has the following properties:
70+
71+
| Property | Type | Optional
72+
|:---------|:-----|:------------------
73+
| `format` | [BarcodeFormats](#barcodeformats) | _No_
74+
| `calendarEvent` | [CalenderEvent](#calenderevent) | _Yes_
75+
| `contactInfo` | [ContactInfo](#contactinfo) | _Yes_
76+
| `bounds` | [Bounds](#bounds) | _Yes_
77+
| `points` | [Point](#point)[] | _Yes_
78+
| `displayValue` | `string` | _Yes_
79+
| `driverLicense`| [DriverLicense](#driverlicense) | _Yes_
80+
| `email` | [Email](#email) | _Yes_
81+
| `geoPoint` | [GeoPoint](#geopoint) | _Yes_
82+
| `phone`| [Phone](#phone) | _Yes_
83+
| `rawBytes`| `any[]` | _Yes_
84+
| `rawValue` | `string` | _Yes_
85+
| `sms`| [Sms](#sms) | _Yes_
86+
| `url`| [UrlBookmark](#urlbookmark) | _Yes_
87+
| `valueType`| [ValueType]() | _Yes_
88+
| `wifi`| [WiFi](#wifi) | _Yes_
89+
90+
#### WiFi
91+
92+
| Property | Type | Optional
93+
|:---------|:-----|:-------
94+
| `encryptionType` | `string` | _No_
95+
| `password`| `string` | _No_
96+
| `ssid`| `string` | _No_
97+
98+
#### UrlBookmark
99+
| Property | Type | Optional
100+
|:---------|:-----|:-------
101+
| `title` | `string` | _Yes_
102+
| `url`| `string` | _Yes_
103+
104+
#### Sms
105+
| Property | Type | Optional
106+
|:---------|:-----|:-------
107+
| `message` | `string` | _No_
108+
| `honeNumber`| `string` | _No_
109+
110+
#### Phone
111+
| Property | Type | Optional
112+
|:---------|:-----|:-------
113+
| `number` | `string` | _No_
114+
| `type`| [PhoneType](#phonetype) | _No_
115+
116+
#### Email
117+
| Property | Type | Optional
118+
|:---------|:-----|:-------
119+
| `address` | `string` | _No_
120+
| `subject` | `string` | _No_
121+
| `body` | `string` | _No_
122+
| `type` | [EmailType](#emailtype)
123+
124+
#### DriverLicense
125+
| Property | Type | Optional
126+
|:---------|:-----|:-------
127+
| `documentType`| `string` | _No_
128+
| `firstName`| `string` | _No_
129+
| `middleName`| `string` | _No_
130+
| `lastName`| `string` | _No_
131+
| `gender`| `string` | _No_
132+
| `addressStreet`| `string` | _No_
133+
| `addressCity`| `string` | _No_
134+
| `addressState`| `string` | _No_
135+
| `addressZip`| `string` | _No_
136+
| `licenseNumber`| `string` | _No_
137+
| `issueDate`| `string` | _No_
138+
| `expiryDate`| `string` | _No_
139+
| `birthDate`| `string` | _No_
140+
| `issuingCountry`| `string` | _No_
141+
142+
#### CalenderEvent
143+
144+
| Property | Type | Optional
145+
|:---------|:-----|:-------
146+
| `description`| `string` | _Yes_
147+
| `location`| `string` | _Yes_
148+
| `organizer`| `string` | _Yes_
149+
| `status`| `string` | _Yes_
150+
| `summary`| `string` | _Yes_
151+
| `start`| `string` | _Yes_
152+
| `end`| `string` | _Yes_
153+
#### Address
154+
155+
| Property | Type | Optional
156+
|:---------|:-----|:-------
157+
| `addressLines`| `string[]`| _No_
158+
| `type` | [AddressType](#addresstype) | _No_
159+
160+
#### ContactInfo
161+
162+
| Property | Type | Optional
163+
|:---------|:-----|:-------
164+
| `addresses`| [Address](#address)[] | _No_
165+
166+
#### Origin
167+
168+
| Property | Type | Optional
169+
|:---------|:-----|:-------
170+
| `x`| `number` | _No_
171+
| `y`| `number` | _No_
172+
173+
#### Size
174+
| Property | Type | Optional
175+
|:---------|:-----|:-------
176+
| `width`| `number` | _No_
177+
| `height`| `number` | _No_
178+
179+
#### Bounds
180+
| Property | Type | Optional
181+
|:---------|:-----|:-------
182+
| `origin` | [Origin](#origin) | _No_
183+
| `size` | [Size](#size) | _No_
184+
185+
#### Point
186+
187+
| Property | Type | Optional
188+
|:---------|:-----|:-------
189+
| `x`| `number` | _No_
190+
| `y`| `number` | _No_
191+
192+
#### GeoPoint
193+
| Property | Type | Optional
194+
|:---------|:-----|:-------
195+
| `lat`| `number` | _No_
196+
| `lng`| `number` | _No_
197+
198+
### Enums
199+
200+
#### EncryptionType
201+
202+
- `Open` = `'open'`
203+
- `WPA` = `'wpa'`
204+
- `WEP` = `'wep'`
205+
- `Unknown` = `'unknown'`
206+
207+
#### PhoneType
208+
209+
- `Unknown` = `"unknown"`
210+
- `Home` = `"home"`
211+
- `Work` = `"work"`
212+
- `Fax` = `"fax"`
213+
- `Mobile` = `"mobile"`
214+
215+
#### EmailType
216+
217+
- `Unknown` = `"unknown"`
218+
- `Home` = `"home"`
219+
- `Work` = `"work"`
220+
221+
#### AddressType
222+
223+
- `Unknown` = `"unknown"`
224+
- `Home` = `"home"`
225+
- `Work` = `"work"`
226+
227+
#### ValueType
228+
229+
- `ContactInfo`= `"contactInfo"`
230+
- `Email`= `"email"`
231+
- `ISBN`= `"isbn"`
232+
- `Phone`= `"phone"`
233+
- `Product`= `"product"`
234+
- `Text`= `"text"`
235+
- `Sms`= `"sms"`
236+
- `URL`= `"url"`
237+
- `WiFi`= `"wifi"`
238+
- `Geo`= `"geo"`
239+
- `CalenderEvent`= `"calender"`
240+
- `DriverLicense`= `"driverLicense"`
241+
- `Unknown`= `"unknown"`
242+
243+
#### BarcodeFormats
244+
245+
- `ALL` = `'all'`
246+
- `CODE_128` = `'code_128'`
247+
- `CODE_39` = `'code_39'`
248+
- `CODE_93` = `'code_93'`
249+
- `CODABAR` = `'codabar'`
250+
- `DATA_MATRIX` = `'data_matrix'`
251+
- `EAN_13` = '`ean_13'`
252+
- `EAN_8` = `'ean_8'`
253+
- `ITF` = `'itf'`
254+
- `QR_CODE` = `'qr_code'`
255+
- `UPC_A` = `'upc_a'`
256+
- `UPC_E` = `'upc_e'`
257+
- `PDF417` = `'pdf417'`
258+
- `AZTEC` = `'aztec'`
259+
- `UNKOWN` = `'unknown'`
8260

9-
See [@nativescript/mlkit-core](/packages/mlkit-core/README.md) Usage
10261

11262
## License
12263

0 commit comments

Comments
 (0)