Skip to content

Commit 2d11946

Browse files
Merge pull request #27 from SourcePointUSA/DIA-6037-dismiss-message-on-back-press
DIA-6037 dismiss message on back press for Android
2 parents 4fc6f63 + e1245fd commit 2d11946

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ export default function App() {
240240
// is disabled in the Sourcepoint dashboard
241241
language: SPMessageLanguage.ENGLISH,
242242
messageTimeoutInSeconds: 20,
243+
// 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.
244+
androidDismissMessageOnBackPress: true,
243245
}
244246
);
245247

android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
6767
}.build()
6868

6969
reactApplicationContext.currentActivity?.let {
70-
spConsentLib = makeConsentLib(config, it, this)
70+
spConsentLib = makeConsentLib(config, it, this, parsedOptions.androidDismissMessageOnBackPress)
7171
} ?: run {
7272
onError(Error("No activity found when building the SDK"))
7373
}

android/src/main/java/com/sourcepoint/reactnativecmp/arguments/Arguments.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ fun ReadableMap.getDoubleOrNull(name: String) =
168168
null
169169
}
170170

171+
fun ReadableMap.getBooleanOrNull(name: String) =
172+
if (hasKey(name) && !isNull(name)) {
173+
getBoolean(name)
174+
} else {
175+
null
176+
}
177+
171178
inline fun <reified T> ReadableArray.toList(): List<T> = List(size()) {
172179
when (T::class) {
173180
String::class -> getString(it)

android/src/main/java/com/sourcepoint/reactnativecmp/arguments/BuildOptions.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import com.sourcepoint.cmplibrary.model.MessageLanguage.ENGLISH
77
data class BuildOptions(
88
val language: MessageLanguage,
99
val messageTimeoutInSeconds: Long,
10+
val androidDismissMessageOnBackPress: Boolean
1011
) {
1112
val messageTimeoutInMilliseconds = messageTimeoutInSeconds * 1000L
1213

1314
constructor(options: ReadableMap?) : this(
1415
language = MessageLanguage.entries.find { it.value == options?.getString("language") } ?: ENGLISH,
15-
messageTimeoutInSeconds = options?.getDoubleOrNull("messageTimeoutInSeconds")?.toLong() ?: 30L
16+
messageTimeoutInSeconds = options?.getDoubleOrNull("messageTimeoutInSeconds")?.toLong() ?: 30L,
17+
androidDismissMessageOnBackPress = options?.getBooleanOrNull("androidDismissMessageOnBackPress") ?: true
1618
)
1719
}

example/src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const config = {
3737
// is disabled in the Sourcepoint dashboard
3838
language: SPMessageLanguage.ENGLISH,
3939
messageTimeoutInSeconds: 20,
40+
// Allows Android users to dismiss the consent message on back press.
41+
// True by default.
42+
// Set it to false if you wish to prevent this users from dismissing the message on back press.
43+
androidDismissMessageOnBackPress: false,
4044
},
4145
gdprPMId: '488393',
4246
usnatPMId: '988851',

src/NativeReactNativeCmp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export type PreferencesConsent = {
198198
export type SPBuildOptions = {
199199
language?: SPMessageLanguage;
200200
messageTimeoutInSeconds?: number;
201+
androidDismissMessageOnBackPress?: boolean;
201202
}
202203

203204
export interface Spec extends TurboModule {

0 commit comments

Comments
 (0)