Pre-seed navigation when intent is processed before navigator is set.

This commit is contained in:
Alex Hart
2025-09-12 09:33:23 -03:00
committed by Greyson Parrelli
parent b649b8c943
commit 63800306a0
3 changed files with 28 additions and 0 deletions

View File

@@ -753,6 +753,7 @@ class MainActivity : PassphraseRequiredActivity(), VoiceNoteMediaControllerOwner
private fun handleConversationIntent(intent: Intent) {
if (ConversationIntents.isConversationIntent(intent)) {
Log.d(TAG, "Got conversation intent. Navigating to conversation.")
mainNavigationViewModel.goTo(MainNavigationListLocation.CHATS)
mainNavigationViewModel.goTo(MainNavigationDetailLocation.Conversation(intent))
}

View File

@@ -66,6 +66,7 @@ open class ConversationActivity : PassphraseRequiredActivity(), VoiceNoteMediaCo
}
finish()
return
}
enableSavedStateHandles()

View File

@@ -68,6 +68,9 @@ class MainNavigationViewModel(
private val internalTabClickEvents: MutableSharedFlow<MainNavigationListLocation> = MutableSharedFlow()
val tabClickEvents: Observable<MainNavigationListLocation> = internalTabClickEvents.asObservable()
private var earlyNavigationListLocationRequested: MainNavigationListLocation? = null
private var earlyNavigationDetailLocationRequested: MainNavigationDetailLocation? = null
init {
performStoreUpdate(MainNavigationRepository.getNumberOfUnreadMessages()) { unreadChats, state ->
state.copy(chatsCount = unreadChats.toInt())
@@ -94,6 +97,19 @@ class MainNavigationViewModel(
this.goToLegacyDetailLocation = goToLegacyDetailLocation
this.navigatorScope = composeScope
this.navigator = threePaneScaffoldNavigator
earlyNavigationListLocationRequested?.let {
goTo(it)
}
earlyNavigationListLocationRequested = null
earlyNavigationDetailLocationRequested?.let {
goTo(it)
}
earlyNavigationDetailLocationRequested = null
return threePaneScaffoldNavigator
}
@@ -107,6 +123,11 @@ class MainNavigationViewModel(
return
}
if (navigator == null) {
earlyNavigationDetailLocationRequested = location
return
}
internalDetailLocation.update {
location
}
@@ -128,6 +149,11 @@ class MainNavigationViewModel(
}
fun goTo(location: MainNavigationListLocation) {
if (navigator == null) {
earlyNavigationListLocationRequested = location
return
}
if (location != MainNavigationListLocation.CHATS) {
internalDetailLocation.update {
MainNavigationDetailLocation.Empty