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

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 (50) hide show
  1. package/README.md +10 -42
  2. package/RNDocumentReaderApi.podspec +1 -1
  3. package/android/build.gradle +10 -10
  4. package/android/src/main/java/com/regula/documentreader/BluetoothUtil.kt +78 -74
  5. package/android/src/main/java/com/regula/documentreader/Config.kt +690 -0
  6. package/android/src/main/java/com/regula/documentreader/JSONConstructor.kt +2188 -0
  7. package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderModule.kt +537 -0
  8. package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderPackage.kt +11 -0
  9. package/android/src/main/java/com/regula/documentreader/Utils.kt +256 -0
  10. package/example/App.tsx +97 -145
  11. package/example/README.md +37 -0
  12. package/example/android/app/build.gradle +1 -1
  13. package/example/android/app/src/main/java/com/regula/dr/fullrfid/MainApplication.java +0 -1
  14. package/example/android/app/src/main/res/values/styles.xml +1 -2
  15. package/example/android/build.gradle +2 -4
  16. package/example/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  17. package/example/android/gradle.properties +1 -1
  18. package/example/index.js +1 -2
  19. package/example/ios/DocumentReader.xcodeproj/project.pbxproj +8 -4
  20. package/example/ios/Podfile +0 -1
  21. package/example/package-lock.json +3062 -2198
  22. package/example/package.json +24 -23
  23. package/index.d.ts +296 -135
  24. package/index.js +234 -115
  25. package/ios/RGLWConfig.h +48 -0
  26. package/ios/RGLWConfig.m +1325 -0
  27. package/ios/RGLWJSONConstructor.h +173 -69
  28. package/ios/RGLWJSONConstructor.m +1817 -762
  29. package/ios/RNRegulaDocumentReader.h +6 -5
  30. package/ios/RNRegulaDocumentReader.m +392 -584
  31. package/package.json +1 -1
  32. package/android/src/main/java/com/regula/documentreader/Helpers.java +0 -259
  33. package/android/src/main/java/com/regula/documentreader/JSONConstructor.java +0 -1119
  34. package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderModule.java +0 -1153
  35. package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderPackage.java +0 -26
  36. package/android/src/main/java/com/regula/documentreader/RegulaConfig.java +0 -830
  37. package/example/.bundle/config +0 -2
  38. package/example/.eslintrc.js +0 -4
  39. package/example/.prettierrc.js +0 -7
  40. package/example/Gemfile +0 -6
  41. package/example/Gemfile.lock +0 -98
  42. package/example/__tests__/App.test.tsx +0 -17
  43. package/example/app.json +0 -4
  44. package/example/babel.config.js +0 -3
  45. package/example/jest.config.js +0 -3
  46. package/example/tsconfig.json +0 -3
  47. package/ios/RGLWRegulaConfig.h +0 -26
  48. package/ios/RGLWRegulaConfig.m +0 -1152
  49. package/ios/RNRegulaDocumentReader.xcodeproj/project.pbxproj +0 -304
  50. package/ios/RNRegulaDocumentReader.xcworkspace/contents.xcworkspacedata +0 -9
@@ -0,0 +1,256 @@
1
+ //
2
+ // Utils.java
3
+ // DocumentReader
4
+ //
5
+ // Created by Pavel Masiuk on 21.09.2023.
6
+ // Copyright © 2023 Regula. All rights reserved.
7
+ //
8
+ @file:Suppress("UNCHECKED_CAST")
9
+
10
+ package com.regula.documentreader
11
+
12
+ import android.content.Context
13
+ import android.graphics.Bitmap
14
+ import android.graphics.BitmapFactory
15
+ import android.graphics.Canvas
16
+ import android.graphics.Matrix
17
+ import android.graphics.Paint
18
+ import android.graphics.Typeface
19
+ import android.graphics.drawable.BitmapDrawable
20
+ import android.graphics.drawable.Drawable
21
+ import android.util.Base64
22
+ import com.regula.documentreader.api.enums.CustomizationFont
23
+ import com.regula.documentreader.api.params.ParamsCustomization
24
+ import org.json.JSONArray
25
+ import org.json.JSONObject
26
+ import java.io.ByteArrayOutputStream
27
+ import kotlin.math.sqrt
28
+
29
+ fun Any?.toSendable(): Any? = this?.let {
30
+ if (this is JSONObject || this is JSONArray) this.toString()
31
+ else this
32
+ }
33
+
34
+ fun arrayListToJSONArray(list: ArrayList<*>): JSONArray {
35
+ val result = JSONArray()
36
+ for (i in list.indices) {
37
+ when {
38
+ list[i] == null -> result.put(null)
39
+ list[i].javaClass == HashMap::class.java -> result.put(hashMapToJSONObject(list[i] as HashMap<String, *>))
40
+ list[i].javaClass == ArrayList::class.java -> result.put(arrayListToJSONArray(list[i] as ArrayList<*>))
41
+ else -> result.put(list[i])
42
+ }
43
+ }
44
+ return result
45
+ }
46
+
47
+ fun hashMapToJSONObject(map: HashMap<String, *>): JSONObject {
48
+ val result = JSONObject()
49
+ for ((key, value) in map) {
50
+ when {
51
+ value == null -> result.put(key, null)
52
+ value.javaClass == HashMap::class.java -> result.put(key, hashMapToJSONObject(value as HashMap<String, *>))
53
+ value.javaClass == ArrayList::class.java -> result.put(key, arrayListToJSONArray(value as ArrayList<*>))
54
+ else -> result.put(key, value)
55
+ }
56
+ }
57
+ return result
58
+ }
59
+
60
+ fun <T> generateList(list: List<T>?) = list?.let {
61
+ val result = JSONArray()
62
+ for (t in list) if (t != null) result.put(t)
63
+ result
64
+ }
65
+
66
+ fun <T> generateList(list: List<T>, toJson: (T?) -> JSONObject?): JSONArray {
67
+ val result = JSONArray()
68
+ for (t in list) if (t != null) result.put(toJson(t))
69
+ return result
70
+ }
71
+
72
+ fun <T> listFromJSON(input: JSONArray?, fromJson: (JSONObject?) -> T) = input?.let {
73
+ val result: MutableList<T> = ArrayList()
74
+ for (i in 0 until input.length()) {
75
+ val item = input.getJSONObject(i)
76
+ result.add(fromJson(item))
77
+ }
78
+ result
79
+ }
80
+
81
+ fun <T> listFromJSON(input: JSONArray): List<T> {
82
+ val result: MutableList<T> = ArrayList()
83
+ for (i in 0 until input.length()) result.add(input.opt(i) as T)
84
+ return result
85
+ }
86
+
87
+ fun <T> arrayFromJSON(input: JSONArray?, fromJson: (JSONObject?) -> T, result: Array<T>) = input?.let {
88
+ for (i in 0 until input.length())
89
+ result[i] = fromJson(input.getJSONObject(i))
90
+ result
91
+ }
92
+
93
+ fun <T> generateList(list: List<T>, toJson: (T?, Context?) -> JSONObject?, context: Context?): JSONArray {
94
+ val result = JSONArray()
95
+ for (t in list) if (t != null) result.put(toJson(t, context))
96
+ return result
97
+ }
98
+
99
+ fun <T> generateArray(array: Array<T>?) = array?.let {
100
+ val result = JSONArray()
101
+ for (i in array.indices) result.put(i, array[i])
102
+ result
103
+ }
104
+
105
+ fun <T> generateArray(array: Array<T>?, toJson: (T?) -> JSONObject?) = array?.let {
106
+ val result = JSONArray()
107
+ for (i in array.indices) result.put(i, toJson(array[i]))
108
+ result
109
+ }
110
+
111
+ fun generateLongArray(array: LongArray?) = array?.let {
112
+ val result = JSONArray()
113
+ for (i in array.indices) result.put(i, array[i])
114
+ result
115
+ }
116
+
117
+ fun stringListFromJson(jsonArray: JSONArray): List<String> {
118
+ val result: MutableList<String> = ArrayList()
119
+ for (i in 0 until jsonArray.length()) result.add(jsonArray.optString(i))
120
+ return result
121
+ }
122
+
123
+ fun stringArrayFromJson(jsonArray: JSONArray): Array<String?> {
124
+ val result = arrayOfNulls<String>(jsonArray.length())
125
+ for (i in 0 until jsonArray.length()) result[i] = jsonArray.optString(i)
126
+ return result
127
+ }
128
+
129
+ fun paintCapToInt(cap: Paint.Cap) = when (cap) {
130
+ Paint.Cap.BUTT -> 0
131
+ Paint.Cap.ROUND -> 1
132
+ Paint.Cap.SQUARE -> 2
133
+ }
134
+
135
+ fun JSONObject.forEach(action: (String, Any?) -> Unit) {
136
+ val keys: Iterator<String> = keys()
137
+ while (keys.hasNext()) {
138
+ val key = keys.next()
139
+ action(key, get(key))
140
+ }
141
+ }
142
+
143
+ fun Map<String, Any?>.toJsonObject(): JSONObject {
144
+ val result = JSONObject()
145
+ forEach { (key, value) -> result.put(key, value) }
146
+ return result
147
+ }
148
+
149
+ fun stringMapFromJson(input: JSONObject): Map<String, String> {
150
+ val result: MutableMap<String, String> = HashMap()
151
+ input.forEach { key, value -> result[key] = value as String }
152
+ return result
153
+ }
154
+
155
+ fun generateStringMap(input: Map<String, String?>?) = input?.let {
156
+ val result = JSONObject()
157
+ for ((key, value) in input) result.put(key, value)
158
+ result
159
+ }
160
+
161
+ fun Any?.toInt() = when (this) {
162
+ is Double -> toInt()
163
+ is Long -> toInt()
164
+ else -> this as Int
165
+ }
166
+
167
+ fun Any?.toLong() = when (this) {
168
+ is Double -> toLong()
169
+ is Int -> toLong()
170
+ else -> this as Long
171
+ }
172
+
173
+ fun Any?.toColor() = "#" + toLong().toString(16)
174
+
175
+ fun Any?.toFloat() =
176
+ if (this is Double) toFloat()
177
+ else this as Float
178
+
179
+ fun Any?.toMatrix() = this?.let {
180
+ val matrix = Matrix()
181
+ val result = FloatArray((this as JSONArray).length())
182
+ for (i in 0 until length()) result[i] = getDouble(i).toFloat()
183
+ matrix.setValues(result)
184
+ matrix
185
+ }
186
+
187
+ fun Any?.toIntArray() = (this as JSONArray?)?.let {
188
+ val result = IntArray(it.length())
189
+ for (i in 0 until it.length()) result[i] = it.getInt(i)
190
+ result
191
+ }
192
+
193
+ fun IntArray?.generate() = this?.let {
194
+ val result = JSONArray()
195
+ for (i in indices) result.put(i, this[i])
196
+ result
197
+ }
198
+
199
+ fun String?.toLong() = this?.let {
200
+ if (this[0] == '#') this.substring(1).toLong(16)
201
+ else this.toLong(16)
202
+ }
203
+
204
+ fun Matrix?.generate() = this?.let {
205
+ val floats = FloatArray(9)
206
+ getValues(floats)
207
+ val result = JSONArray()
208
+ for (f in floats) result.put(java.lang.Float.valueOf(f))
209
+ result
210
+ }
211
+
212
+ fun CustomizationFont.generate(fonts: Map<CustomizationFont, Typeface>, sizes: Map<CustomizationFont, Int>) = generateTypeface(fonts[this], sizes[this])
213
+
214
+ fun CustomizationFont.setFont(editor: ParamsCustomization.CustomizationEditor, value: Any?) {
215
+ val font = typefaceFromJSON(value as JSONObject)
216
+ editor.setFont(this, font.first)
217
+ font.second?.let { editor.setFontSize(this, it) }
218
+ }
219
+
220
+ internal object Convert {
221
+ fun byteArrayFromBase64(base64: String?) = base64?.let { Base64.decode(it, Base64.NO_WRAP) }
222
+ fun generateByteArray(array: ByteArray?) = array?.let { Base64.encodeToString(it, Base64.NO_WRAP) }
223
+
224
+ fun bitmapFromBase64(base64: String?) = base64?.let {
225
+ val decodedString = byteArrayFromBase64(base64)
226
+ var result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString!!.size)
227
+ val sizeMultiplier = result.byteCount / 5000000
228
+ if (result.byteCount > 5000000) result = Bitmap.createScaledBitmap(result, result.width / sqrt(sizeMultiplier.toDouble()).toInt(), result.height / sqrt(sizeMultiplier.toDouble()).toInt(), false)
229
+ result
230
+ }
231
+
232
+ fun bitmapToBase64(bitmap: Bitmap?) = bitmap?.let {
233
+ val byteArrayOutputStream = ByteArrayOutputStream()
234
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream)
235
+ val byteArray = byteArrayOutputStream.toByteArray()
236
+ generateByteArray(byteArray)
237
+ }
238
+
239
+ fun Any?.toDrawable(context: Context) = (this as String?)?.let {
240
+ val decodedByte = byteArrayFromBase64(it)
241
+ val bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte!!.size)
242
+ val density = context.resources.displayMetrics.density
243
+ val width = (bitmap.width * density).toInt()
244
+ val height = (bitmap.height * density).toInt()
245
+ BitmapDrawable(context.resources, Bitmap.createScaledBitmap(bitmap, width, height, false))
246
+ }
247
+
248
+ fun Drawable?.toString() = this?.let {
249
+ if (this is BitmapDrawable) if (bitmap != null) return bitmapToBase64(bitmap)
250
+ 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)
251
+ val canvas = Canvas(bitmap)
252
+ setBounds(0, 0, canvas.width, canvas.height)
253
+ draw(canvas)
254
+ bitmapToBase64(bitmap)
255
+ }
256
+ }
package/example/App.tsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import React from 'react'
2
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'
3
+ import DocumentReader, { Enum, DocumentReaderCompletion, DocumentReaderScenario, RNRegulaDocumentReader, DocumentReaderResults, DocumentReaderNotification, ScannerConfig, RecognizeConfig, DocReaderConfig } from '@regulaforensics/react-native-document-reader-api'
4
4
  import * as RNFS from 'react-native-fs'
5
- import RadioGroup from 'react-native-radio-buttons-group'
5
+ import RadioGroup, { RadioButtonProps } from 'react-native-radio-buttons-group'
6
6
  import { CheckBox } from '@rneui/themed'
7
7
  import Icon from 'react-native-vector-icons/FontAwesome'
8
8
  import { launchImageLibrary } from 'react-native-image-picker'
@@ -30,72 +30,54 @@ interface IState {
30
30
  }
31
31
 
32
32
  export default class App extends React.Component<IProps, IState> {
33
+ onInitialized() {
34
+ this.setState({ fullName: "Ready" })
35
+
36
+ DocumentReader.setFunctionality({
37
+ showCaptureButton: true
38
+ }, _ => { }, _ => { })
39
+ }
40
+
33
41
  constructor(props: {} | Readonly<{}>) {
34
42
  super(props)
35
43
  Icon.loadFont()
36
44
 
37
45
  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))
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'] })
96
77
  }, error => console.log(error))
97
- })
98
- }, error => console.log(error))
78
+ this.onInitialized()
79
+ }, error => console.log(error))
80
+ })
99
81
 
100
82
  this.state = {
101
83
  fullName: "Please wait...",
@@ -115,25 +97,26 @@ export default class App extends React.Component<IProps, IState> {
115
97
  }
116
98
 
117
99
  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)
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!))
134
107
  this.handleResults(completion.results!)
135
108
  }
136
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
+
137
120
  showRfidUI() {
138
121
  // show animation
139
122
  this.setState({ isReadingRfidCustomUi: true })
@@ -141,6 +124,7 @@ export default class App extends React.Component<IProps, IState> {
141
124
 
142
125
  hideRfidUI() {
143
126
  // show animation
127
+ DocumentReader.stopRFIDReader(_ => { }, _ => { });
144
128
  this.restartRfidUI()
145
129
  this.setState({ isReadingRfidCustomUi: false, rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" })
146
130
  }
@@ -187,7 +171,7 @@ export default class App extends React.Component<IProps, IState> {
187
171
  this.setState({ fullName: "COPYING IMAGE..." })
188
172
  var response = r.assets
189
173
 
190
- var images = []
174
+ var images: any = []
191
175
 
192
176
  for (var i = 0; i < response!.length; i++) {
193
177
  images.push(response![i].base64!)
@@ -221,16 +205,16 @@ export default class App extends React.Component<IProps, IState> {
221
205
 
222
206
  customRFID() {
223
207
  this.showRfidUI()
224
- DocumentReader.readRFID(_ => { }, _ => { })
208
+ DocumentReader.readRFID(false, false, false, _ => { }, _ => { })
225
209
  }
226
210
 
227
211
  usualRFID() {
228
212
  isReadingRfid = true
229
- DocumentReader.startRFIDReader(_ => { }, _ => { })
213
+ DocumentReader.startRFIDReader(false, false, false, _ => { }, _ => { })
230
214
  }
231
215
 
232
216
  handleResults(results: DocumentReaderResults) {
233
- if (this.state.doRfid && !isReadingRfid && results != null && results.chipPage != 0) {
217
+ if (this.state.doRfid && !isReadingRfid && results.chipPage != 0) {
234
218
  // this.customRFID()
235
219
  this.usualRFID()
236
220
  } else {
@@ -242,73 +226,25 @@ export default class App extends React.Component<IProps, IState> {
242
226
  render() {
243
227
  return (
244
228
  <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
229
  {!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>
230
+ <Text style={styles.title}>{this.state.fullName}</Text>
231
+
265
232
  <View style={{ flexDirection: "row", padding: 5 }}>
266
233
  <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
- />
234
+ <Text style={styles.imageLabel}>Portrait</Text>
235
+ <Image style={{ height: 150, width: 150 }} source={this.state.portrait} resizeMode="contain" />
283
236
  </View>
284
237
  <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
- />
238
+ <Text style={styles.imageLabel}>Document image</Text>
239
+ <Image style={{ height: 150, width: 200 }} source={this.state.docFront} resizeMode="contain" />
301
240
  </View>
302
241
  </View>
303
242
 
304
243
  <ScrollView style={{ padding: 5, alignSelf: 'center' }} showsVerticalScrollIndicator={false}>
305
- <RadioGroup containerStyle={styles.radio}
244
+ <RadioGroup
245
+ containerStyle={{ alignItems: 'flex-start' }}
306
246
  radioButtons={this.state.radioButtons}
307
- onPress={
308
- (selectedID) => {
309
- this.setState({ selectedScenario: selectedID })
310
- }
311
- }
247
+ onPress={(selectedID) => { this.setState({ selectedScenario: selectedID }) }}
312
248
  selectedId={this.state.selectedScenario}
313
249
  />
314
250
  </ScrollView>
@@ -328,10 +264,18 @@ export default class App extends React.Component<IProps, IState> {
328
264
  <View style={{ flexDirection: 'row' }}>
329
265
  <Button color="#4285F4" title="Scan document" onPress={() => this.scan()} />
330
266
  <Text style={{ padding: 5 }}></Text>
331
- <Button color="#4285F4" title=" Scan image " onPress={() => this.recognize()} />
267
+ <Button color="#4285F4" title="Scan image" onPress={() => this.recognize()} />
332
268
  </View>
333
- </View>
334
- }
269
+ </View>}
270
+
271
+ {(this.state.isReadingRfidCustomUi) && <View style={styles.container}>
272
+ <Text style={{ paddingBottom: 30, fontSize: 23, color: this.state.rfidUIHeaderColor }}>{this.state.rfidUIHeader}</Text>
273
+ <Text style={{ paddingBottom: 50, fontSize: 20 }}>{this.state.rfidDescription}</Text>
274
+ <Progress.Bar style={{ marginBottom: 30 }} width={200} useNativeDriver={true} color="#4285F4" progress={this.state.rfidProgress} />
275
+ <TouchableOpacity style={styles.cancelButton} onPress={() => { this.hideRfidUI() }}>
276
+ <Text style={{ fontSize: 20 }}>X</Text>
277
+ </TouchableOpacity>
278
+ </View>}
335
279
  </SafeAreaView>
336
280
  )
337
281
  }
@@ -347,12 +291,20 @@ const styles = StyleSheet.create({
347
291
  backgroundColor: '#F5FCFF',
348
292
  marginBottom: 12,
349
293
  },
350
- radio: {
351
- alignItems: 'flex-start'
352
- },
353
294
  cancelButton: {
354
295
  position: 'absolute',
355
296
  bottom: 0,
356
297
  right: 20
298
+ },
299
+ imageLabel: {
300
+ top: 1,
301
+ right: 1,
302
+ padding: 5
303
+ },
304
+ title: {
305
+ top: 1,
306
+ left: 1,
307
+ padding: 30,
308
+ fontSize: 20
357
309
  }
358
310
  })
@@ -0,0 +1,37 @@
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).
@@ -71,7 +71,7 @@ def jscFlavor = 'org.webkit:android-jsc:+'
71
71
  android {
72
72
  ndkVersion rootProject.ext.ndkVersion
73
73
 
74
- compileSdkVersion rootProject.ext.compileSdkVersion
74
+ compileSdk rootProject.ext.compileSdkVersion
75
75
 
76
76
  namespace "com.regula.dr.fullrfid"
77
77
  defaultConfig {
@@ -57,6 +57,5 @@ public class MainApplication extends Application implements ReactApplication {
57
57
  // If you opted-in for the New Architecture, we load the native entry point for this app.
58
58
  DefaultNewArchitectureEntryPoint.load();
59
59
  }
60
- ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
61
60
  }
62
61
  }
@@ -1,9 +1,8 @@
1
1
  <resources>
2
-
3
2
  <!-- Base application theme. -->
4
3
  <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
5
4
  <!-- Customize your theme here. -->
6
5
  <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
6
+ <item name="android:textColor">#000000</item>
7
7
  </style>
8
-
9
8
  </resources>
@@ -1,11 +1,9 @@
1
- // Top-level build file where you can add configuration options common to all sub-projects/modules.
2
-
3
1
  buildscript {
4
2
  ext {
5
3
  buildToolsVersion = "33.0.0"
6
4
  minSdkVersion = 21
7
- compileSdkVersion = 33
8
- targetSdkVersion = 33
5
+ compileSdkVersion = 34
6
+ targetSdkVersion = 34
9
7
 
10
8
  // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
11
9
  ndkVersion = "23.1.7779620"