@kontextso/sdk-react-native 3.3.0-rc.5 → 3.3.0

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,13 +1,16 @@
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.Arguments
7
+ import com.facebook.react.bridge.Promise
8
+ import com.facebook.react.bridge.ReactApplicationContext
9
+ import com.facebook.react.bridge.WritableMap
10
+
9
11
 
10
12
  class RNKontextModuleImpl(private val reactContext: ReactApplicationContext) {
13
+
11
14
  fun isSoundOn(promise: Promise?) {
12
15
  val audioManager = reactContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
13
16
  val current = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)
@@ -19,34 +22,38 @@ class RNKontextModuleImpl(private val reactContext: ReactApplicationContext) {
19
22
 
20
23
  fun getTcfData(promise: Promise?) {
21
24
  if (promise == null) return
22
-
25
+
23
26
  try {
24
27
  val prefs = PreferenceManager.getDefaultSharedPreferences(reactContext.applicationContext)
25
-
28
+
26
29
  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
- }
30
+
31
+ val gdprAppliesRaw: Int? =
32
+ if (prefs.contains("IABTCF_gdprApplies")) {
33
+ try {
34
+ prefs.getInt("IABTCF_gdprApplies", 0)
35
+ } catch (_: Throwable) {
36
+ prefs.getString("IABTCF_gdprApplies", null)?.toIntOrNull()
37
+ }
38
+ } else null
39
+
40
+ val gdprApplies: Int? = when (gdprAppliesRaw) {
41
+ 0 -> 0
42
+ 1 -> 1
43
+ else -> null
41
44
  }
42
-
43
- val out = HashMap<String, Any?>(2)
44
- out["tcString"] = tcString
45
- out["gdprApplies"] = gdprApplies
46
-
45
+
46
+ val out: WritableMap = Arguments.createMap()
47
+
48
+ if (tcString != null) out.putString("tcString", tcString) else out.putNull("tcString")
49
+ if (gdprApplies != null) out.putInt("gdprApplies", gdprApplies) else out.putNull("gdprApplies")
50
+
51
+ promise.resolve(out)
52
+ } catch (_: Throwable) {
53
+ val out: WritableMap = Arguments.createMap()
54
+ out.putNull("tcString")
55
+ out.putNull("gdprApplies")
47
56
  promise.resolve(out)
48
- } catch (t: Throwable) {
49
- promise.reject("TCF_ERROR", "Failed to read IABTCF TC data from SharedPreferences", t)
50
57
  }
51
58
  }
52
59
 
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime'
2
- import { FormatProps, AdsProviderProps } from '@kontextso/sdk-react'
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { FormatProps, AdsProviderProps } from '@kontextso/sdk-react';
3
3
 
4
- declare const InlineAd: ({ code, messageId, wrapper, ...props }: FormatProps) => react_jsx_runtime.JSX.Element
4
+ declare const InlineAd: ({ code, messageId, wrapper, ...props }: FormatProps) => react_jsx_runtime.JSX.Element;
5
5
 
6
- declare const AdsProvider: (props: AdsProviderProps) => react_jsx_runtime.JSX.Element
6
+ declare const AdsProvider: (props: AdsProviderProps) => react_jsx_runtime.JSX.Element;
7
7
 
8
- export { AdsProvider, InlineAd }
8
+ export { AdsProvider, InlineAd };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime'
2
- import { FormatProps, AdsProviderProps } from '@kontextso/sdk-react'
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { FormatProps, AdsProviderProps } from '@kontextso/sdk-react';
3
3
 
4
- declare const InlineAd: ({ code, messageId, wrapper, ...props }: FormatProps) => react_jsx_runtime.JSX.Element
4
+ declare const InlineAd: ({ code, messageId, wrapper, ...props }: FormatProps) => react_jsx_runtime.JSX.Element;
5
5
 
6
- declare const AdsProvider: (props: AdsProviderProps) => react_jsx_runtime.JSX.Element
6
+ declare const AdsProvider: (props: AdsProviderProps) => react_jsx_runtime.JSX.Element;
7
7
 
8
- export { AdsProvider, InlineAd }
8
+ export { AdsProvider, InlineAd };