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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import cloud.mindbox.mobile_sdk.logger.mindboxLogI
import cloud.mindbox.mobile_sdk.px
import kotlin.math.abs

internal class InAppConstraintLayout : ConstraintLayout, BackButtonLayout {

private var backButtonHandler: BackButtonHandler? = null
internal class InAppConstraintLayout : ConstraintLayout {

fun setSwipeToDismissCallback(callback: () -> Unit) {
swipeToDismissCallback = callback
Expand Down Expand Up @@ -255,22 +253,6 @@ internal class InAppConstraintLayout : ConstraintLayout, BackButtonLayout {
) : super(
context, attrs, defStyleAttr, defStyleRes
)

override fun setDismissListener(listener: OnClickListener?) {
backButtonHandler = BackButtonHandler(this, listener)
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean =
if (keyCode == KeyEvent.KEYCODE_BACK && backButtonHandler != null) {
true
} else {
super.onKeyDown(keyCode, event)
}

override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
val handled = backButtonHandler?.dispatchKeyEvent(event)
return handled ?: super.dispatchKeyEvent(event)
}
}

internal data class InAppInsets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.activity.OnBackPressedCallback
import androidx.core.view.isVisible
import cloud.mindbox.mobile_sdk.R
import cloud.mindbox.mobile_sdk.inapp.domain.models.Element
Expand All @@ -21,16 +22,30 @@ internal class ModalWindowInAppViewHolder(
) : AbstractInAppViewHolder<InAppType.ModalWindow>() {

private var currentBackground: ViewGroup? = null
private var backPressedCallback: OnBackPressedCallback? = null

override val isActive: Boolean
get() = isInAppMessageActive

override fun bind() {
inAppLayout.setDismissListener {
inAppCallback.onInAppDismissed(wrapper.inAppType.inAppId)
mindboxLogI("In-app dismissed by dialog click")
hide()
private fun registerBackPressedCallback(): OnBackPressedCallback {
clearBackPressedCallback()
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
inAppCallback.onInAppDismissed(wrapper.inAppType.inAppId)
mindboxLogI("In-app dismissed by back press")
hide()
}
}
backPressedCallback = callback
return callback
}

private fun clearBackPressedCallback() {
backPressedCallback?.remove()
backPressedCallback = null
}

override fun bind() {
wrapper.inAppType.elements.forEach { element ->
when (element) {
is Element.CloseButton -> {
Expand Down Expand Up @@ -88,6 +103,12 @@ internal class ModalWindowInAppViewHolder(
}
mindboxLogI("Show ${wrapper.inAppType.inAppId} on ${this.hashCode()}")
currentDialog.requestFocus()
currentRoot.registerBack(registerBackPressedCallback())
}

override fun hide() {
clearBackPressedCallback()
super.hide()
}

override fun initView(currentRoot: ViewGroup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ internal class WebViewInAppViewHolder(
override val isActive: Boolean
get() = isInAppMessageActive

override fun bind() {
inAppLayout.setDismissListener {
inAppCallback.onInAppDismissed(wrapper.inAppType.inAppId)
mindboxLogI("In-app dismissed by dialog click")
hide()
}
}
override fun bind() {}

suspend fun sendActionAndAwaitResponse(
controller: WebViewController,
Expand Down