From 6aa723bc22919411a60b976666d41081bc135fbd Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Mon, 31 Jul 2023 11:25:23 -0400 Subject: [PATCH] Fix lifecycle crashes when fragment is destroy before async callbacks. --- .../conversation/v2/ConversationFragment.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt index 04e6884163..7268e026ef 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationFragment.kt @@ -798,6 +798,12 @@ class ConversationFragment : private fun doAfterFirstRender() { Log.d(TAG, "doAfterFirstRender") + + if (!isAdded || view == null) { + Log.w(TAG, "Bailing, fragment no longer added") + return + } + activity?.supportStartPostponedEnterTransition() backPressedCallback = BackPressedDelegate() @@ -2149,6 +2155,10 @@ class ConversationFragment : private inner class StartPositionScroller(private val meta: ConversationData) : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { + if (!isAdded || view == null) { + return + } + val rect = Rect() binding.toolbar.getGlobalVisibleRect(rect) val toolbarOffset = rect.bottom @@ -3907,6 +3917,10 @@ class ConversationFragment : } override fun onGlobalLayout() { + if (!isAdded || view == null) { + return + } + val rect = Rect() toolbar.getGlobalVisibleRect(rect) threadHeaderMarginDecoration.toolbarMargin = rect.bottom + 16.dp