Skip to content

Commit

Permalink
Added dialog compose for uiTakeOver
Browse files Browse the repository at this point in the history
  • Loading branch information
navratan-soni committed Aug 21, 2024
1 parent 4639ee4 commit b7e4b39
Showing 1 changed file with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,7 +72,8 @@ internal fun MessageScreen(
inAppMessageSettings = inAppMessageSettings,
gestureTracker = gestureTracker,
onCreated = { onCreated(it) },
onDisposed = { onDisposed() }
onDisposed = { onDisposed() },
onBackPressed = onBackPressed
)
}

Expand All @@ -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
)

Check warning on line 139 in code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/views/Message.kt

View check run for this annotation

Codecov / codecov/patch

code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/message/views/Message.kt#L139

Added line #L139 was not covered by tests
}
} 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
)
}

0 comments on commit b7e4b39

Please sign in to comment.