https://kotlinlang.org logo
#compose-wear
Title
# compose-wear
j

Jeremiah Jordan

05/24/2022, 6:51 PM
Quick question: To implement a horizontal pager (or carousel) on Wear Compose, do I use the ViewPager2 components or the HorizontalPager components (from accompanist)?
Or do you simply make the element larger than the screen width and enable
Modifier.horizontalScroll
?
y

yschimke

05/25/2022, 8:06 AM
HorizontalPager works well.
👍 1
Horologist has a PagerScreen component that combines Accompanist HorizontalPager with Wear Compose PageIndicator. You can steal the code or use the component. https://github.com/google/horologist/blob/450c3da7ed79118d003e5ff1071fbeb339c3268f[…]java/com/google/android/horologist/compose/pager/PagerScreen.kt
❤️ 1
You can ignore the over-engineered lifecycle code in PagerScreen, it's only needed if you have Individual page Screens with no reference to the HorizontalPager state (you are reusing a screen that could be top level) and you want to activate scrolling of ScalingLazyColumn etc.
j

Jeremiah Jordan

05/25/2022, 10:57 PM
Actually I do have two screens which would both be considered "top level" that the user will need to navigate between, so I might need the lifecycle cleanup 🙂
y

yschimke

05/26/2022, 5:41 AM
Try out PagerScreen and let me know how you go.
👍 1
60 Views