@regulaforensics/react-native-document-reader-api 6.8.1 → 6.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/RNDocumentReaderApi.podspec +1 -1
  2. package/android/build.gradle +18 -1
  3. package/android/src/main/java/com/regula/documentreader/BluetoothUtil.kt +6 -6
  4. package/android/src/main/java/com/regula/documentreader/Helpers.java +117 -3
  5. package/android/src/main/java/com/regula/documentreader/JSONConstructor.java +182 -261
  6. package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderModule.java +142 -125
  7. package/android/src/main/java/com/regula/documentreader/RegulaConfig.java +114 -26
  8. package/example/.bundle/config +2 -0
  9. package/example/.eslintrc.js +1 -1
  10. package/example/.prettierrc.js +2 -2
  11. package/example/.watchmanconfig +1 -1
  12. package/example/App.tsx +358 -0
  13. package/example/Gemfile +6 -0
  14. package/example/Gemfile.lock +98 -0
  15. package/example/__tests__/{App-test.js → App.test.tsx} +3 -0
  16. package/example/android/app/build.gradle +77 -59
  17. package/example/android/app/src/debug/AndroidManifest.xml +1 -1
  18. package/example/android/app/src/debug/java/com/regula/dr/fullrfid/ReactNativeFlipper.java +7 -4
  19. package/example/android/app/src/main/AndroidManifest.xml +4 -9
  20. package/example/android/app/src/main/java/com/regula/dr/fullrfid/MainActivity.java +17 -0
  21. package/example/android/app/src/main/java/com/regula/dr/fullrfid/MainApplication.java +17 -36
  22. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  23. package/example/android/app/src/main/res/values/styles.xml +2 -2
  24. package/example/android/app/src/release/java/com/regula/dr/fullrfid/ReactNativeFlipper.java +20 -0
  25. package/example/android/build.gradle +7 -18
  26. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  27. package/example/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  28. package/example/android/gradle.properties +42 -2
  29. package/example/android/gradlew +164 -105
  30. package/example/android/gradlew.bat +92 -89
  31. package/example/android/settings.gradle +2 -1
  32. package/example/app.json +1 -1
  33. package/example/ios/.xcode.env +11 -0
  34. package/example/ios/DocumentReader/AppDelegate.h +2 -4
  35. package/example/ios/DocumentReader/AppDelegate.mm +26 -0
  36. package/example/ios/DocumentReader/DocumentReader.entitlements +0 -1
  37. package/example/ios/DocumentReader/Images.xcassets/AppIcon.appiconset/Contents.json +30 -15
  38. package/example/ios/DocumentReader/Info.plist +8 -4
  39. package/example/ios/DocumentReader/main.m +2 -1
  40. package/example/ios/DocumentReader.xcodeproj/project.pbxproj +134 -96
  41. package/example/ios/DocumentReaderTests/DocumentReaderTests.m +14 -13
  42. package/example/ios/Podfile +45 -15
  43. package/example/jest.config.js +3 -0
  44. package/example/metro.config.js +18 -15
  45. package/example/package-lock.json +13091 -0
  46. package/example/package.json +32 -22
  47. package/example/tsconfig.json +3 -0
  48. package/index.d.ts +426 -3015
  49. package/index.js +253 -2954
  50. package/ios/RGLWJSONConstructor.h +8 -6
  51. package/ios/RGLWJSONConstructor.m +109 -92
  52. package/ios/RGLWRegulaConfig.h +2 -1
  53. package/ios/RGLWRegulaConfig.m +139 -41
  54. package/ios/RNRegulaDocumentReader.m +55 -42
  55. package/package.json +1 -1
  56. package/example/.buckconfig +0 -6
  57. package/example/.editorconfig +0 -3
  58. package/example/.flowconfig +0 -65
  59. package/example/.gitattributes +0 -3
  60. package/example/App.js +0 -399
  61. package/example/android/app/BUCK +0 -55
  62. package/example/android/app/_BUCK +0 -55
  63. package/example/android/app/build_defs.bzl +0 -19
  64. package/example/android/app/src/main/assets/index.android.bundle +0 -636
  65. package/example/android/app/src/main/res/drawable-mdpi/images_id.png +0 -0
  66. package/example/android/app/src/main/res/drawable-mdpi/images_portrait.png +0 -0
  67. package/example/android/app/src/main/res/drawable-mdpi/node_modules_reactnativecheckbox_img_ic_check_box.png +0 -0
  68. package/example/android/app/src/main/res/drawable-mdpi/node_modules_reactnativecheckbox_img_ic_check_box_outline_blank.png +0 -0
  69. package/example/android/app/src/main/res/drawable-mdpi/node_modules_reactnativecheckbox_img_ic_indeterminate_check_box.png +0 -0
  70. package/example/android/app/src/main/res/drawable-xhdpi/node_modules_reactnativecheckbox_img_ic_check_box.png +0 -0
  71. package/example/android/app/src/main/res/drawable-xhdpi/node_modules_reactnativecheckbox_img_ic_check_box_outline_blank.png +0 -0
  72. package/example/android/app/src/main/res/drawable-xxhdpi/node_modules_reactnativecheckbox_img_ic_check_box.png +0 -0
  73. package/example/android/app/src/main/res/drawable-xxhdpi/node_modules_reactnativecheckbox_img_ic_check_box_outline_blank.png +0 -0
  74. package/example/ios/DocumentReader/AppDelegate.m +0 -62
  75. package/example/ios/DocumentReader/Base.lproj/LaunchScreen.xib +0 -42
@@ -1,31 +1,28 @@
1
1
  package com.regula.documentreader;
2
2
 
3
- import org.json.JSONArray;
4
- import org.json.JSONObject;
5
- import org.json.JSONException;
6
-
7
- import com.regula.documentreader.api.DocumentReader;
8
- import com.regula.documentreader.api.params.ImageQA;
9
- import com.regula.documentreader.api.params.OnlineProcessingConfig;
10
- import com.regula.documentreader.api.params.ParamsCustomization;
11
- import com.regula.documentreader.api.params.Functionality;
12
- import com.regula.documentreader.api.params.ProcessParam;
13
- import com.regula.documentreader.api.params.rfid.RFIDParams;
14
- import com.regula.documentreader.api.params.rfid.ReprocParams;
15
- import com.regula.documentreader.api.params.rfid.dg.DataGroups;
3
+ import static com.regula.documentreader.Helpers.*;
4
+ import static com.regula.documentreader.JSONConstructor.*;
16
5
 
17
6
  import android.annotation.SuppressLint;
18
7
  import android.content.Context;
19
8
  import android.graphics.Paint;
9
+ import android.graphics.Typeface;
20
10
  import android.text.SpannableString;
21
11
  import android.widget.ImageView.ScaleType;
22
- import android.graphics.Typeface;
23
12
 
24
- import java.math.BigDecimal;
13
+ import com.regula.documentreader.api.DocumentReader;
14
+ import com.regula.documentreader.api.params.*;
15
+ import com.regula.documentreader.api.params.rfid.RFIDParams;
16
+ import com.regula.documentreader.api.params.rfid.ReprocParams;
17
+ import com.regula.documentreader.api.params.rfid.dg.DataGroups;
25
18
 
26
- import static com.regula.documentreader.Helpers.*;
27
- import static com.regula.documentreader.JSONConstructor.*;
19
+ import org.json.JSONArray;
20
+ import org.json.JSONException;
21
+ import org.json.JSONObject;
22
+
23
+ import java.math.BigDecimal;
28
24
 
25
+ @SuppressWarnings("deprecation")
29
26
  class RegulaConfig {
30
27
  static void setConfig(DocumentReader reader, JSONObject opts, Context context) throws JSONException {
31
28
  if (opts.has("customization"))
@@ -191,11 +188,8 @@ class RegulaConfig {
191
188
  processParams.fastDocDetect = opts.getBoolean("fastDocDetect");
192
189
  if (opts.has("updateOCRValidityByGlare"))
193
190
  processParams.updateOCRValidityByGlare = opts.getBoolean("updateOCRValidityByGlare");
194
- if (opts.has("imageQA")) {
195
- ImageQA img = new ImageQA();
196
- img.fromJson(opts.getJSONObject("imageQA"));
197
- processParams.imageQA = img;
198
- }
191
+ if (opts.has("imageQA"))
192
+ processParams.imageQA = ImageQAFromJSON(opts.getJSONObject("imageQA"));
199
193
  if (opts.has("forceDocFormat"))
200
194
  processParams.forceDocFormat = opts.getInt("forceDocFormat");
201
195
  if (opts.has("noGraphics"))
@@ -234,6 +228,12 @@ class RegulaConfig {
234
228
  processParams.doFlipYAxis = opts.getBoolean("doFlipYAxis");
235
229
  if (opts.has("rfidParams"))
236
230
  processParams.rfidParams = RFIDParamsFromJSON(opts.getJSONObject("rfidParams"));
231
+ if (opts.has("doDetectCan"))
232
+ processParams.doDetectCan = opts.getBoolean("doDetectCan");
233
+ if (opts.has("faceApiParams"))
234
+ processParams.faceApiParams = FaceApiParamsFromJSON(opts.getJSONObject("faceApiParams"));
235
+ if (opts.has("useFaceApi"))
236
+ processParams.useFaceApi = opts.getBoolean("useFaceApi");
237
237
  }
238
238
 
239
239
  private static void setCustomization(ParamsCustomization customization, JSONObject opts, Context context) throws JSONException {
@@ -308,12 +308,16 @@ class RegulaConfig {
308
308
  editor.setMultipageAnimationFrontImageScaleType(ScaleType.valueOf(opts.getString("multipageAnimationFrontImageScaleType")));
309
309
  if (opts.has("multipageAnimationBackImageScaleType"))
310
310
  editor.setMultipageAnimationBackImageScaleType(ScaleType.valueOf(opts.getString("multipageAnimationBackImageScaleType")));
311
+ if (opts.has("borderBackgroundImageScaleType"))
312
+ editor.setBorderBackgroundImageScaleType(ScaleType.valueOf(opts.getString("borderBackgroundImageScaleType")));
311
313
  if (opts.has("helpAnimationImageMatrix"))
312
314
  editor.setHelpAnimationImageMatrix(matrixFromFloatArray(floatArrayFromJson(opts.getJSONArray("helpAnimationImageMatrix"))));
313
315
  if (opts.has("multipageAnimationFrontImageMatrix"))
314
316
  editor.setMultipageAnimationFrontImageMatrix(matrixFromFloatArray(floatArrayFromJson(opts.getJSONArray("multipageAnimationFrontImageMatrix"))));
315
317
  if (opts.has("multipageAnimationBackImageMatrix"))
316
318
  editor.setMultipageAnimationBackImageMatrix(matrixFromFloatArray(floatArrayFromJson(opts.getJSONArray("multipageAnimationBackImageMatrix"))));
319
+ if (opts.has("borderBackgroundImageMatrix"))
320
+ editor.setBorderBackgroundImageMatrix(matrixFromFloatArray(floatArrayFromJson(opts.getJSONArray("borderBackgroundImageMatrix"))));
317
321
  if (opts.has("customStatusPositionMultiplier"))
318
322
  editor.setCustomStatusPositionMultiplier((float) opts.getDouble("customStatusPositionMultiplier"));
319
323
  if (opts.has("cameraFrameVerticalPositionMultiplier"))
@@ -432,9 +436,11 @@ class RegulaConfig {
432
436
  object.put("helpAnimationImageScaleType", customization.getHelpAnimationImageScaleType());
433
437
  object.put("multipageAnimationFrontImageScaleType", customization.getMultipageAnimationFrontImageScaleType());
434
438
  object.put("multipageAnimationBackImageScaleType", customization.getMultipageAnimationBackImageScaleType());
439
+ object.put("borderBackgroundImageScaleType", customization.getBorderBackgroundImageScaleType());
435
440
  object.put("helpAnimationImageMatrix", customization.getHelpAnimationImageMatrix());
436
441
  object.put("multipageAnimationFrontImageMatrix", customization.getMultipageAnimationFrontImageMatrix());
437
442
  object.put("multipageAnimationBackImageMatrix", customization.getMultipageAnimationBackImageMatrix());
443
+ object.put("borderBackgroundImageMatrix", customization.getBorderBackgroundImageMatrix());
438
444
  object.put("statusTextFont", customization.getStatusTextFont());
439
445
  object.put("resultStatusTextFont", customization.getResultStatusTextFont());
440
446
  object.put("statusPositionMultiplier", customization.getStatusPositionMultiplier());
@@ -475,7 +481,6 @@ class RegulaConfig {
475
481
  object.put("documentIDList", processParams.documentIDList != null ? generateIntArray(processParams.documentIDList) : null);
476
482
  object.put("barcodeTypes", processParams.doBarcodes != null ? generateArray(processParams.doBarcodes) : null);
477
483
  object.put("fieldTypesFilter", processParams.fieldTypesFilter != null ? generateIntArray(processParams.fieldTypesFilter) : null);
478
- object.put("faceMetaData", processParams.faceMetaData != null ? generateArray(processParams.faceMetaData, JSONConstructor::generateFaceMetaData) : null);
479
484
  object.put("scenario", processParams.scenario);
480
485
  object.put("measureSystem", processParams.measureSystem);
481
486
  object.put("uvTorchEnabled", processParams.uvTorchEnabled);
@@ -512,7 +517,7 @@ class RegulaConfig {
512
517
  object.put("matchTextFieldMask", processParams.matchTextFieldMask);
513
518
  object.put("fastDocDetect", processParams.fastDocDetect);
514
519
  object.put("updateOCRValidityByGlare", processParams.updateOCRValidityByGlare);
515
- object.put("imageQA", processParams.imageQA.toJsonObject());
520
+ object.put("imageQA", generateImageQA(processParams.imageQA));
516
521
  object.put("forceDocFormat", processParams.forceDocFormat);
517
522
  object.put("noGraphics", processParams.noGraphics);
518
523
  object.put("documentAreaMin", processParams.documentAreaMin);
@@ -531,6 +536,8 @@ class RegulaConfig {
531
536
  object.put("splitNames", processParams.splitNames);
532
537
  object.put("convertCase", processParams.convertCase);
533
538
  object.put("doFlipYAxis", processParams.doFlipYAxis);
539
+ object.put("doDetectCan", processParams.doDetectCan);
540
+ object.put("useFaceApi", processParams.useFaceApi);
534
541
 
535
542
  return object;
536
543
  }
@@ -695,6 +702,8 @@ class RegulaConfig {
695
702
  else return null;
696
703
  if (input.has("failIfNoService"))
697
704
  result.setFailIfNoService(input.getBoolean("failIfNoService"));
705
+ if (input.has("httpHeaders"))
706
+ result.setHttpHeaders(stringMapFromJson(input.getJSONObject("httpHeaders")));
698
707
  return result;
699
708
  } catch (JSONException e) {
700
709
  e.printStackTrace();
@@ -702,7 +711,8 @@ class RegulaConfig {
702
711
  return null;
703
712
  }
704
713
 
705
- private static OnlineProcessingConfig OnlineProcessingConfigFromJSON(JSONObject input) {
714
+ static OnlineProcessingConfig OnlineProcessingConfigFromJSON(JSONObject input) {
715
+ if(input == null) return null;
706
716
  try {
707
717
  OnlineProcessingConfig.Builder builder;
708
718
  if (input.has("mode"))
@@ -731,8 +741,86 @@ class RegulaConfig {
731
741
  RFIDParams result = new RFIDParams();
732
742
 
733
743
  if (input.has("paIgnoreNotificationCodes"))
734
- result.setPaIgnoreNotificationCodes(JSONConstructor.intArrayFromJSON(input.getJSONArray("paIgnoreNotificationCodes")));
744
+ result.setPaIgnoreNotificationCodes(intArrayFromJSON(input.getJSONArray("paIgnoreNotificationCodes")));
745
+
746
+ return result;
747
+ } catch (JSONException e) {
748
+ e.printStackTrace();
749
+ }
750
+ return null;
751
+ }
752
+
753
+ static FaceApiParams FaceApiParamsFromJSON(JSONObject input) {
754
+ try {
755
+ FaceApiParams result = new FaceApiParams();
756
+ String url;
757
+ if (input.has("url") && !input.isNull("url")) {
758
+ url = input.getString("url");
759
+ result.setUrl(url);
760
+ }
761
+ String mode;
762
+ if (input.has("mode") && !input.isNull("mode")) {
763
+ mode = input.getString("mode");
764
+ result.setMode(mode);
765
+ }
766
+ FaceApiParams.Search search;
767
+ if (input.has("searchParams") && !input.isNull("searchParams")) {
768
+ search = SearchFromJSON(input.getJSONObject("searchParams"));
769
+ result.setSearch(search);
770
+ }
771
+ int threshold;
772
+ if (input.has("threshold") && !input.isNull("threshold")) {
773
+ threshold = input.getInt("threshold");
774
+ result.setThreshold(threshold);
775
+ }
776
+ int serviceTimeout;
777
+ if (input.has("serviceTimeout") && !input.isNull("serviceTimeout")) {
778
+ serviceTimeout = input.getInt("serviceTimeout");
779
+ result.setServiceTimeout(serviceTimeout);
780
+ }
781
+ String proxy;
782
+ if (input.has("proxy") && !input.isNull("proxy")) {
783
+ proxy = input.getString("proxy");
784
+ result.setProxy(proxy);
785
+ }
786
+ String proxyUserPwd;
787
+ if (input.has("proxyPassword") && !input.isNull("proxyPassword")) {
788
+ proxyUserPwd = input.getString("proxyPassword");
789
+ result.setProxyUserPwd(proxyUserPwd);
790
+ }
791
+ int proxyType;
792
+ if (input.has("proxyType") && !input.isNull("proxyType")) {
793
+ proxyType = input.getInt("proxyType");
794
+ result.setProxyType(proxyType);
795
+ }
796
+ return result;
797
+ } catch (JSONException e) {
798
+ e.printStackTrace();
799
+ }
800
+ return null;
801
+ }
735
802
 
803
+ static FaceApiParams.Search SearchFromJSON(JSONObject input) {
804
+ try {
805
+ FaceApiParams.Search result = new FaceApiParams.Search();
806
+ int limit;
807
+ if (input.has("limit") && !input.isNull("limit")) {
808
+ limit = input.getInt("limit");
809
+ result.setLimit(limit);
810
+ }
811
+ double threshold;
812
+ if (input.has("threshold") && !input.isNull("threshold")) {
813
+ threshold = input.getDouble("threshold");
814
+ result.setThreshold((float) threshold);
815
+ }
816
+ int[] groupIds;
817
+ if (input.has("groupIds") && !input.isNull("groupIds")) {
818
+ JSONArray jsonArray_groupIds = input.getJSONArray("groupIds");
819
+ groupIds = new int[jsonArray_groupIds.length()];
820
+ for (int i = 0; i < jsonArray_groupIds.length(); i++)
821
+ groupIds[i] = jsonArray_groupIds.getInt(i);
822
+ result.setGroupIds(groupIds);
823
+ }
736
824
  return result;
737
825
  } catch (JSONException e) {
738
826
  e.printStackTrace();
@@ -0,0 +1,2 @@
1
+ BUNDLE_PATH: "vendor/bundle"
2
+ BUNDLE_FORCE_RUBY_PLATFORM: 1
@@ -1,4 +1,4 @@
1
1
  module.exports = {
2
2
  root: true,
3
- extends: '@react-native-community',
3
+ extends: '@react-native',
4
4
  };
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
+ arrowParens: 'avoid',
3
+ bracketSameLine: true,
2
4
  bracketSpacing: false,
3
- jsxBracketSameLine: true,
4
5
  singleQuote: true,
5
6
  trailingComma: 'all',
6
- arrowParens: 'avoid',
7
7
  };
@@ -1 +1 @@
1
- {}
1
+ { }
@@ -0,0 +1,358 @@
1
+ import React from 'react'
2
+ import { SafeAreaView, ScrollView, StyleSheet, Text, View, NativeEventEmitter, Platform, TouchableOpacity, Image, Button } from 'react-native'
3
+ import DocumentReader, { Enum, DocumentReaderCompletion, DocumentReaderScenario, RNRegulaDocumentReader, DocumentReaderResults, DocumentReaderNotification, ScannerConfig, RecognizeConfig } from '@regulaforensics/react-native-document-reader-api'
4
+ import * as RNFS from 'react-native-fs'
5
+ import RadioGroup 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<IProps, IState> {
33
+ constructor(props: {} | Readonly<{}>) {
34
+ super(props)
35
+ Icon.loadFont()
36
+
37
+ var eventManager = new NativeEventEmitter(RNRegulaDocumentReader)
38
+ eventManager.addListener('prepareDatabaseProgressChangeEvent', e => this.setState({ fullName: "Downloading database: " + e["msg"] + "%" }))
39
+ eventManager.addListener('completionEvent', (e) => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))!))
40
+ eventManager.addListener('rfidNotificationCompletionEvent', e => console.log("rfidNotificationCompletionEvent: " + e["msg"]))
41
+ eventManager.addListener('paCertificateCompletionEvent', e => console.log("paCertificateCompletionEvent: " + e["msg"]))
42
+ eventManager.addListener('onCustomButtonTappedEvent', e => console.log("onCustomButtonTappedEvent: " + e["msg"]))
43
+
44
+ DocumentReader.prepareDatabase("Full", (respond) => {
45
+ console.log(respond)
46
+ var licPath = Platform.OS === 'ios' ? (RNFS.MainBundlePath + "/regula.license") : "regula.license"
47
+ var readFile = Platform.OS === 'ios' ? RNFS.readFile : RNFS.readFileAssets
48
+ readFile(licPath, 'base64').then((res) => {
49
+ this.setState({ fullName: "Initializing..." })
50
+ DocumentReader.initializeReader({
51
+ license: res,
52
+ delayedNNLoad: true
53
+ }, (respond) => {
54
+ console.log(respond)
55
+ DocumentReader.isRFIDAvailableForUse((canRfid) => {
56
+ if (canRfid) {
57
+ this.setState({ canRfid: true, rfidUIHeader: "Reading RFID", rfidDescription: "Place your phone on top of the NFC tag", rfidUIHeaderColor: "black" })
58
+ this.setState({ canRfidTitle: '' })
59
+ }
60
+ }, error => console.log(error))
61
+ DocumentReader.getAvailableScenarios((jstring) => {
62
+ var scenarios = JSON.parse(jstring)
63
+ var items = []
64
+ for (var i in scenarios) {
65
+ var scenario = DocumentReaderScenario.fromJson(typeof scenarios[i] === "string" ? JSON.parse(scenarios[i]) : scenarios[i])!.name
66
+ items.push({
67
+ label: scenario,
68
+ id: scenario
69
+ })
70
+ }
71
+ this.setState({ radioButtons: items })
72
+ this.setState({ selectedScenario: this.state.radioButtons[0]['id'] })
73
+ DocumentReader.setConfig({
74
+ functionality: {
75
+ videoCaptureMotionControl: true,
76
+ showCaptureButton: true
77
+ },
78
+ customization: {
79
+ showResultStatusMessages: true,
80
+ showStatusMessages: true
81
+ },
82
+ processParams: {
83
+ scenario: this.state.selectedScenario,
84
+ doRfid: this.state.doRfid,
85
+ },
86
+ }, _ => { }, error => console.log(error))
87
+
88
+ DocumentReader.getDocumentReaderIsReady((isReady) => {
89
+ if (isReady) {
90
+ this.setState({ fullName: "Ready" })
91
+ DocumentReader.setRfidDelegate(Enum.RFIDDelegate.NO_PA, _ => { }, error => console.log(error))
92
+ } else
93
+ this.setState({ fullName: "Failed" })
94
+ }, error => console.log(error))
95
+ }, error => console.log(error))
96
+ }, error => console.log(error))
97
+ })
98
+ }, error => console.log(error))
99
+
100
+ this.state = {
101
+ fullName: "Please wait...",
102
+ doRfid: false,
103
+ isReadingRfidCustomUi: false,
104
+ rfidUIHeader: "",
105
+ rfidUIHeaderColor: "black",
106
+ rfidDescription: "",
107
+ rfidProgress: -1,
108
+ canRfid: false,
109
+ canRfidTitle: "(unavailable)",
110
+ radioButtons: [{ label: 'Loading', id: "0" }],
111
+ selectedScenario: "",
112
+ portrait: require('./images/portrait.png'),
113
+ docFront: require('./images/id.png')
114
+ }
115
+ }
116
+
117
+ handleCompletion(completion: DocumentReaderCompletion) {
118
+ console.log("DocReaderAction: " + completion.action)
119
+ if (this.state.isReadingRfidCustomUi && (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR))
120
+ this.hideRfidUI()
121
+ if (this.state.isReadingRfidCustomUi && completion.action === Enum.DocReaderAction.NOTIFICATION)
122
+ this.updateRfidUI(completion.results!.documentReaderNotification!)
123
+ if (completion.action === Enum.DocReaderAction.COMPLETE)
124
+ if (this.state.isReadingRfidCustomUi)
125
+ if (completion.results!.rfidResult !== 1)
126
+ this.restartRfidUI()
127
+ else {
128
+ this.hideRfidUI()
129
+ this.displayResults(completion.results!)
130
+ }
131
+ else
132
+ this.handleResults(completion.results!)
133
+ if (completion.action === Enum.DocReaderAction.TIMEOUT)
134
+ this.handleResults(completion.results!)
135
+ }
136
+
137
+ showRfidUI() {
138
+ // show animation
139
+ this.setState({ isReadingRfidCustomUi: true })
140
+ }
141
+
142
+ hideRfidUI() {
143
+ // show animation
144
+ this.restartRfidUI()
145
+ this.setState({ isReadingRfidCustomUi: false, rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" })
146
+ }
147
+
148
+ restartRfidUI() {
149
+ this.setState({ rfidUIHeaderColor: "red", rfidUIHeader: "Failed!", rfidDescription: "Place your phone on top of the NFC tag", rfidProgress: -1 })
150
+ }
151
+
152
+ updateRfidUI(notification: DocumentReaderNotification) {
153
+ if (notification.notificationCode === Enum.eRFID_NotificationCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP)
154
+ this.setState({ rfidDescription: "ERFIDDataFileType: " + notification.dataFileType })
155
+ this.setState({ rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" })
156
+ if (notification.progress != null)
157
+ this.setState({ rfidProgress: notification.progress / 100 })
158
+ if (Platform.OS === 'ios')
159
+ DocumentReader.setRfidSessionStatus(this.state.rfidDescription + "\n" + notification.progress + "%", e => { }, e => { })
160
+ }
161
+
162
+ clearResults() {
163
+ this.setState({ fullName: "Ready", docFront: require('./images/id.png'), portrait: require('./images/portrait.png') })
164
+ }
165
+
166
+ scan() {
167
+ this.clearResults()
168
+ var config = new ScannerConfig()
169
+ config.scenario = this.state.selectedScenario
170
+ DocumentReader.scan(config, _ => { }, e => console.log(e))
171
+ }
172
+
173
+ recognize() {
174
+ launchImageLibrary({
175
+ mediaType: 'photo',
176
+ includeBase64: true,
177
+ selectionLimit: 10
178
+ }, r => {
179
+ if (r.errorCode != null) {
180
+ console.log("error code: " + r.errorCode)
181
+ console.log("error message: " + r.errorMessage)
182
+ this.setState({ fullName: r.errorMessage })
183
+ return
184
+ }
185
+ if (r.didCancel) return
186
+ this.clearResults()
187
+ this.setState({ fullName: "COPYING IMAGE..." })
188
+ var response = r.assets
189
+
190
+ var images = []
191
+
192
+ for (var i = 0; i < response!.length; i++) {
193
+ images.push(response![i].base64!)
194
+ }
195
+ this.setState({ fullName: "PROCESSING..." })
196
+
197
+ var config = new RecognizeConfig()
198
+ config.scenario = this.state.selectedScenario
199
+ config.images = images
200
+ DocumentReader.recognize(config, _ => { }, e => console.log(e))
201
+ })
202
+ }
203
+
204
+ displayResults(results: DocumentReaderResults) {
205
+ if (results == null) return
206
+
207
+ results.textFieldValueByType(Enum.eVisualFieldType.FT_SURNAME_AND_GIVEN_NAMES, (value: string | undefined) => {
208
+ this.setState({ fullName: value })
209
+ }, (error: string) => console.log(error))
210
+
211
+ results.graphicFieldImageByType(Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE, (value: string | undefined) => {
212
+ if (value != null && value != "")
213
+ this.setState({ docFront: { uri: "data:image/png;base64," + value } })
214
+ }, (error: string) => console.log(error))
215
+
216
+ results.graphicFieldImageByType(Enum.eGraphicFieldType.GF_PORTRAIT, (value: string | undefined) => {
217
+ if (value != null && value != "")
218
+ this.setState({ portrait: { uri: "data:image/png;base64," + value } })
219
+ }, (error: string) => console.log(error))
220
+ }
221
+
222
+ customRFID() {
223
+ this.showRfidUI()
224
+ DocumentReader.readRFID(_ => { }, _ => { })
225
+ }
226
+
227
+ usualRFID() {
228
+ isReadingRfid = true
229
+ DocumentReader.startRFIDReader(_ => { }, _ => { })
230
+ }
231
+
232
+ handleResults(results: DocumentReaderResults) {
233
+ if (this.state.doRfid && !isReadingRfid && results != null && results.chipPage != 0) {
234
+ // this.customRFID()
235
+ this.usualRFID()
236
+ } else {
237
+ isReadingRfid = false
238
+ this.displayResults(results)
239
+ }
240
+ }
241
+
242
+ render() {
243
+ return (
244
+ <SafeAreaView style={styles.container}>
245
+ {(this.state.isReadingRfidCustomUi) && <View style={styles.container}>
246
+ <Text style={{ paddingBottom: 30, fontSize: 23, color: this.state.rfidUIHeaderColor }}>{this.state.rfidUIHeader}</Text>
247
+ <Text style={{ paddingBottom: 50, fontSize: 20, color: "black" }}>{this.state.rfidDescription}</Text>
248
+ <Progress.Bar width={200} useNativeDriver={true} color="#4285F4" progress={this.state.rfidProgress} />
249
+ <TouchableOpacity style={styles.cancelButton} onPress={() => { this.hideRfidUI() }}>
250
+ <Text style={{ fontSize: 20, color: "black" }}>X</Text>
251
+ </TouchableOpacity>
252
+ </View>
253
+ }
254
+ {!this.state.isReadingRfidCustomUi && <View style={styles.container}>
255
+ <Text /><Text />
256
+ <Text style={{
257
+ top: 1,
258
+ left: 1,
259
+ padding: 30,
260
+ fontSize: 20,
261
+ color: "black"
262
+ }}>
263
+ {this.state.fullName}
264
+ </Text>
265
+ <View style={{ flexDirection: "row", padding: 5 }}>
266
+ <View style={{ flexDirection: "column", alignItems: "center" }}>
267
+ <Text style={{
268
+ top: 1,
269
+ right: 1,
270
+ padding: 5,
271
+ color: "black"
272
+ }}>
273
+ Portrait
274
+ </Text>
275
+ <Image
276
+ style={{
277
+ height: 150,
278
+ width: 150,
279
+ }}
280
+ source={this.state.portrait}
281
+ resizeMode="contain"
282
+ />
283
+ </View>
284
+ <View style={{ flexDirection: "column", alignItems: "center", padding: 5 }}>
285
+ <Text style={{
286
+ top: 1,
287
+ right: 1,
288
+ padding: 5,
289
+ color: "black"
290
+ }}>
291
+ Document image
292
+ </Text>
293
+ <Image
294
+ style={{
295
+ height: 150,
296
+ width: 200,
297
+ }}
298
+ source={this.state.docFront}
299
+ resizeMode="contain"
300
+ />
301
+ </View>
302
+ </View>
303
+
304
+ <ScrollView style={{ padding: 5, alignSelf: 'center' }} showsVerticalScrollIndicator={false}>
305
+ <RadioGroup containerStyle={styles.radio}
306
+ radioButtons={this.state.radioButtons}
307
+ onPress={
308
+ (selectedID) => {
309
+ this.setState({ selectedScenario: selectedID })
310
+ }
311
+ }
312
+ selectedId={this.state.selectedScenario}
313
+ />
314
+ </ScrollView>
315
+
316
+ <View style={{ flexDirection: 'row', padding: 5 }}>
317
+ <CheckBox
318
+ containerStyle={{ backgroundColor: '#F5FCFF' }}
319
+ checked={this.state.doRfid}
320
+ title={'Process rfid reading' + this.state.canRfidTitle}
321
+ onPress={() => {
322
+ if (this.state.canRfid) {
323
+ this.setState({ doRfid: !this.state.doRfid })
324
+ }
325
+ }} />
326
+ </View>
327
+
328
+ <View style={{ flexDirection: 'row' }}>
329
+ <Button color="#4285F4" title="Scan document" onPress={() => this.scan()} />
330
+ <Text style={{ padding: 5 }}></Text>
331
+ <Button color="#4285F4" title=" Scan image " onPress={() => this.recognize()} />
332
+ </View>
333
+ </View>
334
+ }
335
+ </SafeAreaView>
336
+ )
337
+ }
338
+ }
339
+
340
+ const styles = StyleSheet.create({
341
+ container: {
342
+ width: '100%',
343
+ height: '100%',
344
+ flex: 1,
345
+ justifyContent: 'center',
346
+ alignItems: 'center',
347
+ backgroundColor: '#F5FCFF',
348
+ marginBottom: 12,
349
+ },
350
+ radio: {
351
+ alignItems: 'flex-start'
352
+ },
353
+ cancelButton: {
354
+ position: 'absolute',
355
+ bottom: 0,
356
+ right: 20
357
+ }
358
+ })
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4
+ ruby ">= 2.6.10"
5
+
6
+ gem 'cocoapods', '~> 1.12'