From 57af2e8c118dadd84c985a4adf1b5859eb3dc9dc Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 22 Jul 2025 14:04:09 +0200 Subject: [PATCH 01/10] add `postCustomConsent` and implementation for it in android --- .../reactnativecmp/ReactNativeCmpModule.kt | 18 ++++++++++ .../reactnativecmp/arguments/Arguments.kt | 9 +++++ example/src/App.tsx | 36 ++++++++++++++++++- src/NativeReactNativeCmp.ts | 12 +++++++ src/index.tsx | 19 ++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt index 011ea4e..5368298 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt @@ -2,10 +2,12 @@ package com.sourcepoint.reactnativecmp import android.view.View import com.facebook.react.bridge.Arguments.createMap +import com.facebook.react.bridge.Callback import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableMap +import com.facebook.react.bridge.ReadableArray import com.facebook.react.module.annotations.ReactModule import com.sourcepoint.cmplibrary.NativeMessageController import com.sourcepoint.cmplibrary.SpClient @@ -20,6 +22,8 @@ import com.sourcepoint.cmplibrary.model.exposed.SPConsents import com.sourcepoint.cmplibrary.util.clearAllData import com.sourcepoint.cmplibrary.util.userConsents import com.sourcepoint.reactnativecmp.consents.RNSPUserData +import com.sourcepoint.reactnativecmp.consents.RNSPGDPRConsent +import com.sourcepoint.reactnativecmp.arguments.toStringList import org.json.JSONObject data class SPLoadMessageParams(val authId: String?) { @@ -114,6 +118,20 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN runOnMainThread { spConsentLib?.loadPrivacyManager(id, PREFERENCES) } } + @ReactMethod + override fun postCustomConsent(vendors: ReadableArray, categories: ReadableArray, legIntCategories: ReadableArray, callback: Callback) { + runOnMainThread { + spConsentLib?.customConsentGDPR(vendors.toStringList(), categories.toStringList(), legIntCategories.toStringList(), success = { spconsents: SPConsents? -> spconsents?.let { callback.invoke(RNSPGDPRConsent(it.gdpr!!.consent).toRN()) }}) + } + } + + @ReactMethod + override fun postDeleteCustomConsent(vendors: ReadableArray, categories: ReadableArray, legIntCategories: ReadableArray, callback: Callback) { + runOnMainThread { + spConsentLib?.deleteCustomConsentTo(vendors.toStringList(), categories.toStringList(), legIntCategories.toStringList(), success = { spconsents: SPConsents? -> spconsents?.let { callback.invoke(RNSPGDPRConsent(it.gdpr!!.consent).toRN()) }}) + } + } + companion object { const val NAME = "ReactNativeCmp" } diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt index 06c971a..10a7636 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt @@ -3,6 +3,7 @@ package com.sourcepoint.reactnativecmp.arguments import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableArray import com.facebook.react.bridge.WritableMap +import com.facebook.react.bridge.ReadableArray import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject @@ -158,3 +159,11 @@ fun WritableMap.putArray(name: String, value: Iterable<*>) { value.forEach { this.pushAny(it) } }) } + +fun ReadableArray.toStringList(): List { + val list = mutableListOf() + for (i in 0 until this.size()) { + this.getString(i)?.let { list.add(it) } + } + return list +} \ No newline at end of file diff --git a/example/src/App.tsx b/example/src/App.tsx index 2602b2b..6a86581 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -12,7 +12,7 @@ import { LaunchArguments } from 'react-native-launch-arguments'; import SPConsentManager, { SPCampaignEnvironment, } from '@sourcepoint/react-native-cmp'; -import type { SPCampaigns, SPUserData } from '@sourcepoint/react-native-cmp'; +import type { GDPRConsent, SPCampaigns, SPUserData } from '@sourcepoint/react-native-cmp'; import type { LaunchArgs } from './LaunchArgs'; import UserDataView from './UserDataView'; @@ -121,6 +121,30 @@ export default function App() { consentManager.current?.loadPreferenceCenter(config.preferencesCenterId); }, []); + const onCustomConsentPress = useCallback(() => { + setSDKStatus(SDKStatus.Networking); + consentManager.current?.postCustomConsent( + ["5ff4d000a228633ac048be41"], + ["608bad95d08d3112188e0e36", "608bad95d08d3112188e0e2f"], + [], + (consent: GDPRConsent) => { + console.log('GDPRConsent:', consent); + setSDKStatus(SDKStatus.Finished); + }); + }, []); + + const onDeleteCustomConsentPress = useCallback(() => { + setSDKStatus(SDKStatus.Networking); + consentManager.current?.postDeleteCustomConsent( + ["5ff4d000a228633ac048be41"], + ["608bad95d08d3112188e0e36", "608bad95d08d3112188e0e2f"], + [], + (consent: GDPRConsent) => { + console.log('GDPRConsent:', consent); + setSDKStatus(SDKStatus.Finished); + }); + }, []); + const onClearDataPress = useCallback(() => { consentManager.current?.clearLocalData(); consentManager.current?.build( @@ -176,6 +200,16 @@ export default function App() { onPress={onPreferencesPress} disabled={disable || config.campaigns.preferences == undefined} /> +