fix: KeyboardAvoidingView + autoFocus + native-stack#880
Merged
kirillzyusko merged 1 commit intomainfrom Mar 29, 2025
Merged
Conversation
Contributor
📊 Package size report
|
7759193 to
12b7471
Compare
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.
📜 Description
Fixed incorrect
KeyboardAvoidingViewlayout when it's used together with input (autoFocus) innative-stack.💡 Motivation and Context
The problem happens because of this:
I added condition
initialFrame.value === nullin the beginning of implementation (we also discussed potential but in https://github.com/kirillzyusko/react-native-keyboard-controller/pull/229/files#r1318714840)After that I changed condition to
keyboard.isClosed.valuein #239And after ~6 months I added
initialFrame.value === nullagain in #391So the current condition looks like "update layout only when keyboard closed or if layout is unknown". While it works it may produce issues as in the description above. (i. e. if keyboard opens, and first layout is incorrect, then resize will be incorrect too).
I though a lot on how to fix it, and realized, that layout actually is not changing if we are using
padding,bottomortranslate-with-paddingmodes. So technically that condition was added only forbehavior==="height". After thinking a while I decided, that the best fix here at the moment will be to add additionalbehavior !== "height"condition. It fixes the problem and theoretically it shouldn't have any negative impact for all 3 modes, as they do not change layout when keyboard is visible.If that condition indeed works and I will not receive new bug reports, then we can modify the condition for
heightas well and removekeyboard.isClosed.value || initialFrame.value === nulltotally (in this case, when we receiveonLayoutwithheightmode we will have to addrelativeKeyboardHeightto layout event to exclude the keyboard frame from layout event 😎).Closes #759
📢 Changelog
JS
behavior !== "height"condition toonLayoutcallback (to update layout whenever it's fired for all modes excludingheight);🤔 How Has This Been Tested?
In manual testing I used
📸 Screenshots (if appropriate):
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2025-03-28.at.10.41.12.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2025-03-28.at.10.38.47.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2025-03-28.at.10.40.02.mp4
📝 Checklist