Hi. Have any faced this issue? I have a LazyColumn...
# compose
f
Hi. Have any faced this issue? I have a LazyColumn where items are HorizontalPagers. When I swipe on my item multiple pages are being changed. Here is my code
Copy code
val pagerState = rememberPagerState(
    initialPage = Int.MAX_VALUE / 2,
    pageCount = { Int.MAX_VALUE }
)

HorizontalPager(
    state = pagerState,
    beyondBoundsPageCount = 1,
    modifier = modifier
        .height(116.dp)
        .fillMaxWidth()
) { page ->
    if (page % 2 == 0) {
        // Page 2
    } else {
        // Page 1
    }
}
k
This is happening due to recomposition. Don't use if condition directly, Try to use LauchEffect instead.
f
But I can't call composables from LaunchedEffect. The problem is not with pages recomposition but with HorizontalPager's frequent changing pages. In one swipe I change around 10 pages, even though HorizontalPager's maximumPages swipe is 1.
I managed to fix this. Instead of Int.MAX_VALUE I used a constant page count less than 1000.
l
yes, actually from Compose 1.6 onwards, passing Int.MAX_VALUE or any large number for that matter to
pagerState
causes anr and crashes