@@ -18,6 +18,7 @@ import net.idscan.components.android.multiscan.components.mrz.MRZComponent
1818import net.idscan.components.android.multiscan.components.mrz.MRZData
1919import net.idscan.components.android.multiscan.components.pdf417.PDF417Component
2020import net.idscan.components.android.multiscan.components.pdf417.PDF417Data
21+ import kotlin.collections.HashMap
2122
2223@ReactModule(name = IdscanSdkModule .NAME )
2324class IdscanSdkModule (reactContext : ReactApplicationContext ) :
@@ -27,6 +28,7 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
2728 private var scannerPDFKey: String? = null
2829 private var scannerMRZKey: String? = null
2930 private var parserKey: String? = null
31+ private var callbackCalled: Boolean = false ;
3032
3133 private val mActivityEventListener: ActivityEventListener =
3234 object : BaseActivityEventListener () {
@@ -83,9 +85,9 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
8385 Log .d(NAME , errorMessage)
8486 if (errorMessage.length > 1 ) {
8587 scanResult.putString(" success" , " false" )
86- callback !! .invoke (errorMessage, scanResult)
88+ executeCallback (errorMessage, scanResult)
8789 } else {
88- callback !! .invoke (null , scanResult)
90+ executeCallback (null , scanResult)
8991 }
9092 }
9193 }
@@ -103,6 +105,15 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
103105 return mappedResult
104106 }
105107
108+ private fun executeCallback (vararg args : Any? ) {
109+ if (callbackCalled) {
110+ return
111+ }
112+
113+ callback!! .invoke(* args)
114+ callbackCalled = true
115+ }
116+
106117 private fun parsePdfData (pdfData : PDF417Data ): WritableNativeMap {
107118 val parser = DLParser ()
108119 parser.setup(reactApplicationContext, parserKey)
@@ -137,6 +148,7 @@ class IdscanSdkModule(reactContext: ReactApplicationContext) :
137148 parserKey = apiKeys.getString(KEY_PARSER_KEY )
138149
139150 this .callback = callback
151+ this .callbackCalled = false
140152 showDefaultScanView()
141153 }
142154
0 commit comments