Fix Keyboard events and KeyboardAvoidingView on Android (edge-to-edge)#55855
Closed
zoontek wants to merge 5 commits into
Closed
Fix Keyboard events and KeyboardAvoidingView on Android (edge-to-edge)#55855zoontek wants to merge 5 commits into
zoontek wants to merge 5 commits into
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. |
Collaborator
|
This pull request was successfully merged by @zoontek in 4a6c933 When will my fix make it into a release? | How to file a pick request? |
alanleedev
added a commit
to alanleedev/react-native
that referenced
this pull request
Apr 23, 2026
Summary: Follow-up to facebook#55855 (D100437445), which replaced the legacy height-based IME detector in `ReactRootView.CustomGlobalLayoutListener` with a visibility-only detector (`WindowInsetsCompat.Type.ime()`). The legacy code also re-emitted `keyboardDidShow` whenever the IME *height* changed while still visible (e.g., user toggles the emoji panel or predictive bar). Removing that left these JS consumers reading stale `endCoordinates`: - `KeyboardAvoidingView` — caches `_keyboardEvent`, no longer resizes on IME height changes. - `ScrollView` — caches `_keyboardMetrics`; focused `TextInput` auto-scroll uses stale `screenY`/`height`. - `Keyboard.metrics()` — public API returning the cached payload from the last `keyboardDidShow`. Fix: track the last reported IME height and re-emit `keyboardDidShow` when the keyboard is visible AND (it just appeared OR the height changed), restoring pre-D100437445 semantics. The hide branch is gated on `mKeyboardIsVisible` so it still fires exactly once per cycle. Changelog: [Android][Fixed] KeyboardAvoidingView and TextInput auto-scroll not responding to IME height changes (e.g., when toggling emoji panel or predictive bar) Differential Revision: D101385688
alanleedev
added a commit
to alanleedev/react-native
that referenced
this pull request
Apr 23, 2026
Summary: Follow-up to facebook#55855 (D100437445), which replaced the legacy height-based IME detector in `ReactRootView.CustomGlobalLayoutListener` with a visibility-only detector (`WindowInsetsCompat.Type.ime()`). The legacy code also re-emitted `keyboardDidShow` whenever the IME *height* changed while still visible (e.g., user toggles the emoji panel or predictive bar). Removing that left these JS consumers reading stale `endCoordinates`: - `KeyboardAvoidingView` — caches `_keyboardEvent`, no longer resizes on IME height changes. - `ScrollView` — caches `_keyboardMetrics`; focused `TextInput` auto-scroll uses stale `screenY`/`height`. - `Keyboard.metrics()` — public API returning the cached payload from the last `keyboardDidShow`. Fix: track the last reported IME height and re-emit `keyboardDidShow` when the keyboard is visible AND (it just appeared OR the height changed), restoring pre-D100437445 semantics. The hide branch is gated on `mKeyboardIsVisible` so it still fires exactly once per cycle. Changelog: [Android][Fixed] KeyboardAvoidingView and TextInput auto-scroll not responding to IME height changes (e.g., when toggling emoji panel or predictive bar) Differential Revision: D101385688
meta-codesync Bot
pushed a commit
that referenced
this pull request
Apr 24, 2026
Summary: Pull Request resolved: #56486 Follow-up to #55855 (D100437445), which replaced the legacy height-based IME detector in `ReactRootView.CustomGlobalLayoutListener` with a visibility-only detector (`WindowInsetsCompat.Type.ime()`). The legacy code also re-emitted `keyboardDidShow` whenever the IME *height* changed while still visible (e.g., user toggles the emoji panel or predictive bar). Removing that left these JS consumers reading stale `endCoordinates`: - `KeyboardAvoidingView` — caches `_keyboardEvent`, no longer resizes on IME height changes. - `ScrollView` — caches `_keyboardMetrics`; focused `TextInput` auto-scroll uses stale `screenY`/`height`. - `Keyboard.metrics()` — public API returning the cached payload from the last `keyboardDidShow`. Fix: track the last reported IME height and re-emit `keyboardDidShow` when the keyboard is visible AND (it just appeared OR the height changed), restoring pre-D100437445 semantics. The hide branch is gated on `mKeyboardIsVisible` so it still fires exactly once per cycle. Changelog: [Android][Fixed] KeyboardAvoidingView and TextInput auto-scroll not responding to IME height changes (e.g., when toggling emoji panel or predictive bar) Reviewed By: mdvacca, javache Differential Revision: D101385688 fbshipit-source-id: 071707bc6fb9e7173e491135b27a66dc177c14c5
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