Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
Jetpack Compose component(s) used:
My short code with exact components which are used:
```
Column {
TabsRow {
ScrollableTabsRow{}
}
Horizontal Pager {
Column {
SubCategories { ScrollableHorizontalTabsRow or LazyHorizontalStaggeredGrid() }
ProductsContent { LazyColumn {} }
}
}
}
```
Android Studio Build: Android Studio Koala Feature Drop | 2024.1.2
Kotlin version: 1.9.21
Steps to Reproduce or Code Sample to Reproduce:
I have issue with HorizontalPager.
Sometimes it works for some tabs, but sometimes after changing tabs using horizontal pager it start infinite recompositions with logs seen at the bottom of the post.
Basically parameter `page` from `horizontal pager` doesn't know if it's 5 or 4 or 6 page and stars recompose, but in the screen it is still 5 page.
So imagine it is:
Category Tabs (one row)
SubCategories (one row or multiple rows)
Products
```
@Composable
fun ComposableContent() {
val categories = state.categories
val pagerState = rememberPagerState(
initialPage = initialPage
)
BaseCategoriesTabRow(
state = pagerState,
categories = categories,
)
Spacer(
modifier = Modifier
.height(10.dp)
.fillMaxWidth()
.background(Color.White)
)
HorizontalPager(
state = pagerState,
pageCount = categories.size
) { page ->
val listState = rememberLazyListState()
categories.getOrNull(page)?.let { categoryItem ->
val showItemsInOneRow = remember {
derivedStateOf {
listState.firstVisibleItemIndex > 1 || categoryItem.subCategories.size < SUBCATEGORIES_ROW_TWO_MIN
}
}
Log.d("horizontalagertest", "PAGE: ${page} + CURRENTPAGE: ${pagerState.currentPage}")
Column {
if (categoryItem.subCategories.size > 1) {
SubCategoriesTabRow(
state = listState,
showItemsInOneRow = showItemsInOneRow.value,
events = events,
category = categoryItem,
rows = constRowQuantity,
initialSubCategoryId = initialSubCategoryId
) {
events.invoke(CategoryEvent.InitialSubcategoryHandled)
}
}
}
```
At the beginning I was using accompanist, then migrate to compose foundation last release 1.6.1. And it still run like this. ( I tried higher versions but there is still a problem with this library)
Thanks for any advice or alternative solution with Horizontal Pager that could works.
Stack trace (if applicable):
```
PAGE: 5, CURRENTPAGE: 5
PAGE: 6, CURRENTPAGE: 5
PAGE: 4, CURRENTPAGE: 5
PAGE: 6, CURRENTPAGE: 5
PAGE: 5, CURRENTPAGE: 5
PAGE: 4, CURRENTPAGE: 5
PAGE: 5, CURRENTPAGE: 5
PAGE: 6, CURRENTPAGE: 5
PAGE: 4, CURRENTPAGE: 5
PAGE: 6, CURRENTPAGE: 5
PAGE: 5, CURRENTPAGE: 5
PAGE: 4, CURRENTPAGE: 5
```