Last active
November 20, 2023 01:17
-
-
Save CostaFot/098c1d31801823d223320dbb2c17ec98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyViewModel: ViewModel() { | |
private val _stateflowSingleLiveEvent = MutableStateFlow<SingleLiveEvent<Event>?>(null) | |
val stateflowSingleLiveEvent: StateFlow<SingleLiveEvent<Event>?> = _stateflowSingleLiveEvent | |
} | |
// compose layer | |
LaunchedEffect(lifecycleOwner) { | |
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { | |
viewModel.stateflowSingleLiveEvent.collect { singleLiveEvent -> | |
singleLiveEvent?.getContentIfNotHandled()?.let { event -> | |
when (event) { | |
// handle one-time event | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment