Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to disable pager animation of HorizontalPager

I create a page which has 4 tabs and subpages, the HorizontalPager with dragEnabled = false, then I want to disable the animation when I click the tabs for changing the pages. How can I do it?

Column(modifier = Modifier.padding(bottom = 0.dp)) {
    HorizontalPager(
        state = pagerState,
        flingBehavior = PagerDefaults.rememberPagerFlingConfig(pagerState),
        verticalAlignment = Alignment.CenterVertically,
        horizontalAlignment = Alignment.CenterHorizontally,
        dragEnabled = false,
        modifier = Modifier.fillMaxSize()
    ) { pagePosition ->
        when (pagePosition) {
            0 -> GuideScreen()
            1 -> WebViewScreen()
            2 -> WebViewScreen()
            3 -> MineScreen()
        }
    }

    TabRow(selectedTabIndex = pagerState.currentPage,
        modifier = Modifier.fillMaxWidth(),
        backgroundColor = Color.White,
        indicator = {},
        divider = {}) {
        //...
    }
}

I try to repeat the HorizontalPager by when(){} code, but the WebViewScreen(a webview page) reloads every time when the page was changed, so that is not a good way.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

if you want to disable transition of each page during switching, instead of calling ,

pagerState.animateScrollToPage(index)

just simply call,

pagerState.scrollToPage(index)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading