Last active
October 6, 2021 14:19
-
-
Save Skyyo/e7a3d6359e39251015890f4286cdf254 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 LifecycleAwareCurrencyPriceCard( | |
currencyPrice: CurrencyPrice, | |
currencyPriceUpdateFlow: Flow<Int>, | |
onCurrencyUpdated: (progress: Int) -> Unit, | |
onDisposed: () -> Unit, | |
) { | |
val lifecycleOwner = LocalLifecycleOwner.current | |
val lifecycleAwareCurrencyPriceFlow = remember(currencyPriceUpdateFlow, lifecycleOwner) { | |
currencyPriceUpdateFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED) | |
} | |
LaunchedEffect(Unit) { | |
lifecycleAwareCurrencyPriceFlow.collect { progress -> onCurrencyUpdated(progress) } | |
} | |
DisposableEffect(Unit) { onDispose { onDisposed() } } | |
CurrencyCard(currencyPrice.name, "${currencyPrice.price}", currencyPrice.priceFluctuation) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment