Jake
10/25/2022, 9:49 AMHorizontalPager
.
By testing the sample code from the guide works great:
// Display 10 items
HorizontalPager(count = 10) { page ->
// Our page content
Text(
text = "Page: $page",
modifier = Modifier.fillMaxWidth()
)
}
But I need to display different `Composable`s in different pages instead of same element. The only way I figured how to do this is the following:
HorizontalPager(count = 3) {
if(currentPage == 0){
FirstView() // Composable
} else if (currentPage == 1) {
SecondView() // Composable
} else if (currentPage == 2){
ThirdView() // Composable
}
The problem with this implementation is that when I swipe to navigate, it appears like the view coming from the side is the same as the current view. When the currentpage
updates to the next view it suddenly updates the view to the upcoming view. So there is no smooth animation like in the sample code. Suggestions how to implement this better?ste
10/25/2022, 9:50 AMit
(page
parameter) in the second snippetJake
10/25/2022, 9:53 AMpage
parameter and it works wonders. Thanks a lot!Alex Centi
10/25/2022, 1:20 PMHorizontalPager(count = 3) { page ->
when (page) {
0 -> FirstView()
1 -> Second View()
2 -> ThirdView()
}