From 53a6b0c71978ed779cd7c72aec4148adf63ce4f0 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 12 Sep 2025 11:04:48 -0300 Subject: [PATCH] Fix navigator to ensure we don't end up with a weird backstack. --- .../thoughtcrime/securesms/MainActivity.kt | 4 +++ .../securesms/main/MainNavigationViewModel.kt | 25 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/MainActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/MainActivity.kt index 843054aa7e..c8e02ff2c8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MainActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/MainActivity.kt @@ -347,13 +347,17 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner val mutableInteractionSource = remember { MutableInteractionSource() } LaunchedEffect(mainNavigationDetailLocation) { + println("Detail Location Changed pane:${wrappedNavigator.currentDestination?.pane}") if (paneExpansionState.currentAnchor == listOnlyAnchor && wrappedNavigator.currentDestination?.pane == ThreePaneScaffoldRole.Primary) { + println("Animate detail") paneExpansionState.animateTo(detailOnlyAnchor) } } LaunchedEffect(mainNavigationState.currentListLocation) { + println("List Location Changed pane:${wrappedNavigator.currentDestination?.pane}") if (paneExpansionState.currentAnchor == detailOnlyAnchor && wrappedNavigator.currentDestination?.pane == ThreePaneScaffoldRole.Secondary) { + println("Animate list") paneExpansionState.animateTo(listOnlyAnchor) } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/main/MainNavigationViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/main/MainNavigationViewModel.kt index cd39e87e16..415e22c9ab 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/main/MainNavigationViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/main/MainNavigationViewModel.kt @@ -144,7 +144,20 @@ class MainNavigationViewModel( } navigatorScope?.launch { - navigator?.navigateTo(focusedPane) + val currentPane: ThreePaneScaffoldRole = navigator?.currentDestination?.pane ?: return@launch + + if (currentPane == focusedPane) { + return@launch + } + + if (currentPane == ThreePaneScaffoldRole.Secondary) { + navigator?.navigateTo(focusedPane) + } else { + navigator?.navigateBack() + if (navigator?.currentDestination == null) { + navigator?.navigateTo(ThreePaneScaffoldRole.Secondary) + } + } } } @@ -169,7 +182,15 @@ class MainNavigationViewModel( } navigatorScope?.launch { - navigator?.navigateTo(ThreePaneScaffoldRole.Secondary) + val currentPane = navigator?.currentDestination?.pane ?: return@launch + if (currentPane == ThreePaneScaffoldRole.Secondary) { + return@launch + } else { + navigator?.navigateBack() + if (navigator?.currentDestination == null) { + navigator?.navigateTo(ThreePaneScaffoldRole.Secondary) + } + } } }