feat: prevent dialogs from being covered by keyboard - #87
Open
sandeepsengupta wants to merge 1 commit into
Open
Conversation
Dialogs containing TextInputs do not move up when the keyboard is opened, which can result in the keyboard obscuring part of the dialog. This commit fixes that issue by changing the overlay view (the <View> with overlayStyle) to a KeyboardAvoidingView with behavior="height". Partially inspired by callstack/react-native-paper#5023
Owner
|
Nice job, thank you! Three things to consider:
|
Author
Owner
|
Nice, let's expose only the |
Author
|
Sounds good! And yes, I agree that the behavior with excessive dialog content is not an issue here. |
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.






This will probably need some tweaking before release (as described below), but I wanted to share what I have found so far.
Dialogs containing
TextInputobjects do not currently move up when the keyboard is opened, which can result in the keyboard obscuring part of the dialog. This commit fixes this by changing the overlay view (the<View>withoverlayStyle) to aKeyboardAvoidingViewwithbehavior="height".As discussed here, using
android:windowSoftInputMode="adjustResize"is no longer sufficient on Android, now that Android is enforcing edge-to-edge mode.This fixes #5 and fixes #35.
Important note: It may be best to make these changes optional by placing them behind a boolean
avoidKeyboardprop. See the "Alternative to Avoid Issues and Breaking Changes" section at the end of this comment.This solution is partially inspired by callstack/react-native-paper#5023.
Screen Recordings
Current behavior on Android 17 (API 37.0):
Note: This behavior occurs even though
android:windowSoftInputMode="adjustResize"is set inAndroidManifest.xml.Screen.Recording.2026-07-30.at.10.13.47.AM.mov
Behavior on Android 17 (API 37.0) with patch applied:
Screen.Recording.2026-07-30.at.10.19.29.AM.mov
Current behavior on iOS 26.5:
Screen.Recording.2026-07-30.at.10.27.19.AM.mov
Behavior on iOS 26.5 with patch applied:
Screen.Recording.2026-07-30.at.10.29.48.AM.mov
Known Issues
This change unfortunately seems to cause some minor side effects, as described below.
Side effect 1: Slightly different behavior when dialog content exceeds available space
The following screenshots are of Android 7, where edge-to-edge is not enforced. Here, the dialog contains too much content and no ScrollView, so it cannot be expected to render in a reasonable way. The only relevant thing to notice here is that the screenshots on the right are slightly different from those on the left:
Android 7 without patch (left) and with patch (right):
Android 7 without patch (left) and with patch (right):
Side effect 2: Dialog positioned slightly below center
This happens on older versions of Android where edge-to-edge is not enforced (i.e., where this patch is not necessary). Applying this fix sometimes causes the dialog to appear slightly below center, as shown below. This may not happen the first time the keyboard is opened, but it does happen when the keyboard is opened for the second time.
Android 14 without patch (left) and with patch (right):
Android 14 without patch (left) and with patch (right):
Side effect 3: Dialogs with ScrollViews can be too tall
When edge-to-edge is not enabled (that is, on older versions of Android), dialogs containing ScrollViews are often slightly too tall when the keyboard is visible:
Android 14 without patch (left) and with patch (right):
Side effect 4: Occasional visual glitch
With the patch applied, in rare cases, dismissing the keyboard results in the following strange visual glitch. This only happens occasionally; it works fine most of the time.
Alternative to Avoid Issues and Breaking Changes
This may constitute a breaking change, since some users of this library may already be implementing their own workarounds to reposition the dialog when the keyboard is visible.
To prevent it from being a breaking change, and to give users the option to avoid the side effects described in "Known Issues" above, I wonder if we can add a boolean
avoidKeyboardprop to enable or disable these changes. What do you think?Thanks for this useful library!