Skip to content

fix: prevent composer keyboard from dismissing on open on small Android screens#7387

Open
OtavioStasiak wants to merge 3 commits into
developfrom
fix.android-composer-keyboard-dismisses-on-keyboard-open
Open

fix: prevent composer keyboard from dismissing on open on small Android screens#7387
OtavioStasiak wants to merge 3 commits into
developfrom
fix.android-composer-keyboard-dismisses-on-keyboard-open

Conversation

@OtavioStasiak

@OtavioStasiak OtavioStasiak commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

On some small-screen Android devices (e.g. Zebra TC21, also seen on Android 11), the keyboard would open and
immediately close again the moment you tapped the message composer, making it impossible to type.

The cause was the useCloseKeyboardWhenOrientationChanges hook. It decided "portrait vs landscape" by comparing
the width and height of the safe-area frame, and dismissed the keyboard whenever that orientation flipped.
The problem: with adjustResize + edge-to-edge, that frame shrinks when the keyboard opens. On small screens
the reduced height drops close to the width, so the hook mistook the keyboard opening for a screen rotation
and called Keyboard.dismiss() right after the keyboard appeared.

This PR changes the hook to:

  • Read the orientation from Dimensions.get('screen'), which reflects the physical display size and is not
    affected by the soft keyboard — so opening the keyboard no longer looks like a rotation.
  • React to real dimension changes via a Dimensions change subscription (in a useEffect) instead of running a
    side effect during render.

The keyboard now stays open when typing, while still dismissing correctly on a genuine device rotation.

Issue(s)

https://rocketchat.atlassian.net/browse/SUP-1055

How to test or reproduce

Screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard dismissal behavior in the message composer to only trigger when device orientation actually changes, rather than on render mismatches.

…creens

useCloseKeyboardWhenOrientationChanges read useSafeAreaFrame to detect
rotation, but under adjustResize + edge-to-edge that frame shrinks when the
soft keyboard opens. On small screens (e.g. Zebra TC21) the reduced height
drops to roughly the width, flipping the portrait check, so the hook fired
Keyboard.dismiss() immediately after the keyboard appeared — Gboard opened
and instantly closed.

Detect rotation from Dimensions.get('screen'), which reflects the physical
display and is unaffected by the keyboard, and react to genuine dimension
changes via a subscription instead of a render-time side effect.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@OtavioStasiak OtavioStasiak temporarily deployed to approve_e2e_testing June 8, 2026 19:33 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The useCloseKeyboardWhenOrientationChanges hook was refactored to track real device orientation via the Dimensions API instead of safe-area frame size. The hook now maintains orientation state in a ref, subscribes to dimension change events, and dismisses the keyboard only when orientation actually flips.

Changes

Orientation Change Detection via Dimensions API

Layer / File(s) Summary
Orientation helper using Dimensions
app/containers/MessageComposer/hooks/useCloseKeyboardWhenOrientationChanges.ts
New getIsPortrait() helper derives portrait/landscape state from Dimensions.get('screen') rather than safe-area frame size to avoid false keyboard dismissals when the keyboard itself shrinks the safe-area during appearance.
Hook implementation with event listener
app/containers/MessageComposer/hooks/useCloseKeyboardWhenOrientationChanges.ts
Hook stores initial portrait state in useRef, subscribes to Dimensions change events in useEffect, recomputes portrait on each event, dismisses keyboard only when orientation state flips, and cleans up subscription via subscription.remove() on unmount.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

type: bug

Suggested reviewers

  • diegolmello
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main fix: preventing the composer keyboard from dismissing on small Android screens, which directly aligns with the core change refactoring orientation detection to use Dimensions instead of safe-area frame.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@OtavioStasiak

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@OtavioStasiak OtavioStasiak marked this pull request as ready for review June 10, 2026 00:27
@github-actions

Copy link
Copy Markdown

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant