Fix Keyboard events and KeyboardAvoidingView on Android (edge-to-edge)#55855
Open
zoontek wants to merge 5 commits intofacebook:mainfrom
Open
Fix Keyboard events and KeyboardAvoidingView on Android (edge-to-edge)#55855zoontek wants to merge 5 commits intofacebook:mainfrom
zoontek wants to merge 5 commits intofacebook:mainfrom
Conversation
zoontek
commented
Mar 3, 2026
| } | ||
| } | ||
|
|
||
| private void checkForKeyboardEventsLegacy() { |
Contributor
Author
There was a problem hiding this comment.
In order to simplify the codebase here, checkForKeyboardEventsLegacy is removed and checkForKeyboardEvents now uses AndroidX.
zoontek
commented
Mar 3, 2026
| "keyboardDidHide", | ||
| createKeyboardEventPayload( | ||
| PixelUtil.toDIPFromPixel(mVisibleViewArea.height()), | ||
| PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom + barInsets.bottom), |
Contributor
Author
zoontek
commented
Mar 3, 2026
| } else { | ||
| this._subscriptions = [ | ||
| Keyboard.addListener('keyboardDidHide', this._onKeyboardChange), | ||
| Keyboard.addListener('keyboardDidHide', this._onKeyboardHide), |
Contributor
Author
There was a problem hiding this comment.
This solves a crazy render loop (with the UI jumping back and forth) when using KeyboardAvoidingView with behavior="height"
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Summary:
KeyboardAvoidingViewhas several issues on Android 15+ and whenedgeToEdgeEnabledis set totrueon older Android versions:Keyboard events relied on a legacy detection path for Android < 30 (
checkForKeyboardEventsLegacy), which used height heuristics (heightDiff > mMinKeyboardHeightDetected) to guess whether the keyboard was visible. This approach is unreliable with edge-to-edge, where the visible display frame and screen dimensions differ from what the heuristic expects.keyboardDidHidereported incorrectscreenYvalues. It usedmVisibleViewArea.height(), which in edge-to-edge mode doesn't correspond to the actual screen bottom. This causedKeyboardAvoidingViewto compute a non-zero keyboard overlap even after the keyboard was dismissed.KeyboardAvoidingViewused_onKeyboardChangeforkeyboardDidHideon Android, which stores the event instead of nullifying it. After keyboard dismissal, any subsequentonLayoutwould re-enter_updateBottomIfNecessarywith stale coordinates, causing a render loop (especially visible withbehavior="height"in edge-to-edge mode, whereframe.yshifts slightly on each layout cycle).This PR:
checkForKeyboardEventsLegacyand usesWindowInsetsCompatAPIs (via AndroidX) for all Android versions, providing reliable keyboard detection in both legacy and edge-to-edge modes.keyboardDidHideto reportscreenYasmVisibleViewArea.bottom + barInsets.bottom(the actual screen bottom including navigation bars).keyboardDidHidelistener inKeyboardAvoidingViewto use_onKeyboardHide(which nullifies_keyboardEvent), matching the iOS behavior and breaking the render loop.Closes #49759
Changelog:
[ANDROID] [FIXED] - Fix
KeyboardAvoidingViewon Android 15+ / withedgeToEdgeEnabledTest Plan:
Tested with
rn-testerKeyboardAvoidingView example on:edgeToEdgeEnabledset totrueorfalseedgeToEdgeEnabledset totrueorfalseFor each, verified:
behavior="padding": keyboard open/close adjusts padding correctlybehavior="position": keyboard open/close translates content correctlybehavior="height": keyboard open/close works without render loop or glitchingkeyboardDidShowandkeyboardDidHideevents report correct coordinates