Skip to content

Commit

Permalink
Merge pull request #3 from blinkinput/release/v4.2.0
Browse files Browse the repository at this point in the history
Release/v4.3.0
  • Loading branch information
matvidako authored May 27, 2020
2 parents 30b3539 + dbf6a03 commit 1c27454
Show file tree
Hide file tree
Showing 126 changed files with 6,134 additions and 64 deletions.
69 changes: 7 additions & 62 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,68 +1,13 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
# OSX
.DS_Store

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
# Xcode
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
xcuserdata
xcshareddata

iOSInjectionProject/
#Demo App
/BlinkInputReactNative
23 changes: 23 additions & 0 deletions BlinkInput/blinkinput-react-native.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
s.name = package['name']
s.version = package['version']
s.summary = package['description']

s.authors = package['author']
s.homepage = package['homepage']
s.license = package['license']
s.platform = :ios, "9.0"

s.source = { :git => "https://github.com/BlinkInput/blinkinput-react-native.git", :tag => "v#{s.version}" }
s.source_files = "src/ios", "src/ios/**/*.{h,m}"
s.header_dir = "blinkinput-react-native"

s.dependency 'React'
s.dependency 'PPBlinkOCR', '~> 4.3.0'

s.frameworks = 'UIKit'
end
255 changes: 255 additions & 0 deletions BlinkInput/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
'use strict';

import { Platform, NativeModules } from 'react-native';

import { RecognizerResultState } from './recognizer'

const BlinkInputNative = Platform.select({
ios: NativeModules.BlinkInputIos,
android: NativeModules.BlinkInputAndroid
})

/**
* This exposes the appropriate native BlinkInput module module as a JS module, based on
* detected platform: Android or iOS. This has functions:
* -> 'scanWithCamera' which takes the following parameters:
* 1. Object overlaySettings: instance of OverlaySettings, contains settings for desired camera overlay
* 2. RecognizerCollection recognizerCollection: object containing recognizers to use for scanning
* 3. String license: BlinkInput base64 license key bound to application ID for Android or iOS. To obtain
* valid license key, please visit http://microblink.com/login or
* contact us at http://help.microblink.com
*
* OR
*
* Object license: containing:
* - mandatory parameter 'licenseKey': base64 license key bound to application ID
* for Android or iOS. To obtain valid license key, please visit
* http://microblink.com/login or contact us at http://help.microblink.com
* - optioanl parameter 'licensee' when license for multiple apps is used
* - optional flag 'showTimeLimitedLicenseKeyWarning' which indicates
* whether warning for time limited license key will be shown
* in format
* {
* licenseKey: '<base64iOSLicense or base64AndroidLicense>',
* licensee: String,
* showTimeLimitedLicenseKeyWarning: Boolean
* }
* -> 'captureDocument' which takes following parameters:
* 1. DocumentCaptureRecognizer documentCaptureRecognizer: object containing settings for document capture recognizer
* 2. String license: the same as 'license' for 'scanWithCamera' function
*/
class BlinkInputWrapper {
async scanWithCamera(overlaySettings, recognizerCollection, license) {
try {
var bla = NativeModules;
console.log(bla);
var licenseObject = license;
if (typeof license === 'string' || license instanceof String) {
licenseObject = { licenseKey: license };
}
const nativeResults = await BlinkInputNative.scanWithCamera(overlaySettings, recognizerCollection, licenseObject);
if (nativeResults.length != recognizerCollection.recognizerArray.length) {
console.log("INTERNAL ERROR: native plugin returned wrong number of results!");
return [];
} else {
let results = [];
for (let i = 0; i < nativeResults.length; ++i) {
// native plugin must ensure types match
// recognizerCollection.recognizerArray[i].result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]);

// unlike Cordova, ReactNative does not allow mutation of user-provided recognizers, so we need to
// return results and let user handle them manually.
let result = recognizerCollection.recognizerArray[i].createResultFromNative(nativeResults[i]);
if (result.resultState != RecognizerResultState.empty) {
results.push(result);
}
}
return results;
}
} catch (error) {
console.log(error);
return [];
}
}
async captureDocument(documentCaptureRecognizer, license) {
try {
var licenseObject = license;
if (typeof license === 'string' || license instanceof String) {
licenseObject = { licenseKey: license };
}
const nativeDocumentCaptureResult = await BlinkInputNative.captureDocument(documentCaptureRecognizer, licenseObject);

return new DocumentCaptureResult(nativeDocumentCaptureResult);
} catch (error) {
console.log(error);
return [];
}
}
async scanWithFieldByField(fieldByFieldCollection, license) {
try {
var licenseObject = license;
if (typeof license === 'string' || license instanceof String) {
licenseObject = { licenseKey: license };
}
const nativeFieldByFieldResult = await BlinkInputNative.scanWithFieldByField(fieldByFieldCollection, licenseObject);

let results = [];
for (let i = 0; i < nativeFieldByFieldResult.length; ++i) {
let result = new FieldByFieldResult(nativeFieldByFieldResult[i]);
results.push(result);
}
return results;
} catch (error) {
console.log(error);
return [];
}
}
}

export var BlinkInput = new BlinkInputWrapper();

import { Recognizer } from './recognizer'

/**
* Represents a collection of recognizer objects.
*/
export class RecognizerCollection {
/**
*
* @param recognizerArray Array of recognizer objects that will be used for recognition. Must not be empty!
*/
constructor(recognizerArray) {
/** Array of recognizer objects that will be used for recognition */
this.recognizerArray = recognizerArray;
/**
* Whether or not it is allowed for multiple recognizers to process the same image.
* If not, then first recognizer that will be successful in processing the image will
* end the processing chain and other recognizers will not get the chance to process
* that image.
*/
this.allowMultipleResults = false;
/** Number of miliseconds after first non-empty result becomes available to end scanning with a timeout */
this.milisecondsBeforeTimeout = 10000;

if (!(this.recognizerArray instanceof Array)) {
throw new Error("recognizerArray must be array of Recognizer objects!");
}
// ensure every element in array is Recognizer
for (var i = 0; i < this.recognizerArray.length; ++i) {
if (!(this.recognizerArray[i] instanceof Recognizer )) {
throw new Error( "Each element in recognizerArray must be instance of Recognizer" );
}
}
}
}

import { Parser } from './parser'

/**
* Represents a collection of scane elements
*/
export class FieldByFieldCollection {
/**
*
* @param fieldByFieldElementArray Array of field by field elements objects that will be used for recognition. Must not be empty!
*/
constructor(fieldByFieldElementArray) {
/** Array of recognizer objects that will be used for recognition */
this.fieldByFieldElementArray = fieldByFieldElementArray;

if (!(this.fieldByFieldElementArray instanceof Array)) {
throw new Error("recognizerArray must be array of Recognizer objects!");
}
// ensure every element in array is Recognizer
for (var i = 0; i < this.fieldByFieldElementArray.length; ++i) {
if (!(this.fieldByFieldElementArray[i] instanceof FieldByFieldElement )) {
throw new Error( "Each element in fieldByFieldElementArray must be instance of FieldByFieldElement" );
}
}
}
}

export class FieldByFieldElement {
constructor(identifier, parser, localizedTitle, localizedTooltip) {
/**
* Unique name of the element
*/
this.identifier = identifier;

/**
Parser object which is reponsible scanning the text.
*/
this.parser = parser;

/**
* Localized title (used in the Pivot control)
*/
this.localizedTitle = localizedTitle;

/**
* Localized tooltip (used in the tooltip label above the viewfinder)
*/
this.localizedTooltip = localizedTooltip;

if (!(this.parser instanceof Parser)) {
throw new Error("Parser must be instance of Parser!");
}
}
}

export class FieldByFieldResult {
constructor(nativeFieldByFieldResult) {
/**
* Unique name of the element
*/
this.identifier = nativeFieldByFieldResult.identifier;

/**
Value of parser object after scanning.
*/
this.value = nativeFieldByFieldResult.value;
}
}
import { DocumentCaptureRecognizerResult } from './recognizers/documentCaptureRecognizer'
/**
* Represents a result of 'captureDocument' functionality.
*/
export class DocumentCaptureResult {
constructor(nativeDocumentCaptureResult) {
this.documentCaptureRecognizerResult = new DocumentCaptureRecognizerResult(nativeDocumentCaptureResult.documentCaptureRecognizerResult);
this.capturedFullImage = nativeDocumentCaptureResult.capturedFullImage;
}
}

export { RecognizerResultState } from './recognizer'
export * from './types'

// export overlays that can be used
export * from './overlays/barcodeOverlays'

// export recognizers that can be used and their results
export * from './recognizers/successFrameGrabberRecognizer'
export * from './recognizers/barcodeRecognizer'
export * from './recognizers/documentCaptureRecognizer'
export * from './recognizers/pdf417Recognizer'
export * from './recognizers/simNumberRecognizer'
// export * from './recognizers/blinkInputRecognizer'

export { ParserResultState } from './parser'
export { ProcessorResultState } from './processor'

// export parsers that can be used and their results
export * from './parsers/amountParser'
export * from './parsers/dateParser'
export * from './parsers/emailParser'
export * from './parsers/ibanParser'
export * from './parsers/licensePlatesParser'
export * from './parsers/rawParser'
export * from './parsers/topUpParser'
export * from './parsers/vinParser'
export * from './parsers/regexParser'

// // export processors that can be used and their results
// export * from './processors/parserGroupProcessor'
//

17 changes: 17 additions & 0 deletions BlinkInput/overlaySettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** Base class for all overlay settings objects */
export class OverlaySettings {
constructor(overlaySettingsType) {
/** type of the overlay settings object */
this.overlaySettingsType = overlaySettingsType;
/** whether front camera should be used instead of the default camera */
this.useFrontCamera = false;
/** whether beep sound will be played on successful scan */
this.enableBeep = false;
/** (optional) if default overlay contains textual information, text will be localized to this language. Otherwise device langauge will be used */
/** example: "en" */
this.language = null;
/** (optional) to be used with language variable, it defines the country locale */
/** example: "US" to use "en_US" on Android and en-US on iOS */
this.country = null;
}
}
11 changes: 11 additions & 0 deletions BlinkInput/overlays/barcodeOverlays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { OverlaySettings } from '../overlaySettings'

/**
* Class for setting up barcode overlay.
* Barcode overlay is best suited for recognizers that perform barcode scanning.
*/
export class BarcodeOverlaySettings extends OverlaySettings {
constructor() {
super('BarcodeOverlaySettings');
}
}
Loading

0 comments on commit 1c27454

Please sign in to comment.