Skip to content

Fix Page Up/Down in grids not moving focus to target card - #2193

Open
AJadkarim wants to merge 1 commit into
damontecres:mainfrom
AJadkarim:fix-grid-page-key-focus
Open

AJadkarim wants to merge 1 commit into
damontecres:mainfrom
AJadkarim:fix-grid-page-key-focus

Conversation

@AJadkarim

@AJadkarim AJadkarim commented Nov 8, 2026 •

Copy link
Copy Markdown

Description

In CardGrid, using Page Up / Page Down or remote jump buttons (fast-forward / rewind) scrolls the grid to the target position, but focus does not transfer to the target card. Because currentFocusedIndex was not included in the remember keys for GridItemDetails, item focus modifiers were not updated when the jump target changed, and programmatic focus was never requested on the target card after jump scrolling. Consequently, focus remained on the old item (or was lost when it scrolled off-screen), and subsequent D-pad navigation continued from the old card rather than the target card.

This PR adds currentFocusedIndex to the remember keys in CardGrid so item modifiers update when the focused index changes, and requests focus via firstFocus once the target card is composed after a jump.

Related issues

I searched existing issues and pull requests on damontecres/Wholphin for Page Up/Down and grid jump focus and did not find an existing issue or pull request for this behavior.

Steps to reproduce:

  1. Open any library grid (such as Movies or TV Shows) with more than 6 rows.
  2. Focus on the first item (item 0).
  3. Press Page Down (or remote fast-forward). The grid scrolls down by the jump stride (e.g. 36 items).
  4. Press D-pad Right. Navigation moves from the old card (moving to item 1) instead of continuing from the target card.

Testing

  • Unit tests: 1 test in TestGridPageKeys (pageDownTransfersFocusToTargetCard) verifies that pressing Page Down transfers focus to the target card and subsequent D-pad Down navigation continues from that target card. The test fails on the unfixed code and passes with this fix.
  • ktlint: clean (0 errors) on modified files.
  • Automated tests: Robolectric Compose UI test runner (simulating Android TV key input and verifying focus hierarchy).

Screenshots

None (no UI change).

AI or LLM usage

I used AI tools for this change: Codex found the bug and wrote an earlier version of the fix, Google Gemini drafted this commit and test, and Claude assisted with planning and review. This covers the changes in CardGrid.kt and TestGridPageKeys.kt.

I tested the change with the unit test above and ktlint. I have reviewed and understand the changes in this pull request and take responsibility for them.

Grid jump scrolling updated scroll position and focused index
without requesting focus on the target card. Invalidate item
details when focused index changes and request focus once the
target card is composed so D-pad navigation continues from it.

Assisted-by: agy:gemini-3.8-flash-high
bonfiglioalessio added a commit to bonfiglioalessio/Nigiro that referenced this pull request Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant