From b7e4b3976bc8c5577d43173cb23ca936dca8e333 Mon Sep 17 00:00:00 2001 From: Navratan Soni Date: Wed, 21 Aug 2024 23:05:12 +0530 Subject: [PATCH] Added dialog compose for uiTakeOver --- .../services/ui/message/views/Message.kt | 72 +++++++++++++++---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/views/Message.kt b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/views/Message.kt index 1f7bc8309..4403c80ef 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/views/Message.kt +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/views/Message.kt @@ -15,7 +15,12 @@ import android.webkit.WebView import androidx.activity.compose.BackHandler import androidx.compose.animation.core.MutableTransitionState import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalView +import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties +import androidx.compose.ui.window.DialogWindowProvider import com.adobe.marketing.mobile.services.ui.Presentable import com.adobe.marketing.mobile.services.ui.common.PresentationStateManager import com.adobe.marketing.mobile.services.ui.message.GestureTracker @@ -67,7 +72,8 @@ internal fun MessageScreen( inAppMessageSettings = inAppMessageSettings, gestureTracker = gestureTracker, onCreated = { onCreated(it) }, - onDisposed = { onDisposed() } + onDisposed = { onDisposed() }, + onBackPressed = onBackPressed ) } @@ -85,23 +91,61 @@ internal fun Message( inAppMessageSettings: InAppMessageSettings, gestureTracker: GestureTracker, onCreated: (WebView) -> Unit, - onDisposed: () -> Unit + onDisposed: () -> Unit, + onBackPressed: () -> Unit ) { - // Backdrop for the InAppMessage only takes into effect if the InAppMessage is taking over the UI if (inAppMessageSettings.shouldTakeOverUi) { - MessageBackdrop( + /* Dialog is used to take over the UI when the InAppMessage is set to take over the UI. + This is necessary to ensure that the InAppMessage is displayed on top of the UI. + Which will ensure that ScreenReader can read the content of the InAppMessage only and not the underlying UI. + */ + Dialog( + properties = DialogProperties( + usePlatformDefaultWidth = false, + dismissOnBackPress = true, + dismissOnClickOutside = false + ), + onDismissRequest = { + onBackPressed() + } + ) { + /* Remove the default dim and animations for the dialog window + Customer can set their own dim and animations if needed and those will be honoured in MessageBackdrop inside Message + */ + + val dialogWindow = (LocalView.current.parent as? DialogWindowProvider)?.window + + SideEffect { + dialogWindow?.let { + it.setDimAmount(0f) + it.setWindowAnimations(-1) + } + } + + // Backdrop for the InAppMessage only takes into effect if the InAppMessage is taking over the UI + MessageBackdrop( + visibility = isVisible, + inAppMessageSettings = inAppMessageSettings, + gestureTracker = gestureTracker + ) + + // Frame that holds the InAppMessage + MessageFrame( + visibility = isVisible, + inAppMessageSettings = inAppMessageSettings, + gestureTracker = gestureTracker, + onCreated = onCreated, + onDisposed = onDisposed + ) + } + } else { + // Frame that holds the InAppMessage + MessageFrame( visibility = isVisible, inAppMessageSettings = inAppMessageSettings, - gestureTracker = gestureTracker + gestureTracker = gestureTracker, + onCreated = onCreated, + onDisposed = onDisposed ) } - - // Frame that holds the InAppMessage - MessageFrame( - visibility = isVisible, - inAppMessageSettings = inAppMessageSettings, - gestureTracker = gestureTracker, - onCreated = onCreated, - onDisposed = onDisposed - ) }