Skip to content

Commit

Permalink
restore showwebview before merge
Browse files Browse the repository at this point in the history
  • Loading branch information
grablack committed Aug 13, 2024
1 parent 1e72734 commit 88ed428
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions library/src/main/java/com/paypal/messages/PayPalMessageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ class PayPalMessageView @JvmOverloads constructor(
}

private fun showWebView(response: ApiMessageData.Response) {
val modal = this.modal ?: run {
val newModal = ModalFragment(clientID)
val modal = modal ?: run {
val modal = ModalFragment(clientID)
// Build modal config
val modalConfig = ModalConfig(
amount = this.amount,
Expand All @@ -302,37 +302,28 @@ class PayPalMessageView @JvmOverloads constructor(
modalCloseButton = response.meta?.modalCloseButton!!,
)

newModal.init(modalConfig)
modal.init(modalConfig)
modal.show((context as AppCompatActivity).supportFragmentManager, modal.tag)

val activity = context as? AppCompatActivity
if (activity != null && !activity.isFinishing && !activity.isDestroyed) {
newModal.show(activity.supportFragmentManager, newModal.tag)
this.modal = newModal
}
this.modal = modal

newModal
modal
}

// modal.show() above will display the modal on initial view, but if the user closes the modal
// it will become visually hidden and this method will re-display the modal without
// attempting to reattach it
// the delay prevents noticeable shift when the offer type is changed
handler.postDelayed({
if (modal.isAdded) {
modal.expand()
}
modal.expand()
}, 250)
}

override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
// The modal will not dismiss (destroy) itself, it will only hide/show when opening and closing
// so we need to clean up the modal instance if the message is removed
this.modal?.let {
if (it.isAdded) {
it.dismiss()
}
}
this.modal?.dismiss()
}

/**
Expand Down

0 comments on commit 88ed428

Please sign in to comment.