Vaibhav Jaiswal
01/23/2024, 5:00 PMLaunchedEffect(listState){
snapshotFlow { listState.layoutInfo }
.map { it.visibleItemsInfo }
.map { items -> items.map { news[it.index] } }
.onEach { it.log("Recording Viewed") }
.map { it.filterNotNull() }
.safeCatch()
.collect { it.onEach(component::recordViewed) }
}
here news is a LazyPagingItems<T>
Vaibhav Jaiswal
01/23/2024, 5:20 PMZach Klippenstein (he/him) [MOD]
01/23/2024, 5:58 PMVaibhav Jaiswal
01/23/2024, 6:24 PM@Composable
fun NewsTab(
component: NewsTabComponent,
bottomNavVisibility:(Boolean) -> Unit
) {
val news = component.newsFeed.collectAsLazyPagingItems()
val listState = rememberLazyListState()
LaunchedEffect(component){
component.onTabReselected
.onEach { listState.fastScrollToTop() }
.safeCatch()
.launchIn(this)
}
val isScrollingUp = listState.isScrollingUp()
bottomNavVisibility(isScrollingUp)
BaseScreenContent(
component = component,
onRefresh = { component.withSwipeRefresh { news.refresh() }},
){
MedialLazyColumn(
modifier = Modifier.fillMaxSize(),
state = listState,
loadState = news.loadState.mediator,
items = news,
contentType = { this.type },
loader = remember { { item { Loader(Modifier.fillParentMaxSize()) } } }
) {
when (it) {
is NewsMedia.News -> NewsCard(it, Modifier.fillMaxWidth(), onAction = component::handleAction)
is NewsMedia.Poll -> PollCard(it, Modifier.fillMaxWidth(), onAction = component::handleAction)
is NewsMedia.Quiz -> QuizCard(it, Modifier.fillMaxWidth(), onAction = component::handleAction)
}
}
}
LaunchedEffect(listState){
snapshotFlow { listState.layoutInfo }
.map { it.visibleItemsInfo }
.map { items -> items.map { news.peek(it.index) } }
.onEach { it.log("Recording Viewed") }
.map { it.filterNotNull() }
.safeCatch()
.collect { it.onEach(component::recordViewed) }
}
}
Zach Klippenstein (he/him) [MOD]
01/23/2024, 6:35 PMsnapshotFlow
lambda itself and spit out something about the visible items, are you seeing anything then?Vaibhav Jaiswal
01/24/2024, 10:56 AMVaibhav Jaiswal
01/24/2024, 11:06 AMVaibhav Jaiswal
01/24/2024, 11:15 AMLaunchedEffect(listState){
snapshotFlow { listState.isScrollInProgress }
.filterNot { it }
.map { listState.layoutInfo.visibleItemsInfo.map { news.peek(it.index) } }
.map { it.filterNotNull() }
.safeCatch()
.onEach { it.onEach(component::recordViewed) }
.launchIn(this)
}
Zach Klippenstein (he/him) [MOD]
01/24/2024, 6:43 PMVaibhav Jaiswal
01/25/2024, 7:56 AMZach Klippenstein (he/him) [MOD]
01/25/2024, 4:11 PMVaibhav Jaiswal
01/25/2024, 4:13 PM