nativescript-barcodescanner
Advanced tools
Comparing version 2.0.0 to 2.1.0
import { ScanOptions } from "./barcodescanner.common"; | ||
export declare class BarcodeScanner { | ||
private broadcastManager; | ||
private _onReceiveCallback; | ||
private _continuousScanCallback; | ||
private _scannedArray; | ||
private _onPermissionGranted; | ||
private _reject; | ||
private onScanReceivedCallback; | ||
private onContinuousScanResult; | ||
private uniquelyScannedCodes; | ||
private onPermissionGranted; | ||
private onPermissionRejected; | ||
private rememberedContext; | ||
constructor(); | ||
private _cameraPermissionGranted; | ||
private _requestCameraPermission; | ||
private wasCameraPermissionGranted; | ||
private requestCameraPermissionInternal; | ||
available(): Promise<boolean>; | ||
@@ -14,0 +14,0 @@ hasCameraPermission(): Promise<boolean>; |
@@ -10,3 +10,3 @@ "use strict"; | ||
this.rememberedContext = null; | ||
this._cameraPermissionGranted = function () { | ||
this.wasCameraPermissionGranted = function () { | ||
var hasPermission = android.os.Build.VERSION.SDK_INT < 23; | ||
@@ -19,5 +19,5 @@ if (!hasPermission) { | ||
}; | ||
this._requestCameraPermission = function (onPermissionGranted, reject) { | ||
this._onPermissionGranted = onPermissionGranted; | ||
this._reject = reject; | ||
this.requestCameraPermissionInternal = function (onPermissionGranted, reject) { | ||
this.onPermissionGranted = onPermissionGranted; | ||
this.onPermissionRejected = reject; | ||
android.support.v4.app.ActivityCompat.requestPermissions(appModule.android.currentContext, [android.Manifest.permission.CAMERA], 234); | ||
@@ -29,8 +29,8 @@ }; | ||
if (args.grantResults[i] === android.content.pm.PackageManager.PERMISSION_DENIED) { | ||
self._reject("Please allow access to the Camera and try again."); | ||
self.onPermissionRejected("Please allow access to the Camera and try again."); | ||
return; | ||
} | ||
} | ||
if (self._onPermissionGranted) { | ||
self._onPermissionGranted(); | ||
if (self.onPermissionGranted) { | ||
self.onPermissionGranted(); | ||
} | ||
@@ -57,3 +57,3 @@ else { | ||
return new Promise(function (resolve) { | ||
var granted = self._cameraPermissionGranted(); | ||
var granted = self.wasCameraPermissionGranted(); | ||
resolve(granted); | ||
@@ -67,3 +67,3 @@ }); | ||
try { | ||
self._requestCameraPermission(resolve, reject); | ||
self.requestCameraPermissionInternal(resolve, reject); | ||
} | ||
@@ -83,4 +83,4 @@ catch (ex) { | ||
self.broadcastManager.sendBroadcast(stopIntent); | ||
self.broadcastManager.unregisterReceiver(self._onReceiveCallback); | ||
self._onReceiveCallback = undefined; | ||
self.broadcastManager.unregisterReceiver(self.onScanReceivedCallback); | ||
self.onScanReceivedCallback = undefined; | ||
resolve(); | ||
@@ -121,5 +121,5 @@ } | ||
} | ||
self._continuousScanCallback = arg.continuousScanCallback; | ||
self.onContinuousScanResult = arg.continuousScanCallback; | ||
intent.putExtra(com.google.zxing.client.android.Intents.Scan.BULK_SCAN, true); | ||
self._scannedArray = []; | ||
self.uniquelyScannedCodes = new Array(); | ||
var CallbackReceiver = android.content.BroadcastReceiver.extend({ | ||
@@ -129,5 +129,5 @@ onReceive: function (context, data) { | ||
var text = data.getStringExtra(com.google.zxing.client.android.Intents.Scan.RESULT); | ||
if (self._scannedArray.indexOf("[" + text + "][" + format + "]") == -1) { | ||
self._scannedArray.push("[" + text + "][" + format + "]"); | ||
self._continuousScanCallback({ | ||
if (self.uniquelyScannedCodes.indexOf("[" + text + "][" + format + "]") == -1) { | ||
self.uniquelyScannedCodes.push("[" + text + "][" + format + "]"); | ||
self.onContinuousScanResult({ | ||
format: format, | ||
@@ -139,4 +139,4 @@ text: text | ||
}); | ||
self._onReceiveCallback = new CallbackReceiver(); | ||
self.broadcastManager.registerReceiver(self._onReceiveCallback, new android.content.IntentFilter("bulk-barcode-result")); | ||
self.onScanReceivedCallback = new CallbackReceiver(); | ||
self.broadcastManager.registerReceiver(self.onScanReceivedCallback, new android.content.IntentFilter("bulk-barcode-result")); | ||
} | ||
@@ -153,4 +153,4 @@ if (intent.resolveActivity(com.tns.NativeScriptApplication.getInstance().getPackageManager()) !== null) { | ||
if (isContinuous) { | ||
self.broadcastManager.unregisterReceiver(self._onReceiveCallback); | ||
self._onReceiveCallback = undefined; | ||
self.broadcastManager.unregisterReceiver(self.onScanReceivedCallback); | ||
self.onScanReceivedCallback = undefined; | ||
} | ||
@@ -182,4 +182,4 @@ else { | ||
}; | ||
if (!self._cameraPermissionGranted()) { | ||
self._requestCameraPermission(onPermissionGranted, reject); | ||
if (!self.wasCameraPermissionGranted()) { | ||
self.requestCameraPermissionInternal(onPermissionGranted, reject); | ||
return; | ||
@@ -186,0 +186,0 @@ } |
export interface CommonScanOptions { | ||
formats?: string; | ||
continuousScanCallback?: Function; | ||
preferFrontCamera?: boolean; | ||
showFlipCameraButton?: boolean; | ||
} | ||
@@ -8,7 +10,6 @@ export interface IOS extends CommonScanOptions { | ||
openSettingsIfPermissionWasPreviouslyDenied?: boolean; | ||
showTorchButton?: boolean; | ||
} | ||
export interface Android extends CommonScanOptions { | ||
message?: string; | ||
preferFrontCamera?: boolean; | ||
showFlipCameraButton?: boolean; | ||
orientation?: string; | ||
@@ -15,0 +16,0 @@ } |
import { ScanOptions } from "./barcodescanner.common"; | ||
import { ContentView } from "ui/content-view"; | ||
export declare class BarcodeScannerView extends ContentView { | ||
private _reader; | ||
private _scanner; | ||
private _ios; | ||
private _continuous; | ||
constructor(); | ||
ios: any; | ||
continuous: boolean; | ||
} | ||
export declare class BarcodeScanner { | ||
private _observer; | ||
private _currentVolume; | ||
private _scanner; | ||
constructor(); | ||
@@ -6,0 +17,0 @@ private _hasCameraPermission; |
"use strict"; | ||
var content_view_1 = require("ui/content-view"); | ||
var utils = require("utils/utils"); | ||
var frame = require("ui/frame"); | ||
var BarcodeScannerView = (function (_super) { | ||
__extends(BarcodeScannerView, _super); | ||
function BarcodeScannerView() { | ||
_super.call(this); | ||
var closeButtonLabel = "bla"; | ||
var types = [AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, | ||
AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code, | ||
AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode]; | ||
this._reader = QRCodeReader.readerWithMetadataObjectTypes(types); | ||
var torch = false; | ||
var flip = false; | ||
var startScanningAtLoad = true; | ||
var isContinuous = false; | ||
var delegate = QRCodeReaderDelegateImpl.new().initWithCallback(isContinuous, function (reader, text, format) { | ||
delegate = undefined; | ||
}); | ||
console.log("--- ios: " + this._ios); | ||
this._ios = this._reader.previewLayer; | ||
this._reader.startScanning(); | ||
} | ||
Object.defineProperty(BarcodeScannerView.prototype, "ios", { | ||
get: function () { | ||
return this._ios; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(BarcodeScannerView.prototype, "continuous", { | ||
set: function (value) { | ||
this._continuous = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return BarcodeScannerView; | ||
}(content_view_1.ContentView)); | ||
exports.BarcodeScannerView = BarcodeScannerView; | ||
var BarcodeScanner = (function () { | ||
@@ -127,4 +165,11 @@ function BarcodeScanner() { | ||
} | ||
var bs = QRCodeReaderViewController.readerWithCancelButtonTitleMetadataObjectTypes(closeButtonLabel, types); | ||
bs.modalPresentationStyle = 2; | ||
var reader = QRCodeReader.readerWithMetadataObjectTypes(types); | ||
if (arg.preferFrontCamera && reader.hasFrontDevice()) { | ||
reader.switchDeviceInput(); | ||
} | ||
var torch = arg.showTorchButton; | ||
var flip = arg.showFlipCameraButton; | ||
var startScanningAtLoad = true; | ||
self._scanner = QRCodeReaderViewController.readerWithCancelButtonTitleCodeReaderStartScanningAtLoadShowSwitchCameraButtonShowTorchButton(closeButtonLabel, reader, startScanningAtLoad, flip, torch); | ||
self._scanner.modalPresentationStyle = 2; | ||
var delegate_1 = QRCodeReaderDelegateImpl.new().initWithCallback(isContinuous_1, function (reader, text, format) { | ||
@@ -150,3 +195,3 @@ if (text === undefined) { | ||
}); | ||
bs.delegate = delegate_1; | ||
self._scanner.delegate = delegate_1; | ||
var topMostFrame = frame.topmost(); | ||
@@ -156,3 +201,3 @@ if (topMostFrame) { | ||
if (vc) { | ||
vc.presentViewControllerAnimatedCompletion(bs, true, null); | ||
vc.presentViewControllerAnimatedCompletion(self._scanner, true, null); | ||
} | ||
@@ -159,0 +204,0 @@ } |
{ | ||
"name": "nativescript-barcodescanner", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Scan QR/barcodes with a {N} app.", | ||
@@ -5,0 +5,0 @@ "main": "barcodescanner.js", |
@@ -68,4 +68,5 @@ # NativeScript BarcodeScanner | ||
message: "Use the volume buttons for extra light", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.' | ||
preferFrontCamera: front, // Android only, default false | ||
showFlipCameraButton: flip, // Android only, default false (on iOS it's always available) | ||
showFlipCameraButton: true, // default false | ||
preferFrontCamera: false, // default false | ||
showTorchButton: true, // iOS only, default false | ||
orientation: orientation, // Android only, default undefined (sensor-driven orientation), other options: portrait|landscape | ||
@@ -95,4 +96,5 @@ openSettingsIfPermissionWasPreviouslyDenied: true // On iOS you can send the user to the settings app if access was previously denied | ||
message: "Use the volume buttons for extra light", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.' | ||
preferFrontCamera: false, // Android only, default false | ||
showFlipCameraButton: true, // Android only, default false (on iOS it's always available) | ||
showFlipCameraButton: true, // default false | ||
preferFrontCamera: false, // default false | ||
showTorchButton: true, // iOS only, default false | ||
orientation: "landscape", // Android only, optionally lock the orientation to either "portrait" or "landscape" | ||
@@ -241,4 +243,5 @@ openSettingsIfPermissionWasPreviouslyDenied: true // On iOS you can send the user to the settings app if access was previously denied | ||
## Changelog | ||
* __2.1.0__ iOS now also honors the `preferFrontCamera` and `showFlipCameraButton` settings. Also, added `showTorchButton` (iOS only for now). | ||
* __2.0.0__ Conversion to TypeScript (note that the JS require syntax is now slightly different!). | ||
* __1.5.0__ Auto-permission handling. Use the volume up/down buttons to toggle the torch. | ||
* __1.4.0__ Bulk scanning. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1618759
244
0
30
569