@regulaforensics/document-reader 8.2.186-beta → 8.3.242-beta

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 (69) hide show
  1. package/RNDocumentReader.podspec +2 -2
  2. package/android/build.gradle +1 -1
  3. package/android/cordova.gradle +1 -1
  4. package/android/src/main/java/com/regula/plugin/documentreader/Config.kt +4 -0
  5. package/android/src/main/java/com/regula/plugin/documentreader/Main.kt +6 -0
  6. package/examples/capacitor/README.md +10 -0
  7. package/examples/capacitor/index.html +2 -7
  8. package/examples/capacitor/index.tsx +39 -0
  9. package/examples/capacitor/package.json +3 -3
  10. package/examples/capacitor/scripts/setup.sh +4 -0
  11. package/examples/capacitor/src/extra/bt_device.tsx +7 -6
  12. package/examples/capacitor/src/extra/custom_rfid.tsx +29 -42
  13. package/examples/capacitor/src/main.css +4 -1
  14. package/examples/capacitor/src/main.html +1 -4
  15. package/examples/capacitor/src/main.tsx +85 -86
  16. package/examples/cordova/README.md +10 -0
  17. package/examples/cordova/config.xml +6 -2
  18. package/examples/cordova/package-lock.json +459 -1
  19. package/examples/cordova/package.json +5 -4
  20. package/examples/cordova/scripts/bundle.sh +4 -0
  21. package/examples/cordova/www/bootstrap.js +30 -0
  22. package/examples/cordova/www/images/portrait.png +0 -0
  23. package/examples/cordova/www/index.html +2 -17
  24. package/examples/cordova/www/index.js +30 -0
  25. package/examples/cordova/www/src/extra/bt_device.js +32 -0
  26. package/examples/cordova/www/src/extra/custom_rfid.js +60 -0
  27. package/examples/cordova/www/src/main.css +11 -7
  28. package/examples/cordova/www/src/main.html +7 -32
  29. package/examples/cordova/www/src/main.js +154 -31
  30. package/examples/ionic/README.md +10 -0
  31. package/examples/ionic/config.xml +11 -4
  32. package/examples/ionic/index.ts +41 -4
  33. package/examples/ionic/package-lock.json +1862 -1638
  34. package/examples/ionic/package.json +3 -6
  35. package/examples/ionic/src/extra/bt_device.ts +33 -0
  36. package/examples/ionic/src/extra/custom_rfid.ts +61 -0
  37. package/examples/ionic/src/images/portrait.png +0 -0
  38. package/examples/ionic/src/main.css +11 -7
  39. package/examples/ionic/src/main.html +36 -61
  40. package/examples/ionic/src/main.ts +158 -50
  41. package/examples/react_native/README.md +10 -0
  42. package/examples/react_native/app.config.ts +3 -1
  43. package/examples/react_native/images/portrait.png +0 -0
  44. package/examples/react_native/index.tsx +34 -6
  45. package/examples/react_native/package-lock.json +476 -421
  46. package/examples/react_native/package.json +10 -10
  47. package/examples/react_native/src/extra/bt_device.tsx +34 -0
  48. package/examples/react_native/src/extra/custom_rfid.tsx +62 -0
  49. package/examples/react_native/src/main.css +11 -7
  50. package/examples/react_native/src/main.html +7 -32
  51. package/examples/react_native/src/main.tsx +152 -27
  52. package/ios/RGLWConfig.m +4 -0
  53. package/ios/RGLWMain.m +10 -0
  54. package/package.json +1 -1
  55. package/plugin.xml +2 -2
  56. package/www/capacitor/index.js +32 -16
  57. package/www/capacitor/params/customization/Customization.js +7 -0
  58. package/www/capacitor/params/process_params/ProcessParams.js +7 -0
  59. package/www/capacitor/results/visual_results/FieldType.js +3 -1
  60. package/www/cordova.js +49 -17
  61. package/www/react-native/index.js +32 -16
  62. package/www/react-native/internal/bridge.js +1 -1
  63. package/www/react-native/params/customization/Customization.js +7 -0
  64. package/www/react-native/params/process_params/ProcessParams.js +7 -0
  65. package/www/react-native/results/visual_results/FieldType.js +3 -1
  66. package/www/types/index.d.ts +14 -8
  67. package/www/types/params/customization/Customization.d.ts +5 -0
  68. package/www/types/params/process_params/ProcessParams.d.ts +4 -0
  69. package/www/types/results/visual_results/FieldType.d.ts +5 -1
@@ -6,17 +6,15 @@
6
6
  "android": "scripts/android.sh"
7
7
  },
8
8
  "dependencies": {
9
- "@regulaforensics/document-reader": "8.2.186-beta",
10
- "@regulaforensics/document-reader-core-fullauthrfid": "8.2.8-beta",
11
- "@regulaforensics/document-reader-btdevice": "8.2.8-beta",
9
+ "@regulaforensics/document-reader": "8.3.242-beta",
10
+ "@regulaforensics/document-reader-core-fullauthrfid": "8.3.9-beta",
11
+ "@regulaforensics/document-reader-btdevice": "8.3.10-beta",
12
12
  "@awesome-cordova-plugins/file": "6.14.0",
13
13
  "@awesome-cordova-plugins/camera": "6.14.0",
14
- "@awesome-cordova-plugins/dialogs": "6.14.0",
15
14
  "cordova-ios": "7.1.1",
16
15
  "cordova-android": "13.0.0",
17
16
  "cordova-plugin-file": "8.1.3",
18
17
  "cordova-plugin-camera": "8.0.0",
19
- "cordova-plugin-dialogs": "2.0.2",
20
18
  "cordova-plugin-ionic-webview": "^5.0.0",
21
19
  "@angular/cli": "19.2.0",
22
20
  "@angular/core": "19.2.0",
@@ -36,7 +34,6 @@
36
34
  "@regulaforensics/document-reader-btdevice": {},
37
35
  "cordova-plugin-file": {},
38
36
  "cordova-plugin-camera": {},
39
- "cordova-plugin-dialogs": {},
40
37
  "cordova-plugin-ionic-webview": {}
41
38
  },
42
39
  "platforms": [
@@ -0,0 +1,33 @@
1
+ import { DocumentReader, InitConfig } from "@regulaforensics/document-reader"
2
+ import { handleException, init, setStatus } from "../main"
3
+
4
+ export const useBtDevice = false
5
+ export const btDeviceName = "Regula 0000"
6
+
7
+ export function setupBTDevice() {
8
+ var connectButton = document.getElementById("connect")
9
+ connectButton.style.display = "flex"
10
+ connectButton.onclick = () => connect()
11
+ setStatus("Connect to a bluetooth device")
12
+ }
13
+
14
+ async function connect() {
15
+ setStatus("Searching for devices...")
16
+ if (await DocumentReader.instance.connectBluetoothDevice(btDeviceName)) {
17
+ await init()
18
+ DocumentReader.instance.functionality.useAuthenticator = true
19
+ document.getElementById("bt-device").style.display = "none"
20
+ } else
21
+ setStatus("Failed to connect")
22
+ }
23
+
24
+ export async function initializeWithBTDevice() {
25
+ setStatus("Initializing...")
26
+
27
+ var initConfig = InitConfig.withBleDevice()
28
+ initConfig.delayedNNLoad = true
29
+ var [success, error] = await DocumentReader.instance.initialize(initConfig)
30
+
31
+ handleException(error)
32
+ return success
33
+ }
@@ -0,0 +1,61 @@
1
+ import { DocReaderAction, DocumentReader, RFIDConfig, RFIDDataFileType, RFIDNotificationCodes } from "@regulaforensics/document-reader"
2
+ import { displayResults, setStatus } from "../main"
3
+
4
+ export const useRfidSelfHostedUI = false
5
+
6
+ export function rfidSelfHostedUI() {
7
+ var config = RFIDConfig.withoutUI((action, results, _) => {
8
+ if (DocReaderAction.stopped(action)) stop()
9
+ if (DocReaderAction.finished(action)) displayResults(results)
10
+ if (DocReaderAction.interrupted(action)) setStatus("Error reading RFID")
11
+ })
12
+
13
+ config.onProgress = async (notification) => {
14
+ if (notification.progress == 1) return
15
+ if (notification.notificationCode == RFIDNotificationCodes.PCSC_READING_DATAGROUP)
16
+ setDescription(await RFIDDataFileType.getTranslation(notification.dataFileType))
17
+ setStatus("Reading RFID")
18
+ setProgress(notification.progress)
19
+ }
20
+
21
+ setup()
22
+ DocumentReader.instance.rfid(config)
23
+ }
24
+
25
+ function setup() {
26
+ setStatus("Reading RFID")
27
+ setDescription("Place your phone on top of the NFC tag")
28
+ setProgress(-1)
29
+ currentProgress = -1
30
+ setShowing(true)
31
+ document.getElementById("cancel-rfid").onclick = () => stop()
32
+ }
33
+
34
+ function stop() {
35
+ DocumentReader.instance.stopRFIDReader()
36
+ displayResults(null)
37
+ setShowing(false)
38
+ }
39
+
40
+ function setDescription(data) {
41
+ document.getElementById("rfid-description").innerHTML = data
42
+ }
43
+
44
+ var currentProgress = -1
45
+ function setProgress(next) {
46
+ var progress = document.getElementById("progress")
47
+ // make progress bar look better
48
+ if (next == 0) return // ignore idle 0s, leave progress at 100 while its not moving
49
+ if (next < currentProgress) next = 0 // move to 0 if progress finaly started moving
50
+ if (next >= 95) next = 100 // rfid never returns 100 and it looks ugly, fix it
51
+ if (next < currentProgress) progress.style.transition = 'none' // instantly reset progress
52
+ else progress.style.transition = 'width 0.5s' // smoothly increase progress
53
+
54
+ progress.style.width = next + "%"
55
+ currentProgress = next
56
+ }
57
+
58
+ function setShowing(data) {
59
+ document.getElementById("main").style.display = data ? "none" : "flex"
60
+ document.getElementById("custom-rfid").style.display = data ? "flex" : "none"
61
+ }
@@ -1,8 +1,10 @@
1
1
  html,
2
2
  body {
3
- width: 99%;
3
+ margin: 0;
4
+ width: 100%;
4
5
  height: 99vh;
5
6
  display: flex;
7
+ overflow: hidden;
6
8
  flex-direction: column;
7
9
  }
8
10
 
@@ -59,6 +61,7 @@ body {
59
61
  color: white;
60
62
  border: none;
61
63
  padding: 10px 20px;
64
+ justify-content: center;
62
65
  font-size: 16px;
63
66
  border-radius: 100px;
64
67
  cursor: pointer;
@@ -88,10 +91,12 @@ body {
88
91
  top: 1px;
89
92
  }
90
93
 
94
+ .radio {
95
+ align-items: baseline;
96
+ padding: 15px;
97
+ }
98
+
91
99
  input[type="checkbox"] {
92
- appearance: none;
93
- -webkit-appearance: none;
94
- -moz-appearance: none;
95
100
  width: 20px;
96
101
  height: 20px;
97
102
  border: 2px solid black;
@@ -121,10 +126,9 @@ input[type="text"] {
121
126
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
122
127
  }
123
128
 
124
- .progress {
129
+ #progress {
125
130
  width: 0%;
126
131
  height: 20px;
127
132
  background-color: #4285F4;
128
133
  border-radius: 5px;
129
- transition: width 0.5s ease-in-out;
130
- }
134
+ }
@@ -1,63 +1,38 @@
1
1
  <div class="column" style="height: 100%">
2
- <div class="column header">
3
- <span id="status" class="title">Loading...</span>
4
- <div class="column divider"></div>
5
- </div>
6
- <div id="main" class="column no-scroll">
7
- <div class="row">
8
- <div class="column" style="padding: 5px;">
9
- <p>Portrait</p>
10
- <img id="portrait-image" src="images/portrait.png" height="150px" width="150px">
11
- </div>
12
- <div class="column" style="padding: 5px;">
13
- <p>Document image</p>
14
- <img id="document-image" src="images/document.png" height="150px" width="200px">
15
- </div>
16
- </div>
17
- <div id="scenario-container" class="column no-scroll"
18
- style="margin-top: 15px; background-color: rgba(0, 0, 0, 0.03);">
19
- <div id="scenarios" class="scroll">
20
- <div class="row" style="align-items: baseline; padding: 15px;">
21
- <input type="radio" name="scenario" value="Aaa">
22
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
23
- </div>
24
- <div class="row" style="align-items: baseline; padding: 15px;">
25
- <input type="radio" name="scenario" value="Aaa">
26
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
27
- </div>
28
- <div class="row" style="align-items: baseline; padding: 15px;">
29
- <input type="radio" name="scenario" value="Aaa">
30
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
31
- </div>
32
- <div class="row" style="align-items: baseline; padding: 15px;">
33
- <input type="radio" name="scenario" value="Aaa">
34
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
35
- </div>
36
- <div class="row" style="align-items: baseline; padding: 15px;">
37
- <input type="radio" name="scenario" value="Aaa">
38
- <span style="width: 200px; padding-left: 5px;">Aaa</span>
39
- </div>
40
- </div>
41
- </div>
42
- <div class="row" style="width: 360px; padding-top: 15px;">
43
- <span id="rfid-checkbox-description" style="font-size: 18px;">Process rfid reading</span>
44
- <input id="rfid-checkbox" type="checkbox" style="margin-left: auto;" />
45
- </div>
46
- <div id="bt-device" class="row" style="display: none;">
47
- <input type="text" placeholder="Regula 0000" />
48
- <button class="button">Connect</button>
49
- </div>
50
- <div class="row">
51
- <button id="scan" class="button">Scan document</button>
52
- <button id="recognize" class="button">Scan image</button>
53
- </div>
54
- <div style="padding-top: 20px;"></div>
55
- </div>
56
- <div id="custom-rfid" class="column no-scroll" style="display: none;">
57
- <span id="rfid-description" style="font-size: 22px">Place your phone on top of the NFC tag</span>
58
- <div class="progress-bar">
59
- <div id="progress"></div>
60
- </div>
61
- <button id="cancel-rfid" class="text-button" style="margin-top: 50px;">X</button>
62
- </div>
2
+ <div class="column header">
3
+ <span id="status" class="title">Loading...</span>
4
+ <div class="column divider"></div>
5
+ </div>
6
+ <div id="main" class="column no-scroll">
7
+ <div class="row">
8
+ <div class="column" style="padding: 5px;">
9
+ <p>Portrait</p>
10
+ <img id="portrait-image" src="images/portrait.png" height="160px" width="120px">
11
+ </div>
12
+ <div class="column" style="padding: 5px;">
13
+ <p>Document image</p>
14
+ <img id="document-image" src="images/document.png" height="160px" width="200px">
15
+ </div>
16
+ </div>
17
+ <div id="scenario-container" class="column no-scroll" style="margin-top: 15px; background-color: rgba(0, 0, 0, 0.03);">
18
+ <div id="scenarios" class="scroll"></div>
19
+ </div>
20
+ <div class="row" style="width: 360px; padding-top: 15px;">
21
+ <span id="rfid-checkbox-description" style="font-size: 18px;width: 100%;">Process rfid reading(unavailable)</span>
22
+ <input id="rfid-checkbox" type="checkbox" style="margin-left: auto;" disabled />
23
+ </div>
24
+ <div class="row">
25
+ <button id="scan" class="button">Scan document</button>
26
+ <button id="recognize" class="button">Scan image</button>
27
+ </div>
28
+ <button id="connect" class="button" style="width: 360px; display: none;">Connect</button>
29
+ <div style="padding-top: 20px;"></div>
30
+ </div>
31
+ <div id="custom-rfid" class="column no-scroll" style="display: none;">
32
+ <span id="rfid-description" style="font-size: 22px">Place your phone on top of the NFC tag</span>
33
+ <div class="progress-bar">
34
+ <div id="progress"></div>
35
+ </div>
36
+ <button id="cancel-rfid" class="text-button" style="margin-top: 50px;">X</button>
37
+ </div>
63
38
  </div>
@@ -1,66 +1,174 @@
1
- import { Component } from '@angular/core'
2
- import { Dialogs } from '@awesome-cordova-plugins/dialogs/ngx'
3
- import { File } from '@awesome-cordova-plugins/file'
4
- import { Camera } from '@awesome-cordova-plugins/camera/ngx'
5
- import { Platform } from '@ionic/angular'
6
- import { DocumentReader, InitConfig } from '@regulaforensics/document-reader'
7
-
8
- var useBtDevice = false
9
- var ready = false
10
- var isReadingCustomRfid = false
11
-
12
- async function init() {
1
+ import { DocumentReader, DocReaderAction, FieldType, GraphicFieldType, InitConfig, RecognizeConfig, ResultType, RFIDConfig, ScannerConfig, Scenario } from '@regulaforensics/document-reader'
2
+ import { loadAsset, pickImage } from '../index'
3
+ import { initializeWithBTDevice, setupBTDevice, useBtDevice } from './extra/bt_device'
4
+ import { useRfidSelfHostedUI, rfidSelfHostedUI } from './extra/custom_rfid'
5
+
6
+ var documentReader = DocumentReader.instance
7
+ var selectedScenario
8
+ var doRfid = false
9
+ var isReadingRfid = false
10
+
11
+ export async function init() {
13
12
  if (!await initialize()) return
13
+ setScenarios(documentReader.availableScenarios)
14
+ setCanRfid(await documentReader.isRFIDAvailableForUse())
14
15
  setStatus("Ready")
15
16
  }
16
17
 
17
- async function initialize() {
18
+ async function scan() {
19
+ if (!await documentReader.isReady()) return
20
+ clearResults()
21
+ documentReader.startScanner(
22
+ ScannerConfig.withScenario(selectedScenario),
23
+ handleCompletion,
24
+ )
25
+ }
26
+
27
+ async function recognize() {
28
+ if (!await documentReader.isReady()) return
29
+ var image = await pickImage()
30
+ if (image == null) return
31
+
32
+ clearResults()
33
+ documentReader.recognize(
34
+ RecognizeConfig.withScenario(selectedScenario, { image: image }),
35
+ handleCompletion,
36
+ )
37
+ }
38
+
39
+ export function handleCompletion(action, results, error) {
40
+ handleException(error)
41
+ if (DocReaderAction.stopped(action) && !shouldRfid(results)) {
42
+ displayResults(results)
43
+ } else if (DocReaderAction.finished(action) && shouldRfid(results)) {
44
+ isReadingRfid = true
45
+ readRfid()
46
+ }
47
+ }
48
+
49
+ export async function displayResults(results) {
50
+ isReadingRfid = false
51
+ clearResults()
52
+ if (results == null) return
53
+
54
+ var name = await results.textFieldValueByType(FieldType.SURNAME_AND_GIVEN_NAMES)
55
+ var docImage = await results.graphicFieldImageByType(GraphicFieldType.DOCUMENT_IMAGE)
56
+ var portrait = await results.graphicFieldImageByType(GraphicFieldType.PORTRAIT)
57
+ portrait = await results.graphicFieldImageByTypeSource(GraphicFieldType.PORTRAIT, ResultType.RFID_IMAGE_DATA) ?? portrait
58
+
59
+ setStatus(name)
60
+ setPortrait(portrait)
61
+ setDocImage(docImage)
62
+ }
63
+
64
+ var readRfid = () => {
65
+ documentReader.rfid(new RFIDConfig(handleCompletion))
66
+ }
67
+
68
+ function shouldRfid(results) {
69
+ return doRfid &&
70
+ !isReadingRfid &&
71
+ results != null && results.chipPage != 0
72
+ }
73
+
74
+ var initialize = async () => {
18
75
  setStatus("Initializing...")
19
76
 
20
- var license = await loadAssetIfExists("regula.license")
21
- var config = new InitConfig(license)
22
- var [success, error] = await documentReader.initialize(config)
23
-
24
- if (!success && error != null) {
77
+ var license = await loadAsset("regula.license")
78
+ var initConfig = new InitConfig(license)
79
+ var [success, error] = await documentReader.initialize(initConfig)
80
+
81
+ handleException(error)
82
+ return success
83
+ }
84
+
85
+ export function handleException(error) {
86
+ if (error != null) {
25
87
  setStatus(error.message)
26
88
  console.log(error.code + ": " + error.message)
27
89
  }
28
- return success
29
90
  }
30
91
 
31
- async function loadAssetIfExists(path: string): Promise<string | null> {
32
- try {
33
- var dir = await File.resolveDirectoryUrl(File.applicationDirectory + "www/assets")
34
- var fileEntry = await File.getFile(dir, path, null)
35
- var result = await new Promise<string | null>((resolve, _) => {
36
- fileEntry.file(file => {
37
- var reader = new FileReader()
38
- reader.onloadend = (_) => resolve(reader.result as string)
39
- reader.readAsDataURL(file)
40
- }, _ => resolve(null))
41
- })
42
- return result
43
- } catch (_) {
44
- return null
92
+ // --------------------------------------------------------------------------------------------------------------------
93
+
94
+ var documentUIImage
95
+ var portraitUIImage
96
+ export function main() {
97
+ documentUIImage = document.getElementById("document-image")
98
+ portraitUIImage = document.getElementById("portrait-image")
99
+ document.getElementById("scan").onclick = () => scan()
100
+ document.getElementById("recognize").onclick = () => recognize()
101
+
102
+ // custom rfid
103
+ if (useRfidSelfHostedUI) readRfid = () => rfidSelfHostedUI()
104
+
105
+ // bt device
106
+ if (!useBtDevice) init()
107
+ else {
108
+ setupBTDevice()
109
+ initialize = initializeWithBTDevice
45
110
  }
46
111
  }
47
112
 
48
- var documentReader = DocumentReader.instance
49
- var setStatus = (data: string) => document.getElementById("status").innerHTML = data
50
-
51
- @Component({
52
- selector: 'app-root',
53
- templateUrl: 'main.html',
54
- styleUrl: 'main.css'
55
- })
56
- export class Main {
57
- constructor(platform: Platform, dialogs: Dialogs, camera: Camera) {
58
- platform.ready().then(() => {
59
- document.getElementById("main").style.display = isReadingCustomRfid ? "none" : "flex"
60
- document.getElementById("custom-rfid").style.display = isReadingCustomRfid ? "flex" : "none"
61
- document.getElementById("bt-device").style.display = (useBtDevice && !ready) ? "flex" : "none"
62
-
63
- init()
64
- });
113
+ export function setStatus(data) {
114
+ if (data != null)
115
+ document.getElementById("status").innerHTML = data
116
+ }
117
+
118
+ function setPortrait(data) {
119
+ if (data != null)
120
+ portraitUIImage.src = "data:image/png;base64," + data
121
+ }
122
+
123
+ function setDocImage(data) {
124
+ if (data != null)
125
+ documentUIImage.src = "data:image/png;base64," + data
126
+ }
127
+
128
+ function clearResults() {
129
+ setStatus("Ready")
130
+ portraitUIImage.src = "images/portrait.png"
131
+ documentUIImage.src = "images/document.png"
132
+ }
133
+
134
+ function setCanRfid(data) {
135
+ var checkbox // implicitly any, since cordova sample is pure js
136
+ checkbox = document.getElementById('rfid-checkbox')
137
+ var checkboxDescription = document.getElementById("rfid-checkbox-description")
138
+ if (data) {
139
+ checkbox.disabled = false
140
+ checkboxDescription.innerHTML = "Process rfid reading"
141
+ var onclick = () => {
142
+ doRfid = !doRfid
143
+ checkbox.checked = doRfid
144
+ }
145
+ checkbox.onclick = onclick
146
+ checkboxDescription.onclick = onclick
65
147
  }
66
148
  }
149
+
150
+ function setScenarios(data) {
151
+ selectedScenario = Scenario.MRZ
152
+ var scenariosContainer = document.getElementById("scenarios")
153
+
154
+ data.forEach(scenario => {
155
+ var checked = selectedScenario == scenario.name ? "checked" : ""
156
+ var scenarioElement = `<div class="row radio">
157
+ <input type="radio" name="scenario" id="${scenario.name}" value="${scenario.name}" ${checked}>
158
+ <span id="${scenario.name}-caption" style="width: 200px; padding-left: 5px;">${scenario.caption}</span>
159
+ </div>`
160
+ scenariosContainer.insertAdjacentHTML("beforeend", scenarioElement)
161
+ })
162
+
163
+ data.forEach(scenario => {
164
+ var element
165
+ element = document.getElementById(scenario.name)
166
+ var elementCaption = document.getElementById(scenario.name + "-caption")
167
+ var onclick = () => {
168
+ selectedScenario = scenario.name
169
+ element.checked = true
170
+ }
171
+ element.onclick = onclick
172
+ elementCaption.onclick = onclick
173
+ })
174
+ }
@@ -10,3 +10,13 @@
10
10
  * Android: `npm run android`.
11
11
 
12
12
  **Note**: this is just one way of running the app. You can also pass `-o` or `--open` argument to the command, and this will open Xcode/Android Studio, then run the app directly from the IDE. Overall, this is a more consistent way, so if you're having troubles running the app from terminal, try running it from the IDE. Just don't forget to make sure that Metro Bundler is running(`npm start`).
13
+
14
+ ## Additional examples
15
+
16
+ ### Bluetooth device
17
+
18
+ In order to connect to an external scanning device, change the `useBtDevice` constant to true in `src/extra/bt_device`, and set `btDeviceName` to the name of you device. After running the app, click `Connect`.
19
+
20
+ ### RFID self hosted UI
21
+
22
+ This app also demonstraits how you can implement you own UI for the RFID reading process. To enable it, change the `useRfidSelfHostedUI` constant to true in `src/extra/custom_rfid`. Run the app and initiate RFID reading.
@@ -28,7 +28,9 @@ export default ({ config }: ConfigContext): ExpoConfig => ({
28
28
  },
29
29
  android: {
30
30
  package: 'com.regula.dr.fullauthrfid',
31
- permissions: ['android.permission.BLUETOOTH_CONNECT'],
31
+ permissions: [
32
+ 'android.permission.BLUETOOTH_CONNECT',
33
+ 'android.permission.NFC'],
32
34
  adaptiveIcon: {
33
35
  foregroundImage: './images/icon/adaptive-icon.png',
34
36
  backgroundColor: '#ffffff'
@@ -1,12 +1,16 @@
1
1
  import { registerRootComponent } from 'expo'
2
2
  import WebView from 'react-native-webview'
3
- import { onload } from './src/main'
3
+ import React from 'react'
4
+ import * as RNFS from 'react-native-fs'
5
+ import { Platform } from 'react-native'
6
+ import { launchImageLibrary } from 'react-native-image-picker'
7
+ import { main } from './src/main'
4
8
 
5
9
  var webViewRef: any
6
10
  const onclicks: any = {}
7
11
  const onMessage = (json: any) => {
8
12
  const event = JSON.parse(json.nativeEvent.data)
9
- if (event.id === "ready") onload()
13
+ if (event.id === "ready") main()
10
14
  if (event.id === "onclick") {
11
15
  onclicks[event.value]()
12
16
  }
@@ -24,29 +28,53 @@ export const document = {
24
28
  }; true
25
29
  `)
26
30
  } else
27
- webViewRef.injectJavaScript(`document.getElementById("${id}").${prop} = "${value}"; true`)
31
+ webViewRef.injectJavaScript(`document.getElementById("${id}").${prop} = ${parseValue(value)}; true`)
28
32
  return true
29
33
  },
30
34
  get(_, prop: string) {
31
35
  if (prop === "style") return new Proxy({}, {
32
36
  set(_, styleProp: string, value) {
33
- webViewRef.injectJavaScript(`document.getElementById("${id}").style.${styleProp} = "${value}"; true`)
37
+ webViewRef.injectJavaScript(`document.getElementById("${id}").style.${styleProp} = ${parseValue(value)}; true`)
34
38
  return true
35
39
  }
36
40
  })
41
+ if (prop === "insertAdjacentHTML") return (position: string, html: string) => {
42
+ webViewRef.injectJavaScript(`document.getElementById("${id}").insertAdjacentHTML('${position}', \`${html}\`); true`)
43
+ return true
44
+ }
37
45
  return undefined
38
- },
46
+ }
39
47
  }
40
48
  )
41
49
  }
42
50
  }
43
51
 
52
+ function parseValue(value: any) {
53
+ if (value !== true && value !== false) return `"${value}"`
54
+ return value
55
+ }
56
+
44
57
  registerRootComponent(() =>
45
58
  <WebView
46
59
  ref={ref => { webViewRef = ref }}
47
60
  onMessage={onMessage}
48
61
  source={require("./index.html")}
49
62
  scrollEnabled={false}
50
- injectedJavaScript="document.body.addEventListener('touchmove', function(e) { e.preventDefault() }, { passive: false })"
63
+ overScrollMode={'content'}
51
64
  />
52
65
  )
66
+
67
+ export async function loadAsset(path: string): Promise<string> {
68
+ if (Platform.OS === 'ios') path = RNFS.MainBundlePath + "/" + path
69
+ var readFile = Platform.OS === 'ios' ? RNFS.readFile : RNFS.readFileRes
70
+ return await readFile(path, 'base64')
71
+ }
72
+
73
+ export async function pickImage(): Promise<string | null> {
74
+ var response = await launchImageLibrary({
75
+ mediaType: 'photo',
76
+ selectionLimit: 1,
77
+ includeBase64: true
78
+ })
79
+ return response?.assets?.[0].base64!
80
+ }