@regulaforensics/react-native-document-reader-api 6.4.0 → 6.5.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.
- package/RNDocumentReaderApi.podspec +1 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/regula/documentreader/Helpers.java +1 -1
- package/android/src/main/java/com/regula/documentreader/JSONConstructor.java +24 -47
- package/android/src/main/java/com/regula/documentreader/RNRegulaDocumentReaderModule.java +12 -14
- package/android/src/main/java/com/regula/documentreader/RegulaConfig.java +46 -6
- package/core/.gitkeep +0 -0
- package/example/App.js +168 -168
- package/example/metro.config.js +7 -8
- package/example/package.json +2 -2
- package/index.d.ts +3410 -3289
- package/index.js +3256 -3177
- package/ios/RGLWJSONConstructor.h +1 -0
- package/ios/RGLWJSONConstructor.m +22 -3
- package/ios/RNRegulaDocumentReader.m +8 -8
- package/ios/RegulaConfig.m +37 -6
- package/package.json +1 -1
package/example/App.js
CHANGED
|
@@ -3,7 +3,7 @@ import { StyleSheet, View, Button, Text, Image, ScrollView, NativeEventEmitter,
|
|
|
3
3
|
import DocumentReader, { Enum, DocumentReaderCompletion, DocumentReaderScenario, RNRegulaDocumentReader } from '@regulaforensics/react-native-document-reader-api'
|
|
4
4
|
import * as RNFS from 'react-native-fs'
|
|
5
5
|
import RadioGroup from 'react-native-radio-buttons-group'
|
|
6
|
-
import {
|
|
6
|
+
import { launchImageLibrary } from 'react-native-image-picker';
|
|
7
7
|
import * as Progress from 'react-native-progress'
|
|
8
8
|
import CheckBox from 'react-native-check-box'
|
|
9
9
|
import { LogBox } from 'react-native';
|
|
@@ -16,197 +16,191 @@ var certDir = Platform.OS === 'ios' ? (RNFS.MainBundlePath + "/certificates") :
|
|
|
16
16
|
var readDir = Platform.OS === 'ios' ? RNFS.readDir : RNFS.readDirAssets
|
|
17
17
|
var readFile = Platform.OS === 'ios' ? RNFS.readFile : RNFS.readFileAssets
|
|
18
18
|
|
|
19
|
+
var isReadingRfid = false;
|
|
20
|
+
|
|
19
21
|
async function addCertificates() {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
var certificates = []
|
|
23
|
+
var items = await readDir(certDir, 'base64')
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
for (var i in items) {
|
|
26
|
+
var item = items[i]
|
|
27
|
+
if (item.isFile()) {
|
|
28
|
+
var findExt = item.name.split('.')
|
|
29
|
+
var pkdResourceType = 0
|
|
30
|
+
if (findExt.length > 0)
|
|
31
|
+
pkdResourceType = Enum.PKDResourceType.getType(findExt[findExt.length - 1].toLowerCase())
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
33
|
+
var file = await readFile(item.path, 'base64')
|
|
34
|
+
certificates.push({
|
|
35
|
+
'binaryData': file,
|
|
36
|
+
'resourceType': pkdResourceType
|
|
37
|
+
})
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
}
|
|
40
|
+
DocumentReader.addPKDCertificates(certificates, s => {
|
|
41
|
+
console.log("certificates added")
|
|
42
|
+
}, e => console.log(e))
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
export default class App extends Component {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this.setState({ fullName: "Ready" })
|
|
91
|
-
DocumentReader.setRfidDelegate(Enum.RFIDDelegate.NO_PA, (r) => {}, error => console.log(error))
|
|
92
|
-
// addCertificates()
|
|
93
|
-
} else
|
|
94
|
-
this.setState({ fullName: "Failed" })
|
|
95
|
-
}, error => console.log(error))
|
|
96
|
-
}, error => console.log(error))
|
|
97
|
-
}, error => console.log(error))
|
|
46
|
+
constructor(props) {
|
|
47
|
+
super(props)
|
|
48
|
+
eventManager.addListener('prepareDatabaseProgressChangeEvent', e => this.setState({ fullName: "Downloading database: " + e["msg"] + "%" }))
|
|
49
|
+
eventManager.addListener('completionEvent', e => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))))
|
|
50
|
+
eventManager.addListener('rfidNotificationCompletionEvent', e => console.log("rfidNotificationCompletionEvent: " + e["msg"]))
|
|
51
|
+
eventManager.addListener('paCertificateCompletionEvent', e => console.log("paCertificateCompletionEvent: " + e["msg"]))
|
|
52
|
+
DocumentReader.prepareDatabase("Full", (respond) => {
|
|
53
|
+
console.log(respond)
|
|
54
|
+
readFile(licPath, 'base64').then((res) => {
|
|
55
|
+
this.setState({ fullName: "Initializing..." })
|
|
56
|
+
DocumentReader.initializeReader({
|
|
57
|
+
license: res,
|
|
58
|
+
delayedNNLoad: true
|
|
59
|
+
}, (respond) => {
|
|
60
|
+
console.log(respond)
|
|
61
|
+
DocumentReader.isRFIDAvailableForUse((canRfid) => {
|
|
62
|
+
if (canRfid) {
|
|
63
|
+
this.setState({ canRfid: true, rfidUIHeader: "Reading RFID", rfidDescription: "Place your phone on top of the NFC tag", rfidUIHeaderColor: "black" })
|
|
64
|
+
this.setState({ canRfidTitle: '' })
|
|
65
|
+
}
|
|
66
|
+
}, error => console.log(error))
|
|
67
|
+
DocumentReader.getAvailableScenarios((jstring) => {
|
|
68
|
+
var scenariosTemp = JSON.parse(jstring)
|
|
69
|
+
var scenariosL = []
|
|
70
|
+
for (var i in scenariosTemp) {
|
|
71
|
+
scenariosL.push({
|
|
72
|
+
label: DocumentReaderScenario.fromJson(typeof scenariosTemp[i] === "string" ? JSON.parse(scenariosTemp[i]) : scenariosTemp[i]).name,
|
|
73
|
+
id: i
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
this.setState({ scenarios: scenariosL })
|
|
77
|
+
this.setState({ selectedScenario: this.state.scenarios[0]['label'] })
|
|
78
|
+
this.setState({ radio: null })
|
|
79
|
+
this.setState({
|
|
80
|
+
radio: < RadioGroup containerStyle={styles.radio}
|
|
81
|
+
radioButtons={this.state.scenarios}
|
|
82
|
+
onPress={
|
|
83
|
+
(data) => {
|
|
84
|
+
var selectedItem
|
|
85
|
+
for (var index in data)
|
|
86
|
+
if (data[index]['selected'])
|
|
87
|
+
selectedItem = data[index]['label']
|
|
88
|
+
this.setState({ selectedScenario: selectedItem })
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/>
|
|
98
92
|
})
|
|
93
|
+
DocumentReader.getDocumentReaderIsReady((isReady) => {
|
|
94
|
+
if (isReady) {
|
|
95
|
+
this.setState({ fullName: "Ready" })
|
|
96
|
+
DocumentReader.setRfidDelegate(Enum.RFIDDelegate.NO_PA, (r) => { }, error => console.log(error))
|
|
97
|
+
// addCertificates()
|
|
98
|
+
} else
|
|
99
|
+
this.setState({ fullName: "Failed" })
|
|
100
|
+
}, error => console.log(error))
|
|
101
|
+
}, error => console.log(error))
|
|
99
102
|
}, error => console.log(error))
|
|
103
|
+
})
|
|
104
|
+
}, error => console.log(error))
|
|
100
105
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
this.state = {
|
|
107
|
+
fullName: "Please wait...",
|
|
108
|
+
doRfid: false,
|
|
109
|
+
isReadingRfidCustomUi: false,
|
|
110
|
+
canRfid: false,
|
|
111
|
+
canRfidTitle: '(unavailable)',
|
|
112
|
+
scenarios: [],
|
|
113
|
+
selectedScenario: "",
|
|
114
|
+
portrait: require('./images/portrait.png'),
|
|
115
|
+
docFront: require('./images/id.png'),
|
|
116
|
+
radio: < RadioGroup containerStyle={styles.radio}
|
|
117
|
+
radioButtons={
|
|
118
|
+
[{ label: 'Loading', id: 0 }]}
|
|
119
|
+
onPress={null}
|
|
120
|
+
/>
|
|
116
121
|
}
|
|
122
|
+
}
|
|
117
123
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
handleCompletion(completion) {
|
|
125
|
+
if (this.state.isReadingRfidCustomUi && (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR))
|
|
126
|
+
this.hideRfidUI()
|
|
127
|
+
if (this.state.isReadingRfidCustomUi && completion.action === Enum.DocReaderAction.NOTIFICATION)
|
|
128
|
+
this.updateRfidUI(completion.results.documentReaderNotification)
|
|
129
|
+
if (completion.action === Enum.DocReaderAction.COMPLETE)
|
|
130
|
+
if (this.state.isReadingRfidCustomUi)
|
|
131
|
+
if (completion.results.rfidResult !== 1)
|
|
132
|
+
this.restartRfidUI()
|
|
133
|
+
else {
|
|
134
|
+
this.hideRfidUI()
|
|
135
|
+
this.displayResults(completion.results)
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
this.handleResults(completion.results)
|
|
139
|
+
if (completion.action === Enum.DocReaderAction.TIMEOUT)
|
|
140
|
+
this.handleResults(completion.results)
|
|
141
|
+
if (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR)
|
|
142
|
+
isReadingRfid = false
|
|
143
|
+
}
|
|
134
144
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
showRfidUI() {
|
|
146
|
+
// show animation
|
|
147
|
+
this.setState({ isReadingRfidCustomUi: true })
|
|
148
|
+
}
|
|
139
149
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
hideRfidUI() {
|
|
151
|
+
// show animation
|
|
152
|
+
this.restartRfidUI()
|
|
153
|
+
this.setState({ isReadingRfidCustomUi: false, rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" })
|
|
154
|
+
}
|
|
145
155
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
156
|
+
restartRfidUI() {
|
|
157
|
+
this.setState({ rfidUIHeaderColor: "red", rfidUIHeader: "Failed!", rfidDescription: "Place your phone on top of the NFC tag", rfidProgress: -1 })
|
|
158
|
+
}
|
|
149
159
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
160
|
+
updateRfidUI(results) {
|
|
161
|
+
if (results.code === Enum.eRFID_NotificationCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP)
|
|
162
|
+
this.setState({ rfidDescription: Enum.eRFID_DataFile_Type.getTranslation(results.number) })
|
|
163
|
+
this.setState({ rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black", rfidProgress: results.value / 100 })
|
|
164
|
+
if (Platform.OS === 'ios')
|
|
165
|
+
DocumentReader.setRfidSessionStatus(this.state.rfidDescription + "\n" + results.value + "%", e => { }, e => { })
|
|
166
|
+
}
|
|
157
167
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
clearResults() {
|
|
169
|
+
this.setState({ fullName: "Ready", docFront: require('./images/id.png'), portrait: require('./images/portrait.png') })
|
|
170
|
+
}
|
|
161
171
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
172
|
+
displayResults(results) {
|
|
173
|
+
this.setState({ fullName: results.getTextFieldValueByType({ fieldType: Enum.eVisualFieldType.FT_SURNAME_AND_GIVEN_NAMES }) })
|
|
174
|
+
if (results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE }) != null)
|
|
175
|
+
this.setState({ docFront: { uri: "data:image/png;base64," + results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE }) } })
|
|
176
|
+
if (results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT }) != null)
|
|
177
|
+
this.setState({ portrait: { uri: "data:image/png;base64," + results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT }) } })
|
|
178
|
+
}
|
|
169
179
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
180
|
+
customRFID() {
|
|
181
|
+
this.showRfidUI()
|
|
182
|
+
DocumentReader.readRFID(e => { }, e => { })
|
|
183
|
+
}
|
|
174
184
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
usualRFID() {
|
|
186
|
+
isReadingRfid = true
|
|
187
|
+
DocumentReader.startRFIDReader(e => { }, e => { })
|
|
188
|
+
}
|
|
179
189
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
mrz: accessKey,
|
|
188
|
-
pacePasswordType: Enum.eRFID_Password_Type.PPT_MRZ,
|
|
189
|
-
}, e => {}, error => console.log(error))
|
|
190
|
-
} else {
|
|
191
|
-
accessKey = null
|
|
192
|
-
accessKey = results.getTextFieldValueByType(159)
|
|
193
|
-
if (accessKey != null && accessKey != "") {
|
|
194
|
-
DocumentReader.setRfidScenario({
|
|
195
|
-
password: accessKey,
|
|
196
|
-
pacePasswordType: Enum.eRFID_Password_Type.PPT_CAN,
|
|
197
|
-
}, e => {}, error => console.log(error))
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// this.customRFID()
|
|
201
|
-
this.usualRFID()
|
|
202
|
-
} else
|
|
203
|
-
this.displayResults(results)
|
|
190
|
+
handleResults(results) {
|
|
191
|
+
if (this.state.doRfid && !isReadingRfid && results != null && results.chipPage != 0) {
|
|
192
|
+
// this.customRFID()
|
|
193
|
+
this.usualRFID()
|
|
194
|
+
} else {
|
|
195
|
+
isReadingRfid = false
|
|
196
|
+
this.displayResults(results)
|
|
204
197
|
}
|
|
198
|
+
}
|
|
205
199
|
|
|
206
200
|
render() {
|
|
207
201
|
return (
|
|
208
202
|
<View style={styles.container}>
|
|
209
|
-
{(this.state.
|
|
203
|
+
{(this.state.isReadingRfidCustomUi && Platform.OS === 'android') && <View style={styles.container}>
|
|
210
204
|
<Text style={{ paddingBottom: 30, fontSize: 23, color: this.state.rfidUIHeaderColor }}>{this.state.rfidUIHeader}</Text>
|
|
211
205
|
<Text style={{ paddingBottom: 50, fontSize: 20 }}>{this.state.rfidDescription}</Text>
|
|
212
206
|
<Progress.Bar width={200} useNativeDriver={true} color="#4285F4" progress={this.state.rfidProgress} />
|
|
@@ -215,7 +209,7 @@ export default class App extends Component {
|
|
|
215
209
|
</TouchableOpacity>
|
|
216
210
|
</View>
|
|
217
211
|
}
|
|
218
|
-
{!this.state.
|
|
212
|
+
{!this.state.isReadingRfidCustomUi && <View style={styles.container}>
|
|
219
213
|
<Text style={{
|
|
220
214
|
top: 1,
|
|
221
215
|
left: 1,
|
|
@@ -275,7 +269,13 @@ export default class App extends Component {
|
|
|
275
269
|
}}
|
|
276
270
|
disabled={!this.state.canRfid}
|
|
277
271
|
/>
|
|
278
|
-
<Text
|
|
272
|
+
<Text
|
|
273
|
+
style={{ padding: 5 }}
|
|
274
|
+
onPress={() => {
|
|
275
|
+
if (this.state.canRfid) {
|
|
276
|
+
this.setState({ doRfid: !this.state.doRfid })
|
|
277
|
+
}
|
|
278
|
+
}}>
|
|
279
279
|
{'Process rfid reading' + this.state.canRfidTitle}
|
|
280
280
|
</Text>
|
|
281
281
|
</View>
|
package/example/metro.config.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* https://github.com/facebook/react-native
|
|
4
|
-
*
|
|
5
|
-
* @format
|
|
6
|
-
*/
|
|
7
|
-
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const folders = ["../", "../core", path.resolve(path.join(__dirname, './node_modules'))];
|
|
8
3
|
module.exports = {
|
|
9
4
|
transformer: {
|
|
10
5
|
getTransformOptions: async () => ({
|
|
@@ -14,4 +9,8 @@ module.exports = {
|
|
|
14
9
|
},
|
|
15
10
|
}),
|
|
16
11
|
},
|
|
17
|
-
|
|
12
|
+
resolver: {
|
|
13
|
+
nodeModulesPaths: folders
|
|
14
|
+
},
|
|
15
|
+
watchFolders: folders,
|
|
16
|
+
};
|
package/example/package.json
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"lint": "eslint ."
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@regulaforensics/react-native-document-reader-api": "
|
|
14
|
-
"@regulaforensics/react-native-document-reader-core-fullrfid": "
|
|
13
|
+
"@regulaforensics/react-native-document-reader-api": "6.5.0",
|
|
14
|
+
"@regulaforensics/react-native-document-reader-core-fullrfid": "6.5.0",
|
|
15
15
|
"react": "17.0.2",
|
|
16
16
|
"react-native": "^0.67.0",
|
|
17
17
|
"react-native-check-box": "^2.1.7",
|