@@ -18,6 +18,7 @@ import net.idscan.components.android.multiscan.components.mrz.MRZComponent
18
18
import net.idscan.components.android.multiscan.components.mrz.MRZData
19
19
import net.idscan.components.android.multiscan.components.pdf417.PDF417Component
20
20
import net.idscan.components.android.multiscan.components.pdf417.PDF417Data
21
+ import kotlin.collections.HashMap
21
22
22
23
@ReactModule(name = IdscanSdkModule .NAME )
23
24
class IdscanSdkModule (reactContext : ReactApplicationContext ) :
@@ -27,6 +28,7 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
27
28
private var scannerPDFKey: String? = null
28
29
private var scannerMRZKey: String? = null
29
30
private var parserKey: String? = null
31
+ private var callbackCalled: Boolean = false ;
30
32
31
33
private val mActivityEventListener: ActivityEventListener =
32
34
object : BaseActivityEventListener () {
@@ -83,9 +85,9 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
83
85
Log .d(NAME , errorMessage)
84
86
if (errorMessage.length > 1 ) {
85
87
scanResult.putString(" success" , " false" )
86
- callback !! .invoke (errorMessage, scanResult)
88
+ executeCallback (errorMessage, scanResult)
87
89
} else {
88
- callback !! .invoke (null , scanResult)
90
+ executeCallback (null , scanResult)
89
91
}
90
92
}
91
93
}
@@ -103,6 +105,15 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
103
105
return mappedResult
104
106
}
105
107
108
+ private fun executeCallback (vararg args : Any? ) {
109
+ if (callbackCalled) {
110
+ return
111
+ }
112
+
113
+ callback!! .invoke(* args)
114
+ callbackCalled = true
115
+ }
116
+
106
117
private fun parsePdfData (pdfData : PDF417Data ): WritableNativeMap {
107
118
val parser = DLParser ()
108
119
parser.setup(reactApplicationContext, parserKey)
@@ -137,6 +148,7 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
137
148
parserKey = apiKeys.getString(KEY_PARSER_KEY )
138
149
139
150
this .callback = callback
151
+ this .callbackCalled = false
140
152
showDefaultScanView()
141
153
}
142
154
0 commit comments