Fix <KeyboardAvoidingView>
with floating keyboard on iPad
#44859
+19
−0
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 iPadOS, users can change the kind of keyboard displayed onscreen, going from normal keyboard, to split keyboard (one half on the left of the screen, one half on the right), or a floating keyboard that you can move around the screen.
When a non-normal kind of keyboard is used,
<KeyboardAvoidingView>
calculations are all wrong and, depending on thebehavior
prop, can make your screen completely hidden.This PR attempts to detect that the keyboard is not the "normal displayed-at-bottom-of-screen" keyboard, and forces
enable={false}
if this happens.The approach of comparing the keyboard width with the window width comes from this comment: #29473 (comment)
A better fix might be to detect the kind of keyboard used, but this involves native code changes and I do not know iOS enough to do that. In addition, I have not found an easy way to do it using iOS APIs after a quick search.
I also chose to cache the window width as a class attribute. Maybe this is not needed as
Dimensions.get('window').width
is very fast and can be called on every keyboard event?This fixes #44068 and #29473
Changelog:
[IOS] [FIXED] - Fix
<KeyboardAvoidingView>
with floating keyboard on iPadOSTest Plan:
Tested using RNTester and the "Keyboard Avoiding View with different behaviors" example.
Before:
RPReplay_Final1718035077.mov
After:
RPReplay_Final1718035202.mov