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"
82c14b2 to
78143c0
Compare
|
@alanleedev has imported this pull request. If you are a Meta employee, you can view this in D100437445. |
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 Android < 15:checkForKeyboardEventsLegacy), which used height heuristics (heightDiff > mMinKeyboardHeightDetected) to guess whether the keyboard was visible.keyboardDidHidereported incorrectscreenYvalues. It usedmVisibleViewArea.height(), which in edge-to-edge mode doesn't correspond to the actual screen bottom.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)keyboardDidHideto reportscreenYasmVisibleViewArea.bottom + barInsets.bottomkeyboardDidHidelistener inKeyboardAvoidingViewto use_onKeyboardHide, 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