From 2c98bbaf7e91e91693d54bc160ea97f1139e640f Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Mon, 30 Mar 2026 14:13:58 -0300 Subject: [PATCH] Fix back navigation stuck in conversation after activity recreation. Co-authored-by: Greyson Parrelli --- .../securesms/conversation/v2/ConversationFragment.kt | 10 +++++++++- .../securesms/conversation/v2/ConversationViewModel.kt | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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 b7e3984909..7c39f4bd97 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 @@ -650,6 +650,7 @@ class ConversationFragment : } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + viewModel.resetBackPressedState() binding.toolbar.isBackInvokedCallbackEnabled = false binding.root.setUseWindowTypes(args.conversationScreenType == ConversationScreenType.NORMAL && !resources.getWindowSizeClass().isSplitPane()) if (args.conversationScreenType == ConversationScreenType.BUBBLE) { @@ -1042,7 +1043,14 @@ class ConversationFragment : state.isInActionMode -> finishActionMode() - state.isMediaKeyboardShowing -> container.hideInput() + state.isMediaKeyboardShowing -> { + if (container.isInputShowing) { + container.hideInput() + } else { + Log.d(TAG, "handleBackPressed() - media keyboard state was stale, clearing") + viewModel.setIsMediaKeyboardShowing(false) + } + } else -> { // State has changed since the back handler was enabled. Let the back press proceed diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt index 8c82440628..d77ec8dd51 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationViewModel.kt @@ -733,6 +733,10 @@ class ConversationViewModel( } } + fun resetBackPressedState() { + internalBackPressedState.value = BackPressedState() + } + fun toggleVote(poll: PollRecord, pollOption: PollOption, isChecked: Boolean) { viewModelScope.launch(Dispatchers.IO) { val voteCount = if (isChecked) {