@@ -59,7 +59,6 @@ import androidx.compose.ui.text.font.FontWeight
5959import androidx.compose.ui.text.style.TextOverflow
6060import androidx.compose.ui.unit.dp
6161import androidx.compose.ui.unit.sp
62- import androidx.compose.ui.util.fastForEachIndexed
6362import androidx.compose.ui.zIndex
6463import androidx.paging.compose.LazyPagingItems
6564import androidx.paging.compose.collectAsLazyPagingItems
@@ -518,15 +517,25 @@ fun FlowPage(
518517 if (markAsReadOnScroll && filterState.filter.isUnread()) {
519518 LaunchedEffect (listState.isScrollInProgress) {
520519 if (! listState.isScrollInProgress) {
521- val firstItemIndex = listState.firstVisibleItemIndex
520+ val firstItemKey =
521+ listState.layoutInfo.visibleItemsInfo
522+ .firstOrNull { it.contentType == CONTENT_TYPE_ARTICLE }
523+ ?.key
522524 val items = mutableListOf<ArticleWithFeed >()
523- if (firstItemIndex < pagingItems.itemCount) {
524- for (index in 0 until firstItemIndex) {
525- pagingItems.peek(index).let {
526- if (it is ArticleFlowItem .Article )
527- items.add(it.articleWithFeed)
525+ var found = false
526+ val itemCount = pagingItems.itemCount
527+ for (index in 0 until itemCount) {
528+ pagingItems.peek(index).let {
529+ if (it is ArticleFlowItem .Article ) {
530+ items.add(it.articleWithFeed)
531+ if (it.articleWithFeed.article.id == firstItemKey) {
532+ found = true
533+ break
534+ }
528535 }
529536 }
537+ }
538+ if (items.isNotEmpty() && found) {
530539 viewModel.diffMapHolder.updateDiff(
531540 articleWithFeed = items.toTypedArray(),
532541 isUnread = false ,
0 commit comments