I am experiencing some weird behaviour with Accomp...
# compose
s
I am experiencing some weird behaviour with Accompanist Pager v0.19.0 (after it’s adjustment to use LazyX under the hood). More details in the thread🧵
👀 2
The above video showcases it. The fling behaviour (and the indicators by extension) don’t really settle where they should. Not sure if this is happening due to me adding a bigger contentPadding horizontally than I do itemSpacing between the items. But this is the behaviour I am looking to achieve, I want the items to purposefully take less screen space than they need so that the next item also shows, indicating that there’s more items to see. Has someone experienced this as well? Does it feel like a problem that exists in the Pager itself or something I am messing up somehow? Any way to tell?
Code looks like this:
Copy code
val claimStatusDataList: List<ClaimStatusData> = ...
val pagerState = rememberPagerState()
Column {
    HorizontalPager(
        count = claimStatusDataList.size,
        key = { page: Int -> claimStatusDataList[page].id },
        state = pagerState,
        itemSpacing = 16.dp,
        contentPadding = PaddingValues(horizontal = 12.dp),
    ) { page: Int ->
        val claimStatusData = claimStatusDataList[page]
        ClaimStatusCard(
            claimStatusData = claimStatusData,
        )
    }

    Spacer(Modifier.height(16.dp))

    HorizontalPagerIndicator(
        pagerState = pagerState,
        modifier = Modifier.align(Alignment.CenterHorizontally)
    )
}
With
ClaimStatusCard
being that card item you’re looking at. Not sure if that composable’s internals are important or not.
When having both
itemSpacing
contentPadding
be 0.dp, it seems to always work. When
itemSpacing
is 0 and
contentPadding
is non-zero, it works just fine too. When
itemSpacing
is non-zero and
contentPadding
is 0, it stops working, getting this weird behaviour that doesn’t settle properly in the centre of the item again.
l
I just upgraded to Accompanist 0.19.0, and I have the same weird behaviour. And it's super inconsistent, sometimes it's always visible, sometimes not 🤔
👍 1
a
seems like
itemSpacing
is incorrectly handled, please file a bug in Accompanist repo
s
Okay, I shall do that!
a
I think you should be able to workaround it if you add an item spacing as Modifier.padding(end = 16.dp) directly on ClaimStatusCard() for all but last pages
s
That’s exactly what I am doing for now:
Copy code
val extraPadding = PaddingValues(
    start = if (page == 0) { 0.dp } else { 6.dp },
    end = if (page == claimStatusDataList.lastIndex) { 0.dp } else { 6.dp },
)
to “fake” a 12.dp spacing between them. Your approach should work too, but I want the item to look centred when it’s the one selected, I’m guessing adding only an end padding would make it look a bit off. I am in the process of writing the bug report now. Is it ok if I add a link to this discussion as well? This isn’t a public channel that’s why I wonder.
a
sure, that is fine
s
Linking here for future reference: https://github.com/google/accompanist/issues/793
👍 1