@pagopa/io-react-native-cie 1.3.1 → 1.3.2

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.
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m,mm,swift}"
17
17
 
18
18
  # CieSDK dependency
19
- s.dependency "CieSDK", "~> 0.1.16"
19
+ s.dependency "CieSDK", "~> 0.1.17"
20
20
 
21
21
  # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
22
22
  # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
@@ -1,6 +1,7 @@
1
1
  package com.pagopa.ioreactnativecie
2
2
 
3
3
  import android.util.Base64
4
+ import android.app.Activity
4
5
  import com.facebook.react.bridge.Promise
5
6
  import com.facebook.react.bridge.ReactApplicationContext
6
7
  import com.facebook.react.bridge.ReactContextBaseJavaModule
@@ -26,10 +27,15 @@ import it.pagopa.io.app.cie.pace.PaceCallback
26
27
  import it.pagopa.io.app.cie.toHex
27
28
  import it.pagopa.io.app.cie.cie.CieCertificateDataCallback
28
29
  import java.net.URL
30
+ import java.lang.ref.WeakReference
29
31
 
30
32
  class IoReactNativeCieModule(reactContext: ReactApplicationContext) :
31
33
  ReactContextBaseJavaModule(reactContext) {
32
34
 
35
+ private var _cieSdk: CieSDK? = null
36
+ private var _sdkActivityRef: WeakReference<Activity>? = null
37
+ private var _customIdpUrl: String? = null
38
+
33
39
  init {
34
40
  CieLogger.enabled = BuildConfig.DEBUG
35
41
  }
@@ -39,11 +45,27 @@ class IoReactNativeCieModule(reactContext: ReactApplicationContext) :
39
45
  }
40
46
 
41
47
  /**
42
- * Lazy value ensures it is initialized with a valid activity when first used.
48
+ * Getter for a valid Cie SDK instance. Because the SDK is initialized with an activity,
49
+ * the instance must be recreated if the original activity has changed.
43
50
  */
44
- val cieSdk: CieSDK by lazy {
45
- CieSDK.withContext(reactApplicationContext.currentActivity)
46
- };
51
+ val cieSdk: CieSDK
52
+ get() {
53
+ val currentActivity = reactApplicationContext.currentActivity
54
+ ?: throw Exception("Can not initialize Cie SDK with a null activity")
55
+
56
+ val hasActivityChanged = _sdkActivityRef?.get() != currentActivity
57
+
58
+ if (_cieSdk == null || hasActivityChanged) {
59
+ val newSdk = CieSDK.withContext(currentActivity)
60
+ // Re-apply saved configurations
61
+ _customIdpUrl?.let { newSdk.withCustomIdpUrl(it) }
62
+ // Update references
63
+ _cieSdk = newSdk
64
+ _sdkActivityRef = WeakReference(currentActivity)
65
+ }
66
+
67
+ return _cieSdk!!
68
+ }
47
69
 
48
70
  @Suppress("unused")
49
71
  @ReactMethod
@@ -113,6 +135,7 @@ class IoReactNativeCieModule(reactContext: ReactApplicationContext) :
113
135
  @Suppress("unused")
114
136
  @ReactMethod
115
137
  fun setCustomIdpUrl(url: String) {
138
+ _customIdpUrl = url
116
139
  cieSdk.withCustomIdpUrl(url)
117
140
  }
118
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-cie",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Native support for CIE",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/module/index.js",