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
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ internal class InAppMessageViewDisplayerImpl(private val inAppImageSizeStorage:
isRestored: Boolean = false,
) {
if (!isRestored) isActionExecuted = false
if (isRestored && tryReattachRestoredInApp(wrapper.inAppType.inAppId)) return

val callbackWrapper = InAppCallbackWrapper(inAppCallback) {
wrapper.inAppActionCallbacks.onInAppDismiss.onDismiss()
pausedHolder?.hide()
Expand Down Expand Up @@ -235,6 +237,32 @@ internal class InAppMessageViewDisplayerImpl(private val inAppImageSizeStorage:
}
}

private fun tryReattachRestoredInApp(inAppId: String): Boolean {
val restoredHolder: InAppViewHolder<*> = pausedHolder
?.takeIf { it.canReuseOnRestore(inAppId) }
?: return false
currentHolder = restoredHolder
pausedHolder = null
val root: ViewGroup = currentActivity?.root ?: run {
mindboxLogE("failed to reattach inApp: currentRoot is null")
return true
}
restoredHolder.reattach(createMindboxView(root))
return true
}

private fun createMindboxView(root: ViewGroup): MindboxView {
return object : MindboxView {
override val container: ViewGroup = root

override fun requestPermission() {
currentActivity?.let { activity ->
mindboxNotificationManager.requestPermission(activity = activity)
}
}
}
}

override fun hideCurrentInApp() {
loggingRunCatching {
if (isInAppActive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@ internal abstract class AbstractInAppViewHolder<T : InAppType> : InAppViewHolder
inAppLayout.prepareLayoutForInApp(wrapper.inAppType)
}

private fun attachToRoot(currentRoot: ViewGroup) {
if (_currentDialog == null) {
initView(currentRoot)
return
}
currentRoot.removeChildById(R.id.inapp_layout_container)
_currentDialog?.parent.safeAs<ViewGroup>()?.removeView(_currentDialog)
currentRoot.addView(currentDialog)
}

private fun startPositionController(currentRoot: ViewGroup) {
positionController?.stop()
positionController = null
val isRepositioningEnabled = currentRoot.context.resources.getBoolean(R.bool.mindbox_support_inapp_on_fragment)
positionController = isRepositioningEnabled.takeIf { it }?.run {
InAppPositionController().apply { start(currentDialog) }
}
}

private fun restoreKeyboard() {
typingView?.let { view ->
view.requestFocus()
Expand All @@ -184,11 +203,16 @@ internal abstract class AbstractInAppViewHolder<T : InAppType> : InAppViewHolder

override fun show(currentRoot: MindboxView) {
isInAppMessageActive = true
initView(currentRoot.container)
val isRepositioningEnabled = currentRoot.container.context.resources.getBoolean(R.bool.mindbox_support_inapp_on_fragment)
positionController = isRepositioningEnabled.takeIf { it }?.run {
InAppPositionController().apply { start(currentDialog) }
}
attachToRoot(currentRoot.container)
startPositionController(currentRoot.container)
hideKeyboard(currentRoot.container)
inAppActionHandler.mindboxView = currentRoot
}

override fun reattach(currentRoot: MindboxView) {
isInAppMessageActive = true
attachToRoot(currentRoot.container)
startPositionController(currentRoot.container)
hideKeyboard(currentRoot.container)
inAppActionHandler.mindboxView = currentRoot
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ internal interface InAppViewHolder<T : InAppType> {

fun show(currentRoot: MindboxView)

fun reattach(currentRoot: MindboxView) {
show(currentRoot)
}

fun canReuseOnRestore(inAppId: String): Boolean = false

fun hide()

fun release() {}
Expand Down

This file was deleted.

Loading