accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Pager] Moving focus selects the next page

Open olaf-a opened this issue 3 years ago • 2 comments

If you create a Horizontal pager like this:

    HorizontalPager(
        count = 4,
        state = pagerState
    ) {
        Column {
            Text("Page $currentPage")
            TextField(
                value = textValue.value,
                onValueChange = { new ->
                    textValue.value = new
                },
                keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next)
            )
        }
    }

If you click the TextField, and then press the next button on the on-screen keyboard, the focus will move to the next element, but the next element is on the next page so the pager will scroll.

I don't think this is intended, but if it is there should be way of preventing this from happening.

olaf-a avatar Aug 04 '22 14:08 olaf-a

As far as I know, the BringIntoView is responsible for scrolling to focused composables, the Pager has nothing to do with it. I didn't find a way to turn it off so far. If you don't find it either, feel free to request the feature in Compose issue tracker.

dmitrytavpeko avatar Aug 14 '22 12:08 dmitrytavpeko

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.

github-actions[bot] avatar Sep 14 '22 04:09 github-actions[bot]

If anyone else runs into this, you can work around it by adding Modifier.focusProperties { canFocus = page == pagerState.currentPage } to the root of each page.

keyboardr avatar Oct 06 '23 01:10 keyboardr