ursus
03/09/2026, 12:04 AMNav3 change the opinion on navigating from view model? (Say once a suspend action in vm finishes, one should navigate to screen B)
Is it still exposing a ViewModel.events (a mutable shared flow of sealed class events) to the ui composable and changing the backstack there?
Or is there a better approach?Pablichjenkov
03/09/2026, 12:34 AMursus
03/09/2026, 1:18 AMPablichjenkov
03/09/2026, 1:23 AMursus
03/09/2026, 1:38 AMPablichjenkov
03/09/2026, 1:45 AMursus
03/09/2026, 1:47 AMPablichjenkov
03/09/2026, 2:12 AMursus
03/09/2026, 2:15 AMMark
03/09/2026, 2:58 AMStateFlow nor a SharedFlow for events. Use a Channel-backed Flow instead (receiveAsFlow)ursus
03/09/2026, 3:00 AMMark
03/09/2026, 3:02 AMreceiveAsFlow works. https://elizarov.medium.com/shared-flows-broadcast-channels-899b675e805cOleksandr Balan
03/09/2026, 8:31 AMNav3, we maintain our own backstack, so I believe it is valid to keep it as a MutableStateFlow within a repository and expose methods to observe and update it 🤷
class InMemoryNavigationRepository : NavigationRepository {
private val _screens = MutableStateFlow(listOf(Screen.startDestination()))
override val screens: StateFlow<List<Screen>> = _screens.asStateFlow()
override fun navigateTo(screen: Screen) {
_screens.update { backStack ->
backStack + screen
}
}
override fun navigateBack() {
_screens.update { backStack ->
if (backStack.isNotEmpty()) {
backStack.dropLast(1)
} else {
backStack
}
}
}
...
}Jack Boswell
03/09/2026, 8:51 AMJack Boswell
03/09/2026, 8:54 AMJack Boswell
03/09/2026, 8:54 AMJack Boswell
03/09/2026, 8:56 AMursus
03/09/2026, 9:20 AMursus
03/09/2026, 9:25 AMOf course, if your primary navigation model is "this work needs to finish before navigating" then it might make sense to rethink that
what do you mean by that specifically? a new pattern? since first half of you message sounded like youre arguing for LoginDoneEvent vs GoToHomeEvent, i.e. semantics, but events nonetheless
Jack Boswell
03/09/2026, 9:31 AMursus
03/09/2026, 9:32 AMOleksandr Balan
03/09/2026, 9:33 AMursus
03/09/2026, 9:33 AMJack Boswell
03/09/2026, 9:35 AMursus
03/09/2026, 9:36 AMJack Boswell
03/09/2026, 9:36 AMursus
03/09/2026, 9:38 AMJack Boswell
03/09/2026, 9:40 AMursus
03/09/2026, 9:44 AMursus
03/09/2026, 9:45 AMMark
03/09/2026, 9:46 AMSharedFlowursus
03/09/2026, 9:57 AMThis happens in a design with a type of event that usually has a single subscriber, but intermittently (at startup or during some kind of reconfiguration) there are no subscribers at all, and there is a requirement that all posted events must be retained until a subscriber appears.
okay so this is what you were referencing, right?