Prevent conversation re-launch on reconfiguration of screen.

This commit is contained in:
Alex Hart
2025-04-09 10:45:37 -03:00
committed by Michelle Tang
parent 6ea63f3e34
commit d81616d23c
2 changed files with 10 additions and 7 deletions

View File

@@ -130,7 +130,7 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
setContent {
val navState = rememberFragmentState()
val listHostState = rememberFragmentState()
val detailLocation by navigator.viewModel.detailLocation.collectAsStateWithLifecycle()
val detailLocation by navigator.viewModel.detailLocation.collectAsStateWithLifecycle(MainNavigationDetailLocation.Empty)
LaunchedEffect(detailLocation) {
if (detailLocation is MainNavigationDetailLocation.Conversation) {

View File

@@ -6,16 +6,19 @@
package org.thoughtcrime.securesms.main
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.launch
class MainNavigationViewModel : ViewModel() {
private val detailLocationFlow = MutableStateFlow<MainNavigationDetailLocation>(MainNavigationDetailLocation.Empty)
private val detailLocationFlow = MutableSharedFlow<MainNavigationDetailLocation>()
val detailLocation: StateFlow<MainNavigationDetailLocation> = detailLocationFlow
val detailLocation: SharedFlow<MainNavigationDetailLocation> = detailLocationFlow
fun goTo(location: MainNavigationDetailLocation) {
detailLocationFlow.update { location }
viewModelScope.launch {
detailLocationFlow.emit(location)
}
}
}