google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.43k stars 598 forks source link

[Pager] Horizontal Pager compose page twice when has exact 2 pages #1511

Closed debbiefu closed 1 year ago

debbiefu commented 1 year ago

Reproduce:

  1. run Horizontal Pager: Looping with indicators

  2. com/google/accompanist/sample/pager/HorizontalPagerLoopingIndicatorSample.kt val pageCount = 2

     HorizontalPager(
                // Set the raw page count to a really large number
                count = loopingCount,
                state = pagerState,
                // Add 32.dp horizontal padding to 'center' the pages
                contentPadding = PaddingValues(horizontal = 32.dp),
                // Add some horizontal spacing between items
                itemSpacing = 4.dp,
                modifier = Modifier
                    .weight(1f)
                    .fillMaxWidth()
            ) { index ->
                // We calculate the page from the given index
                val page = pageMapper(index)
                Log.d("pager", "compose index: $index for page $page at ${System.currentTimeMillis()} ")
                PagerSampleItem(
                    page = page,
                    modifier = Modifier
                        .fillMaxWidth()
                        .aspectRatio(1f)
                )
            }
  3. The log shows compose each page twice: image

Note: It only happens when pager has exact 2 pages

bentrengrove commented 1 year ago

Accompanist Pager has now been deprecated as we have upstreamed it to the main Compose library and so I am closing this bug.

Please retest your issue using Compose Foundation Pager in the March release. You can see our migration guide for help and if this is still an issue, please file a bug at goo.gle/compose-feedback