Luis Mierez
06/07/2021, 9:51 PMLazyColumn
without the paging library and I’ve come up with something that works but just want a sanity check since I’m still new to compose. Code in threadval listState = rememberLazyListState()
LazyColumn(
modifier = Modifier.fillMaxWidth(),
state = listState,
contentPadding = PaddingValues(all = 8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
itemsIndexed(items) { index, i ->
ContactRow(
imageUrl = "<https://via.placeholder.com/150?text=User$i>",
initials = "LM$i",
fullName = "Luis Mierez $i",
email = "lmierez$i@gmail.com"
)
}
}
val loadMore = remember {
derivedStateOf {
val layoutInfo = listState.layoutInfo
val totalItemsNumber = layoutInfo.totalItemsCount
val lastVisibleItemIndex = (layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0) + 1
val loadMore = lastVisibleItemIndex > (totalItemsNumber - buffer)
loadMore
}
}
LaunchedEffect(key1 = loadMore) {
snapshotFlow { loadMore.value }
.distinctUntilChanged()
.collect {
Timber.d("Load more: $it")
}
}
Load more
log message triggers when it should, but I’m wondering if that is the correct usage of LaunchedEffect
with snapshotFlow
Shakil Karim
06/07/2021, 9:57 PMLuis Mierez
06/07/2021, 9:59 PM