Add explicit destructor
This commit is contained in:
parent
d9d8592179
commit
f577c0ef8c
@ -11,6 +11,7 @@ import com.facebook.react.bridge.WritableNativeMap
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
import xyz.twenty_two.PortalSdk
|
||||
@ -19,7 +20,7 @@ import xyz.twenty_two.GenerateMnemonicWords
|
||||
class LibportalReactNativeModule(reactContext: ReactApplicationContext) :
|
||||
ReactContextBaseJavaModule(reactContext) {
|
||||
|
||||
val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
||||
var scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
||||
var instance: PortalSdk? = null
|
||||
|
||||
override fun getName(): String {
|
||||
@ -28,10 +29,15 @@ class LibportalReactNativeModule(reactContext: ReactApplicationContext) :
|
||||
|
||||
@ReactMethod
|
||||
fun constructor(useFastOps: Boolean, promise: Promise) {
|
||||
if (instance == null) {
|
||||
instance = PortalSdk(useFastOps)
|
||||
promise.resolve(null)
|
||||
}
|
||||
scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
|
||||
instance = PortalSdk(useFastOps)
|
||||
promise.resolve(null)
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun destructor() {
|
||||
scope.cancel()
|
||||
instance = null
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
|
||||
@ -6,6 +6,8 @@ RCT_EXTERN_METHOD(constructor: (BOOL)useFastOps
|
||||
withResolver:(RCTPromiseResolveBlock)resolve
|
||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
RCT_EXTERN_METHOD(destructor)
|
||||
|
||||
RCT_EXTERN_METHOD(poll: (RCTPromiseResolveBlock)resolve
|
||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
|
||||
@ -29,6 +29,8 @@ class LibportalReactNative: NSObject {
|
||||
self.sdk = PortalSdk(useFastOps: useFastOps)
|
||||
resolve(nil)
|
||||
}
|
||||
|
||||
@objc func destructor() -> Void {}
|
||||
|
||||
@objc func poll(_ resolve: @escaping RCTPromiseResolveBlock, withRejecter reject: @escaping RCTPromiseRejectBlock) -> Void {
|
||||
Task {
|
||||
|
||||
@ -23,6 +23,10 @@ export class PortalSdk {
|
||||
.catch((e: any) => console.warn(e))
|
||||
}
|
||||
|
||||
destroy() {
|
||||
LibportalReactNative.destructor()
|
||||
}
|
||||
|
||||
poll(): Promise<NfcOut> {
|
||||
return LibportalReactNative.poll()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user