Display back button when the conversation pane is expanded.

This commit is contained in:
Alex Hart
2025-10-20 16:17:31 -03:00
committed by Greyson Parrelli
parent f38262c0ab
commit 43bb32e64b
3 changed files with 53 additions and 2 deletions

View File

@@ -415,6 +415,26 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
}
}
val scope = rememberCoroutineScope()
BackHandler(paneExpansionState.currentAnchor == detailOnlyAnchor) {
scope.launch {
paneExpansionState.animateTo(listOnlyAnchor)
}
}
LaunchedEffect(paneExpansionState.currentAnchor, detailOnlyAnchor, listOnlyAnchor, detailAndListAnchor) {
val isFullScreenPane = when (paneExpansionState.currentAnchor) {
listOnlyAnchor, detailOnlyAnchor -> {
true
}
else -> {
false
}
}
mainNavigationViewModel.onPaneAnchorChanged(isFullScreenPane)
}
LaunchedEffect(paneExpansionState, detailOnlyAnchor, listOnlyAnchor, wrappedNavigator) {
mainNavigationViewModel.detailLocation.collect {
if (paneExpansionState.currentAnchor == listOnlyAnchor) {

View File

@@ -261,6 +261,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreview
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModelV2
import org.thoughtcrime.securesms.longmessage.LongMessageFragment
import org.thoughtcrime.securesms.main.MainNavigationListLocation
import org.thoughtcrime.securesms.main.MainNavigationViewModel
import org.thoughtcrime.securesms.main.VerticalInsets
import org.thoughtcrime.securesms.mediaoverview.MediaOverviewActivity
import org.thoughtcrime.securesms.mediapreview.MediaIntentFactory
@@ -491,6 +492,8 @@ class ConversationFragment :
private val shareDataTimestampViewModel: ShareDataTimestampViewModel by activityViewModels()
private val mainNavigationViewModel: MainNavigationViewModel by activityViewModels()
private val inlineQueryController: InlineQueryResultsControllerV2 by lazy {
InlineQueryResultsControllerV2(
this,
@@ -1401,16 +1404,37 @@ class ConversationFragment :
}
private fun presentNavigationIconForNormal() {
if (!resources.getWindowSizeClass().isSplitPane()) {
if (WindowSizeClass.isLargeScreenSupportEnabled()) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
mainNavigationViewModel.isFullScreenPane.collect { isFullScreenPane ->
updateNavigationIconForNormal(isFullScreenPane)
}
}
}
} else {
updateNavigationIconForNormal(true)
}
}
private fun updateNavigationIconForNormal(isFullScreenPane: Boolean) {
if (!resources.getWindowSizeClass().isSplitPane() || isFullScreenPane) {
binding.toolbar.setNavigationIcon(R.drawable.symbol_arrow_start_24)
binding.toolbar.setNavigationContentDescription(R.string.ConversationFragment__content_description_back_button)
binding.toolbar.setNavigationOnClickListener {
binding.root.hideKeyboard(composeText)
requireActivity().onBackPressedDispatcher.onBackPressed()
}
binding.toolbar.setContentInsetsRelative(
46.dp,
binding.toolbar.contentInsetEnd
)
} else {
binding.toolbar.navigationIcon = null
binding.toolbar.contentInsetStartWithNavigation = 0
binding.toolbar.setContentInsetsRelative(
24.dp,
binding.toolbar.contentInsetEnd
)
}
}

View File

@@ -69,6 +69,9 @@ class MainNavigationViewModel(
private val internalMainNavigationState = MutableStateFlow(MainNavigationState(currentListLocation = initialListLocation))
val mainNavigationState: StateFlow<MainNavigationState> = internalMainNavigationState
private val internalIsFullScreenPane = MutableStateFlow(false)
val isFullScreenPane: StateFlow<Boolean> = internalIsFullScreenPane
/**
* This is Rx because these are still accessed from Java.
*/
@@ -121,6 +124,10 @@ class MainNavigationViewModel(
}
}
fun onPaneAnchorChanged(isFullScreenPane: Boolean) {
internalIsFullScreenPane.update { isFullScreenPane }
}
/**
* Sets the navigator on the view-model. This wraps the given navigator in our own delegating implementation
* such that we can react to navigateTo/Back signals and maintain proper state for internalDetailLocation.