Last active
August 30, 2022 08:30
-
-
Save Skyyo/c024c76b23c01ce0027a562b8d93929d 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 CurrenciesScreen(viewModel: CurrenciesViewModel) { | |
val currencyPrices by viewModel.currencyPrices.collectAsStateWithLifecycle() | |
LazyColumn { | |
itemsIndexed(currencyPrices) { index, currencyPrice -> | |
CurrencyPriceCard( | |
currencyPrice = currencyPrice, | |
onActive = { viewModel.onCardActive(currencyPrice.id, index) }, | |
onDisposed = { viewModel.onCardDisposed(currencyPrice.id) }) | |
} | |
} | |
} | |
@Composable | |
fun CurrencyPriceCard( | |
currencyPrice: CurrencyPrice, | |
onActive: () -> Unit, | |
onDisposed: () -> Unit, | |
) { | |
LaunchedEffect(Unit) { onActive() } | |
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