@usercentrics/react-native-sdk 2.2.2-RC1 → 2.5.1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/android/build.gradle +1 -1
  3. package/android/src/androidTest/java/com/usercentrics/reactnativemodule/RNUsercentricsModuleTest.kt +16 -132
  4. package/android/src/androidTest/java/com/usercentrics/reactnativemodule/api/FakeUsercentricsProxy.kt +4 -31
  5. package/android/src/androidTest/java/com/usercentrics/reactnativemodule/mock/GetTCFDataMock.kt +3 -1
  6. package/android/src/androidTest/java/com/usercentrics/reactnativemodule/mock/GetUSPDataMock.kt +1 -0
  7. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/RNUsercentricsModule.kt +8 -83
  8. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/api/UsercentricsProxy.kt +12 -64
  9. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/extensions/BannerFontExtensions.kt +26 -0
  10. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/extensions/CCPADataExtensions.kt +1 -0
  11. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/extensions/FirstLayerOptionsExtensions.kt +39 -14
  12. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/extensions/TCFDataExtensions.kt +2 -1
  13. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/extensions/UserOptionsExtensions.kt +12 -0
  14. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/extensions/UsercentricsReadyStatusExtensions.kt +1 -1
  15. package/ios/Extensions/BannerSettings+Dict.swift +103 -16
  16. package/ios/Extensions/CCPAData+Dict.swift +1 -0
  17. package/ios/Extensions/ReadyStatus+Dict.swift +1 -1
  18. package/ios/Extensions/UsercentricsOptions+Dict.swift +20 -6
  19. package/ios/Manager/UsercentricsManager.swift +8 -36
  20. package/ios/RNUsercentricsModule.swift +35 -63
  21. package/ios/RNUsercentricsModule.xcodeproj/project.pbxproj +0 -8
  22. package/lib/Usercentrics.d.ts +4 -5
  23. package/lib/Usercentrics.js +4 -8
  24. package/lib/Usercentrics.js.map +1 -1
  25. package/lib/models/BannerSettings.d.ts +26 -4
  26. package/lib/models/BannerSettings.js +25 -1
  27. package/lib/models/BannerSettings.js.map +1 -1
  28. package/lib/models/CCPAData.d.ts +2 -1
  29. package/lib/models/CCPAData.js +2 -1
  30. package/lib/models/CCPAData.js.map +1 -1
  31. package/lib/models/FirstLayerOptions.d.ts +14 -12
  32. package/lib/models/FirstLayerOptions.js +10 -8
  33. package/lib/models/FirstLayerOptions.js.map +1 -1
  34. package/lib/models/NetworkMode.d.ts +4 -0
  35. package/lib/models/NetworkMode.js +6 -0
  36. package/lib/models/NetworkMode.js.map +1 -0
  37. package/lib/models/SecondLayerOptions.d.ts +7 -3
  38. package/lib/models/SecondLayerOptions.js +6 -1
  39. package/lib/models/SecondLayerOptions.js.map +1 -1
  40. package/lib/models/TCFData.d.ts +2 -1
  41. package/lib/models/TCFData.js +2 -1
  42. package/lib/models/TCFData.js.map +1 -1
  43. package/lib/models/UsercentricsOptions.d.ts +3 -2
  44. package/lib/models/UsercentricsOptions.js +2 -1
  45. package/lib/models/UsercentricsOptions.js.map +1 -1
  46. package/lib/models/UsercentricsReadyStatus.d.ts +2 -2
  47. package/lib/models/UsercentricsReadyStatus.js +2 -2
  48. package/lib/models/UsercentricsReadyStatus.js.map +1 -1
  49. package/lib/models/index.d.ts +12 -12
  50. package/lib/models/index.js +12 -12
  51. package/lib/models/index.js.map +1 -1
  52. package/package.json +79 -79
  53. package/android/src/main/java/com/usercentrics/reactnativeusercentrics/extensions/UsercentricsUserInterfaceExtensions.kt +0 -45
  54. package/ios/Extensions/UIFont+UsercentricsFontDict.swift +0 -15
  55. package/ios/Extensions/UsercentricsUISettings+Dict.swift +0 -27
  56. package/lib/models/UsercentricsUIOptions.d.ts +0 -18
  57. package/lib/models/UsercentricsUIOptions.js +0 -21
  58. package/lib/models/UsercentricsUIOptions.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,96 @@
1
+ [Release Notes](https://docs.usercentrics.com/cmp_in_app_sdk/latest/about/history/)
2
+
3
+ # 2.5.1
4
+
5
+ ## Resolved Issues
6
+
7
+ * TCF String solved issue with encoding to shorten the length of the string
8
+
9
+ # 2.5.0
10
+
11
+ ## Features
12
+
13
+ - **[UI]** Controller ID section was redesigned to have a better UX.
14
+ - `CCPAData` exposes the encoded `uspString`.
15
+
16
+ ## Improvements
17
+
18
+ - Improve stability and performance issues.
19
+
20
+ ## Resolved Issues
21
+
22
+ - General bug fixes.
23
+ - **[iOS]** Access to `rootViewController` depending on API version.
24
+
25
+ # 2.4.0
26
+
27
+ ## Features
28
+
29
+ - **[Customization]** You now have full control over the appearance of the First & Second Layer via our Admin Interface Style options and our Programmatic API. We have updated and extended our Programmatic API to simplify banner customization.
30
+ - **[UI]** Legal links are now added to our the First Layer, and can be hidden or shown as desired via programmatic API.
31
+ - **[CCPA]** Consent button can now be customized via the Admin Interface.
32
+
33
+ ## Improvements
34
+
35
+ - Improve initialization flow for stability and avoid edge case crashes.
36
+
37
+ ## Resolved Issues
38
+
39
+ - Solve stability issues and bug fixes.
40
+
41
+ # 2.3.0
42
+
43
+ ## Features
44
+
45
+ - **[API Update]** `shouldShowCMP` has been deprecated in favor of `shouldCollectConsent`. See [Initializing the SDK](https://docs.usercentrics.com/cmp_in_app_sdk/latest/getting_started/initialize/#initializing-the-sdk)
46
+ - **[Banner API v2]** Banner API v1 is now discontinued and removed from the SDK. If you don't wish to upgrade, please stick to v2.0.3 to avoid unexpected behaviour. See the [alert in the "Banner API V1" tab](https://docs.usercentrics.com/cmp_in_app_sdk/latest/collect_consent/present_cmp/)
47
+ - **[Banner API v2]** BannerSettings now requires a BannerFont object to pass a Bold and Regular font separately to apply for both layers. See [Banner Settings](https://docs.usercentrics.com/cmp_in_app_sdk/latest/collect_consent/customize_cmp/#banner-style-settings)
48
+ - **[Demo App]** You can now find a demo app in our documentation to test out your configuration before writing a single line of code. See [Sample Apps](https://docs.usercentrics.com/cmp_in_app_sdk/latest/samples/ios-android-demos/).
49
+
50
+ ## Improvements
51
+
52
+ - Updates to TCF 2.0 framework.
53
+
54
+ ## Resolved Issues
55
+
56
+ - Issue with position of logo on Second Layer is now solved.
57
+ - UI/UX improvements and fixes.
58
+
59
+ # 2.2.1
60
+
61
+ ## Features
62
+
63
+ - **[Banner API v2]** A complete revamp of our banner API will enable you to have high customisation and versatility to build a end-user friendly consent banner. We can't wait for you to give it a try. For more details, see: Presenting the Banner.
64
+ - Add a Header Image to your banner.
65
+ - Have full control over the layour of your action buttons with Column, Row or Grid configurations.
66
+ - Launch the second layer directly.
67
+ - Landscape Mode support.
68
+ - You can now add a "More Information" link to your banner message to forward users to the 2nd Layer. Appearance > Settings > More Information Link in Banner Message. Then you will be able to add this link in the banner message text editor.
69
+ - **[Usability]** Collect consent only at a category level. Option available in your Admin Interface: Configure > Legal Specifications > Settings > Category Consent.
70
+ - **[CNIL]** "Continue wthout Accepting" feature is now supported. (French regulation)
71
+ - **[Fonts]** Admin Interface fonts are now deprecated for App. To enable custom fonts, please inject the font via banner API.
72
+
73
+ ## Improvements
74
+
75
+ - **[API]** Expose user's consent history.
76
+ - **[TCF 2.0]** Adding support to actively inform users when vendors are sharing data outside a region.
77
+ - **[CCPA]** Improve API to facilitate compliance with new Banner API.
78
+
79
+ ## Resolved Issues
80
+ - **[TCF 2.0]** Minor design upgrades to improve usability.
81
+ - **[iOS]** Edge case with RestoreUserSession failing is now solved.
82
+ - **[iOS]** Issue with local and remote images losing quality is now solved.
83
+ - UI/UX improvements and fixes.
84
+
85
+ # 2.0.3
86
+
87
+ - Minor fix on UI related to consent toggles.
88
+ - Corner radius on iOS.
89
+
90
+ # 2.0.2
91
+
92
+ - Custom UI API.
93
+
94
+ # 2.0.1
95
+
96
+ - Initial version of the library.
@@ -1,4 +1,4 @@
1
- def usercentrics_version = "2.2.1"
1
+ def usercentrics_version = "2.5.1"
2
2
  version usercentrics_version
3
3
 
4
4
  buildscript {
@@ -2,7 +2,10 @@ package com.usercentrics.reactnativemodule
2
2
 
3
3
  import androidx.test.ext.junit.runners.AndroidJUnit4
4
4
  import androidx.test.platform.app.InstrumentationRegistry
5
- import com.facebook.react.bridge.*
5
+ import com.facebook.react.bridge.JavaOnlyMap
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.bridge.WritableArray
8
+ import com.facebook.react.bridge.WritableMap
6
9
  import com.facebook.soloader.SoLoader
7
10
  import com.usercentrics.reactnativemodule.api.FakeUsercentricsProxy
8
11
  import com.usercentrics.reactnativemodule.fake.FakePromise
@@ -12,15 +15,16 @@ import com.usercentrics.reactnativeusercentrics.extensions.serialize
12
15
  import com.usercentrics.reactnativeusercentrics.extensions.toWritableMap
13
16
  import com.usercentrics.sdk.*
14
17
  import com.usercentrics.sdk.errors.UsercentricsError
18
+ import com.usercentrics.sdk.models.common.NetworkMode
15
19
  import com.usercentrics.sdk.models.common.UsercentricsLoggerLevel
16
20
  import com.usercentrics.sdk.models.common.UsercentricsVariant
17
21
  import com.usercentrics.sdk.models.settings.UsercentricsConsentType
18
22
  import com.usercentrics.sdk.services.tcf.TCFDecisionUILayer
23
+ import com.usercentrics.sdk.services.tcf.interfaces.TCFData
19
24
  import io.mockk.every
20
25
  import io.mockk.mockk
21
26
  import io.mockk.verify
22
27
  import org.junit.Assert.assertEquals
23
- import org.junit.Assert.assertThrows
24
28
  import org.junit.Before
25
29
  import org.junit.Test
26
30
  import org.junit.runner.RunWith
@@ -34,6 +38,7 @@ class RNUsercentricsModuleTest {
34
38
  putInt("loggerlevel", 0)
35
39
  putInt("timeoutMillis", 1000)
36
40
  putString("version", "1.2.3")
41
+ putInt("networkMode", 1)
37
42
  }
38
43
 
39
44
  private val usercentricsConsentHistoryEntries = listOf(
@@ -45,7 +50,7 @@ class RNUsercentricsModuleTest {
45
50
  )
46
51
 
47
52
  private val usercentricsReadyStatus = UsercentricsReadyStatus(
48
- shouldShowCMP = false,
53
+ shouldCollectConsent = false,
49
54
  consents = listOf(
50
55
  UsercentricsServiceConsent(
51
56
  templateId = "ocv9HNX_g",
@@ -58,37 +63,6 @@ class RNUsercentricsModuleTest {
58
63
  )
59
64
  )
60
65
  )
61
-
62
- private val usercentricsUIOptions = JavaOnlyMap().apply {
63
- putBoolean("showCloseButton", false)
64
- putMap("customLogo", JavaOnlyMap().apply {
65
- putString("logoName", "logo.png")
66
- putString(
67
- "logoPath",
68
- "http://10.0.2.2:8081/assets/assets/images/logo.png"
69
- )
70
- })
71
- putMap("customFont", JavaOnlyMap().apply {
72
- putString("fontName", "Lora")
73
- putInt("fontSize", 14)
74
- })
75
- }
76
-
77
- private val usercentricsConsentUserResponse = UsercentricsConsentUserResponse(
78
- consents = listOf(
79
- UsercentricsServiceConsent(
80
- templateId = "ocv9HNX_g",
81
- status = false,
82
- dataProcessor = "Facebook SDK",
83
- type = UsercentricsConsentType.EXPLICIT,
84
- version = "1.0.1",
85
- isEssential = false,
86
- history = usercentricsConsentHistoryEntries
87
- )
88
- ),
89
- controllerId = "8620135313b043696b806868b20da905886a3a2598ddddc2b52973f9807d6b45",
90
- userInteraction = UsercentricsUserInteraction.ACCEPT_ALL
91
- )
92
66
  }
93
67
 
94
68
  @Before
@@ -123,6 +97,7 @@ class RNUsercentricsModuleTest {
123
97
  )
124
98
  assertEquals(1000L, usercentricsProxy.initializeOptionsArgument?.timeoutMillis)
125
99
  assertEquals("1.2.3", usercentricsProxy.initializeOptionsArgument?.version)
100
+ assertEquals(NetworkMode.EU, usercentricsProxy.initializeOptionsArgument?.networkMode)
126
101
  }
127
102
 
128
103
  @Test
@@ -148,7 +123,7 @@ class RNUsercentricsModuleTest {
148
123
  val consent = result.getArray("consents")?.getMap(0)!!
149
124
 
150
125
  assertEquals(1, usercentricsProxy.isReadyCount)
151
- assertEquals(false, result.getBoolean("shouldShowCMP"))
126
+ assertEquals(false, result.getBoolean("shouldCollectConsent"))
152
127
  assertEquals(false, consent.getBoolean("status"))
153
128
  assertEquals("ocv9HNX_g", consent.getString("templateId"))
154
129
  assertEquals("Facebook SDK", consent.getString("dataProcessor"))
@@ -191,7 +166,7 @@ class RNUsercentricsModuleTest {
191
166
  val result = promise.resolveValue as WritableMap
192
167
  val consent = result.getArray("consents")?.getMap(0)!!
193
168
 
194
- assertEquals(false, result.getBoolean("shouldShowCMP"))
169
+ assertEquals(false, result.getBoolean("shouldCollectConsent"))
195
170
  assertEquals(false, consent.getBoolean("status"))
196
171
  assertEquals("ocv9HNX_g", consent.getString("templateId"))
197
172
  assertEquals("Facebook SDK", consent.getString("dataProcessor"))
@@ -233,98 +208,6 @@ class RNUsercentricsModuleTest {
233
208
  assertEquals("abc", promise.resolveValue)
234
209
  }
235
210
 
236
- @Test
237
- fun testGetTCString() {
238
- val usercentricsSDK = mockk<UsercentricsSDK>()
239
- every { usercentricsSDK.getTCString() }.returns("abc")
240
- val usercentricsProxy = FakeUsercentricsProxy(usercentricsSDK)
241
- val contextMock = mockk<ReactApplicationContext>(relaxed = true)
242
- val module = RNUsercentricsModule(contextMock, usercentricsProxy)
243
- val promise = FakePromise()
244
-
245
- module.getTCFString(promise)
246
-
247
- verify(exactly = 1) { usercentricsSDK.getTCString() }
248
- assertEquals("abc", promise.resolveValue)
249
- }
250
-
251
- @Test
252
- fun testShowCMP() {
253
- val usercentricsProxy = FakeUsercentricsProxy()
254
- usercentricsProxy.createIntentValue = mockk(relaxed = true)
255
-
256
- val contextMock = mockk<ReactApplicationContext>(relaxed = true)
257
- val module = RNUsercentricsModule(contextMock, usercentricsProxy)
258
- val promise = FakePromise()
259
-
260
- module.showCMP(usercentricsUIOptions, promise)
261
-
262
- val responseUsercentricsOptions = usercentricsProxy.usercentricsOptions!!
263
- val customLogoURL =
264
- (responseUsercentricsOptions.customLogo as UsercentricsImage.ImageUrl).imageUrl
265
-
266
- assertEquals(false, responseUsercentricsOptions.showCloseButton)
267
- assertEquals(
268
- "http://10.0.2.2:8081/assets/assets/images/logo.png",
269
- customLogoURL
270
- )
271
- }
272
-
273
- @Test
274
- fun testOnActivityResultWithOtherCode() {
275
- val usercentricsProxy = FakeUsercentricsProxy()
276
- val contextMock = mockk<ReactApplicationContext>(relaxed = true)
277
- val module = RNUsercentricsModule(contextMock, usercentricsProxy)
278
-
279
- val otherRequestCode = 123
280
- val consumed = module.parseActivityResult(otherRequestCode, 123, null)
281
-
282
- assertEquals(false, consumed)
283
- }
284
-
285
- @Test
286
- fun testOnActivityResultWithNoPendingResult() {
287
- val usercentricsProxy = FakeUsercentricsProxy()
288
- val contextMock = mockk<ReactApplicationContext>(relaxed = true)
289
- val module = RNUsercentricsModule(contextMock, usercentricsProxy)
290
-
291
- assertThrows(AssertionError::class.java) {
292
- module.parseActivityResult(81420, 123, null)
293
- }
294
- }
295
-
296
- @Test
297
- fun testOnActivityResultWithPendingResult() {
298
- val resultCode = 123
299
- val usercentricsProxy = FakeUsercentricsProxy()
300
- usercentricsProxy.createIntentValue = mockk(relaxed = true)
301
- usercentricsProxy.parseResultValue = usercentricsConsentUserResponse
302
-
303
- val contextMock = mockk<ReactApplicationContext>(relaxed = true)
304
- val module = RNUsercentricsModule(contextMock, usercentricsProxy)
305
-
306
- val promise = FakePromise()
307
- module.showCMP(usercentricsUIOptions, promise)
308
-
309
- module.parseActivityResult(81420, resultCode, null)
310
-
311
- assertEquals(resultCode, usercentricsProxy.parseResultResultCodeArgument)
312
-
313
- val result = promise.resolveValue as WritableMap
314
- val consent = result.getArray("consents")?.getMap(0)!!
315
-
316
- assertEquals(
317
- "8620135313b043696b806868b20da905886a3a2598ddddc2b52973f9807d6b45",
318
- result.getString("controllerId")
319
- )
320
- assertEquals(0, result.getInt("userInteraction"))
321
- assertEquals(false, consent.getBoolean("status"))
322
- assertEquals("ocv9HNX_g", consent.getString("templateId"))
323
- assertEquals("Facebook SDK", consent.getString("dataProcessor"))
324
- assertEquals(0, consent.getInt("type"))
325
- assertEquals("1.0.1", consent.getString("version"))
326
- }
327
-
328
211
  @Test
329
212
  fun testGetConsents() {
330
213
  val usercentricsSDK = mockk<UsercentricsSDK>()
@@ -412,7 +295,9 @@ class RNUsercentricsModuleTest {
412
295
  @Test
413
296
  fun testGetTCFData() {
414
297
  val usercentricsSDK = mockk<UsercentricsSDK>()
415
- every { usercentricsSDK.getTCFData() }.returns(GetTCFDataMock.fake)
298
+ every { usercentricsSDK.getTCFData(any()) }.answers {
299
+ firstArg<(TCFData) -> Unit>().invoke(GetTCFDataMock.fake)
300
+ }
416
301
 
417
302
  val usercentricsProxy = FakeUsercentricsProxy(usercentricsSDK)
418
303
  val contextMock = mockk<ReactApplicationContext>(relaxed = true)
@@ -423,7 +308,7 @@ class RNUsercentricsModuleTest {
423
308
 
424
309
  val result = promise.resolveValue
425
310
 
426
- verify(exactly = 1) { usercentricsSDK.getTCFData() }
311
+ verify(exactly = 1) { usercentricsSDK.getTCFData(any()) }
427
312
  assertEquals(GetTCFDataMock.expected.toWritableMap(), result)
428
313
  }
429
314
 
@@ -669,7 +554,6 @@ class RNUsercentricsModuleTest {
669
554
  GetConsentsMock.fakeWithData
670
555
  )
671
556
 
672
-
673
557
  val usercentricsProxy = FakeUsercentricsProxy(usercentricsSDK)
674
558
  val contextMock = mockk<ReactApplicationContext>(relaxed = true)
675
559
  val module = RNUsercentricsModule(contextMock, usercentricsProxy)
@@ -696,4 +580,4 @@ class RNUsercentricsModuleTest {
696
580
 
697
581
  assertEquals(1, usercentricsProxy.resetCount)
698
582
  }
699
- }
583
+ }
@@ -42,26 +42,6 @@ internal class FakeUsercentricsProxy(
42
42
  }
43
43
  }
44
44
 
45
- var createIntentValue: Intent? = null
46
- var usercentricsOptions: UsercentricsUISettings? = null
47
- private set
48
-
49
- override fun createIntent(
50
- context: Context,
51
- usercentricsOptions: UsercentricsUISettings
52
- ): Intent {
53
- this.usercentricsOptions = usercentricsOptions
54
- return createIntentValue!!
55
- }
56
-
57
- var parseResultResultCodeArgument: Int = 0
58
- private set
59
- var parseResultValue: UsercentricsConsentUserResponse? = null
60
- override fun parseResult(resultCode: Int, data: Intent?): UsercentricsConsentUserResponse? {
61
- this.parseResultResultCodeArgument = resultCode
62
- return parseResultValue
63
- }
64
-
65
45
  var resetCount: Int = 0
66
46
  private set
67
47
 
@@ -73,19 +53,12 @@ internal class FakeUsercentricsProxy(
73
53
  var showFirstLayerBannerSettings: BannerSettings? = null
74
54
  var showFirstLayerStyle: FirstLayerStyleSettings? = null
75
55
 
76
- override fun showFirstLayer(
77
- activity: Activity,
78
- layout: UsercentricsLayout,
79
- bannerSettings: BannerSettings?,
80
- firstLayerStyleSettings: FirstLayerStyleSettings?,
81
- promise: Promise
82
- ) {
56
+ override fun showFirstLayer(activity: Activity, layout: UsercentricsLayout, bannerSettings: BannerSettings?, promise: Promise) {
83
57
  this.showFirstLayerLayout = layout
84
58
  this.showFirstLayerBannerSettings = bannerSettings
85
- this.showFirstLayerStyle = firstLayerStyleSettings
59
+ this.showFirstLayerStyle = bannerSettings?.firstLayerSettings
86
60
  }
87
61
 
88
- override fun showSecondLayer() {
89
-
62
+ override fun showSecondLayer(activity: Activity, bannerSettings: BannerSettings?, promise: Promise) {
90
63
  }
91
- }
64
+ }
@@ -95,6 +95,7 @@ internal class GetTCFDataMock {
95
95
  dataSharedOutsideEU = false
96
96
  )
97
97
  ),
98
+ tcString = "abc"
98
99
  )
99
100
 
100
101
  // From the debugger
@@ -186,6 +187,7 @@ internal class GetTCFDataMock {
186
187
  "dataSharedOutsideEU" to false
187
188
  ),
188
189
  ),
190
+ "tcString" to "abc"
189
191
  )
190
192
  }
191
- }
193
+ }
@@ -13,6 +13,7 @@ internal class GetUSPDataMock {
13
13
 
14
14
  // From the debugger
15
15
  val expected = mapOf(
16
+ "uspString" to "1YN-",
16
17
  "version" to 1,
17
18
  "noticeGiven" to true,
18
19
  "optedOut" to false,
@@ -1,15 +1,10 @@
1
1
  package com.usercentrics.reactnativeusercentrics
2
2
 
3
- import android.app.Activity
4
- import android.content.Intent
5
3
  import com.facebook.react.bridge.*
6
4
  import com.usercentrics.reactnativeusercentrics.api.UsercentricsProxy
7
5
  import com.usercentrics.reactnativeusercentrics.extensions.*
8
- import com.usercentrics.sdk.UsercentricsBanner
9
- import com.usercentrics.sdk.UsercentricsLayout
10
6
  import com.usercentrics.sdk.models.settings.UsercentricsConsentType
11
7
  import com.usercentrics.sdk.services.tcf.TCFDecisionUILayer
12
- import java.lang.Exception
13
8
 
14
9
  internal class RNUsercentricsModule(
15
10
  reactContext: ReactApplicationContext,
@@ -19,39 +14,10 @@ internal class RNUsercentricsModule(
19
14
 
20
15
  override fun getName() = "RNUsercentricsModule"
21
16
 
22
- private var pendingPromise: Promise? = null
23
- private val listener: ActivityEventListener = object : BaseActivityEventListener() {
24
- override fun onActivityResult(
25
- activity: Activity?,
26
- requestCode: Int,
27
- resultCode: Int,
28
- data: Intent?
29
- ) {
30
- parseActivityResult(requestCode, resultCode, data)
31
- }
32
- }
33
-
34
- init {
35
- reactApplicationContext.addActivityEventListener(listener)
36
- }
37
-
38
- companion object {
39
- private const val showCMPRequestCode = 81420
40
- }
41
-
42
17
  @ReactMethod
43
18
  fun configure(options: ReadableMap) {
44
- var alreadyConfigured = false
45
- usercentricsProxy.isReady({
46
- alreadyConfigured = true
47
- }, {
48
- alreadyConfigured = true
49
- })
50
-
51
- if (!alreadyConfigured) {
52
- val usercentricsOptions = options.usercentricsOptionsFromMap() ?: return
53
- usercentricsProxy.initialize(reactApplicationContext, usercentricsOptions)
54
- }
19
+ val usercentricsOptions = options.usercentricsOptionsFromMap() ?: return
20
+ usercentricsProxy.initialize(reactApplicationContext, usercentricsOptions)
55
21
  }
56
22
 
57
23
  @ReactMethod
@@ -63,15 +29,6 @@ internal class RNUsercentricsModule(
63
29
  })
64
30
  }
65
31
 
66
- @ReactMethod
67
- fun showCMP(options: ReadableMap, promise: Promise) {
68
- val usercentricsOptions = options.usercentricsUISettingsFromMap(currentActivity!!.assets)
69
- this.pendingPromise = promise
70
-
71
- val intent = usercentricsProxy.createIntent(reactApplicationContext, usercentricsOptions)
72
- currentActivity?.startActivityForResult(intent, showCMPRequestCode)
73
- }
74
-
75
32
  @ReactMethod
76
33
  fun showFirstLayer(options: ReadableMap, promise: Promise) {
77
34
  UiThreadUtil.runOnUiThread {
@@ -81,16 +38,7 @@ internal class RNUsercentricsModule(
81
38
  val layout = options.getString("layout")!!.usercentricsLayoutFromEnumString()
82
39
  val bannerSettings =
83
40
  options.getMap("bannerSettings")?.bannerSettingsFromMap(assetManager)
84
- val styleSettings =
85
- options.getMap("styleSettings")?.firstLayerStyleSettingsFromMap(assetManager)
86
-
87
- usercentricsProxy.showFirstLayer(
88
- currentActivity!!,
89
- layout,
90
- bannerSettings,
91
- styleSettings,
92
- promise
93
- )
41
+ usercentricsProxy.showFirstLayer(currentActivity!!, layout, bannerSettings, promise)
94
42
 
95
43
  } catch (e: Exception) {
96
44
  promise.reject(e)
@@ -106,33 +54,13 @@ internal class RNUsercentricsModule(
106
54
 
107
55
  val bannerSettings =
108
56
  options.getMap("bannerSettings")?.bannerSettingsFromMap(assetManager)
109
- val showCloseButton = options.getBoolean("showCloseButton")
110
-
111
-
112
- UsercentricsBanner(currentActivity!!, bannerSettings).showSecondLayer(
113
- showCloseButton
114
- ) {
115
- promise.resolve(it?.toWritableMap())
116
- }
117
-
57
+ usercentricsProxy.showSecondLayer(currentActivity!!, bannerSettings, promise)
118
58
  } catch (e: Exception) {
119
59
  promise.reject(e)
120
60
  }
121
61
  }
122
62
  }
123
63
 
124
- internal fun parseActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
125
- if (requestCode != showCMPRequestCode) return false
126
- assert(pendingPromise != null)
127
-
128
- val response = usercentricsProxy.parseResult(resultCode, data)?.toWritableMap()
129
-
130
- pendingPromise?.resolve(response)
131
- pendingPromise = null
132
-
133
- return true
134
- }
135
-
136
64
  @ReactMethod
137
65
  fun restoreUserSession(controllerId: String, promise: Promise) {
138
66
  usercentricsProxy.instance.restoreUserSession(controllerId, {
@@ -142,11 +70,6 @@ internal class RNUsercentricsModule(
142
70
  })
143
71
  }
144
72
 
145
- @ReactMethod
146
- fun getTCFString(promise: Promise) {
147
- promise.resolve(usercentricsProxy.instance.getTCString())
148
- }
149
-
150
73
  @ReactMethod
151
74
  fun getControllerId(promise: Promise) {
152
75
  promise.resolve(usercentricsProxy.instance.getControllerId())
@@ -169,7 +92,9 @@ internal class RNUsercentricsModule(
169
92
 
170
93
  @ReactMethod
171
94
  fun getTCFData(promise: Promise) {
172
- promise.resolve(usercentricsProxy.instance.getTCFData().serialize())
95
+ usercentricsProxy.instance.getTCFData {
96
+ promise.resolve(it.serialize())
97
+ }
173
98
  }
174
99
 
175
100
  @ReactMethod
@@ -271,4 +196,4 @@ internal class RNUsercentricsModule(
271
196
  fun reset() {
272
197
  usercentricsProxy.reset()
273
198
  }
274
- }
199
+ }
@@ -2,45 +2,19 @@ package com.usercentrics.reactnativeusercentrics.api
2
2
 
3
3
  import android.app.Activity
4
4
  import android.content.Context
5
- import android.content.Intent
6
- import android.util.Log
7
5
  import com.facebook.react.bridge.Promise
8
- import com.facebook.react.bridge.ReadableMap
9
- import com.usercentrics.reactnativeusercentrics.extensions.bannerSettingsFromMap
10
- import com.usercentrics.reactnativeusercentrics.extensions.firstLayerStyleSettingsFromMap
11
6
  import com.usercentrics.reactnativeusercentrics.extensions.toWritableMap
12
- import com.usercentrics.reactnativeusercentrics.extensions.usercentricsLayoutFromEnumString
13
7
  import com.usercentrics.sdk.*
14
8
  import com.usercentrics.sdk.errors.UsercentricsError
15
- import java.lang.Exception
16
9
 
17
10
  interface UsercentricsProxy {
11
+
18
12
  val instance: UsercentricsSDK
19
13
 
20
14
  fun initialize(context: Context, options: UsercentricsOptions)
21
-
22
- fun isReady(
23
- onSuccess: (UsercentricsReadyStatus) -> Unit,
24
- onFailure: (UsercentricsError) -> Unit
25
- )
26
-
27
- fun createIntent(
28
- context: Context,
29
- usercentricsOptions: UsercentricsUISettings
30
- ): Intent
31
-
32
- fun parseResult(resultCode: Int, data: Intent?): UsercentricsConsentUserResponse?
33
-
34
- fun showFirstLayer(
35
- activity: Activity,
36
- layout: UsercentricsLayout,
37
- bannerSettings: BannerSettings?,
38
- firstLayerStyleSettings: FirstLayerStyleSettings?,
39
- promise: Promise
40
- )
41
-
42
- fun showSecondLayer()
43
-
15
+ fun isReady(onSuccess: (UsercentricsReadyStatus) -> Unit, onFailure: (UsercentricsError) -> Unit)
16
+ fun showFirstLayer(activity: Activity, layout: UsercentricsLayout, bannerSettings: BannerSettings?, promise: Promise)
17
+ fun showSecondLayer(activity: Activity, bannerSettings: BannerSettings?, promise: Promise)
44
18
  fun reset()
45
19
  }
46
20
 
@@ -57,45 +31,19 @@ internal class UsercentricsProxyImpl : UsercentricsProxy {
57
31
  }
58
32
  }
59
33
 
60
- override fun isReady(
61
- onSuccess: (UsercentricsReadyStatus) -> Unit,
62
- onFailure: (UsercentricsError) -> Unit
63
- ) = Usercentrics.isReady(onSuccess, onFailure)
64
-
65
- override fun createIntent(
66
- context: Context,
67
- usercentricsOptions: UsercentricsUISettings
68
- ): Intent {
69
- return UsercentricsActivityContract().createIntent(
70
- context,
71
- usercentricsOptions
72
- )
73
- }
74
-
75
- override fun parseResult(resultCode: Int, data: Intent?): UsercentricsConsentUserResponse? {
76
- return UsercentricsActivityContract()
77
- .parseResult(resultCode, data)
78
- }
34
+ override fun isReady(onSuccess: (UsercentricsReadyStatus) -> Unit, onFailure: (UsercentricsError) -> Unit) = Usercentrics.isReady(onSuccess, onFailure)
79
35
 
80
- override fun showFirstLayer(
81
- activity: Activity,
82
- layout: UsercentricsLayout,
83
- bannerSettings: BannerSettings?,
84
- firstLayerStyleSettings: FirstLayerStyleSettings?,
85
- promise: Promise
86
- ) {
87
- UsercentricsBanner(activity, bannerSettings).showFirstLayer(
88
- layout,
89
- firstLayerStyleSettings
90
- ) {
36
+ override fun showFirstLayer(activity: Activity, layout: UsercentricsLayout, bannerSettings: BannerSettings?, promise: Promise) {
37
+ UsercentricsBanner(activity, bannerSettings).showFirstLayer(layout) {
91
38
  promise.resolve(it?.toWritableMap())
92
39
  }
93
40
  }
94
41
 
95
- override fun showSecondLayer() {
96
-
42
+ override fun showSecondLayer(activity: Activity, bannerSettings: BannerSettings?, promise: Promise) {
43
+ UsercentricsBanner(activity, bannerSettings).showSecondLayer {
44
+ promise.resolve(it?.toWritableMap())
45
+ }
97
46
  }
98
47
 
99
48
  override fun reset() = Usercentrics.reset()
100
-
101
- }
49
+ }