diff --git a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt index 81024276d..bf1f5d5dc 100644 --- a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt +++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/AuthorsCarousel.kt @@ -77,7 +77,7 @@ fun AuthorsCarousel( } }.collect() } - + LazyRow(modifier, lazyListState) { items(items = authors, key = { item -> item.author.id }) { followableAuthor -> AuthorItem( diff --git a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt index b29a3b6e0..8a3782a8b 100644 --- a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt +++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt @@ -44,6 +44,7 @@ import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyHorizontalGrid import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.lazy.grid.rememberLazyGridState import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.CornerSize @@ -320,7 +321,25 @@ private fun TopicSelection( onTopicCheckedChanged: (String, Boolean) -> Unit, modifier: Modifier = Modifier ) { + val lazyGridState = rememberLazyGridState() + JankMetricEffect(lazyGridState) { metricsHolder -> + combine( + snapshotFlow { lazyGridState.isScrollInProgress }, + snapshotFlow { lazyGridState.firstVisibleItemIndex }, + ) { isScrollInProgress, firstVisibleItemIndex -> + if (isScrollInProgress) { + metricsHolder.state?.addState( + "ForYou:TopicSelection:Scrolling", + "index=${firstVisibleItemIndex}" + ) + } else { + metricsHolder.state?.removeState("ForYou:TopicSelection:Scrolling") + } + }.collect() + } + LazyHorizontalGrid( + state = lazyGridState, rows = GridCells.Fixed(3), horizontalArrangement = Arrangement.spacedBy(12.dp), verticalArrangement = Arrangement.spacedBy(12.dp),