diff --git a/code/core/src/main/res/values/styles.xml b/code/core/src/main/res/values/styles.xml new file mode 100644 index 000000000..573648e60 --- /dev/null +++ b/code/core/src/main/res/values/styles.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/alert/AlertPresentable.kt b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/alert/AlertPresentable.kt index 1ff171fce..66875b2e2 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/alert/AlertPresentable.kt +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/alert/AlertPresentable.kt @@ -44,7 +44,7 @@ internal class AlertPresentable( mainScope ) { override fun getContent(activityContext: Context): ComposeView { - return ComposeView(activityContext).apply { + return ComposeView(getThemedContext(activityContext)).apply { setContent { AlertScreen( presentationStateManager = presentationStateManager, diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/common/AEPPresentable.kt b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/common/AEPPresentable.kt index 034c146b6..e585824cd 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/common/AEPPresentable.kt +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/common/AEPPresentable.kt @@ -13,11 +13,13 @@ package com.adobe.marketing.mobile.services.ui.common import android.app.Activity import android.content.Context +import android.view.ContextThemeWrapper import android.view.View import android.view.ViewGroup import androidx.annotation.MainThread import androidx.annotation.VisibleForTesting import androidx.compose.ui.platform.ComposeView +import com.adobe.marketing.mobile.core.R import com.adobe.marketing.mobile.internal.util.ActivityCompatOwnerUtils import com.adobe.marketing.mobile.services.Log import com.adobe.marketing.mobile.services.ServiceConstants @@ -291,6 +293,37 @@ internal abstract class AEPPresentable> : onAnimationComplete() } + /** + * Returns a themed context that applies overrides to the base context theme + * to ensure that the presentable UI is consistent with the rest of the application while + * ensuring that specific attributes like view background are not inherited from the base theme. + */ + protected fun getThemedContext(context: Context): Context { + // Theme overrides are supported only for API level 23 and above. For lower API levels, + // return the base context as is. + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) { + return context + } + + try { + val newTheme = context.resources.newTheme() + // Apply the base theme attributes to the new theme + newTheme.setTo(context.theme) + val themedContext = ContextThemeWrapper(context, newTheme) + // Apply the override theme to the themed context + themedContext.theme.applyStyle(R.style.AepSdkUiService_OverrideTheme, true) + return themedContext + } catch (e: Exception) { + Log.error( + ServiceConstants.LOG_TAG, + LOG_SOURCE, + "Error while creating themed context", + e + ) + } + return context + } + /** * Fetches the [ComposeView] associated with the presentable. This ComposeView is used to * render the UI of the presentable by attaching it to the content view of the activity. diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/FloatingButtonPresentable.kt b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/FloatingButtonPresentable.kt index 0826a0de8..2deccd5ad 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/FloatingButtonPresentable.kt +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/FloatingButtonPresentable.kt @@ -62,7 +62,7 @@ internal class FloatingButtonPresentable( } override fun getContent(activityContext: Context): ComposeView { - return ComposeView(activityContext).apply { + return ComposeView(getThemedContext(activityContext)).apply { setContent { FloatingButtonScreen( presentationStateManager = presentationStateManager, diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/views/FloatingButton.kt b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/views/FloatingButton.kt index fecb21432..733f7ea53 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/views/FloatingButton.kt +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/floatingbutton/views/FloatingButton.kt @@ -90,6 +90,7 @@ internal fun FloatingButton( modifier = Modifier .height(heightDp.value) .width(widthDp.value) + .background(Color.Transparent) .testTag(FloatingButtonTestTags.FLOATING_BUTTON_AREA) ) { FloatingActionButton( diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/InAppMessagePresentable.kt b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/InAppMessagePresentable.kt index 34d680ba9..cb0d00776 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/InAppMessagePresentable.kt +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/InAppMessagePresentable.kt @@ -77,7 +77,7 @@ internal class InAppMessagePresentable( * @param activityContext the context of the activity */ override fun getContent(activityContext: Context): ComposeView { - return ComposeView(activityContext).apply { + return ComposeView(getThemedContext(activityContext)).apply { layoutParams = ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT