Skip to content

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

Open
KisaneNeko wants to merge 1 commit into
callstack:masterfrom
KisaneNeko:fix/android-page-change-focus
Open

KisaneNeko wants to merge 1 commit into
callstack:masterfrom
KisaneNeko:fix/android-page-change-focus

Conversation

@KisaneNeko

@KisaneNeko KisaneNeko commented Oct 2, 2026 •

Copy link
Copy Markdown

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

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 .maestro/android-only/issue_1154_page_change_focus_repro.yaml:

  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, lint (no new warnings) and test pass, plus the Android unit tests.
  • The new Maestro flow fails on 9.0.6 and passes with the fix (Pixel 4 emulator, API 34, debug build).
  • Full Android Maestro suite with the fix: 12/13 pass. issue_1096_keyboard_shrink_repro fails the same way without the fix (the keyboard covers the row it taps). pager_vertical_basic_example and issue_1083_modal_set_page_repro failed on the first run and passed on a rerun, with and without the fix.
  • 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
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)

1 participant