nativescript-barcodescanner
Advanced tools
Comparing version 2.1.1 to 2.1.2
import { ScanOptions } from "./barcodescanner.common"; | ||
export declare class BarcodeScanner { | ||
private broadcastManager; | ||
private onScanReceivedCallback; | ||
private onContinuousScanResult; | ||
private uniquelyScannedCodes; | ||
private onPermissionGranted; | ||
@@ -8,0 +5,0 @@ private onPermissionRejected; |
@@ -6,2 +6,4 @@ "use strict"; | ||
var SCANNER_REQUEST_CODE = 444; | ||
var _onScanReceivedCallback = undefined; | ||
var _onContinuousScanResult = undefined; | ||
var BarcodeScanner = (function () { | ||
@@ -35,5 +37,2 @@ function BarcodeScanner() { | ||
} | ||
else { | ||
console.log("No after-permission callback function specified for requestCode " + args.requestCode + ". That's a bug in the nativescript-barcodescanner plugin, please report it!"); | ||
} | ||
}); | ||
@@ -84,5 +83,5 @@ } | ||
self.broadcastManager.sendBroadcast(stopIntent); | ||
if (self.onScanReceivedCallback) { | ||
self.broadcastManager.unregisterReceiver(self.onScanReceivedCallback); | ||
self.onScanReceivedCallback = undefined; | ||
if (_onScanReceivedCallback) { | ||
self.broadcastManager.unregisterReceiver(_onScanReceivedCallback); | ||
_onScanReceivedCallback = undefined; | ||
} | ||
@@ -124,5 +123,4 @@ resolve(); | ||
if (isContinuous) { | ||
self.onContinuousScanResult = arg.continuousScanCallback; | ||
_onContinuousScanResult = arg.continuousScanCallback; | ||
intent.putExtra(com.google.zxing.client.android.Intents.Scan.BULK_SCAN, true); | ||
self.uniquelyScannedCodes = new Array(); | ||
var CallbackReceiver = android.content.BroadcastReceiver.extend({ | ||
@@ -132,5 +130,8 @@ onReceive: function (context, data) { | ||
var text = data.getStringExtra(com.google.zxing.client.android.Intents.Scan.RESULT); | ||
if (self.uniquelyScannedCodes.indexOf("[" + text + "][" + format + "]") == -1) { | ||
self.uniquelyScannedCodes.push("[" + text + "][" + format + "]"); | ||
self.onContinuousScanResult({ | ||
if (!this.uniquelyScannedCodes) { | ||
this.uniquelyScannedCodes = new Array(); | ||
} | ||
if (arg.reportDuplicates || this.uniquelyScannedCodes.indexOf("[" + text + "][" + format + "]") === -1) { | ||
this.uniquelyScannedCodes.push("[" + text + "][" + format + "]"); | ||
_onContinuousScanResult({ | ||
format: format, | ||
@@ -142,4 +143,4 @@ text: text | ||
}); | ||
self.onScanReceivedCallback = new CallbackReceiver(); | ||
self.broadcastManager.registerReceiver(self.onScanReceivedCallback, new android.content.IntentFilter("bulk-barcode-result")); | ||
_onScanReceivedCallback = new CallbackReceiver(); | ||
self.broadcastManager.registerReceiver(_onScanReceivedCallback, new android.content.IntentFilter("bulk-barcode-result")); | ||
} | ||
@@ -156,4 +157,6 @@ if (intent.resolveActivity(com.tns.NativeScriptApplication.getInstance().getPackageManager()) !== null) { | ||
if (isContinuous) { | ||
self.broadcastManager.unregisterReceiver(self.onScanReceivedCallback); | ||
self.onScanReceivedCallback = undefined; | ||
if (_onScanReceivedCallback) { | ||
self.broadcastManager.unregisterReceiver(_onScanReceivedCallback); | ||
_onScanReceivedCallback = undefined; | ||
} | ||
} | ||
@@ -160,0 +163,0 @@ else { |
export interface CommonScanOptions { | ||
formats?: string; | ||
continuousScanCallback?: Function; | ||
reportDuplicates?: boolean; | ||
preferFrontCamera?: boolean; | ||
@@ -5,0 +6,0 @@ showFlipCameraButton?: boolean; |
@@ -142,3 +142,3 @@ "use strict"; | ||
self._scanner.modalPresentationStyle = 2; | ||
var delegate_1 = QRCodeReaderDelegateImpl.new().initWithCallback(isContinuous_1, function (reader, text, format) { | ||
var delegate_1 = QRCodeReaderDelegateImpl.new().initWithCallback(isContinuous_1, arg.reportDuplicates, function (reader, text, format) { | ||
if (text === undefined) { | ||
@@ -193,4 +193,5 @@ self._removeVolumeObserver(); | ||
}; | ||
QRCodeReaderDelegateImpl.prototype.initWithCallback = function (isContinuous, callback) { | ||
QRCodeReaderDelegateImpl.prototype.initWithCallback = function (isContinuous, reportDuplicates, callback) { | ||
this._isContinuous = isContinuous; | ||
this._reportDuplicates = reportDuplicates; | ||
this._callback = callback; | ||
@@ -210,3 +211,3 @@ return this; | ||
} | ||
if (this._scannedArray.indexOf("[" + text + "][" + type + "]") === -1) { | ||
if (this._reportDuplicates || this._scannedArray.indexOf("[" + text + "][" + type + "]") === -1) { | ||
this._scannedArray.push("[" + text + "][" + type + "]"); | ||
@@ -213,0 +214,0 @@ this._callback(reader, text, type); |
# Change Log | ||
## [2.1.2](https://github.com/EddyVerbruggen/nativescript-barcodescanner/tree/2.1.2) (2016-11-01) | ||
[Full Changelog](https://github.com/EddyVerbruggen/nativescript-barcodescanner/compare/2.1.1...2.1.2) | ||
**Fixed bugs:** | ||
- Bulk scan callback is not updating after routing change [\#44](https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/44) | ||
**Closed issues:** | ||
- Conflict with another similar plugin [\#42](https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/42) | ||
- angular 2 can not set reportDuplicates :false [\#45](https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/45) | ||
- iOS Barcode Scanning is Broken [\#41](https://github.com/EddyVerbruggen/nativescript-barcodescanner/issues/41) | ||
## [2.1.1](https://github.com/EddyVerbruggen/nativescript-barcodescanner/tree/2.1.1) (2016-10-17) | ||
@@ -4,0 +17,0 @@ [Full Changelog](https://github.com/EddyVerbruggen/nativescript-barcodescanner/compare/2.1.0...2.1.1) |
{ | ||
"name": "nativescript-barcodescanner", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Scan QR/barcodes with a {N} app.", | ||
@@ -5,0 +5,0 @@ "main": "barcodescanner.js", |
@@ -116,3 +116,3 @@ # NativeScript BarcodeScanner | ||
The plugin handles duplicates for you so don't worry about checking those; | ||
every result withing the same scan session is unique. | ||
every result withing the same scan session is unique unless you set `reportDuplicates` to `true`. | ||
@@ -134,3 +134,4 @@ Here's an example of scanning 3 unique QR codes and then stopping scanning programmatically. | ||
} | ||
} | ||
}, | ||
reportDuplicates: false // which is the default | ||
}).then( | ||
@@ -193,17 +194,2 @@ function() { | ||
1. Set up an [opaque token](https://angular.io/docs/ts/latest/guide/dependency-injection.html#!#dependency-injection-tokens) | ||
```ts | ||
//barcodescanner.ts | ||
import { OpaqueToken } from '@angular/core'; | ||
import * as scanner from 'nativescript-barcodescanner'; | ||
export const BARCODE_SCANNER = new OpaqueToken('barcodescanner'); | ||
//These are re-exported for convenience (so you don't have to import from two places) | ||
export const barcodescanner = new scanner.BarcodeScanner(); | ||
export type BarcodeScanner = scanner.BarcodeScanner; | ||
export type ScanOptions = scanner.ScanOptions; | ||
export type IosScanOptions = scanner.IOS; | ||
export type AndroidScanOptions = scanner.Android; | ||
``` | ||
1. Register the provider with your module | ||
@@ -213,3 +199,3 @@ ```ts | ||
import { NgModule, ValueProvider } from '@angular/core'; | ||
import { BARCODE_SCANNER, barcodescanner } from './barcodescanner'; | ||
import { BarcodeScanner } from 'nativescript-barcodescanner'; | ||
//other imports | ||
@@ -220,3 +206,3 @@ | ||
providers: [ | ||
<ValueProvider>{ provide: BARCODE_SCANNER, useValue: barcodescanner } | ||
BarcodeScanner | ||
] | ||
@@ -230,3 +216,3 @@ }) | ||
import { Component, Inject } from '@angular/core'; | ||
import { BARCODE_SCANNER, BarcodeScanner } from './barcodescanner'; | ||
import { BarcodeScanner } from 'nativescript-barcodescanner'; | ||
//other imports | ||
@@ -236,3 +222,3 @@ | ||
export class MyComponent { | ||
constructor(@Inject(BARCODE_SCANNER) private barcodeScanner: BarcodeScanner) { | ||
constructor(private barcodeScanner: BarcodeScanner) { | ||
} | ||
@@ -248,5 +234,5 @@ | ||
## Changelog | ||
* __2.1.0__ iOS now also honors the `preferFrontCamera` and `showFlipCameraButton` settings. Also, added `showTorchButton` (iOS only for now). | ||
* __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. |
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
1645425
38
536
231