@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/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 { launchCamera, launchImageLibrary } from 'react-native-image-picker';
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
- var certificates = []
21
- var items = await readDir(certDir, 'base64')
22
+ var certificates = []
23
+ var items = await readDir(certDir, 'base64')
22
24
 
23
- for (var i in items) {
24
- var item = items[i]
25
- if (item.isFile()) {
26
- var findExt = item.name.split('.')
27
- var pkdResourceType = 0
28
- if (findExt.length > 0)
29
- pkdResourceType = Enum.PKDResourceType.getType(findExt[findExt.length - 1].toLowerCase())
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
- var file = await readFile(item.path, 'base64')
32
- certificates.push({
33
- 'binaryData': file,
34
- 'resourceType': pkdResourceType
35
- })
36
- }
33
+ var file = await readFile(item.path, 'base64')
34
+ certificates.push({
35
+ 'binaryData': file,
36
+ 'resourceType': pkdResourceType
37
+ })
37
38
  }
38
- DocumentReader.addPKDCertificates(certificates, s => {
39
- console.log("certificates added")
40
- }, e => console.log(e))
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
- constructor(props) {
45
- super(props)
46
- eventManager.addListener('prepareDatabaseProgressChangeEvent', e => this.setState({ fullName: "Downloading database: " + e["msg"] + "%" }))
47
- eventManager.addListener('completionEvent', e => this.handleCompletion(DocumentReaderCompletion.fromJson(JSON.parse(e["msg"]))))
48
- eventManager.addListener('rfidNotificationCompletionEvent', e => console.log("rfidNotificationCompletionEvent: " + e["msg"]))
49
- eventManager.addListener('paCertificateCompletionEvent', e => console.log("paCertificateCompletionEvent: " + e["msg"]))
50
- DocumentReader.prepareDatabase("Full", (respond) => {
51
- console.log(respond)
52
- readFile(licPath, 'base64').then((res) => {
53
- this.setState({ fullName: "Initializing..." })
54
- DocumentReader.initializeReader(res, (respond) => {
55
- console.log(respond)
56
- DocumentReader.isRFIDAvailableForUse((canRfid) => {
57
- if (canRfid) {
58
- this.setState({ canRfid: true, rfidUIHeader: "Reading RFID", rfidDescription: "Place your phone on top of the NFC tag", rfidUIHeaderColor: "black" })
59
- this.setState({ canRfidTitle: '' })
60
- }
61
- }, error => console.log(error))
62
- DocumentReader.getAvailableScenarios((jstring) => {
63
- var scenariosTemp = JSON.parse(jstring)
64
- var scenariosL = []
65
- for (var i in scenariosTemp) {
66
- scenariosL.push({
67
- label: DocumentReaderScenario.fromJson(typeof scenariosTemp[i] === "string" ? JSON.parse(scenariosTemp[i]) : scenariosTemp[i]).name,
68
- id: i
69
- })
70
- }
71
- this.setState({ scenarios: scenariosL })
72
- this.setState({ selectedScenario: this.state.scenarios[0]['label'] })
73
- this.setState({ radio: null })
74
- this.setState({
75
- radio: < RadioGroup containerStyle = { styles.radio }
76
- radioButtons = { this.state.scenarios }
77
- onPress = {
78
- (data) => {
79
- var selectedItem
80
- for (var index in data)
81
- if (data[index]['selected'])
82
- selectedItem = data[index]['label']
83
- this.setState({ selectedScenario: selectedItem })
84
- }
85
- }
86
- />
87
- })
88
- DocumentReader.getDocumentReaderIsReady((isReady) => {
89
- if (isReady) {
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
- this.state = {
102
- fullName: "Please wait...",
103
- doRfid: false,
104
- canRfid: false,
105
- canRfidTitle: '(unavailable)',
106
- scenarios: [],
107
- selectedScenario: "",
108
- portrait: require('./images/portrait.png'),
109
- docFront: require('./images/id.png'),
110
- radio: < RadioGroup containerStyle = { styles.radio }
111
- radioButtons = {
112
- [{ label: 'Loading', id: 0 }] }
113
- onPress = { null }
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
- handleCompletion(completion) {
119
- if (this.state.isReadingRfid && (completion.action === Enum.DocReaderAction.CANCEL || completion.action === Enum.DocReaderAction.ERROR))
120
- this.hideRfidUI()
121
- if (this.state.isReadingRfid && completion.action === Enum.DocReaderAction.NOTIFICATION)
122
- this.updateRfidUI(completion.results.documentReaderNotification)
123
- if (completion.action === Enum.DocReaderAction.COMPLETE)
124
- if (this.state.isReadingRfid)
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
- }
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
- showRfidUI() {
136
- // show animation
137
- this.setState({ isReadingRfid: true })
138
- }
145
+ showRfidUI() {
146
+ // show animation
147
+ this.setState({ isReadingRfidCustomUi: true })
148
+ }
139
149
 
140
- hideRfidUI() {
141
- // show animation
142
- this.restartRfidUI()
143
- this.setState({ isReadingRfid: false, rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" })
144
- }
150
+ hideRfidUI() {
151
+ // show animation
152
+ this.restartRfidUI()
153
+ this.setState({ isReadingRfidCustomUi: false, rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black" })
154
+ }
145
155
 
146
- restartRfidUI() {
147
- this.setState({ rfidUIHeaderColor: "red", rfidUIHeader: "Failed!", rfidDescription: "Place your phone on top of the NFC tag", rfidProgress: -1 })
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
- updateRfidUI(results) {
151
- if (results.code === Enum.eRFID_NotificationCodes.RFID_NOTIFICATION_PCSC_READING_DATAGROUP)
152
- this.setState({ rfidDescription: Enum.eRFID_DataFile_Type.getTranslation(results.number) })
153
- this.setState({ rfidUIHeader: "Reading RFID", rfidUIHeaderColor: "black", rfidProgress: results.value / 100 })
154
- if (Platform.OS === 'ios')
155
- DocumentReader.setRfidSessionStatus(this.state.rfidDescription + "\n" + results.value + "%", e => {}, e => {})
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
- clearResults() {
159
- this.setState({ fullName: "Ready", docFront: require('./images/id.png'), portrait: require('./images/portrait.png') })
160
- }
168
+ clearResults() {
169
+ this.setState({ fullName: "Ready", docFront: require('./images/id.png'), portrait: require('./images/portrait.png') })
170
+ }
161
171
 
162
- displayResults(results) {
163
- this.setState({ fullName: results.getTextFieldValueByType({ fieldType: Enum.eVisualFieldType.FT_SURNAME_AND_GIVEN_NAMES }) })
164
- if (results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE }) != null)
165
- this.setState({ docFront: { uri: "data:image/png;base64," + results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE }) } })
166
- if (results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT }) != null)
167
- this.setState({ portrait: { uri: "data:image/png;base64," + results.getGraphicFieldImageByType({ fieldType: Enum.eGraphicFieldType.GF_PORTRAIT }) } })
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
- customRFID() {
171
- this.showRfidUI()
172
- DocumentReader.readRFID(e => {}, e => {})
173
- }
180
+ customRFID() {
181
+ this.showRfidUI()
182
+ DocumentReader.readRFID(e => { }, e => { })
183
+ }
174
184
 
175
- usualRFID() {
176
- this.setState({ doRfid: false })
177
- DocumentReader.startRFIDReader(e => {}, e => {})
178
- }
185
+ usualRFID() {
186
+ isReadingRfid = true
187
+ DocumentReader.startRFIDReader(e => { }, e => { })
188
+ }
179
189
 
180
- handleResults(results) {
181
- if (this.state.doRfid && results != null && results.chipPage != 0) {
182
- accessKey = null
183
- accessKey = results.getTextFieldValueByType(Enum.eVisualFieldType.FT_MRZ_STRINGS)
184
- if (accessKey != null && accessKey != "") {
185
- accessKey = accessKey.replace(/^/g, '').replace(/\n/g, '')
186
- DocumentReader.setRfidScenario({
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.isReadingRfid && Platform.OS === 'android') && <View style={styles.container}>
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.isReadingRfid && <View style={styles.container}>
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 style={{ padding: 5 }}>
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>
@@ -1,10 +1,5 @@
1
- /**
2
- * Metro configuration for React Native
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
+ };
@@ -10,8 +10,8 @@
10
10
  "lint": "eslint ."
11
11
  },
12
12
  "dependencies": {
13
- "@regulaforensics/react-native-document-reader-api": "^6.4.0",
14
- "@regulaforensics/react-native-document-reader-core-fullrfid": "^6.4.0",
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",