Skip to content

Instantly share code, notes, and snippets.

@Skyyo
Last active August 30, 2022 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skyyo/c024c76b23c01ce0027a562b8d93929d to your computer and use it in GitHub Desktop.
Save Skyyo/c024c76b23c01ce0027a562b8d93929d to your computer and use it in GitHub Desktop.
@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