Skip to content

Commit 5477903

Browse files
committed
Feat: Add overloads for rememberConsent with parameters
This commit introduces new overloads for the `rememberConsent` composable function, allowing for the direct provision of `ConsentRequestParameters` or `ConsentDebugSettings`. * **New Overloads:** * `rememberConsent(requestParameters: ConsentRequestParameters)`: Allows initializing consent management with specific request parameters. * `rememberConsent(debugSettings: ConsentDebugSettings)`: Simplifies configuring consent for debugging by directly accepting debug settings. * **Platform Implementation:** * Added `actual` implementations for both Android and iOS to handle the new overloads. * The functions now automatically call `requestConsentInfoUpdate` with the provided parameters upon composition.
1 parent 14cef9e commit 5477903

3 files changed

Lines changed: 183 additions & 2 deletions

File tree

‎basic-ads/src/androidMain/kotlin/app/lexilabs/basic/ads/composable/RememberConsent.kt‎

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import androidx.compose.runtime.mutableStateOf
66
import androidx.compose.runtime.remember
77
import androidx.compose.ui.platform.LocalContext
88
import app.lexilabs.basic.ads.Consent
9+
import app.lexilabs.basic.ads.ConsentDebugSettings
10+
import app.lexilabs.basic.ads.ConsentRequestParameters
11+
import app.lexilabs.basic.ads.DependsOnGoogleMobileAds
912
import app.lexilabs.basic.ads.DependsOnGoogleUserMessagingPlatform
1013
import app.lexilabs.basic.ads.getActivity
1114

@@ -32,4 +35,70 @@ public actual fun rememberConsent(): MutableState<Consent> {
3235
consent.value.isPrivacyOptionsRequired()
3336
consent.value.canRequestAds()
3437
return consent
35-
}
38+
}
39+
40+
/**
41+
* Composable function to remember and manage user consent for ads.
42+
*
43+
* This function creates and remembers a [Consent] object, which handles interactions
44+
* with the Google User Messaging Platform (UMP) SDK to obtain and manage user consent
45+
* for personalized advertising.
46+
*
47+
* It initializes the consent state and checks if privacy options are required and if ads can be requested.
48+
*
49+
* @param requestParameters The [ConsentRequestParameters] to use for consent requests.
50+
* @return A [MutableState] holding the [Consent] object. This allows observing and reacting
51+
* to changes in the consent status within your Composable UI.
52+
*
53+
* @see Consent
54+
* @see DependsOnGoogleUserMessagingPlatform
55+
*/
56+
@DependsOnGoogleMobileAds
57+
@DependsOnGoogleUserMessagingPlatform
58+
@Composable
59+
public actual fun rememberConsent(requestParameters: ConsentRequestParameters): MutableState<Consent> {
60+
val activity = LocalContext.current.getActivity()
61+
val consent = remember(activity) { mutableStateOf(Consent(activity)) }
62+
consent.value.requestConsentInfoUpdate(
63+
params = requestParameters,
64+
onCompletion = {
65+
consent.value.isPrivacyOptionsRequired()
66+
consent.value.canRequestAds()
67+
}
68+
)
69+
return consent
70+
}
71+
72+
/**
73+
* Composable function to remember and manage user consent for ads.
74+
*
75+
* This function creates and remembers a [Consent] object, which handles interactions
76+
* with the Google User Messaging Platform (UMP) SDK to obtain and manage user consent
77+
* for personalized advertising.
78+
*
79+
* It initializes the consent state and checks if privacy options are required and if ads can be requested.
80+
*
81+
* @param debugSettings The [ConsentDebugSettings] to use for debugging purposes.
82+
* @return A [MutableState] holding the [Consent] object. This allows observing and reacting
83+
* to changes in the consent status within your Composable UI.
84+
*
85+
* @see Consent
86+
* @see DependsOnGoogleUserMessagingPlatform
87+
*/
88+
@DependsOnGoogleMobileAds
89+
@DependsOnGoogleUserMessagingPlatform
90+
@Composable
91+
public actual fun rememberConsent(debugSettings: ConsentDebugSettings): MutableState<Consent> {
92+
val activity = LocalContext.current.getActivity()
93+
val consent = remember(activity) { mutableStateOf(Consent(activity)) }
94+
val params = ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build()
95+
consent.value.requestConsentInfoUpdate(
96+
params = params,
97+
onCompletion = {
98+
consent.value.isPrivacyOptionsRequired()
99+
consent.value.canRequestAds()
100+
}
101+
)
102+
return consent
103+
}
104+

‎basic-ads/src/commonMain/kotlin/app/lexilabs/basic/ads/composable/RememberConsent.kt‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import androidx.compose.runtime.MutableState
55
import androidx.compose.runtime.mutableStateOf
66
import androidx.compose.runtime.remember
77
import app.lexilabs.basic.ads.Consent
8+
import app.lexilabs.basic.ads.ConsentDebugSettings
9+
import app.lexilabs.basic.ads.ConsentRequestParameters
10+
import app.lexilabs.basic.ads.DependsOnGoogleMobileAds
811
import app.lexilabs.basic.ads.DependsOnGoogleUserMessagingPlatform
912

1013
/**
@@ -53,4 +56,50 @@ public fun rememberConsent(
5356
consent.value.isPrivacyOptionsRequired()
5457
consent.value.canRequestAds()
5558
return consent
56-
}
59+
}
60+
61+
/**
62+
* Composable function to remember and manage user consent for ads.
63+
*
64+
* This function creates and remembers a [Consent] object, which handles interactions
65+
* with the Google User Messaging Platform (UMP) SDK to obtain and manage user consent
66+
* for personalized advertising.
67+
*
68+
* It initializes the consent state and checks if privacy options are required and if ads can be requested.
69+
*
70+
* @param requestParameters The [ConsentRequestParameters] to use for consent requests.
71+
* @return A [MutableState] holding the [Consent] object. This allows observing and reacting
72+
* to changes in the consent status within your Composable UI.
73+
*
74+
* @see Consent
75+
* @see DependsOnGoogleUserMessagingPlatform
76+
*/
77+
@DependsOnGoogleMobileAds
78+
@DependsOnGoogleUserMessagingPlatform
79+
@Composable
80+
public expect fun rememberConsent(
81+
requestParameters: ConsentRequestParameters
82+
): MutableState<Consent>
83+
84+
/**
85+
* Composable function to remember and manage user consent for ads.
86+
*
87+
* This function creates and remembers a [Consent] object, which handles interactions
88+
* with the Google User Messaging Platform (UMP) SDK to obtain and manage user consent
89+
* for personalized advertising.
90+
*
91+
* It initializes the consent state and checks if privacy options are required and if ads can be requested.
92+
*
93+
* @param debugSettings The [ConsentDebugSettings] to use for debugging purposes.
94+
* @return A [MutableState] holding the [Consent] object. This allows observing and reacting
95+
* to changes in the consent status within your Composable UI.
96+
*
97+
* @see Consent
98+
* @see DependsOnGoogleUserMessagingPlatform
99+
*/
100+
@DependsOnGoogleMobileAds
101+
@DependsOnGoogleUserMessagingPlatform
102+
@Composable
103+
public expect fun rememberConsent(
104+
debugSettings: ConsentDebugSettings
105+
): MutableState<Consent>

‎basic-ads/src/iosMain/kotlin/app/lexilabs/basic/ads/composable/RememberConsent.kt‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import androidx.compose.runtime.MutableState
55
import androidx.compose.runtime.mutableStateOf
66
import androidx.compose.runtime.remember
77
import app.lexilabs.basic.ads.Consent
8+
import app.lexilabs.basic.ads.ConsentDebugSettings
9+
import app.lexilabs.basic.ads.ConsentRequestParameters
810
import app.lexilabs.basic.ads.DependsOnGoogleUserMessagingPlatform
911

1012
/**
@@ -29,4 +31,65 @@ public actual fun rememberConsent(): MutableState<Consent> {
2931
consent.value.isPrivacyOptionsRequired()
3032
consent.value.canRequestAds()
3133
return consent
34+
}
35+
36+
/**
37+
* Composable function to remember and manage user consent for ads.
38+
*
39+
* This function creates and remembers a [Consent] object, which handles interactions
40+
* with the Google User Messaging Platform (UMP) SDK to obtain and manage user consent
41+
* for personalized advertising.
42+
*
43+
* It initializes the consent state and checks if privacy options are required and if ads can be requested.
44+
*
45+
* @param requestParameters The [ConsentRequestParameters] to use for consent requests.
46+
* @return A [MutableState] holding the [Consent] object. This allows observing and reacting
47+
* to changes in the consent status within your Composable UI.
48+
*
49+
* @see Consent
50+
* @see DependsOnGoogleUserMessagingPlatform
51+
*/
52+
@DependsOnGoogleUserMessagingPlatform
53+
@Composable
54+
public actual fun rememberConsent(requestParameters: ConsentRequestParameters): MutableState<Consent> {
55+
val consent = remember(null) { mutableStateOf(Consent(null)) }
56+
consent.value.requestConsentInfoUpdate(
57+
params = requestParameters,
58+
onCompletion = {
59+
consent.value.isPrivacyOptionsRequired()
60+
consent.value.canRequestAds()
61+
}
62+
)
63+
return consent
64+
}
65+
66+
/**
67+
* Composable function to remember and manage user consent for ads.
68+
*
69+
* This function creates and remembers a [Consent] object, which handles interactions
70+
* with the Google User Messaging Platform (UMP) SDK to obtain and manage user consent
71+
* for personalized advertising.
72+
*
73+
* It initializes the consent state and checks if privacy options are required and if ads can be requested.
74+
*
75+
* @param debugSettings The [ConsentDebugSettings] to use for debugging purposes.
76+
* @return A [MutableState] holding the [Consent] object. This allows observing and reacting
77+
* to changes in the consent status within your Composable UI.
78+
*
79+
* @see Consent
80+
* @see DependsOnGoogleUserMessagingPlatform
81+
*/
82+
@DependsOnGoogleUserMessagingPlatform
83+
@Composable
84+
public actual fun rememberConsent(debugSettings: ConsentDebugSettings): MutableState<Consent> {
85+
val consent = remember(null) { mutableStateOf(Consent(null)) }
86+
val params = ConsentRequestParameters.Builder().setConsentDebugSettings(debugSettings).build()
87+
consent.value.requestConsentInfoUpdate(
88+
params = params,
89+
onCompletion = {
90+
consent.value.isPrivacyOptionsRequired()
91+
consent.value.canRequestAds()
92+
}
93+
)
94+
return consent
3295
}

0 commit comments

Comments
 (0)