https://kotlinlang.org logo
#compose
Title
# compose
q

Qamar Khan

09/27/2023, 4:25 PM
how to prevent Horizontal pager to load 2 pages. initially it loads 2 pages, on swipe to 3rd or 4th item again it loads next page, let say page current visible page is 3 when scroll or swipe i want to just load the 4th page only, not 5th.. is their any way we have.
Copy code
val numberOfPages = 7
    HorizontalPager(
        state = pagerState,
        modifier = Modifier
            .fillMaxWidth()
            .height(90.dp)
            .padding(top = 12.dp)
    ) { currentPage ->
        Column(
            modifier = Modifier.fillMaxWidth(),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            if (currentPageIndex == currentPage) {
                BarChart(
                    modifier = Modifier.fillMaxWidth(),
                    lables = labels,
                    listOfPredicationBarItems =  listOfPredicationBarItems
                )
            }
        }
    }
#compose #compose-android
a

ascii

09/27/2023, 5:14 PM
There's
beyondBoundsPageCount
(default 0) but that doesn't change prefetcher behaviour. At the moment you can't adjust the latter.
q

Qamar Khan

09/27/2023, 8:24 PM
i fixed the problem with slightly change in code like this
Copy code
if (pagerState.settledPage == currentPage) {
this is worked and now i am able to see only the current visible page bar chart data only.
3 Views