-
Notifications
You must be signed in to change notification settings - Fork 34
fix(mobile): tap outside to dismiss mention popup #5740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wca4a
wants to merge
2
commits into
develop
Choose a base branch
from
wa/mobile-mention-tap-dismiss
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 The useKeyboardHeight hook in InputMentionPopup.tsx initializes to 0 and relies solely on keyboardDidShow/keyboardDidHide events, so if the keyboard is already visible when the component mounts (e.g., navigating to a new channel while the keyboard stays up), keyboardHeight remains 0 for the session. This causes the mention popup bottomOffset to fall back to insets.bottom (~34px) instead of the actual keyboard height (~350-400px), placing the popup ~300px below its intended position—behind the keyboard—until the user dismisses and re-shows it. Fix: initialize with Keyboard.metrics()?.height ?? 0 to read the current keyboard state synchronously on mount.
Extended reasoning...
What the bug is and how it manifests
The new useKeyboardHeight hook in InputMentionPopup.tsx (lines 12-27) initializes state with useState(0) and updates only via keyboardDidShow/keyboardDidHide event listeners. This is a gap: if the keyboard is already visible at the time InputMentionPopupInternal first mounts, no keyboardDidShow event fires and keyboardHeight stays 0 for the entire lifetime of that component instance.
The specific code path that triggers it
Why existing code does not prevent it
The existing useKeyboardHeight in BareChatInput/index.tsx has the same event-listener-only pattern but uses Keyboard.metrics() inside the handler and has a DEFAULT_KEYBOARD_HEIGHT=300 fallback. The new hook in InputMentionPopup.tsx has no such fallback. The effect dependency array is [] so it never re-runs on re-render to pick up the current state.
What the impact would be
Cross-channel navigation with a persistent keyboard is a common and natural flow on iOS (keyboard often stays up as users switch channels) and even more so on Android. When it occurs, the mention popup is hidden behind the keyboard for the entire channel session — the feature that this PR specifically introduces for mobile. The visual regression is severe and immediate: the popup appears in the wrong place with no workaround short of keyboard dismiss and re-show.
How to fix it
Initialize the hook with the synchronous Keyboard.metrics() call:
Keyboard.metrics() returns the current keyboard dimensions synchronously if the keyboard is visible, so the initial render uses the real height and no event is needed for the common mount-with-keyboard-already-up case.
Step-by-step proof