Created
June 7, 2025 16:57
-
-
Save euri16/be39a09f67681bc7168ab00256a336f6 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
| @Composable | |
| fun <EFFECT> LaunchedUiEffectHandler( | |
| effectFlow: Flow<EFFECT?>, | |
| onEffect: suspend (EFFECT) -> Unit, | |
| onConsumeEffect: () -> Unit, | |
| ) { | |
| val effect by effectFlow.collectAsStateWithLifecycle(null) | |
| val currentOnEffect by rememberUpdatedState(onEffect) | |
| val currentOnConsumeEffect by rememberUpdatedState(onConsumeEffect) | |
| LaunchedEffect(effect) { | |
| effect?.let { | |
| currentOnEffect(it) | |
| currentOnConsumeEffect() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment