fix: jitter removed in keyboard avoiding view behaviour - #1515
Open
anshulsingh1210 wants to merge 1 commit into
Open
fix: jitter removed in keyboard avoiding view behaviour#1515anshulsingh1210 wants to merge 1 commit into
anshulsingh1210 wants to merge 1 commit into
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.
📜 Description
Fixes a flicker in KeyboardAvoidingView where, on Android with behavior="padding" (any non-"height" behavior) and automaticOffset={true}, the wrapped content jitters up and down while the keyboard opens instead of animating up smoothly once.
onLayoutWorklet re-records initialFrame on every onLayout for non-"height" behaviors. With automaticOffset, each onLayout resolves the frame through an async KeyboardControllerNative.viewPositionInWindow() call, and those promises settle out of order — a late callback delivers a stale, smaller y + height after a newer larger one already landed. Because initialFrame feeds relativeKeyboardHeight() (which drives paddingBottom), every stale dip yanks the frame back down and shows up as flicker.
This PR keeps the resting-frame capture on first layout / when the keyboard is closed, but while the keyboard is open it accepts a new layout only when its bottom edge (y + height) exceeds the stored one — the resting bottom edge only grows as the keyboard opens, so this discards the out-of-order/stale measurements and lets the frame settle monotonically.
💡 Motivation and Context
Fixes #.
Repro: KeyboardAvoidingView with behavior="padding", automaticOffset, and a content-sized child (no flex: 1) near the bottom of the screen. Logging initialFrame.value across one keyboard open showed height climbing 280 → 396 and y + height ramping 555 → 613 with out-of-order dips in between — confirming the keyboard signals were stable and the oscillation came entirely from the re-recorded frame. The change targets only that re-record path; position (which animates a separate inner view) and height (already frozen while open) are unaffected.
📢 Changelog
JS
🤔 How Has This Been Tested?
Tested on a physical Android device and emulator:
Library public API is unchanged, so no new mocks were required.
📸 Screenshots (if appropriate):
Before Updating::
https://github.com/user-attachments/assets/c16b51a9-b96e-4446-a27f-714991bbb57e
After Updating::
https://github.com/user-attachments/assets/a3e1e7b3-0b0d-4a8a-83e0-ced261190e20