Keyboard plugin - replace setWindowInsetsAnimationCallback with setOnApplyWindowInsetsListener#2398
Open
rafaelbrendler-pixieset wants to merge 1 commit intoionic-team:mainfrom
Open
Conversation
I noticed an issue when the number row is enabled in my Gboard. The Keyboard plugin doesn't resize the view properly in this case. The reason is that the number row is added after the keyboard opening lifecycle is finished. Since the Keyboard plugin listens to `setWindowInsetsAnimationCallback` events (onStart and onEnd) to update the view height, it misses this last inset change after the keyboard opening animation is complete. I propose replacing the current listener with `setOnApplyWindowInsetsListener`, which listens to all inset changes, enabling the plugin to properly adjust the view height whenever the keyboard height changes. Here's the link to the issue I commented on: https://github.com/ionic-team/capacitor-plugins/issues/2371
samsam-026
reviewed
Sep 3, 2025
Comment on lines
+69
to
+72
| if (showingKeyboard) { | ||
| keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density)); | ||
| } else { | ||
| keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0); |
There was a problem hiding this comment.
Tried this out myself. Thank you so much for fixing this issue. A small bit of feedback. There is no local variable keyboardEventListener, so it should refer to the class one
Suggested change
| if (showingKeyboard) { | |
| keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density)); | |
| } else { | |
| keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0); | |
| if (showingKeyboard) { | |
| this.keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density)); | |
| } else { | |
| this.keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0); |
There was a problem hiding this comment.
Hi. Thank you for looking into my PR.
The keyboardEventListener variable is actually declared above in line 36. I didn't change anything related to it; my change preserves the way the previous code was using the event listener variable. I only replaced the usage of setWindowInsetsAnimationCallback() with setOnApplyWindowInsetsListener() for the reason I mentioned in the description.
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.
I noticed an issue with the Keyboard plugin inaccurately resizing the view when the number row is enabled in my Gboard. The Keyboard plugin doesn't resize the view properly in this case. The reason is that the number row is added after the keyboard opening lifecycle is finished. Since the Keyboard plugin listens to
setWindowInsetsAnimationCallbackevents (onStart and onEnd) to update the view height, it misses this last inset change after the keyboard opening animation is complete.I propose replacing the current listener with
setOnApplyWindowInsetsListener, which listens to all inset changes, enabling the plugin to properly adjust the view height whenever the keyboard height changes.Device: Pixel 9 Pro running API level 36
Dependencies:
Gboard number row option: Settings -> System -> Keyboard -> On-screen keyboard -> Gboard -> Preferences -> Number row
Capacitor configs: