https://kotlinlang.org logo
#compose
Title
# compose
n

Nikolas Guillen Leon

02/23/2023, 12:06 PM
Hi guys, do you know if in Accompanist's Pager it is possible to have 2 items per page? For example, if the list of images I'm showing has 10 images, in the first screen I want to show page 1 and 2, then swiping you go to page 3-4 etc.
c

cb

02/23/2023, 12:10 PM
You can't do that with Pager, but you can with via snapping fling behavior. Snapper supported this out of the box: https://chrisbanes.github.io/snapper/usage/#snapping-groups
In fact, you can do with via Pager, but you'll need to manually create a
Row
for each page, placing
n
and
n+1
in the row
n

Nikolas Guillen Leon

02/23/2023, 12:13 PM
thank you very much!
a

Andrey Kulikov

02/28/2023, 2:23 PM
Our new HorizontalPager from compose:foundation allows to have any number of items having the same width. see https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PageSize
c

curioustechizen

03/02/2023, 6:49 AM
@Andrey Kulikov have you considered enhancing the PageSize API to take into account the index of the page? i.e., have you considered allowing different pages to have different sizes?
a

Andrey Kulikov

03/02/2023, 11:34 AM
no. we decided Pager will be optimized for the use case of each page having the same size (regardless of if the page is filling the whole screen, or not) . for other use cases it is recommended to use LazyRow + SnapFlingBehavior
88 Views