google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.43k stars 598 forks source link

Make HorizontalPager central item on top of other elements #1457

Closed rafaelasobralguerra closed 1 year ago

rafaelasobralguerra commented 1 year ago

Describe the bug

Central item on horizontal pager his behind the right items and it's impossible to applying a z-index to the modifier because Box container modifier it's not exposed (| Box[Page] | Box[Page] | Box[Page]).

Applying .zIndex(if (page == currentPage) 1f else 0f) to the Page doesn't work

To Reproduce

image

@Suppress("CorrectDpValuesDetector")
@Composable
private fun SquaresCodesPager(state: SquaresGroupState, onSelectedListener: (Int) -> Unit, onClickedListener: (Int) -> Unit) {
    val pagerState = rememberPagerState(initialPage = 0)
    LaunchedEffect(pagerState) {
        snapshotFlow { pagerState.currentPage }.collect { page ->
            onSelectedListener(page)
        }
    }
    HorizontalPager(
        itemSpacing = -Grid.DP_40,
        contentPadding = PaddingValues(horizontal = (LocalConfiguration.current.screenWidthDp.dp - QR_SIZE) / 2),
        count = state.items.size,
        state = pagerState
    ) { page ->
        Square(pagerState.currentPage, page, state.items[page].square, onClickedListener)
    }
}

@Composable
private fun PagerScope.Square(currentPage: Int, page: Int, bitmap: Bitmap, onClickListener: (Int) -> Unit) {
    Image(
        modifier = Modifier
            .graphicsLayer(animation(page))
            .background(Background.BgSecondary)
            .size(SQUARE_SIZE),
        bitmap = ...
        contentDescription = ...
    )
}

Expected behavior

Blue square should be on top of other items once it's the viewpager item selected (square focused)

Screenshots?

Blue square = items[0] is the item selected on the viewpager image

Environment:

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

bentrengrove commented 1 year ago

Accompanist Pager has now been deprecated as we have upstreamed it to the main Compose library and so I am closing this bug.

Please retest your issue using Compose Foundation Pager in the March release. You can see our migration guide for help and if this is still an issue, please file a bug at goo.gle/compose-feedback.