├── example ├── .watchmanconfig ├── android │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── assets │ │ │ │ │ ├── Regula │ │ │ │ │ │ └── .gitignore │ │ │ │ │ └── certificates │ │ │ │ │ │ └── .gitignore │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── drawable │ │ │ │ │ │ └── rn_edit_text_material.xml │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── regula │ │ │ │ │ └── dr │ │ │ │ │ └── fullauthrfid │ │ │ │ │ ├── MainActivity.java │ │ │ │ │ └── MainApplication.java │ │ │ ├── debug │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── java │ │ │ │ │ └── com │ │ │ │ │ └── regula │ │ │ │ │ └── dr │ │ │ │ │ └── fullrfid │ │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── release │ │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── regula │ │ │ │ └── dr │ │ │ │ └── fullrfid │ │ │ │ └── ReactNativeFlipper.java │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── images │ ├── id.png │ └── portrait.png ├── ios │ ├── DocumentReader │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── DocumentReader.entitlements │ │ ├── AppDelegate.mm │ │ ├── Info.plist │ │ └── LaunchScreen.storyboard │ ├── DocumentReader.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── .xcode.env │ ├── DocumentReaderTests │ │ ├── Info.plist │ │ └── DocumentReaderTests.m │ ├── Podfile │ └── DocumentReader.xcodeproj │ │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── DocumentReader.xcscheme │ │ └── project.pbxproj ├── react-native.config.js ├── index.js ├── metro.config.js ├── .gitignore ├── package.json ├── README.md └── App.tsx ├── .gitignore ├── android ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── regula │ │ └── plugin │ │ └── documentreader │ │ ├── RNRegulaDocumentReaderModule.kt │ │ ├── BluetoothUtil.kt │ │ ├── Utils.kt │ │ └── Main.kt └── build.gradle ├── .github └── ISSUE_TEMPLATE │ └── config.yml ├── ios ├── RNRegulaDocumentReader.h ├── RNRegulaDocumentReader.m ├── RGLWMain.h ├── RGLWConfig.h ├── RGLWJSONConstructor.h └── RGLWMain.m ├── RNDocumentReaderApi.podspec ├── package.json └── README.md /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | { } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/Regula/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/android/app/src/main/assets/certificates/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/images/id.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/images/id.png -------------------------------------------------------------------------------- /example/images/portrait.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/images/portrait.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DocumentReader 3 | 4 | -------------------------------------------------------------------------------- /example/ios/DocumentReader/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/ios/DocumentReader/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/react-native.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | dependencies: { 3 | ...{ 'react-native-flipper': { platforms: { ios: null } } } 4 | } 5 | } -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import {AppRegistry} from 'react-native'; 6 | import App from './App'; 7 | 8 | AppRegistry.registerComponent("DocumentReader", () => App); 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/regulaforensics/react-native-document-reader/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Submit a request 4 | url: https://support.regulaforensics.com/hc/requests/new?utm_source=github 5 | about: Submit any requests to Regula Support Team 6 | -------------------------------------------------------------------------------- /ios/RNRegulaDocumentReader.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | #import "RGLWMain.h" 5 | @import UIKit; 6 | 7 | @interface RNRegulaDocumentReader : RCTEventEmitter 8 | @end 9 | -------------------------------------------------------------------------------- /example/ios/DocumentReader/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /example/ios/DocumentReader.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/DocumentReader.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/DocumentReader/DocumentReader.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.developer.nfc.readersession.formats 6 | 7 | TAG 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } 2 | plugins { id("com.facebook.react.settings") } 3 | extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } 4 | rootProject.name = 'com.regula.dr.fullauthrfid' 5 | include ':app' 6 | includeBuild('../node_modules/@react-native/gradle-plugin') 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | buildToolsVersion = "35.0.0" 4 | minSdkVersion = 24 5 | compileSdkVersion = 35 6 | targetSdkVersion = 35 7 | 8 | ndkVersion = "27.1.12297006" 9 | kotlinVersion = "2.0.21" 10 | } 11 | repositories { 12 | google() 13 | mavenCentral() 14 | } 15 | dependencies { 16 | classpath("com.android.tools.build:gradle") 17 | classpath("com.facebook.react:react-native-gradle-plugin") 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); 2 | 3 | const path = require('path'); 4 | const folders = [ 5 | path.resolve(path.join(__dirname, './node_modules')) 6 | ]; 7 | 8 | /** 9 | * Metro configuration 10 | * https://facebook.github.io/metro/docs/configuration 11 | * 12 | * @type {import('metro-config').MetroConfig} 13 | */ 14 | const config = { 15 | resolver: { 16 | nodeModulesPaths: folders 17 | }, 18 | watchFolders: folders, 19 | }; 20 | 21 | module.exports = mergeConfig(getDefaultConfig(__dirname), config); 22 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /RNDocumentReaderApi.podspec: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = "RNDocumentReaderApi" 7 | s.version = package['version'] 8 | s.summary = package['description'] 9 | s.license = package['license'] 10 | 11 | s.authors = { 'RegulaForensics' => 'support@regulaforensics.com' } 12 | s.homepage = 'https://regulaforensics.com' 13 | 14 | s.source = { :http => 'file:' + __dir__ } 15 | s.ios.deployment_target = '13.0' 16 | s.source_files = "ios/*.{h,m}" 17 | s.dependency 'DocumentReader', '8.4.5436' 18 | s.dependency 'React' 19 | end 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@regulaforensics/react-native-document-reader-api", 3 | "version": "8.4.327", 4 | "description": "React Native module for reading and validation of identification documents (API framework)", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "react-native", "documentreader", "reader", "scanner", "regula" 11 | ], 12 | "author": "Regulaforensics", 13 | "license": "commercial", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/regulaforensics/react-native-document-reader.git" 17 | }, 18 | "homepage": "https://mobile.regulaforensics.com", 19 | "publishConfig": { 20 | "access": "public" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/android/app/src/release/java/com/regula/dr/fullrfid/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.regula.dr.fullauthrfid; 8 | 9 | import android.content.Context; 10 | import com.facebook.react.ReactInstanceManager; 11 | 12 | /** 13 | * Class responsible of loading Flipper inside your React Native application. This is the release 14 | * flavor of it so it's empty as we don't want to load Flipper. 15 | */ 16 | public class ReactNativeFlipper { 17 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 18 | // Do nothing as we don't want to initialize Flipper on Release. 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/ios/DocumentReaderTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | // Conditional for compatibility with AGP <4.2. 6 | if (project.android.hasProperty("namespace")) { 7 | namespace 'com.regula.plugin.documentreader' 8 | } 9 | 10 | compileSdk 36 11 | 12 | defaultConfig { 13 | minSdkVersion 24 14 | targetSdk 36 15 | versionCode 1 16 | versionName "1.0" 17 | } 18 | } 19 | 20 | rootProject.allprojects { 21 | repositories { 22 | maven { 23 | url "https://maven.regulaforensics.com/RegulaDocumentReader" 24 | } 25 | } 26 | } 27 | 28 | dependencies { 29 | //noinspection GradleDynamicVersion 30 | implementation 'com.facebook.react:react-native:+' 31 | //noinspection GradleDependency 32 | implementation('com.regula.documentreader:api:8.4.12046') { 33 | transitive = true 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /example/ios/DocumentReader/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"DocumentReader"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 15 | } 16 | 17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 18 | { 19 | return [self bundleURL]; 20 | } 21 | 22 | - (NSURL *)bundleURL 23 | { 24 | #if DEBUG 25 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 26 | #else 27 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 28 | #endif 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /example/ios/DocumentReader/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | ios/.xcode.env.local 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | *.hprof 33 | .cxx/ 34 | *.keystore 35 | !debug.keystore 36 | 37 | # node.js 38 | # 39 | node_modules/ 40 | npm-debug.log 41 | yarn-error.log 42 | 43 | # fastlane 44 | # 45 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 46 | # screenshots whenever they are needed. 47 | # For more information about the recommended setup visit: 48 | # https://docs.fastlane.tools/best-practices/source-control/ 49 | 50 | **/fastlane/report.xml 51 | **/fastlane/Preview.html 52 | **/fastlane/screenshots 53 | **/fastlane/test_output 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | 58 | # Ruby / CocoaPods 59 | /ios/Pods/ 60 | /vendor/bundle/ 61 | 62 | # Temporary files created by Metro to check the health of the file watcher 63 | .metro-health-check* 64 | 65 | # testing 66 | /coverage 67 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | source "https://github.com/CocoaPods/Specs.git" 2 | 3 | # Resolve react_native_pods.rb with node to allow for hoisting 4 | require Pod::Executable.execute_command('node', ['-p', 5 | 'require.resolve( 6 | "react-native/scripts/react_native_pods.rb", 7 | {paths: [process.argv[1]]}, 8 | )', __dir__]).strip 9 | 10 | platform :ios, min_ios_version_supported 11 | prepare_react_native_project! 12 | 13 | linkage = ENV['USE_FRAMEWORKS'] 14 | if linkage != nil 15 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 16 | use_frameworks! :linkage => linkage.to_sym 17 | end 18 | 19 | target 'DocumentReader' do 20 | config = use_native_modules! 21 | 22 | use_react_native!( 23 | :path => config[:reactNativePath], 24 | # An absolute path to your application root. 25 | :app_path => "#{Pod::Config.instance.installation_root}/.." 26 | ) 27 | 28 | target 'DocumentReaderTests' do 29 | inherit! :complete 30 | end 31 | 32 | post_install do |installer| 33 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 34 | react_native_post_install( 35 | installer, 36 | config[:reactNativePath], 37 | :mac_catalyst_enabled => false 38 | ) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/regula/dr/fullauthrfid/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.regula.dr.fullauthrfid; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate; 7 | 8 | public class MainActivity extends ReactActivity { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | @Override 15 | protected String getMainComponentName() { 16 | return "DocumentReader"; 17 | } 18 | 19 | /** 20 | * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link 21 | * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React 22 | * (aka React 18) with two boolean flags. 23 | */ 24 | @Override 25 | protected ReactActivityDelegate createReactActivityDelegate() { 26 | return new DefaultReactActivityDelegate( 27 | this, 28 | getMainComponentName(), 29 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 30 | DefaultNewArchitectureEntryPoint.getFabricEnabled()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /ios/RNRegulaDocumentReader.m: -------------------------------------------------------------------------------- 1 | #import "RNRegulaDocumentReader.h" 2 | 3 | RNRegulaDocumentReader* RGLWPlugin; 4 | 5 | @implementation RNRegulaDocumentReader 6 | @synthesize bridge = _bridge; 7 | RCT_EXPORT_MODULE(); 8 | 9 | - (NSArray*)supportedEvents { 10 | return @[completionEvent, 11 | databaseProgressEvent, 12 | rfidOnProgressEvent, 13 | rfidOnChipDetectedEvent, 14 | rfidOnRetryReadChipEvent, 15 | paCertificateCompletionEvent, 16 | taCertificateCompletionEvent, 17 | taSignatureCompletionEvent, 18 | drVideoEncoderCompletionEvent, 19 | drOnCustomButtonTappedEvent]; 20 | } 21 | 22 | static bool hasListeners; 23 | -(void)startObserving { hasListeners = YES; } 24 | -(void)stopObserving { hasListeners = NO; } 25 | 26 | UIViewController*(^RGLWRootViewController)(void) = ^UIViewController*(){ 27 | return RCTPresentedViewController(); 28 | }; 29 | 30 | static RGLWEventSender sendEvent = ^(NSString* event, id data) { 31 | dispatch_async(dispatch_get_main_queue(), ^{ 32 | if (hasListeners) [RGLWPlugin sendEventWithName:event body:@{@"msg": data}]; 33 | }); 34 | }; 35 | 36 | RCT_EXPORT_METHOD(exec:(NSString*)moduleName:(NSString*)action:(NSArray*)args:(RCTResponseSenderBlock)sCallback:(RCTResponseSenderBlock)eCallback) { 37 | RGLWPlugin = self; 38 | RGLWCallback callback = ^(id _Nullable data) { 39 | if (data == nil) sCallback(@[[NSNull null]]); 40 | else sCallback(@[data]); 41 | }; 42 | [RGLWMain methodCall:action :args :callback :sendEvent]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | Introduced a new unified [NPM package](https://www.npmjs.com/package/@regulaforensics/document-reader) that supports React, Ionic, and Cordova wrappers in a single distribution. The individual packages for each wrapper are now deprecated and will only be supported for a few upcoming releases before being removed in future versions. We’ll provide advance notice prior to their removal. Follow the Migration Guide for detailed steps to transition to the new unified package. 4 | 5 | # Regula Document Reader SDK for React Native 6 | 7 | Regula Document Reader SDK allows you to read various kinds of identification documents, passports, driving licenses, ID cards, etc. All processing is performed completely _**offline**_ on your device. No any data leaving your device. 8 | 9 | You can use native camera to scan the documents or image from gallery for extract all data from it. 10 | 11 | This repository contains the source code of the Document Reader API, and the sample application that demonstrates the _**API**_ calls you can use to interact with the Document Reader library. 12 | 13 | ## Documentation 14 | 15 | You can find documentation [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile). 16 | 17 | ## License 18 | 19 | To obtaining the production license or other purchasing information, please [submit an inquiry](https://regulaforensics.com/talk-to-an-expert) and our sales team will contact you shortly. 20 | 21 | ## Support 22 | 23 | Please do not hesitate to [contact us](https://support.regulaforensics.com/hc/requests/new), if you need any assistance or want to report a bug / suggest an improvement. 24 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DocumentReader", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "lint": "eslint .", 9 | "start": "react-native start", 10 | "test": "jest" 11 | }, 12 | "dependencies": { 13 | "@regulaforensics/react-native-document-reader-api": "8.4.327", 14 | "@regulaforensics/react-native-document-reader-core-fullauthrfid": "8.4.1170", 15 | "@rneui/base": "4.0.0-rc.7", 16 | "@rneui/themed": "4.0.0-rc.7", 17 | "react": "19.0.0", 18 | "react-native": "0.79.0", 19 | "react-native-fs": "2.20.0", 20 | "react-native-image-picker": "7.2.3", 21 | "react-native-progress": "5.0.0", 22 | "react-native-radio-buttons-group": "3.0.5", 23 | "react-native-vector-icons": "10.2.0" 24 | }, 25 | "devDependencies": { 26 | "@babel/core": "^7.26.0", 27 | "@babel/preset-env": "^7.26.0", 28 | "@babel/runtime": "^7.28.4", 29 | "@react-native-community/cli": "18.0.1", 30 | "@react-native-community/cli-platform-android": "18.0.1", 31 | "@react-native-community/cli-platform-ios": "18.0.1", 32 | "@react-native/babel-preset": "0.79.0", 33 | "@react-native/eslint-config": "0.79.0", 34 | "@react-native/metro-config": "0.79.0", 35 | "@react-native/typescript-config": "0.79.0", 36 | "@types/react": "^19.0.0", 37 | "@types/react-test-renderer": "^19.0.0", 38 | "babel-jest": "^29.7.0", 39 | "eslint": "^8.19.0", 40 | "jest": "^29.7.0", 41 | "prettier": "2.8.8", 42 | "react-test-renderer": "19.0.0", 43 | "typescript": "5.7.3" 44 | }, 45 | "engines": { 46 | "node": ">=18" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ios/RGLWMain.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "RGLWJSONConstructor.h" 3 | #import "RGLWConfig.h" 4 | 5 | typedef void (^RGLWCallback)(id _Nullable response); 6 | typedef void (^RGLWEventSender)(NSString* _Nonnull event, id _Nullable data); 7 | typedef void (^RGLWRFIDSignatureCallback)(NSData * _Nonnull signature); 8 | extern UIViewController*_Nonnull(^ _Nonnull RGLWRootViewController)(void); 9 | 10 | @interface RGLWMain: NSObject 15 | 16 | +(void)methodCall:(NSString* _Nonnull)method 17 | :(NSArray* _Nonnull)args 18 | :(RGLWCallback _Nonnull)callback 19 | :(RGLWEventSender _Nonnull)eventSender; 20 | 21 | @property NSNumber* _Nonnull doRequestPACertificates; 22 | @property NSNumber* _Nonnull doRequestTACertificates; 23 | @property NSNumber* _Nonnull doRequestTASignature; 24 | 25 | @end 26 | 27 | static NSString* _Nonnull completionEvent = @"completion"; 28 | static NSString* _Nonnull databaseProgressEvent = @"database_progress"; 29 | static NSString* _Nonnull rfidOnProgressEvent = @"rfidOnProgressCompletion"; 30 | static NSString* _Nonnull rfidOnChipDetectedEvent = @"rfidOnChipDetectedEvent"; 31 | static NSString* _Nonnull rfidOnRetryReadChipEvent = @"rfidOnRetryReadChipEvent"; 32 | static NSString* _Nonnull paCertificateCompletionEvent = @"pa_certificate_completion"; 33 | static NSString* _Nonnull taCertificateCompletionEvent = @"ta_certificate_completion"; 34 | static NSString* _Nonnull taSignatureCompletionEvent = @"ta_signature_completion"; 35 | static NSString* _Nonnull drVideoEncoderCompletionEvent = @"video_encoder_completion"; 36 | static NSString* _Nonnull drOnCustomButtonTappedEvent = @"onCustomButtonTappedEvent"; 37 | -------------------------------------------------------------------------------- /ios/RGLWConfig.h: -------------------------------------------------------------------------------- 1 | #ifndef RGLWConfig_h 2 | #define RGLWConfig_h 3 | 4 | #import 5 | #import "RGLWJSONConstructor.h" 6 | 7 | @import CoreGraphics; 8 | @import UIKit; 9 | @import AVFoundation; 10 | 11 | @interface RGLWConfig : NSObject 12 | 13 | +(void)setFunctionality:(NSDictionary*)options :(RGLFunctionality*)functionality; 14 | +(void)setProcessParams:(NSDictionary*)options :(RGLProcessParams*)processParams; 15 | +(void)setCustomization:(NSDictionary*)options :(RGLCustomization*)customization; 16 | +(void)setRfidScenario:(NSDictionary*)options :(RGLRFIDScenario*)rfidScenario; 17 | +(void)setDataGroups:(RGLDataGroup*)dataGroup dict:(NSDictionary*)dict; 18 | +(void)setDTCDataGroup:(RGLDTCDataGroup*)dataGroup dict:(NSDictionary*)dict; 19 | +(void)setImageQA:(RGLImageQA*)result input:(NSDictionary*)input; 20 | +(void)setAuthenticityParams:(RGLAuthenticityParams*)result input:(NSDictionary*)input; 21 | +(void)setLivenessParams:(RGLLivenessParams*)result input:(NSDictionary*)input; 22 | 23 | +(NSDictionary*)getFunctionality:(RGLFunctionality*)functionality; 24 | +(NSDictionary*)getProcessParams:(RGLProcessParams*)processParams; 25 | +(NSDictionary*)getCustomization:(RGLCustomization*)customization; 26 | +(NSDictionary*)getRfidScenario:(RGLRFIDScenario*)rfidScenario; 27 | +(NSDictionary*)getDataGroups:(RGLDataGroup*)dataGroup; 28 | +(NSDictionary*)getDTCDataGroup:(RGLDTCDataGroup*)dataGroup; 29 | +(NSDictionary*)getImageQA:(RGLImageQA*)input; 30 | +(NSDictionary*)getAuthenticityParams:(RGLAuthenticityParams*)input; 31 | +(NSDictionary*)getLivenessParams:(RGLLivenessParams*)input; 32 | 33 | +(RGLImageQualityCheckType)imageQualityCheckTypeWithNumber:(NSNumber*)value; 34 | +(NSNumber*)generateDocReaderAction:(RGLDocReaderAction)action; 35 | +(NSNumber*)generateRFIDCompleteAction:(RGLRFIDCompleteAction)action; 36 | +(NSNumber*)generateImageQualityCheckType:(RGLImageQualityCheckType)value; 37 | 38 | +(RGLDocReaderFrame)docReaderFrameWithString:(NSString*)value; 39 | +(NSString*)generateDocReaderFrame:(RGLDocReaderFrame)value; 40 | 41 | @end 42 | #endif 43 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=1024m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.182.0 29 | 30 | # Use this property to specify which architecture you want to build. 31 | # You can also override it from the CLI using 32 | # ./gradlew -PreactNativeArchitectures=x86_64 33 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 34 | 35 | # Use this property to enable support to the new architecture. 36 | # This will allow you to use TurboModules and the Fabric render in 37 | # your application. You should enable this flag either if you want 38 | # to write custom TurboModules/Fabric components OR use libraries that 39 | # are providing them. 40 | newArchEnabled=false 41 | 42 | # Use this property to enable or disable the Hermes JS engine. 43 | # If set to false, you will be using JSC instead. 44 | hermesEnabled=false 45 | -------------------------------------------------------------------------------- /example/ios/DocumentReaderTests/DocumentReaderTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface DocumentReaderTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation DocumentReaderTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction( 38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 39 | if (level >= RCTLogLevelError) { 40 | redboxError = message; 41 | } 42 | }); 43 | #endif 44 | 45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 48 | 49 | foundElement = [self findSubviewInView:vc.view 50 | matching:^BOOL(UIView *view) { 51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 52 | return YES; 53 | } 54 | return NO; 55 | }]; 56 | } 57 | 58 | #ifdef DEBUG 59 | RCTSetLogFunction(RCTDefaultLogFunction); 60 | #endif 61 | 62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/regula/dr/fullauthrfid/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.regula.dr.fullauthrfid; 2 | 3 | import android.app.Application; 4 | import com.facebook.react.PackageList; 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; 9 | import com.facebook.react.defaults.DefaultReactNativeHost; 10 | import com.facebook.soloader.SoLoader; 11 | 12 | import java.io.IOException; 13 | import java.util.List; 14 | import com.facebook.react.soloader.OpenSourceMergedSoMapping; 15 | 16 | public class MainApplication extends Application implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = 19 | new DefaultReactNativeHost(this) { 20 | @Override 21 | public boolean getUseDeveloperSupport() { 22 | return BuildConfig.DEBUG; 23 | } 24 | 25 | @Override 26 | protected List getPackages() { 27 | @SuppressWarnings("UnnecessaryLocalVariable") 28 | List packages = new PackageList(this).getPackages(); 29 | // Packages that cannot be autolinked yet can be added manually here, for example: 30 | // packages.add(new MyReactNativePackage()); 31 | return packages; 32 | } 33 | 34 | @Override 35 | protected String getJSMainModuleName() { 36 | return "index"; 37 | } 38 | 39 | @Override 40 | protected boolean isNewArchEnabled() { 41 | return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 42 | } 43 | 44 | @Override 45 | protected Boolean isHermesEnabled() { 46 | return BuildConfig.IS_HERMES_ENABLED; 47 | } 48 | }; 49 | 50 | @Override 51 | public ReactNativeHost getReactNativeHost() { 52 | return mReactNativeHost; 53 | } 54 | 55 | @Override 56 | public void onCreate() { 57 | super.onCreate(); 58 | try { 59 | SoLoader.init(this, OpenSourceMergedSoMapping.INSTANCE); 60 | } catch (IOException e) { 61 | throw new RuntimeException(e); 62 | } 63 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 64 | // If you opted-in for the New Architecture, we load the native entry point for this app. 65 | DefaultNewArchitectureEntryPoint.load(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # How to build demo application 2 | 3 | 1. Get the trial license at [client.regulaforensics.com](https://client.regulaforensics.com/) (`regula.license` file). The license creation wizard will guide you through the necessary steps. 4 | 2. Get the trial database at [client.regulaforensics.com/customer/databases](https://client.regulaforensics.com/customer/databases) (`db.dat`) 5 | 2. Download or clone this repository using the command `git clone https://github.com/regulaforensics/react-native-document-reader.git`. 6 | 4. Copy the `regula.license` file to the `example/android/app/src/main/assets/` folder. 7 | 4. Copy the `regula.license` file to the `example/ios/` folder. 8 | 5. Copy the `db.dat` file to the `example/android/app/src/main/assets/Regula/` folder. 9 | 6. Copy the `db.dat` file to the `example/ios/` folder. 10 | 3. Run the following commands in Terminal: 11 | ```bash 12 | $ cd example 13 | $ npm install 14 | $ cd ios 15 | $ pod install 16 | ``` 17 | 18 | **Note**: make sure that Metro Bundler is running when you run your app. Otherwise, run `npx react-native start` command. If it fails to start, run `git init` from Project root, then `npx react-native start`. 19 | 20 | 4. Android: 21 | * Copy the `regula.license` file to the `example/android/app/src/main/assets` folder. 22 | * Run `npx react-native run-android` inside `example` folder - this is just one way to run the app. You can also run it directly from within Android Studio. **Note**: `npx react-native log-android` is used to view logs. 23 | 24 | **Note**: if the running failed with the following error `Error: spawn ./gradlew EACCES`, try to run the following command `chmod +x gradlew` within the `example/android` directory. 25 | 26 | 5. iOS: 27 | * Copy the `regula.license` file to the `example/ios` folder. 28 | * Run `npx react-native run-ios` inside `example` folder - this is just one way to run the app. You can also run it directly from within Xcode. 29 | 30 | # Troubleshooting license issues 31 | 32 | If you have issues with license verification when running the application, please verify that next is true: 33 | 1. The OS, which you use, is specified in the license (e.g., Android and/or iOS). 34 | 3. The license is valid (not expired). 35 | 4. The date and time on the device, where you run the application, are valid. 36 | 5. You use the latest release version of the Document Reader SDK. 37 | 6. You placed the `license` into the correct folder as described [here](#how-to-build-demo-application). 38 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /example/ios/DocumentReader/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | DocumentReader 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(MARKETING_VERSION) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(CURRENT_PROJECT_VERSION) 25 | LSRequiresIPhoneOS 26 | 27 | NFCReaderUsageDescription 28 | To use NFC 29 | NSAppTransportSecurity 30 | 31 | NSExceptionDomains 32 | 33 | localhost 34 | 35 | NSExceptionAllowsInsecureHTTPLoads 36 | 37 | 38 | 39 | 40 | NSCameraUsageDescription 41 | To use camera 42 | NSLocationWhenInUseUsageDescription 43 | 44 | NSPhotoLibraryUsageDescription 45 | To use gallery 46 | UILaunchStoryboardName 47 | LaunchScreen 48 | UIRequiredDeviceCapabilities 49 | 50 | armv7 51 | 52 | UISupportedInterfaceOrientations 53 | 54 | UIInterfaceOrientationPortrait 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | 60 | UIViewControllerBasedStatusBarAppearance 61 | 62 | com.apple.developer.nfc.readersession.iso7816.select-identifiers 63 | 64 | A0000002471001 65 | E80704007F00070302 66 | A000000167455349474E 67 | A0000002480100 68 | A0000002480200 69 | A0000002480300 70 | A00000045645444C2D3031 71 | 72 | UIAppFonts 73 | 74 | AntDesign.ttf 75 | Entypo.ttf 76 | EvilIcons.ttf 77 | Feather.ttf 78 | FontAwesome.ttf 79 | FontAwesome5_Brands.ttf 80 | FontAwesome5_Regular.ttf 81 | FontAwesome5_Solid.ttf 82 | FontAwesome6_Brands.ttf 83 | FontAwesome6_Regular.ttf 84 | FontAwesome6_Solid.ttf 85 | Foundation.ttf 86 | Ionicons.ttf 87 | MaterialIcons.ttf 88 | MaterialCommunityIcons.ttf 89 | SimpleLineIcons.ttf 90 | Octicons.ttf 91 | Zocial.ttf 92 | Fontisto.ttf 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/regula/dr/fullrfid/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.regula.dr.fullauthrfid; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 21 | import com.facebook.react.ReactInstanceEventListener; 22 | import com.facebook.react.ReactInstanceManager; 23 | import com.facebook.react.bridge.ReactContext; 24 | import com.facebook.react.modules.network.NetworkingModule; 25 | import okhttp3.OkHttpClient; 26 | 27 | /** 28 | * Class responsible of loading Flipper inside your React Native application. This is the debug 29 | * flavor of it. Here you can add your own plugins and customize the Flipper setup. 30 | */ 31 | public class ReactNativeFlipper { 32 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 33 | if (FlipperUtils.shouldEnableFlipper(context)) { 34 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 35 | 36 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 37 | client.addPlugin(new DatabasesFlipperPlugin(context)); 38 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 39 | client.addPlugin(CrashReporterPlugin.getInstance()); 40 | 41 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 42 | NetworkingModule.setCustomClientBuilder( 43 | new NetworkingModule.CustomClientBuilder() { 44 | @Override 45 | public void apply(OkHttpClient.Builder builder) { 46 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 47 | } 48 | }); 49 | client.addPlugin(networkFlipperPlugin); 50 | client.start(); 51 | 52 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 53 | // Hence we run if after all native modules have been initialized 54 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 55 | if (reactContext == null) { 56 | reactInstanceManager.addReactInstanceEventListener( 57 | new ReactInstanceEventListener() { 58 | @Override 59 | public void onReactContextInitialized(ReactContext reactContext) { 60 | reactInstanceManager.removeReactInstanceEventListener(this); 61 | reactContext.runOnNativeModulesQueueThread( 62 | new Runnable() { 63 | @Override 64 | public void run() { 65 | client.addPlugin(new FrescoFlipperPlugin()); 66 | } 67 | }); 68 | } 69 | }); 70 | } else { 71 | client.addPlugin(new FrescoFlipperPlugin()); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /example/ios/DocumentReader.xcodeproj/xcshareddata/xcschemes/DocumentReader.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /android/src/main/java/com/regula/plugin/documentreader/RNRegulaDocumentReaderModule.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused", "UNUSED_PARAMETER") 2 | 3 | package com.regula.plugin.documentreader 4 | 5 | import android.app.Activity 6 | import android.content.Context 7 | import android.content.Intent 8 | import android.util.Log 9 | import androidx.appcompat.app.AppCompatActivity 10 | import androidx.lifecycle.Lifecycle 11 | import com.facebook.react.ReactPackage 12 | import com.facebook.react.bridge.ActivityEventListener 13 | import com.facebook.react.bridge.Arguments 14 | import com.facebook.react.bridge.Promise 15 | import com.facebook.react.bridge.ReactApplicationContext 16 | import com.facebook.react.bridge.ReactContext 17 | import com.facebook.react.bridge.ReactContextBaseJavaModule 18 | import com.facebook.react.bridge.ReactMethod 19 | import com.facebook.react.bridge.ReadableArray 20 | import com.facebook.react.modules.core.DeviceEventManagerModule 21 | import com.facebook.react.modules.core.PermissionAwareActivity 22 | import com.facebook.react.uimanager.ViewManager 23 | import org.json.JSONArray 24 | import org.json.JSONObject 25 | 26 | var listenerCount = 0 27 | 28 | lateinit var args: JSONArray 29 | lateinit var binding: ReactContext 30 | val context: Context 31 | get() = binding.applicationContext 32 | val activity: Activity 33 | get() = binding.currentActivity!! 34 | val lifecycle: Lifecycle 35 | get() = (activity as AppCompatActivity).lifecycle 36 | 37 | fun sendEvent(event: String, data: Any? = "") { 38 | if (listenerCount <= 0) return 39 | val result = if (data is JSONObject || data is JSONArray) data.toString() else data.toString() + "" 40 | val map = Arguments.createMap() 41 | map.putString("msg", result) 42 | binding.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java).emit(event, map) 43 | } 44 | 45 | @Suppress("UNCHECKED_CAST") 46 | fun argsNullable(index: Int): T? { 47 | val value = args[index] 48 | if (value is Double && value % 1 == 0.0) return value.toInt() as T 49 | if (value.toString() == "null") return null 50 | return value as T 51 | } 52 | 53 | fun requestPermissions(activity: Activity, permissions: Array, requestCode: Int) { 54 | (activity as PermissionAwareActivity).requestPermissions(permissions, requestCode) { code, perms, grantResults -> 55 | onRequestPermissionsResult(code, perms, grantResults) 56 | } 57 | } 58 | 59 | fun startActivityForResult(activity: Activity, intent: Intent, requestCode: Int) { 60 | activity.startActivityForResult(intent, requestCode) 61 | } 62 | 63 | class RNRegulaDocumentReaderPackage : ReactPackage { 64 | override fun createNativeModules(reactContext: ReactApplicationContext) = listOf(RNRegulaDocumentReaderModule(reactContext)) 65 | override fun createViewManagers(reactContext: ReactApplicationContext) = emptyList>() 66 | } 67 | 68 | class RNRegulaDocumentReaderModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext), ActivityEventListener { 69 | init { 70 | binding = reactContext 71 | binding.addActivityEventListener(this) 72 | } 73 | 74 | @ReactMethod 75 | fun addListener(eventName: String) { 76 | listenerCount += 1 77 | } 78 | 79 | @ReactMethod 80 | fun removeListeners(count: Int) { 81 | listenerCount -= count 82 | } 83 | 84 | override fun onNewIntent(intent: Intent) { 85 | newIntent(intent) 86 | } 87 | 88 | override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) { 89 | onActivityResult(requestCode, resultCode, data) 90 | } 91 | 92 | @ReactMethod 93 | fun exec(moduleName: String, method: String, arguments: ReadableArray, success: com.facebook.react.bridge.Callback, error: com.facebook.react.bridge.Callback) { 94 | args = JSONArray(arguments.toArrayList()) 95 | try { 96 | methodCall(method) { data -> success(data.toSendable()) } 97 | } catch (error: Exception) { 98 | Log.e("REGULA", "Caught exception in \"$method\" function:", error) 99 | } 100 | } 101 | 102 | override fun getName() = "RNRegulaDocumentReader" 103 | } 104 | -------------------------------------------------------------------------------- /example/ios/DocumentReader/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "com.facebook.react" 3 | 4 | 5 | /** 6 | * This is the configuration block to customize your React Native Android app. 7 | * By default you don't need to apply any configuration, just uncomment the lines you need. 8 | */ 9 | react { 10 | /* Folders */ 11 | // The root of your project, i.e. where "package.json" lives. Default is '..' 12 | // root = file("../") 13 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native 14 | // reactNativeDir = file("../node_modules/react-native") 15 | // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen 16 | // codegenDir = file("../node_modules/@react-native/codegen") 17 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js 18 | // cliFile = file("../node_modules/react-native/cli.js") 19 | 20 | /* Variants */ 21 | // The list of variants to that are debuggable. For those we're going to 22 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 23 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 24 | // debuggableVariants = ["liteDebug", "prodDebug"] 25 | 26 | /* Bundling */ 27 | // A list containing the node command and its flags. Default is just 'node'. 28 | // nodeExecutableAndArgs = ["node"] 29 | // 30 | // The command to run when bundling. By default is 'bundle' 31 | // bundleCommand = "ram-bundle" 32 | // 33 | // The path to the CLI configuration file. Default is empty. 34 | // bundleConfig = file(../rn-cli.config.js) 35 | // 36 | // The name of the generated asset file containing your JS bundle 37 | // bundleAssetName = "MyApplication.android.bundle" 38 | // 39 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 40 | // entryFile = file("../js/MyApplication.android.js") 41 | // 42 | // A list of extra flags to pass to the 'bundle' commands. 43 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 44 | // extraPackagerArgs = [] 45 | 46 | /* Hermes Commands */ 47 | // The hermes compiler command to run. By default it is 'hermesc' 48 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 49 | // 50 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 51 | // hermesFlags = ["-O", "-output-source-map"] 52 | 53 | /* Autolinking */ 54 | autolinkLibrariesWithApp() 55 | } 56 | 57 | /** 58 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 59 | */ 60 | def enableProguardInReleaseBuilds = false 61 | 62 | /** 63 | * The preferred build flavor of JavaScriptCore (JSC) 64 | * 65 | * For example, to use the international variant, you can use: 66 | * `def jscFlavor = io.github.react-native-community:jsc-android-intl:2026004.+` 67 | * 68 | * The international variant includes ICU i18n library and necessary data 69 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 70 | * give correct results when using with locales other than en-US. Note that 71 | * this variant is about 6MiB larger per architecture than default. 72 | */ 73 | def jscFlavor = 'io.github.react-native-community:jsc-android:2026004.+' 74 | 75 | android { 76 | ndkVersion rootProject.ext.ndkVersion 77 | 78 | compileSdk rootProject.ext.compileSdkVersion 79 | 80 | namespace "com.regula.dr.fullauthrfid" 81 | defaultConfig { 82 | applicationId "com.regula.dr.fullauthrfid" 83 | minSdkVersion rootProject.ext.minSdkVersion 84 | targetSdkVersion rootProject.ext.targetSdkVersion 85 | versionCode 1 86 | versionName "1.0" 87 | } 88 | signingConfigs { 89 | debug { 90 | storeFile file('debug.keystore') 91 | storePassword 'android' 92 | keyAlias 'androiddebugkey' 93 | keyPassword 'android' 94 | } 95 | } 96 | buildTypes { 97 | debug { 98 | signingConfig signingConfigs.debug 99 | } 100 | release { 101 | // Caution! In production, you need to generate your own keystore file. 102 | // see https://reactnative.dev/docs/signed-apk-android. 103 | signingConfig signingConfigs.debug 104 | minifyEnabled enableProguardInReleaseBuilds 105 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 106 | } 107 | } 108 | } 109 | 110 | dependencies { 111 | // The version of react-native is set by the React Native Gradle Plugin 112 | implementation("com.facebook.react:react-android") 113 | 114 | debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") 115 | debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 116 | exclude group:'com.squareup.okhttp3', module:'okhttp' 117 | } 118 | 119 | debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") 120 | if (hermesEnabled.toBoolean()) { 121 | implementation("com.facebook.react:hermes-android") 122 | } else { 123 | implementation jscFlavor 124 | } 125 | } 126 | 127 | apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" 128 | -------------------------------------------------------------------------------- /android/src/main/java/com/regula/plugin/documentreader/BluetoothUtil.kt: -------------------------------------------------------------------------------- 1 | package com.regula.plugin.documentreader 2 | 3 | import android.Manifest.permission.ACCESS_FINE_LOCATION 4 | import android.Manifest.permission.BLUETOOTH_CONNECT 5 | import android.Manifest.permission.BLUETOOTH_SCAN 6 | import android.annotation.SuppressLint 7 | import android.app.Activity 8 | import android.bluetooth.BluetoothAdapter 9 | import android.content.ComponentName 10 | import android.content.Context.BIND_AUTO_CREATE 11 | import android.content.Intent 12 | import android.content.ServiceConnection 13 | import android.content.pm.PackageManager.PERMISSION_GRANTED 14 | import android.os.Build 15 | import android.os.IBinder 16 | import android.provider.Settings 17 | import android.util.Log 18 | import androidx.core.content.ContextCompat.checkSelfPermission 19 | import com.regula.common.ble.BLEWrapper 20 | import com.regula.common.ble.BleWrapperCallback 21 | import com.regula.common.ble.RegulaBleService 22 | import com.regula.documentreader.api.internal.permission.BluetoothPermissionHelper.BLE_ACCESS_PERMISSION 23 | import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isBluetoothEnabled 24 | import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isLocationServiceEnabled 25 | import java.util.Timer 26 | import java.util.TimerTask 27 | 28 | const val SEARCHING_TIMEOUT: Long = 7000 29 | 30 | const val INTENT_REQUEST_ENABLE_LOCATION = 196 31 | const val INTENT_REQUEST_ENABLE_BLUETOOTH = 197 32 | 33 | @SuppressLint("StaticFieldLeak") 34 | var bluetooth: BLEWrapper? = null 35 | lateinit var savedDeviceNameForPermissionResult: String 36 | lateinit var savedCallbackForPermissionResult: Callback 37 | 38 | fun connectBluetoothDevice(deviceName: String, callback: Callback) { 39 | if (bluetooth?.isConnected == true) { 40 | Log.e("REGULA", "Bluetooth device already connected, returning false") 41 | callback(false) 42 | return 43 | } 44 | 45 | if (!isBluetoothSettingsReady(activity)) { 46 | savedDeviceNameForPermissionResult = deviceName 47 | savedCallbackForPermissionResult = callback 48 | return 49 | } 50 | 51 | val timeout = object : TimerTask() { 52 | override fun run() { 53 | callback(false) 54 | bluetooth?.stopDeviceScan() 55 | bluetooth?.disconnect() 56 | } 57 | } 58 | Timer().schedule(timeout, SEARCHING_TIMEOUT) 59 | 60 | val bleIntent = Intent(context, RegulaBleService::class.java) 61 | bleIntent.putExtra(RegulaBleService.DEVICE_NAME, deviceName) 62 | context.startService(bleIntent) 63 | context.bindService(bleIntent, object : ServiceConnection { 64 | override fun onServiceConnected(name: ComponentName, service: IBinder) { 65 | bluetooth = (service as RegulaBleService.LocalBinder).service.bleManager 66 | if (bluetooth!!.isConnected) callback(true) 67 | else bluetooth!!.addCallback(object : BleWrapperCallback() { 68 | override fun onDeviceReady() { 69 | timeout.cancel() 70 | bluetooth!!.removeCallback(this) 71 | callback(true) 72 | } 73 | }) 74 | } 75 | 76 | override fun onServiceDisconnected(name: ComponentName) {} 77 | }, BIND_AUTO_CREATE) 78 | } 79 | 80 | fun onRequestPermissionsResult( 81 | requestCode: Int, 82 | permissions: Array, 83 | grantResults: IntArray 84 | ): Boolean { 85 | if (requestCode != BLE_ACCESS_PERMISSION || permissions.isEmpty()) return false 86 | if (grantResults.isEmpty() || grantResults[0] != PERMISSION_GRANTED) { 87 | savedCallbackForPermissionResult(false) 88 | return true 89 | } 90 | connectBluetoothDevice(savedDeviceNameForPermissionResult, savedCallbackForPermissionResult) 91 | return true 92 | } 93 | 94 | fun onActivityResult(requestCode: Int, rc: Int, @Suppress("UNUSED_PARAMETER") data: Intent?): Boolean { 95 | var resultCode = rc 96 | if (requestCode == INTENT_REQUEST_ENABLE_LOCATION) 97 | resultCode = if (isLocationServiceEnabled(activity)) Activity.RESULT_OK 98 | else requestCode 99 | 100 | if (requestCode == INTENT_REQUEST_ENABLE_BLUETOOTH || requestCode == INTENT_REQUEST_ENABLE_LOCATION) { 101 | if (resultCode == Activity.RESULT_OK) 102 | connectBluetoothDevice(savedDeviceNameForPermissionResult, savedCallbackForPermissionResult) 103 | else 104 | savedCallbackForPermissionResult(false) 105 | return true 106 | } 107 | return false 108 | } 109 | 110 | fun isBluetoothSettingsReady(activity: Activity): Boolean { 111 | deniedBluetoothPermissions()?.let { 112 | requestPermissions(activity, it, BLE_ACCESS_PERMISSION) 113 | return false 114 | } 115 | if (!isBluetoothEnabled(activity)) { 116 | requestEnableBluetooth(activity) 117 | return false 118 | } 119 | if (!isLocationServiceEnabled(activity)) { 120 | requestEnableLocationService(activity) 121 | return false 122 | } 123 | return true 124 | } 125 | 126 | fun deniedBluetoothPermissions(): Array? { 127 | val result = mutableListOf() 128 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { 129 | result.addAll(deniedBluetoothPermission(BLUETOOTH_SCAN)) 130 | result.addAll(deniedBluetoothPermission(BLUETOOTH_CONNECT)) 131 | } else 132 | result.addAll(deniedBluetoothPermission(ACCESS_FINE_LOCATION)) 133 | return result.let { if (it.isNotEmpty()) it.toTypedArray() else null } 134 | } 135 | 136 | fun deniedBluetoothPermission(permission: String): Array { 137 | if (checkSelfPermission(context, permission) != PERMISSION_GRANTED) 138 | return arrayOf(permission) 139 | return arrayOf() 140 | } 141 | 142 | fun requestEnableBluetooth(activity: Activity) { 143 | val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE) 144 | startActivityForResult(activity, enableIntent, INTENT_REQUEST_ENABLE_BLUETOOTH) 145 | } 146 | 147 | fun requestEnableLocationService(activity: Activity) { 148 | val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS) 149 | startActivityForResult(activity, myIntent, INTENT_REQUEST_ENABLE_LOCATION) 150 | } 151 | 152 | // btDevice functionality(temporary, will be reworked) 153 | 154 | fun btDeviceRequestFlashing() { 155 | bluetooth?.requestFlashing() 156 | } 157 | 158 | fun btDeviceRequestFlashingFullIR() { 159 | bluetooth?.requestFlashingFullIR() 160 | } 161 | 162 | fun btDeviceRequestTurnOffAll() { 163 | bluetooth?.requestTurnOffAll() 164 | } 165 | -------------------------------------------------------------------------------- /android/src/main/java/com/regula/plugin/documentreader/Utils.kt: -------------------------------------------------------------------------------- 1 | @file:SuppressLint("UseKtx") 2 | 3 | package com.regula.plugin.documentreader 4 | 5 | import android.annotation.SuppressLint 6 | import android.graphics.Bitmap 7 | import android.graphics.BitmapFactory 8 | import android.graphics.Canvas 9 | import android.graphics.drawable.BitmapDrawable 10 | import android.graphics.drawable.Drawable 11 | import android.util.Base64 12 | import org.json.JSONArray 13 | import org.json.JSONObject 14 | import java.io.ByteArrayOutputStream 15 | import kotlin.math.sqrt 16 | 17 | fun List<*>.toJson(): JSONArray { 18 | val result = JSONArray() 19 | for (i in indices) 20 | when (val v = this[i]) { 21 | null -> result.put(null) 22 | is Map<*, *> -> result.put(v.toJson()) 23 | is List<*> -> result.put(v.toJson()) 24 | else -> result.put(v) 25 | } 26 | return result 27 | } 28 | 29 | fun Map<*, *>.toJson(): JSONObject { 30 | val result = JSONObject() 31 | for ((k, v) in this) { 32 | when (v) { 33 | null -> result.put(k as String, null) 34 | is Map<*, *> -> result.put(k as String, v.toJson()) 35 | is List<*> -> result.put(k as String, v.toJson()) 36 | else -> result.put(k as String, v) 37 | } 38 | } 39 | return result 40 | } 41 | 42 | fun Any?.toSendable(): Any? = this?.let { 43 | if (it is JSONObject || it is JSONArray) it.toString() 44 | else it 45 | } 46 | 47 | fun List?.toJson(toJson: (T?) -> Any?) = this?.let { 48 | val result = JSONArray() 49 | for (item in it) result.put(toJson(item)) 50 | result 51 | } 52 | 53 | fun List?.toJsonNullable(toJson: (T?) -> Any?) = this?.let { 54 | val result = JSONArray() 55 | for (item in it) result.put(toJson(item)) 56 | result 57 | } 58 | 59 | fun JSONArray?.toList(fromJson: (JSONObject) -> T) = this?.let { 60 | val result: MutableList = ArrayList() 61 | for (i in 0 until it.length()) result.add(fromJson(it.getJSONObject(i))) 62 | result 63 | } 64 | 65 | fun JSONArray.toList() = this.let { 66 | val result = mutableListOf() 67 | @Suppress("UNCHECKED_CAST") 68 | for (i in 0 until length()) result.add(get(i) as T) 69 | result 70 | } 71 | 72 | inline fun JSONArray?.toArray() = this?.let { 73 | val result = arrayOfNulls(length()) 74 | for (i in 0 until length()) result[i] = get(i) as T 75 | result 76 | } 77 | 78 | inline fun JSONArray?.toArray(fromJson: (JSONObject?) -> T) = this?.let { 79 | val result = arrayOfNulls(length()) 80 | for (i in 0 until length()) result[i] = fromJson(getJSONObject(i)) 81 | result 82 | } 83 | 84 | fun Array?.toJson() = this?.let { 85 | val result = JSONArray() 86 | for (i in it.indices) result.put(i, it[i]) 87 | result 88 | } 89 | 90 | fun Array?.toJson(toJson: (T?) -> JSONObject?) = this?.let { 91 | val result = JSONArray() 92 | for (i in indices) result.put(i, toJson(this[i])) 93 | result 94 | } 95 | 96 | fun Any?.toIntArray() = (this as JSONArray?)?.let { 97 | val result = IntArray(it.length()) 98 | for (i in 0 until it.length()) result[i] = it.getInt(i) 99 | result 100 | } 101 | 102 | fun IntArray?.toJson() = this?.let { 103 | val result = JSONArray() 104 | for (i in it.indices) result.put(i, it[i]) 105 | result 106 | } 107 | 108 | fun JSONObject.forEach(action: (String, Any) -> Unit) { 109 | val keys: Iterator = keys() 110 | while (keys.hasNext()) { 111 | val key = keys.next() 112 | action(key, get(key)) 113 | } 114 | } 115 | 116 | fun JSONObject.getJSONObjectOrNull(name: String): JSONObject? { 117 | if (has(name) && get(name).toString() != "null") return getJSONObject(name) 118 | return null 119 | } 120 | 121 | fun JSONObject.getIntOrNull(name: String): Int? { 122 | if (has(name) && get(name).toString() != "null") return getInt(name) 123 | return null 124 | } 125 | 126 | fun JSONObject.getDoubleOrNull(name: String): Double? { 127 | if (has(name) && get(name).toString() != "null") return getDouble(name) 128 | return null 129 | } 130 | 131 | fun JSONObject.getBooleanOrNull(name: String): Boolean? { 132 | if (has(name) && get(name).toString() != "null") return getBoolean(name) 133 | return null 134 | } 135 | 136 | fun JSONObject.getStringOrNull(name: String): String? { 137 | if (has(name) && get(name).toString() != "null") return getString(name) 138 | return null 139 | } 140 | 141 | internal object Convert { 142 | fun String?.toByteArray(): ByteArray? { 143 | var str = this ?: return null 144 | if (str.startsWith("data")) str = str.substring(str.indexOf(",") + 1) 145 | return Base64.decode(str, Base64.NO_WRAP) 146 | } 147 | 148 | fun ByteArray?.toBase64() = this?.let { Base64.encodeToString(it, Base64.NO_WRAP) } 149 | 150 | fun Bitmap?.toBase64() = this?.let { 151 | val byteArrayOutputStream = ByteArrayOutputStream() 152 | it.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream) 153 | byteArrayOutputStream.toByteArray().toBase64() 154 | } 155 | 156 | fun String?.toBitmap() = this?.let { 157 | val decodedString = toByteArray()!! 158 | var result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size) 159 | val sizeMultiplier = result.byteCount / 5000000 160 | if (result.byteCount > 5000000) result = Bitmap.createScaledBitmap(result, result.width / sqrt(sizeMultiplier.toDouble()).toInt(), result.height / sqrt(sizeMultiplier.toDouble()).toInt(), false) 161 | result 162 | } 163 | 164 | fun Any?.toDrawable() = (this as String?)?.let { 165 | val decodedByte = it.toByteArray()!! 166 | val bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.size) 167 | val density = context.resources.displayMetrics.density 168 | val width = (bitmap.width * density).toInt() 169 | val height = (bitmap.height * density).toInt() 170 | BitmapDrawable(context.resources, Bitmap.createScaledBitmap(bitmap, width, height, false)) 171 | } 172 | 173 | fun Drawable?.toBase64() = this?.let { 174 | if (this is BitmapDrawable) if (bitmap != null) return bitmap.toBase64() 175 | val bitmap: Bitmap = if (intrinsicWidth <= 0 || intrinsicHeight <= 0) Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) else Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888) 176 | val canvas = Canvas(bitmap) 177 | setBounds(0, 0, canvas.width, canvas.height) 178 | draw(canvas) 179 | bitmap.toBase64() 180 | } 181 | } 182 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | # Collect all arguments for the java command; 201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 202 | # shell script including quotes and variable substitutions, so put them in 203 | # double quotes to make sure that they get re-expanded; and 204 | # * put everything else in single quotes, so that it's not re-expanded. 205 | 206 | set -- \ 207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 208 | -classpath "$CLASSPATH" \ 209 | org.gradle.wrapper.GradleWrapperMain \ 210 | "$@" 211 | 212 | # Stop when "xargs" is not available. 213 | if ! command -v xargs >/dev/null 2>&1 214 | then 215 | die "xargs is not available" 216 | fi 217 | 218 | # Use "xargs" to parse quoted args. 219 | # 220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 221 | # 222 | # In Bash we could simply go: 223 | # 224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 225 | # set -- "${ARGS[@]}" "$@" 226 | # 227 | # but POSIX shell has neither arrays nor command substitution, so instead we 228 | # post-process each arg (as a line of input to sed) to backslash-escape any 229 | # character that might be a shell metacharacter, then use eval to reverse 230 | # that process (while maintaining the separation between arguments), and wrap 231 | # the whole thing up as a single "set" statement. 232 | # 233 | # This will of course break if any of these variables contains a newline or 234 | # an unmatched quote. 235 | # 236 | 237 | eval "set -- $( 238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 239 | xargs -n1 | 240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 241 | tr '\n' ' ' 242 | )" '"$@"' 243 | 244 | exec "$JAVACMD" "$@" 245 | -------------------------------------------------------------------------------- /example/App.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { ScrollView, StyleSheet, Text, View, NativeEventEmitter, Platform, TouchableOpacity, Image, Button } from 'react-native' 3 | import DocumentReader, { Enum, DocumentReaderCompletion, DocumentReaderScenario, RNRegulaDocumentReader, DocumentReaderResults, DocumentReaderNotification, ScannerConfig, RecognizeConfig, DocReaderConfig, Functionality } from '@regulaforensics/react-native-document-reader-api' 4 | import * as RNFS from 'react-native-fs' 5 | import RadioGroup, { RadioButtonProps } from 'react-native-radio-buttons-group' 6 | import { CheckBox } from '@rneui/themed' 7 | import Icon from 'react-native-vector-icons/FontAwesome' 8 | import { launchImageLibrary } from 'react-native-image-picker' 9 | import * as Progress from 'react-native-progress' 10 | 11 | var isReadingRfid = false 12 | 13 | interface IProps { 14 | } 15 | 16 | interface IState { 17 | fullName: string | undefined 18 | doRfid: boolean 19 | isReadingRfidCustomUi: boolean 20 | rfidUIHeader: string 21 | rfidUIHeaderColor: string 22 | rfidDescription: string 23 | rfidProgress: number 24 | canRfid: boolean 25 | canRfidTitle: string 26 | radioButtons: any 27 | selectedScenario: string 28 | portrait: any 29 | docFront: any 30 | } 31 | 32 | export default class App extends React.Component { 33 | onInitialized() { 34 | this.setState({ fullName: "Ready" }) 35 | 36 | var functionality = new Functionality() 37 | functionality.showCaptureButton = true 38 | DocumentReader.setFunctionality(functionality, _ => { }, _ => { }) 39 | } 40 | 41 | constructor(props: {} | Readonly<{}>) { 42 | super(props) 43 | Icon.loadFont() 44 | 45 | var eventManager = new NativeEventEmitter(RNRegulaDocumentReader) 46 | eventManager.addListener('completion', (e) => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))!)) 47 | eventManager.addListener('rfidOnProgressCompletion', e => this.updateRfidUI(DocumentReaderNotification.fromJson(JSON.parse(e["msg"]))!)) 48 | 49 | var licPath = Platform.OS === 'ios' ? (RNFS.MainBundlePath + "/regula.license") : "regula.license" 50 | var readFile = Platform.OS === 'ios' ? RNFS.readFile : RNFS.readFileAssets 51 | readFile(licPath, 'base64').then((res) => { 52 | this.setState({ fullName: "Initializing..." }) 53 | var config = new DocReaderConfig() 54 | config.license = res 55 | config.delayedNNLoad = true 56 | DocumentReader.initializeReader(config, (response) => { 57 | if (!JSON.parse(response)["success"]) { 58 | console.log(response) 59 | return 60 | } 61 | console.log("Init complete") 62 | DocumentReader.getIsRFIDAvailableForUse((canRfid) => { 63 | if (canRfid) { 64 | this.setState({ canRfid: true, rfidUIHeader: "Reading RFID", rfidDescription: "Place your phone on top of the NFC tag", rfidUIHeaderColor: "black" }) 65 | this.setState({ canRfidTitle: '' }) 66 | } 67 | }, error => console.log(error)) 68 | DocumentReader.getAvailableScenarios((jstring) => { 69 | var scenarios = JSON.parse(jstring) 70 | var items: RadioButtonProps[] = [] 71 | for (var i in scenarios) { 72 | var scenario = DocumentReaderScenario.fromJson(typeof scenarios[i] === "string" ? JSON.parse(scenarios[i]) : scenarios[i])!.name! 73 | items.push({ label: scenario, id: scenario }) 74 | } 75 | this.setState({ radioButtons: items }) 76 | this.setState({ selectedScenario: this.state.radioButtons[0]['id'] }) 77 | }, error => console.log(error)) 78 | this.onInitialized() 79 | }, error => console.log(error)) 80 | }) 81 | 82 | this.state = { 83 | fullName: "Please wait...", 84 | doRfid: false, 85 | isReadingRfidCustomUi: false, 86 | rfidUIHeader: "", 87 | rfidUIHeaderColor: "black", 88 | rfidDescription: "", 89 | rfidProgress: -1, 90 | canRfid: false, 91 | canRfidTitle: "(unavailable)", 92 | radioButtons: [{ label: 'Loading', id: "0" }], 93 | selectedScenario: "", 94 | portrait: require('./images/portrait.png'), 95 | docFront: require('./images/id.png') 96 | } 97 | } 98 | 99 | handleCompletion(completion: DocumentReaderCompletion) { 100 | if (this.state.isReadingRfidCustomUi) { 101 | if (completion.action == Enum.DocReaderAction.ERROR) this.restartRfidUI() 102 | if (this.actionSuccess(completion.action!) || this.actionError(completion.action!)) { 103 | this.hideRfidUI() 104 | this.displayResults(completion.results!) 105 | } 106 | } else if (this.actionSuccess(completion.action!) || this.actionError(completion.action!)) 107 | this.handleResults(completion.results!) 108 | } 109 | 110 | actionSuccess(action: number) { 111 | if (action == Enum.DocReaderAction.COMPLETE || action == Enum.DocReaderAction.TIMEOUT) return true 112 | return false 113 | } 114 | 115 | actionError(action: number) { 116 | if (action == Enum.DocReaderAction.CANCEL || action == Enum.DocReaderAction.ERROR) return true 117 | return false 118 | } 119 | 120 | showRfidUI() { 121 | // show animation 122 | this.setState({ isReadingRfidCustomUi: true }) 123 | } 124 | 125 | hideRfidUI() { 126 | // show animation 127 | DocumentReader.stopRFIDReader(_ => { }, _ => { }); 128 | this.restartRfidUI() 129 | this.setState({ isReadingRfidCustomUi: false, rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" }) 130 | } 131 | 132 | restartRfidUI() { 133 | this.setState({ rfidUIHeaderColor: "red", rfidUIHeader: "Failed!", rfidDescription: "Place your phone on top of the NFC tag", rfidProgress: -1 }) 134 | } 135 | 136 | updateRfidUI(notification: DocumentReaderNotification) { 137 | if (notification.notificationCode === Enum.eRFID_NotificationCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP) 138 | this.setState({ rfidDescription: "ERFIDDataFileType: " + notification.dataFileType }) 139 | this.setState({ rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" }) 140 | if (notification.progress != null) 141 | this.setState({ rfidProgress: notification.progress / 100 }) 142 | if (Platform.OS === 'ios') 143 | DocumentReader.setRfidSessionStatus(this.state.rfidDescription + "\n" + notification.progress + "%", e => { }, e => { }) 144 | } 145 | 146 | clearResults() { 147 | this.setState({ fullName: "Ready", docFront: require('./images/id.png'), portrait: require('./images/portrait.png') }) 148 | } 149 | 150 | scan() { 151 | this.clearResults() 152 | var config = new ScannerConfig() 153 | config.scenario = this.state.selectedScenario 154 | DocumentReader.startScanner(config, _ => { }, e => console.log(e)) 155 | } 156 | 157 | recognize() { 158 | launchImageLibrary({ 159 | mediaType: 'photo', 160 | includeBase64: true, 161 | selectionLimit: 10 162 | }, r => { 163 | if (r.errorCode != null) { 164 | console.log("error code: " + r.errorCode) 165 | console.log("error message: " + r.errorMessage) 166 | this.setState({ fullName: r.errorMessage }) 167 | return 168 | } 169 | if (r.didCancel) return 170 | this.clearResults() 171 | this.setState({ fullName: "COPYING IMAGE..." }) 172 | var response = r.assets 173 | 174 | var images: any = [] 175 | 176 | for (var i = 0; i < response!.length; i++) { 177 | images.push(response![i].base64!) 178 | } 179 | this.setState({ fullName: "PROCESSING..." }) 180 | 181 | var config = new RecognizeConfig() 182 | config.scenario = this.state.selectedScenario 183 | config.images = images 184 | DocumentReader.recognize(config, _ => { }, e => console.log(e)) 185 | }) 186 | } 187 | 188 | displayResults(results: DocumentReaderResults) { 189 | if (results == null) return 190 | 191 | results.textFieldValueByType(Enum.eVisualFieldType.FT_SURNAME_AND_GIVEN_NAMES, (value: string | undefined) => { 192 | this.setState({ fullName: value }) 193 | }, (error: string) => console.log(error)) 194 | 195 | results.graphicFieldImageByType(Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE, (value: string | undefined) => { 196 | if (value != null && value != "") 197 | this.setState({ docFront: { uri: "data:image/png;base64," + value } }) 198 | }, (error: string) => console.log(error)) 199 | 200 | results.graphicFieldImageByType(Enum.eGraphicFieldType.GF_PORTRAIT, (value: string | undefined) => { 201 | if (value != null && value != "") 202 | this.setState({ portrait: { uri: "data:image/png;base64," + value } }) 203 | }, (error: string) => console.log(error)) 204 | 205 | results.graphicFieldImageByTypeSource(Enum.eGraphicFieldType.GF_PORTRAIT, Enum.eRPRM_ResultType.RFID_RESULT_TYPE_RFID_IMAGE_DATA, (value: string | undefined) => { 206 | if (value != null && value != "") 207 | this.setState({ portrait: { uri: "data:image/png;base64," + value } }) 208 | }, (error: string) => console.log(error)) 209 | } 210 | 211 | customRFID() { 212 | this.showRfidUI() 213 | DocumentReader.readRFID(false, false, false, _ => { }, _ => { }) 214 | } 215 | 216 | usualRFID() { 217 | isReadingRfid = true 218 | DocumentReader.startRFIDReader(false, false, false, _ => { }, _ => { }) 219 | } 220 | 221 | handleResults(results: DocumentReaderResults) { 222 | if (this.state.doRfid && !isReadingRfid && results != null && results.chipPage != 0) { 223 | // this.customRFID() 224 | this.usualRFID() 225 | } else { 226 | isReadingRfid = false 227 | this.displayResults(results) 228 | } 229 | } 230 | 231 | render() { 232 | return ( 233 | 234 | {!this.state.isReadingRfidCustomUi && 235 | {this.state.fullName} 236 | 237 | 238 | 239 | Portrait 240 | 241 | 242 | 243 | Document image 244 | 245 | 246 | 247 | 248 | 249 | { this.setState({ selectedScenario: selectedID }) }} 253 | selectedId={this.state.selectedScenario} 254 | /> 255 | 256 | 257 | 258 | { 263 | if (this.state.canRfid) { 264 | this.setState({ doRfid: !this.state.doRfid }) 265 | } 266 | }} /> 267 | 268 | 269 | 270 |