From b65915449122a848e478003ff864d6faa3cddd70 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 19 Aug 2025 16:15:22 +0200 Subject: [PATCH 1/5] add `dismissMessageOnBackPress` to `BuildOptions` --- .../com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt | 2 +- .../sourcepoint/reactnativecmp/arguments/BuildOptions.kt | 4 +++- example/src/App.tsx | 7 +++++-- src/NativeReactNativeCmp.ts | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt index b9b8656..89e673a 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt @@ -67,7 +67,7 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN }.build() reactApplicationContext.currentActivity?.let { - spConsentLib = makeConsentLib(config, it, this) + spConsentLib = makeConsentLib(config, it, this, parsedOptions.dismissMessageOnBackPress) } ?: run { onError(Error("No activity found when building the SDK")) } diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt index e448fc1..f878ac7 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt @@ -7,11 +7,13 @@ import com.sourcepoint.cmplibrary.model.MessageLanguage.ENGLISH data class BuildOptions( val language: MessageLanguage, val messageTimeoutInSeconds: Long, + val dismissMessageOnBackPress: Boolean ) { val messageTimeoutInMilliseconds = messageTimeoutInSeconds * 1000L constructor(options: ReadableMap?) : this( language = MessageLanguage.entries.find { it.value == options?.getString("language") } ?: ENGLISH, - messageTimeoutInSeconds = options?.getDoubleOrNull("messageTimeoutInSeconds")?.toLong() ?: 30L + messageTimeoutInSeconds = options?.getDoubleOrNull("messageTimeoutInSeconds")?.toLong() ?: 30L, + dismissMessageOnBackPress = if (options?.hasKey("dismissMessageOnBackPress") ?: false) options?.getBoolean("dismissMessageOnBackPress") ?: true else true ) } diff --git a/example/src/App.tsx b/example/src/App.tsx index 0e8a93d..28de140 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -37,6 +37,9 @@ const config = { // is disabled in the Sourcepoint dashboard language: SPMessageLanguage.ENGLISH, messageTimeoutInSeconds: 20, + // Preventing android users from dismissing the consent message on back press + // `true` is the default value, allowing users to dismiss the consent message on back press + dismissMessageOnBackPress: true, }, gdprPMId: '488393', usnatPMId: '988851', @@ -45,8 +48,8 @@ const config = { campaigns: { gdpr: {}, usnat: { supportLegacyUSPString: true }, - preferences: {}, - globalcmp: {}, + //preferences: {}, + //globalcmp: {}, environment: SPCampaignEnvironment.Public, } as SPCampaigns, ...launchArgs?.config, diff --git a/src/NativeReactNativeCmp.ts b/src/NativeReactNativeCmp.ts index 3e4f74d..c2fd46c 100644 --- a/src/NativeReactNativeCmp.ts +++ b/src/NativeReactNativeCmp.ts @@ -198,6 +198,7 @@ export type PreferencesConsent = { export type SPBuildOptions = { language?: SPMessageLanguage; messageTimeoutInSeconds?: number; + dismissMessageOnBackPress?: boolean; } export interface Spec extends TurboModule { From 63305fb6a97f50caf074ab7acd4209a406e5c910 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 19 Aug 2025 16:15:39 +0200 Subject: [PATCH 2/5] update `README.md` --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e94b2c3..f609ed5 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,9 @@ export default function App() { // is disabled in the Sourcepoint dashboard language: SPMessageLanguage.ENGLISH, messageTimeoutInSeconds: 20, + // Preventing android users from dismissing the consent message on back press + // `true` is the default value, allowing users to dismiss the consent message on back press + dismissMessageOnBackPress: true, } ); From ff8b80cc11c9baf1b50beaff0e02a4a7b4708d94 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 19 Aug 2025 16:50:55 +0200 Subject: [PATCH 3/5] fix --- example/src/App.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index 28de140..dd2cfa5 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -48,8 +48,8 @@ const config = { campaigns: { gdpr: {}, usnat: { supportLegacyUSPString: true }, - //preferences: {}, - //globalcmp: {}, + preferences: {}, + globalcmp: {}, environment: SPCampaignEnvironment.Public, } as SPCampaigns, ...launchArgs?.config, From 1e6dac6d964861dd6f70888dfcb5e30eb55e4b09 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Thu, 21 Aug 2025 15:17:00 +0200 Subject: [PATCH 4/5] rename `dismissMessageOnBackPress` to `dismissMessageOnBackPressForAndroid` --- .../com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt | 2 +- .../com/sourcepoint/reactnativecmp/arguments/Arguments.kt | 7 +++++++ .../sourcepoint/reactnativecmp/arguments/BuildOptions.kt | 4 ++-- example/src/App.tsx | 2 +- src/NativeReactNativeCmp.ts | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt index 89e673a..7e09e83 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt @@ -67,7 +67,7 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN }.build() reactApplicationContext.currentActivity?.let { - spConsentLib = makeConsentLib(config, it, this, parsedOptions.dismissMessageOnBackPress) + spConsentLib = makeConsentLib(config, it, this, parsedOptions.dismissMessageOnBackPressForAndroid) } ?: run { onError(Error("No activity found when building the SDK")) } 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 7a1fe7f..197aac5 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt @@ -168,6 +168,13 @@ fun ReadableMap.getDoubleOrNull(name: String) = null } +fun ReadableMap.getBooleanOrNull(name: String) = + if (hasKey(name) && !isNull(name)) { + getBoolean(name) + } else { + null + } + inline fun ReadableArray.toList(): List = List(size()) { when (T::class) { String::class -> getString(it) diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt index f878ac7..e74e9f3 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt @@ -7,13 +7,13 @@ import com.sourcepoint.cmplibrary.model.MessageLanguage.ENGLISH data class BuildOptions( val language: MessageLanguage, val messageTimeoutInSeconds: Long, - val dismissMessageOnBackPress: Boolean + val dismissMessageOnBackPressForAndroid: Boolean ) { val messageTimeoutInMilliseconds = messageTimeoutInSeconds * 1000L constructor(options: ReadableMap?) : this( language = MessageLanguage.entries.find { it.value == options?.getString("language") } ?: ENGLISH, messageTimeoutInSeconds = options?.getDoubleOrNull("messageTimeoutInSeconds")?.toLong() ?: 30L, - dismissMessageOnBackPress = if (options?.hasKey("dismissMessageOnBackPress") ?: false) options?.getBoolean("dismissMessageOnBackPress") ?: true else true + dismissMessageOnBackPressForAndroid = options?.getBooleanOrNull("dismissMessageOnBackPressForAndroid") ?: true ) } diff --git a/example/src/App.tsx b/example/src/App.tsx index dd2cfa5..9862374 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -39,7 +39,7 @@ const config = { messageTimeoutInSeconds: 20, // Preventing android users from dismissing the consent message on back press // `true` is the default value, allowing users to dismiss the consent message on back press - dismissMessageOnBackPress: true, + dismissMessageOnBackPressForAndroid: true, }, gdprPMId: '488393', usnatPMId: '988851', diff --git a/src/NativeReactNativeCmp.ts b/src/NativeReactNativeCmp.ts index c2fd46c..c0af7e6 100644 --- a/src/NativeReactNativeCmp.ts +++ b/src/NativeReactNativeCmp.ts @@ -198,7 +198,7 @@ export type PreferencesConsent = { export type SPBuildOptions = { language?: SPMessageLanguage; messageTimeoutInSeconds?: number; - dismissMessageOnBackPress?: boolean; + dismissMessageOnBackPressForAndroid?: boolean; } export interface Spec extends TurboModule { From e1245fdda3bec246697679cefc62145d3e19efae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Thu, 21 Aug 2025 17:42:41 +0200 Subject: [PATCH 5/5] rename dismissMessageOnBackPressForAndroid to androidDismissMessageOnBackPress --- README.md | 5 ++--- .../com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt | 2 +- .../sourcepoint/reactnativecmp/arguments/BuildOptions.kt | 4 ++-- example/src/App.tsx | 7 ++++--- src/NativeReactNativeCmp.ts | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f609ed5..6a78aac 100644 --- a/README.md +++ b/README.md @@ -240,9 +240,8 @@ export default function App() { // is disabled in the Sourcepoint dashboard language: SPMessageLanguage.ENGLISH, messageTimeoutInSeconds: 20, - // Preventing android users from dismissing the consent message on back press - // `true` is the default value, allowing users to dismiss the consent message on back press - dismissMessageOnBackPress: true, + // Allows Android users to dismiss the consent message on back press. True by default. Set it to false if you wish to prevent this users from dismissing the message on back press. + androidDismissMessageOnBackPress: true, } ); diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt index 7e09e83..ed2a2fd 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt @@ -67,7 +67,7 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN }.build() reactApplicationContext.currentActivity?.let { - spConsentLib = makeConsentLib(config, it, this, parsedOptions.dismissMessageOnBackPressForAndroid) + spConsentLib = makeConsentLib(config, it, this, parsedOptions.androidDismissMessageOnBackPress) } ?: run { onError(Error("No activity found when building the SDK")) } diff --git a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt index e74e9f3..2301329 100644 --- a/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt +++ b/android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt @@ -7,13 +7,13 @@ import com.sourcepoint.cmplibrary.model.MessageLanguage.ENGLISH data class BuildOptions( val language: MessageLanguage, val messageTimeoutInSeconds: Long, - val dismissMessageOnBackPressForAndroid: Boolean + val androidDismissMessageOnBackPress: Boolean ) { val messageTimeoutInMilliseconds = messageTimeoutInSeconds * 1000L constructor(options: ReadableMap?) : this( language = MessageLanguage.entries.find { it.value == options?.getString("language") } ?: ENGLISH, messageTimeoutInSeconds = options?.getDoubleOrNull("messageTimeoutInSeconds")?.toLong() ?: 30L, - dismissMessageOnBackPressForAndroid = options?.getBooleanOrNull("dismissMessageOnBackPressForAndroid") ?: true + androidDismissMessageOnBackPress = options?.getBooleanOrNull("androidDismissMessageOnBackPress") ?: true ) } diff --git a/example/src/App.tsx b/example/src/App.tsx index 9862374..d266d5c 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -37,9 +37,10 @@ const config = { // is disabled in the Sourcepoint dashboard language: SPMessageLanguage.ENGLISH, messageTimeoutInSeconds: 20, - // Preventing android users from dismissing the consent message on back press - // `true` is the default value, allowing users to dismiss the consent message on back press - dismissMessageOnBackPressForAndroid: true, + // Allows Android users to dismiss the consent message on back press. + // True by default. + // Set it to false if you wish to prevent this users from dismissing the message on back press. + androidDismissMessageOnBackPress: false, }, gdprPMId: '488393', usnatPMId: '988851', diff --git a/src/NativeReactNativeCmp.ts b/src/NativeReactNativeCmp.ts index c0af7e6..4d34d02 100644 --- a/src/NativeReactNativeCmp.ts +++ b/src/NativeReactNativeCmp.ts @@ -198,7 +198,7 @@ export type PreferencesConsent = { export type SPBuildOptions = { language?: SPMessageLanguage; messageTimeoutInSeconds?: number; - dismissMessageOnBackPressForAndroid?: boolean; + androidDismissMessageOnBackPress?: boolean; } export interface Spec extends TurboModule {