I have a HorizontalPager with a TabRow with two items. Currently you need to swipe almost the entire screen before it snaps to the next page. I'd like it to snap to the other page on a smaller scroll. This is my current code:
val pagerState = rememberPagerState()
val coroutineScope = rememberCoroutineScope()
Column(modifier = Modifier.fillMaxSize()) {
TabRow(
selectedTabIndex = pagerState.currentPage
) {
Tab(
selected = pagerState.currentPage == 0,
onClick = { component.changeChild(0) },
modifier = Modifier.height(53.dp)
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = "First page"
)
}
}
Tab(
selected = pagerState.currentPage == 1,
onClick = { component.changeChild(1) },
modifier = Modifier.height(53.dp)
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = "Second page"
)
}
}
}
HorizontalPager(
pageCount = 2,
state = pagerState,
beyondBoundsPageCount = 1,
modifier = Modifier.fillMaxSize()
) { page ->
when (page) {
0 -> FirstPage()
1 -> SecondPage()
}
}
I've tried to modify the flingBehavior
in HorizontalPager, but nothing I've tried actually modifies the distance needed to swipe. I've also looked online, but all the questions are either for the old HorizontalPager from the Accompanist library, or the Snapper library.