Jetpack Compose ViewPager
Letβs use a few minutes to learn how to write a swipeable pager composable.
Disclaimer
In case you got here looking for a Jetpack Compose implementation of a Pager
, let me suggest you to take a look at the semi-official one provided by Accompanist by Chris Banes.
Accompanist provides variants for both HorizontalPager
and VerticalPager
and for now itβs flagged as an @ExperimentalPagerApi
, since its api surface might still evolve. That said, Iβve tested it and this implementation works much better than the one I was diving into in this post.
For that reason Iβve decided to deprecate the post given the information on it was starting to become misleading and quite outdated given how tied it was to the component implementation details. It already served itβs purpose!
I am keeping the post entry since SEO is good enough here so it can help leading devs to the Accompanist implementation for now.
Finally, let me recommend the official Jetpack Compose samples as a really good way to get familiarized with Compose codebases and architecture π
You might be interested in other posts I wrote about Jetpack Compose:
- Awaiting next animation frame using suspend
- Sneak peek into Compose ConstraintLayout
- Custom layouts, measuring and WithConstraints Composable
I also share thoughts and ideas on Twitter quite regularly. You can also find me on Instagram. See you there!
Stay tunned for Jetpack Compose posts π