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

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.
@@ -17,39 +17,38 @@ class RNKontextModuleImpl(private val reactContext: ReactApplicationContext) {
17
17
  promise?.resolve(volume > MINIMAL_VOLUME_THRESHOLD)
18
18
  }
19
19
 
20
- fun getTcfData(promise: Promise) {
20
+ fun getTcfData(promise: Promise?) {
21
+ if (promise == null) return
22
+
21
23
  try {
22
24
  val prefs = PreferenceManager.getDefaultSharedPreferences(reactContext.applicationContext)
23
- val all = prefs.all
24
25
 
25
- val out = HashMap<String, Any?>(32)
26
+ 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
26
32
 
27
- for ((key, value) in all) {
28
- if (!key.startsWith("IABTCF_")) continue
29
- out[key] = normalizeForReactNative(value)
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
41
  }
31
42
 
32
- // Promise.resolve accepts Map<String, Any?> and RN will bridge it to JS object
43
+ val out = HashMap<String, Any?>(2)
44
+ out["tcString"] = tcString
45
+ out["gdprApplies"] = gdprApplies
46
+
33
47
  promise.resolve(out)
34
48
  } catch (t: Throwable) {
35
- promise.reject("TCF_ERROR", "Failed to read IABTCF_* from SharedPreferences", t)
49
+ promise.reject("TCF_ERROR", "Failed to read IABTCF TC data from SharedPreferences", t)
36
50
  }
37
51
  }
38
-
39
- private fun normalizeForReactNative(value: Any?): Any? {
40
- return when (value) {
41
- null -> null
42
- is String -> value
43
- is Boolean -> value
44
- is Int -> value
45
- is Long -> value
46
- is Float -> value
47
- is Double -> value
48
- is Number -> value
49
- else -> value.toString() // extremely rare, but avoids crashing bridge
50
- }
51
- }
52
-
53
52
 
54
53
  companion object {
55
54
  private const val MINIMAL_VOLUME_THRESHOLD = 0.0f
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 }