Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Composable
fun CurrenciesScreen(viewModel: CurrenciesViewModel) {
val currencyPrices = viewModel.currencyPrices.collectAsState()
LazyColumn {
itemsIndexed(currencyPrices.value) { 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