Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsAnimationCompat;
import androidx.core.view.WindowInsetsCompat;
import com.getcapacitor.Bridge;
import java.util.List;

public class Keyboard {

Expand Down Expand Up @@ -57,57 +54,25 @@ public Keyboard(AppCompatActivity activity, boolean resizeOnFullScreen) {
FrameLayout content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
rootView = content.getRootView();

ViewCompat.setWindowInsetsAnimationCallback(
ViewCompat.setOnApplyWindowInsetsListener(
rootView,
new WindowInsetsAnimationCompat.Callback(WindowInsetsAnimationCompat.Callback.DISPATCH_MODE_STOP) {
@NonNull
@Override
public WindowInsetsCompat onProgress(
@NonNull WindowInsetsCompat insets,
@NonNull List<WindowInsetsAnimationCompat> runningAnimations
) {
return insets;
(View view, WindowInsetsCompat insets) -> {
boolean showingKeyboard = insets.isVisible(WindowInsetsCompat.Type.ime());
int imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final float density = dm.density;

if (resizeOnFullScreen) {
possiblyResizeChildOfContent(showingKeyboard);
}

@NonNull
@Override
public WindowInsetsAnimationCompat.BoundsCompat onStart(
@NonNull WindowInsetsAnimationCompat animation,
@NonNull WindowInsetsAnimationCompat.BoundsCompat bounds
) {
boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
int imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final float density = dm.density;

if (resizeOnFullScreen) {
possiblyResizeChildOfContent(showingKeyboard);
}

if (showingKeyboard) {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density));
} else {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0);
}
return super.onStart(animation, bounds);
if (showingKeyboard) {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_SHOW, Math.round(imeHeight / density));
} else {
keyboardEventListener.onKeyboardEvent(EVENT_KB_WILL_HIDE, 0);
Comment on lines +69 to +72
Copy link

@samsam-026 samsam-026 Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}

@Override
public void onEnd(@NonNull WindowInsetsAnimationCompat animation) {
super.onEnd(animation);
boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(rootView);
int imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
DisplayMetrics dm = activity.getResources().getDisplayMetrics();
final float density = dm.density;

if (showingKeyboard) {
keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_SHOW, Math.round(imeHeight / density));
} else {
keyboardEventListener.onKeyboardEvent(EVENT_KB_DID_HIDE, 0);
}
}
return insets;
}
);

Expand Down