@kontextso/sdk-react-native 3.3.0-rc.4 → 3.3.0-rc.6

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.
@@ -85,4 +85,5 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
85
85
  dependencies {
86
86
  implementation "com.facebook.react:react-android"
87
87
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
88
+ implementation "androidx.preference:preference:1.2.1"
88
89
  }
@@ -1,11 +1,10 @@
1
1
  package so.kontext.react
2
2
 
3
- import com.facebook.react.bridge.Promise
4
- import com.facebook.react.bridge.ReactApplicationContext
5
3
  import android.content.Context
6
- import android.content.SharedPreferences
7
4
  import android.media.AudioManager
8
- import android.preference.PreferenceManager
5
+ import androidx.preference.PreferenceManager
6
+ import com.facebook.react.bridge.Promise
7
+ import com.facebook.react.bridge.ReactApplicationContext
9
8
 
10
9
  class RNKontextModuleImpl(private val reactContext: ReactApplicationContext) {
11
10
  fun isSoundOn(promise: Promise?) {
@@ -19,34 +18,39 @@ class RNKontextModuleImpl(private val reactContext: ReactApplicationContext) {
19
18
 
20
19
  fun getTcfData(promise: Promise?) {
21
20
  if (promise == null) return
22
-
21
+
23
22
  try {
24
23
  val prefs = PreferenceManager.getDefaultSharedPreferences(reactContext.applicationContext)
25
-
24
+
26
25
  val tcString: String? = prefs.getString("IABTCF_TCString", null)
27
-
28
- // gdprApplies is usually stored as Int, but some CMPs could store it as String
29
- val gdprApplies: Int? = run {
30
- val all = prefs.all
31
- val raw = all["IABTCF_gdprApplies"] ?: return@run null
32
-
33
- when (raw) {
34
- is Int -> raw
35
- is Long -> raw.toInt()
36
- is Boolean -> if (raw) 1 else 0
37
- is String -> raw.toIntOrNull()
38
- is Number -> raw.toInt()
39
- else -> null
40
- }
26
+
27
+ val gdprAppliesRaw: Int? =
28
+ if (prefs.contains("IABTCF_gdprApplies")) {
29
+ // Most CMPs store as Int
30
+ try {
31
+ prefs.getInt("IABTCF_gdprApplies", 0)
32
+ } catch (_: Throwable) {
33
+ // Some CMPs might store as String
34
+ prefs.getString("IABTCF_gdprApplies", null)?.toIntOrNull()
35
+ }
36
+ } else null
37
+
38
+ val gdprApplies: Int? = when (gdprAppliesRaw) {
39
+ 0 -> 0
40
+ 1 -> 1
41
+ else -> null
41
42
  }
42
-
43
+
43
44
  val out = HashMap<String, Any?>(2)
44
45
  out["tcString"] = tcString
45
46
  out["gdprApplies"] = gdprApplies
46
-
47
47
  promise.resolve(out)
48
- } catch (t: Throwable) {
49
- promise.reject("TCF_ERROR", "Failed to read IABTCF TC data from SharedPreferences", t)
48
+ } catch (_: Throwable) {
49
+ // Don’t break preload if reading fails
50
+ val out = HashMap<String, Any?>(2)
51
+ out["tcString"] = null
52
+ out["gdprApplies"] = null
53
+ promise.resolve(out)
50
54
  }
51
55
  }
52
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontextso/sdk-react-native",
3
- "version": "3.3.0-rc.4",
3
+ "version": "3.3.0-rc.6",
4
4
  "description": "Kontext SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -54,7 +54,7 @@
54
54
  "react-native-webview": "^13.10.0"
55
55
  },
56
56
  "dependencies": {
57
- "@kontextso/sdk-react": "^3.0.7"
57
+ "@kontextso/sdk-react": "^3.0.7-rc.2"
58
58
  },
59
59
  "files": [
60
60
  "dist/*",