diff --git a/README.md b/README.md index e94b2c3..6a78aac 100644 --- a/README.md +++ b/README.md @@ -240,6 +240,8 @@ export default function App() { // is disabled in the Sourcepoint dashboard language: SPMessageLanguage.ENGLISH, messageTimeoutInSeconds: 20, + // 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 b9b8656..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) + 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/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 e448fc1..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,11 +7,13 @@ import com.sourcepoint.cmplibrary.model.MessageLanguage.ENGLISH data class BuildOptions( val language: MessageLanguage, val messageTimeoutInSeconds: Long, + 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 + messageTimeoutInSeconds = options?.getDoubleOrNull("messageTimeoutInSeconds")?.toLong() ?: 30L, + androidDismissMessageOnBackPress = options?.getBooleanOrNull("androidDismissMessageOnBackPress") ?: true ) } diff --git a/example/src/App.tsx b/example/src/App.tsx index 0e8a93d..d266d5c 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -37,6 +37,10 @@ const config = { // is disabled in the Sourcepoint dashboard language: SPMessageLanguage.ENGLISH, messageTimeoutInSeconds: 20, + // 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 3e4f74d..4d34d02 100644 --- a/src/NativeReactNativeCmp.ts +++ b/src/NativeReactNativeCmp.ts @@ -198,6 +198,7 @@ export type PreferencesConsent = { export type SPBuildOptions = { language?: SPMessageLanguage; messageTimeoutInSeconds?: number; + androidDismissMessageOnBackPress?: boolean; } export interface Spec extends TurboModule {