Search code examples
androidpaginationnavigationwear-os

Pagination in Wear OS


Good Morning, I'm developing a new Wear OS application. The thing is, I can't find anywhere how to make a good pagination.
I would like to change activity on swipe (no matter if it's vertical or horizontal) but can't find anywhere how to do it...
Maybe I should not navigate in my app like that ? Can you help me if you have any answer on how to do it ?
thanks ! (for some reasons I can't say hello on my post ?)


Solution

  • You can use HorizontalPager or VerticalPager from Accompanist.

    https://google.github.io/accompanist/pager/

                    HorizontalPager(
                        modifier = Modifier.fillMaxSize(),
                        count = 10,
                        state = state
                    ) { page ->
                            Box(
                                modifier = Modifier.fillMaxSize(),
                                contentAlignment = Alignment.Center
                            ) {
                                Text(text = "Screen $page")
                            }
                        }
                    
    

    An example https://github.com/google/horologist/blob/e2741cef87774b18d58bb1b0f78bd5b60901f20d/sample/src/main/java/com/google/android/horologist/scratch/ScratchActivity.kt#L79

    If you want something more custom, then it's probably a serious investment in a component. Especially if it needs to work with the system Swipe to Dismiss.