Skip to content

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

Open
OtavioStasiak wants to merge 4 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 4 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 in the message composer so it occurs only when the device changes between portrait and landscape orientation.
  • Prevented unnecessary keyboard dismissal caused by temporary window or safe-area changes, such as those triggered while the keyboard is open.
  • Ensured orientation-change handling is properly cleaned up when no longer needed.

…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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cb0e8f2f-6392-453a-8f9c-53f6144e8e01

📥 Commits

Reviewing files that changed from the base of the PR and between 72921af and 8f69436.

📒 Files selected for processing (1)
  • app/containers/MessageComposer/hooks/useCloseKeyboardWhenOrientationChanges.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/containers/MessageComposer/hooks/useCloseKeyboardWhenOrientationChanges.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: ESLint and Test / run-eslint-and-test
  • GitHub Check: E2E Shard Preflight
  • GitHub Check: format

Walkthrough

The useCloseKeyboardWhenOrientationChanges hook now uses physical screen dimensions to detect orientation changes. It listens for dimension events and dismisses the keyboard only when the portrait or landscape state changes.

Changes

Orientation Change Detection via Dimensions API

Layer / File(s) Summary
Orientation helper using Dimensions
app/containers/MessageComposer/hooks/useCloseKeyboardWhenOrientationChanges.ts
getIsPortrait() derives orientation from Dimensions.get('screen') instead of safe-area frame dimensions.
Hook implementation with event listener
app/containers/MessageComposer/hooks/useCloseKeyboardWhenOrientationChanges.ts
The hook stores orientation in a ref, handles Dimensions change events, dismisses the keyboard when orientation flips, and removes the subscription during cleanup.

Estimated code review effort: 2 (Simple) | ~8 minutes

Merge Risk: ⚪ Minimal · up to 8f694

This localized Android keyboard behavior fix is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main bug fix: preventing the composer keyboard from dismissing when it opens on small Android screens.
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.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • SUP-1055: Request failed with status code 401

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.

@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

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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