Skip to content

Instantly share code, notes, and snippets.

@damianpetla
Created September 6, 2020 09:57
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 damianpetla/e9965d7982c397a14d33cdd9f5649717 to your computer and use it in GitHub Desktop.
Save damianpetla/e9965d7982c397a14d33cdd9f5649717 to your computer and use it in GitHub Desktop.
@ExperimentalCoroutinesApi
@Composable
fun LatestNewsFeed(viewModel: NewsViewModel) {
val state = viewModel.newsState.collectAsState()
val lastIndex = state.value.articles.lastIndex
LazyColumnForIndexed(items = state.value.articles) { i, newsItem ->
if (lastIndex == i) {
onActive {
viewModel.getMoreNews()
}
}
NewsCard(newsItem) {
viewModel.onSelectedNews(newsItem)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment