Skip to content

fix(menu): account for keyboard already open when Menu mounts - #5122

Open
manchoudhary wants to merge 4 commits into
callstack:mainfrom
manchoudhary:fix/menu-keyboard-already-open
Open

manchoudhary wants to merge 4 commits into
callstack:mainfrom
manchoudhary:fix/menu-keyboard-already-open

Conversation

@manchoudhary

@manchoudhary manchoudhary commented Sep 14, 2026 •

Copy link
Copy Markdown

Motivation

Menu only learned keyboard height from keyboardDidShow after mount. iOS does not replay that event for a keyboard that is already open, so a Menu that mounts while the keyboard is visible (for example a row added while typing) measured against the full window and laid items under the keyboard.

This uses Keyboard.metrics() when showing the menu (and seeds the ref on mount) so the already-open keyboard is accounted for.

Related issue

Fixes #5096

Screenshots / Videos

N/A — layout behavior; verified manually on iPhone 16 simulator.

Test plan

  • yarn lint
  • yarn typecheck
  • yarn test
  • Manual: open Menu with keyboard already open; menu stays above keyboard and scrolls instead of placing items under the keyboard

@manchoudhary
manchoudhary force-pushed the fix/menu-keyboard-already-open branch 2 times, most recently from 3dbb724 to 033b0a8 Compare September 14, 2026 18:07
Use Keyboard.metrics() when measuring layout so a Menu that mounts
while the keyboard is visible still avoids it. Fixes callstack#5096.
@manchoudhary
manchoudhary force-pushed the fix/menu-keyboard-already-open branch from 033b0a8 to 26358d5 Compare September 14, 2026 18:08
@Doberjohn Doberjohn added this to the 6.0.0 milestone Oct 30, 2026

@MikitasK MikitasK left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

good job 👍 👍
I reproduced this #5096 issue on iOS: this branch caps the list correctly & stays
scrollable ✅

I suppose, just 1 thing is blocking the merge atm: web crash noted inline.
rest looks good to me 👌

Comment thread src/components/Menu/Menu.tsx Resolved
Comment thread src/components/Menu/Menu.tsx Resolved

@manchoudhary manchoudhary left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review! Addressed both points:

  1. Blocker: The call itself is now optional: Keyboard.metrics?.()?.height ?? fallback. On react-native-web, where Keyboard.metrics is undefined, it no longer throws undefined is not a function. I added a test that sets Keyboard.metrics to undefined and asserts the menu still positions correctly. Spies and the original value are restored in finally.

  2. #5073: It rewrites the same windowLayoutResult.height - keyboardHeightRef.current block without handling an already-open keyboard. This PR changes that line to use getKeyboardHeight(keyboardHeightRef.current). The test “accounts for a keyboard that is already open when the menu mounts” asserts the final rendered height, so it will fail if that call is dropped in a merge. I’ll rebase on whichever lands first, and I’ll also leave a note on #5073.

yarn lint, yarn typecheck and yarn test all pass. Ready for another look.

@MikitasK MikitasK left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

thanks for quick update 🙏
both points look good now 👌

just 2 thing atm:

  1. merge with main broke imports in test file - happy to approve once that's fixed
  2. could we add a short before/after video from simulator? it'd make it much easier for the final pass

@@ -1,3 +1,6 @@
import { Dimensions, Keyboard, StyleSheet, View } from 'react-native';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[blocker] this line duplicates line #4
that's why whole test suite fails to load

could we fix it up?

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.

Menu ignores the keyboard when it mounts while the keyboard is already open

3 participants