Created
June 13, 2021 04:34
-
-
Save hongbeomi/c0b775a700fd6f3a8dafb0844d19f970 to your computer and use it in GitHub Desktop.
This file contains 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
@Composable | |
fun <T> getLifecycleAwareState( | |
flow: Flow<T>, | |
initialValue: T, | |
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, | |
minActiveState: Lifecycle.State = Lifecycle.State.STARTED | |
): State<T> { | |
return remember(flow, lifecycleOwner) { | |
flow.flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState) | |
}.collectAsState(initialValue) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment