-
Notifications
You must be signed in to change notification settings - Fork 73
/
barcodescanner-common.ts
208 lines (171 loc) Β· 5.06 KB
/
barcodescanner-common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import { ContentView } from "tns-core-modules/ui/content-view";
import { Property } from "tns-core-modules/ui/core/properties";
import { booleanConverter } from "tns-core-modules/ui/core/view-base";
export 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";
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;
/**
* 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;
}
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<boolean>;
stop(): Promise<any>;
scan(arg: ScanOptions): Promise<ScanResult>;
}
/**** View-related stuff below ****/
export const formatsProperty = new Property<BarcodeScannerView, string>({
name: "formats",
defaultValue: null,
});
export const preferFrontCameraProperty = new Property<BarcodeScannerView, boolean>({
name: "preferFrontCamera",
defaultValue: false,
valueConverter: booleanConverter
});
export const beepOnScanProperty = new Property<BarcodeScannerView, boolean>({
name: "beepOnScan",
defaultValue: true,
valueConverter: booleanConverter
});
export const reportDuplicatesProperty = new Property<BarcodeScannerView, boolean>({
name: "reportDuplicates",
defaultValue: false,
valueConverter: booleanConverter
});
export abstract class BarcodeScannerView extends ContentView {
static scanResultEvent: string = "scanResult";
protected formats: string;
protected preferFrontCamera: boolean;
protected beepOnScan: boolean;
protected reportDuplicates: boolean;
[formatsProperty.setNative](value: string) {
this.formats = value;
}
[preferFrontCameraProperty.setNative](value: boolean) {
this.preferFrontCamera = value;
}
[beepOnScanProperty.setNative](value: boolean) {
this.beepOnScan = value;
}
[reportDuplicatesProperty.setNative](value: boolean) {
this.reportDuplicates = value;
}
}
formatsProperty.register(BarcodeScannerView);
preferFrontCameraProperty.register(BarcodeScannerView);
beepOnScanProperty.register(BarcodeScannerView);
reportDuplicatesProperty.register(BarcodeScannerView);