Fix auto-expansion of panes on click.

This commit is contained in:
Alex Hart
2025-10-17 11:38:34 -03:00
committed by Cody Henthorne
parent e2b57b55d6
commit 435be7c63d
5 changed files with 20 additions and 13 deletions

View File

@@ -66,6 +66,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChangedBy
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.signal.core.ui.compose.theme.SignalTheme
@@ -403,15 +405,22 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
}
}
LaunchedEffect(mainNavigationDetailLocation) {
if (paneExpansionState.currentAnchor == listOnlyAnchor && wrappedNavigator.currentDestination?.pane == ThreePaneScaffoldRole.Primary) {
paneExpansionState.animateTo(detailOnlyAnchor)
LaunchedEffect(paneExpansionState, detailOnlyAnchor, listOnlyAnchor, wrappedNavigator) {
mainNavigationViewModel.detailLocation.collect {
if (paneExpansionState.currentAnchor == listOnlyAnchor) {
paneExpansionState.animateTo(detailOnlyAnchor)
}
}
}
LaunchedEffect(mainNavigationState.currentListLocation) {
if (paneExpansionState.currentAnchor == detailOnlyAnchor && wrappedNavigator.currentDestination?.pane == ThreePaneScaffoldRole.Secondary) {
paneExpansionState.animateTo(listOnlyAnchor)
LaunchedEffect(paneExpansionState, detailOnlyAnchor, listOnlyAnchor, wrappedNavigator) {
val a = mainNavigationViewModel.mainNavigationState.map { it.currentListLocation }
val b = mainNavigationViewModel.tabClickEvents
merge(a, b).collect {
if (paneExpansionState.currentAnchor == detailOnlyAnchor) {
paneExpansionState.animateTo(listOnlyAnchor)
}
}
}

View File

@@ -206,7 +206,7 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
}
private fun initializeTapToScrollToTop(scrollToPositionDelegate: ScrollToPositionDelegate) {
disposables += mainNavigationViewModel.tabClickEvents
disposables += mainNavigationViewModel.tabClickEventsObservable
.filter { it == MainNavigationListLocation.CALLS }
.subscribeBy(onNext = {
scrollToPositionDelegate.resetScrollPosition()

View File

@@ -398,7 +398,7 @@ public class ConversationListFragment extends MainFragment implements Conversati
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), chatListBackHandler);
lifecycleDisposable.bindTo(getViewLifecycleOwner());
lifecycleDisposable.add(mainNavigationViewModel.getTabClickEvents().filter(tab -> tab == MainNavigationListLocation.CHATS)
lifecycleDisposable.add(mainNavigationViewModel.getTabClickEventsObservable().filter(tab -> tab == MainNavigationListLocation.CHATS)
.subscribe(unused -> {
Log.d(TAG, "Scroll to top please");
LinearLayoutManager layoutManager = (LinearLayoutManager) list.getLayoutManager();

View File

@@ -46,9 +46,6 @@ class MainNavigationViewModel(
private var navigatorScope: CoroutineScope? = null
private var goToLegacyDetailLocation: ((MainNavigationDetailLocation) -> Unit)? = null
/**
* The latest detail location that has been requested, for consumption by other components.
*/
private val internalDetailLocation = MutableSharedFlow<MainNavigationDetailLocation>()
val detailLocation: SharedFlow<MainNavigationDetailLocation> = internalDetailLocation
@@ -76,7 +73,8 @@ class MainNavigationViewModel(
* This is Rx because these are still accessed from Java.
*/
private val internalTabClickEvents: MutableSharedFlow<MainNavigationListLocation> = MutableSharedFlow()
val tabClickEvents: Observable<MainNavigationListLocation> = internalTabClickEvents.asObservable()
val tabClickEvents: SharedFlow<MainNavigationListLocation> = internalTabClickEvents
val tabClickEventsObservable: Observable<MainNavigationListLocation> = internalTabClickEvents.asObservable()
private var earlyNavigationListLocationRequested: MainNavigationListLocation? = null
var earlyNavigationDetailLocationRequested: MainNavigationDetailLocation? = null

View File

@@ -159,7 +159,7 @@ class StoriesLandingFragment : DSLSettingsFragment(layoutId = R.layout.stories_l
}
)
lifecycleDisposable += mainNavigationViewModel.tabClickEvents
lifecycleDisposable += mainNavigationViewModel.tabClickEventsObservable
.filter { it == MainNavigationListLocation.STORIES }
.subscribeBy(onNext = {
val layoutManager = recyclerView?.layoutManager as? LinearLayoutManager ?: return@subscribeBy