Skip to content

fix(android): clear focus and hide the keyboard when leaving a page - #1155

Merged
troZee merged 2 commits into
callstack:mainfrom
KisaneNeko:fix/android-page-change-focus
Oct 9, 2026
Merged

troZee merged 2 commits into
callstack:mainfrom
KisaneNeko:fix/android-page-change-focus

Conversation

@KisaneNeko

@KisaneNeko KisaneNeko commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1154. Reported in Expensify/App#101157 after bumping from 8.0.0 to 9.0.4.

On Android, a focused TextInput keeps focus after its page is left with setPage or a swipe. The keyboard stays open with nothing focused on screen, and typing still goes into the input on the page you just left.

reproduction

Before (9.0.6) After (this PR)
1154-before-9.0.6.mp4
1154-after-fix.mp4
expensify-local-unfixed.mp4
expensify-local-fixed.mp4

What happened

  • v8 used ViewPager2, which clears focus on every page change. The keyboard also closed, but only because ViewPager2's RecyclerView detached the off-screen page.
  • v9 moved to Compose HorizontalPager. It doesn't touch focus, and neighbouring pages stay attached, so the input keeps both focus and the keyboard.

Fix

When a page is selected, ComposePagerView now clears focus held outside that page, and hides the keyboard if it was attached to the input that lost focus.

  • Focus inside the selected page is left alone, so an input focused right after setPage (while the pager is still animating) keeps it. ViewPager2 cleared that one too.
  • The keyboard is hidden manually because the old page is no longer detached.
  • One trade-off: if an app focuses an input from onPageSelected, the keyboard hides and then shows again.

Test Plan

What's required for testing (prerequisites)?

Android emulator or device. A pager with a TextInput on at least two pages.

What are the steps to reproduce (after prerequisites)?

Added Issue #1154 Page Change Focus Repro to the example app and e2e/tests/issues/issue-1154-page-change-focus.e2e.ts:

  1. Open the example, tap Go 1 and focus the input on page 1.
  2. Tap Go 0, or swipe to another page.
  3. Before: the keyboard stays open, nothing on page 0 is focused, and typing goes into page 1's input.
  4. After: the input is blurred and the keyboard closes.
  5. The onSelected / onPress buttons focus the new page's input from onPageSelected or right after setPage. Both still end with that input focused.

Verified

  • typescript (root and example), lint (no new warnings) and test pass, prettier is clean, plus the Android unit tests.
  • The new e2e test fails on 9.0.7 without the fix and passes with it (Pixel 4 emulator, API 34, release build). Without the fix the two blur cases fail; the refocus case passes on both, it's there so the fix doesn't take focus away from the new page.
  • The test checks focus, not the keyboard: agent-device runs with its own headless IME, so the app never sees a keyboard during the run. Keyboard hiding is in the videos.
  • Full Android e2e suite with the fix: 14/14 tests pass.
  • Checked against Expensify's Split screen pattern (material top tabs, tab press, delayed auto-focus) in a scratch screen: the hidden input no longer takes input, and their auto-focus still works.

iOS is untouched.

Compatibility

OS Implemented
iOS n/a
Android ✅

Checklist

  • I have tested this on a device and a simulator: emulator only (Pixel 4, API 34), not on physical hardware
  • I added the documentation in README.md: not applicable
  • I updated the typed files (TS and Flow): not applicable

@KisaneNeko
KisaneNeko marked this pull request as ready for review October 2, 2026 07:35
@troZee
troZee requested a balanced review from Copilot October 7, 2026 18:16
@@ -0,0 +1,80 @@
appId: com.pagerviewexample

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase your branch and migrate it to e2e

@KisaneNeko KisaneNeko Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e migration done, looking into resolving conflicts and this should be ready to re-review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused Android fix is consistent with the stated behavior and has comprehensive regression coverage.

0 open findings

What changed in this PR

Fixes Android focus retention when leaving a pager page.

Changes:

  • Clears focus outside the selected page and hides its keyboard.
  • Adds a dedicated reproduction screen.
  • Adds Android Maestro regression coverage.
File Description
ComposePagerView.kt Implements focus and keyboard cleanup.
Issue1154PageChangeFocusRepro.tsx Adds the reproduction screen.
App.tsx Registers the example.
Maestro setup YAML Opens the reproduction screen.
Maestro Android YAML Tests paging and focus scenarios.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@KisaneNeko
KisaneNeko force-pushed the fix/android-page-change-focus branch from de4a4f3 to 8fe1ce0 Compare October 9, 2026 06:22
@KisaneNeko
KisaneNeko force-pushed the fix/android-page-change-focus branch from 8fe1ce0 to 9ffc841 Compare October 9, 2026 08:28
@troZee
troZee enabled auto-merge (squash) October 9, 2026 08:53
auto-merge was automatically disabled October 9, 2026 09:13

Head branch was pushed to by a user without write access

@troZee
troZee merged commit 8c3ad03 into callstack:main Oct 9, 2026
3 checks passed
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.

[Android] Focused TextInput keeps focus and keyboard after switching pages (v9)

4 participants