Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <reified T> ReadableArray.toList(): List<T> = List(size()) {
when (T::class) {
String::class -> getString(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
4 changes: 4 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/NativeReactNativeCmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export type PreferencesConsent = {
export type SPBuildOptions = {
language?: SPMessageLanguage;
messageTimeoutInSeconds?: number;
androidDismissMessageOnBackPress?: boolean;
}

export interface Spec extends TurboModule {
Expand Down
Loading