Skip to content

Instantly share code, notes, and snippets.

@igorescodro
Created June 9, 2025 23:14
Show Gist options
  • Save igorescodro/fc148110a4e7f40c2db6f1db03105969 to your computer and use it in GitHub Desktop.
Save igorescodro/fc148110a4e7f40c2db6f1db03105969 to your computer and use it in GitHub Desktop.
// NavEventController.kt
interface NavEventController {
val destinationState: SharedFlow<Destination>
fun sendEvent(event: Event)
}
// NavEventControllerImpl.kt
internal class NavEventControllerImpl(
private val appCoroutineScope: AppCoroutineScope,
) : NavEventController {
private val navigationEventState: MutableSharedFlow<Event> = MutableSharedFlow()
override val destinationState: SharedFlow<Destination> =
navigationEventState
.map { event ->
event.nextDestination()
}.shareIn(
scope = CoroutineScope(appCoroutineScope.context),
started = SharingStarted.WhileSubscribed(),
)
override fun sendEvent(event: Event) {
appCoroutineScope.launch {
navigationEventState.emit(event)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment