mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-15 07:28:30 +00:00
Set pane role when we move to a fullscreen anchor.
This commit is contained in:
committed by
jeffrey-signal
parent
b300c911d7
commit
443463aca8
@@ -67,8 +67,6 @@ 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
|
||||
@@ -448,22 +446,30 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
|
||||
mainNavigationViewModel.onPaneAnchorChanged(isFullScreenPane)
|
||||
}
|
||||
|
||||
LaunchedEffect(paneExpansionState, detailOnlyAnchor, listOnlyAnchor, wrappedNavigator) {
|
||||
mainNavigationViewModel.detailLocation.collect {
|
||||
if (paneExpansionState.currentAnchor == listOnlyAnchor) {
|
||||
paneExpansionState.animateTo(detailOnlyAnchor)
|
||||
LaunchedEffect(paneExpansionState.currentAnchor) {
|
||||
when (paneExpansionState.currentAnchor) {
|
||||
listOnlyAnchor -> {
|
||||
mainNavigationViewModel.setFocusedPane(ThreePaneScaffoldRole.Secondary)
|
||||
}
|
||||
detailOnlyAnchor -> {
|
||||
mainNavigationViewModel.setFocusedPane(ThreePaneScaffoldRole.Primary)
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(paneExpansionState, detailOnlyAnchor, listOnlyAnchor, wrappedNavigator) {
|
||||
val a = mainNavigationViewModel.mainNavigationState.map { it.currentListLocation }
|
||||
val b = mainNavigationViewModel.tabClickEvents
|
||||
val paneFocusRequest by mainNavigationViewModel.paneFocusRequests.collectAsStateWithLifecycle(null)
|
||||
LaunchedEffect(paneFocusRequest) {
|
||||
if (paneFocusRequest == null) {
|
||||
return@LaunchedEffect
|
||||
}
|
||||
|
||||
merge(a, b).collect {
|
||||
if (paneExpansionState.currentAnchor == detailOnlyAnchor) {
|
||||
paneExpansionState.animateTo(listOnlyAnchor)
|
||||
}
|
||||
if (paneFocusRequest == ThreePaneScaffoldRole.Secondary && paneExpansionState.currentAnchor == detailOnlyAnchor) {
|
||||
paneExpansionState.animateTo(listOnlyAnchor)
|
||||
}
|
||||
|
||||
if (paneFocusRequest == ThreePaneScaffoldRole.Primary && paneExpansionState.currentAnchor == listOnlyAnchor) {
|
||||
paneExpansionState.animateTo(detailOnlyAnchor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,13 +81,15 @@ class MainNavigationViewModel(
|
||||
* This is Rx because these are still accessed from Java.
|
||||
*/
|
||||
private val internalTabClickEvents: MutableSharedFlow<MainNavigationListLocation> = MutableSharedFlow()
|
||||
val tabClickEvents: SharedFlow<MainNavigationListLocation> = internalTabClickEvents
|
||||
val tabClickEventsObservable: Observable<MainNavigationListLocation> = internalTabClickEvents.asObservable()
|
||||
|
||||
private var earlyNavigationListLocationRequested: MainNavigationListLocation? = null
|
||||
var earlyNavigationDetailLocationRequested: MainNavigationDetailLocation? = null
|
||||
private set
|
||||
|
||||
private val internalPaneFocusRequests = MutableSharedFlow<ThreePaneScaffoldRole?>()
|
||||
val paneFocusRequests: SharedFlow<ThreePaneScaffoldRole?> = internalPaneFocusRequests
|
||||
|
||||
private var earlyFocusedPaneRequested: ThreePaneScaffoldRole? = null
|
||||
|
||||
/**
|
||||
@@ -180,6 +182,10 @@ class MainNavigationViewModel(
|
||||
navigatorScope?.launch {
|
||||
navigator?.navigateTo(roleToGoTo)
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
internalPaneFocusRequests.emit(roleToGoTo)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,6 +284,7 @@ class MainNavigationViewModel(
|
||||
viewModelScope.launch {
|
||||
val currentTab = internalMainNavigationState.value.currentListLocation
|
||||
if (currentTab == destination) {
|
||||
internalPaneFocusRequests.emit(ThreePaneScaffoldRole.Secondary)
|
||||
internalTabClickEvents.emit(destination)
|
||||
} else {
|
||||
setFocusedPane(ThreePaneScaffoldRole.Secondary)
|
||||
|
||||
Reference in New Issue
Block a user