fix: use WindowInsetsCompat to exclude keyboard insets on Android API 23-29#720
Open
tp26610 wants to merge 2 commits intoAppAndFlow:mainfrom
Open
Conversation
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
On Android API 23–29 (Android 6–10),
getRootWindowInsetsCompatMuses the deprecatedmin(systemWindowInsetBottom, stableInsetBottom)to exclude keyboard height from the bottom inset. On some Android 10 devices (confirmed on Samsung One UI and Nokia with stock Android 10),stableInsetBottomincorrectly reports the keyboard height, causingSafeAreaViewto addpaddingBottomequal to the keyboard height. This pushes the entire screen content upward whenever aTextInputis focused — even whenwindowSoftInputModeis set toadjustNothing.Android 11+ (
getRootWindowInsetsCompatR) is unaffected becauseWindowInsets.Type.navigationBars()explicitly excludes IME insets by design.Fix: only the bottom inset calculation is changed.
top,right, andleftcontinue to use the existingsystemWindowInset*values unchanged. The bottom inset is now obtained viaViewCompat.getRootWindowInsets()+WindowInsetsCompat.Type.navigationBars(), which correctly excludes keyboard insets on API 23–29 via the AndroidX compat layer. The originalmin()approach is kept as a fallback.androidx.core:core-ktxis also added as an explicit dependency (it was previously only available transitively viareact-native).Test Plan
Tested on:
To reproduce the original bug: open any screen with a
TextInputand a fixed bottom button inside aSafeAreaViewon an Android 10 device, focus the input, and observe the button jumping upward.