Skip to content

Instantly share code, notes, and snippets.

@CostaFot
Last active November 20, 2023 00:55
Show Gist options
  • Save CostaFot/dd11ac04f518101bf4a7b461f4e3af2d to your computer and use it in GitHub Desktop.
Save CostaFot/dd11ac04f518101bf4a7b461f4e3af2d to your computer and use it in GitHub Desktop.
// viewModel layer
class MyViewModel: ViewModel() {
private val _eventWithSharedFlow = MutableSharedFlow<Event>()
val eventWithSharedFlow: SharedFlow<Event> = _eventWithSharedFlow
}
// compose layer
LaunchedEffect(lifecycleOwner) {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.eventWithSharedFlow.collect {
// handle one-time event
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment