Skip to content

Commit 997a21d

Browse files
committed
Hook into OSPopupWindow to know of dismissal
In InAppMessageView which owns the popup window, it will listen to the popup window's dismissal event and trigger the post-dismissal flow. It also sets the manual flag when `removeAllViews()` is invoked.
1 parent fa46a05 commit 997a21d

File tree

1 file changed

+15
-6
lines changed
  • OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/display/impl

1 file changed

+15
-6
lines changed

OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/display/impl/InAppMessageView.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ internal class InAppMessageView(
8585
private var isDismissTimerSet: Boolean = false
8686
private var cancelDismissTimer: Boolean = false
8787

88+
private val popupWindowListener =
89+
object : OSPopupWindow.PopupWindowListener {
90+
override fun onDismiss(wasDismissedManually: Boolean?) {
91+
if (wasDismissedManually != true) {
92+
Logging.debug("PopupWindowListener.onDismiss called by the system.")
93+
messageController?.onMessageWasDismissed()
94+
}
95+
}
96+
}
97+
8898
init {
8999
setMarginsFromContent(messageContent)
90100
}
@@ -275,6 +285,7 @@ internal class InAppMessageView(
275285
if (hasBackground) WindowManager.LayoutParams.MATCH_PARENT else pageWidth,
276286
if (hasBackground) WindowManager.LayoutParams.MATCH_PARENT else WindowManager.LayoutParams.WRAP_CONTENT,
277287
false,
288+
popupWindowListener
278289
)
279290
popupWindow?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
280291
popupWindow?.isTouchable = true
@@ -301,6 +312,7 @@ internal class InAppMessageView(
301312
popupWindow!!,
302313
displayType,
303314
)
315+
304316
popupWindow?.showAtLocation(
305317
currentActivity!!.window.decorView.rootView,
306318
gravity,
@@ -485,17 +497,14 @@ internal class InAppMessageView(
485497
*/
486498
fun removeAllViews() {
487499
Logging.debug("InAppMessageView.removeAllViews()")
500+
popupWindow?.wasDismissedManually = true
488501
if (isDismissTimerSet) {
489502
// Dismissed before the dismiss delay
490503
cancelDismissTimer = true
491504
}
492-
if (draggableRelativeLayout != null) {
493-
draggableRelativeLayout!!.removeAllViews()
494-
}
495505

496-
if (popupWindow != null) {
497-
popupWindow!!.dismiss()
498-
}
506+
draggableRelativeLayout?.removeAllViews()
507+
popupWindow?.dismiss()
499508

500509
dereferenceViews()
501510
}

0 commit comments

Comments
 (0)