Exploring the official Pager in Compose

With the release of version 1.4, Jetpack Compose has officially received support for a paging layout. While this is something the View-based system has had for a long time in the form of a ViewPager widget, the developers had to use the Accompanist library implementation to achieve a similar effect with Compose.

There are two new composables available, HorizontalPager and VerticalPager. Let’s take a closer look at their usage and behavior.

HorizontalPager

HorizontalPager is a composable that allows scrolling horizontally left and right, either by the user or programmatically.

Horizontal scrolling Pager.

HorizontalPager composable.

VerticalPager

VerticalPager is a composable that allows scrolling vertically up and down, either by the user or programmatically.

Vertical scrolling Pager.

VerticalPager composable.

Taking a Closer Look

Pages/items are lazily composed and laid out when needed, similar to LazyColumn and LazyRow composables. All of these composables use LazyList internal composable under the hood.

Website