Skip to content

Commit 035f74e

Browse files
authored
fix(android): incorrect keyboard height (#2924)
1 parent 7a2a45f commit 035f74e

File tree

1 file changed

+9
-6
lines changed
  • android/capacitor/src/main/java/com/getcapacitor/plugin

1 file changed

+9
-6
lines changed

android/capacitor/src/main/java/com/getcapacitor/plugin/Keyboard.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.view.Display;
1010
import android.view.View;
1111
import android.view.ViewTreeObserver;
12+
import android.view.WindowInsets;
1213
import android.view.inputmethod.InputMethodManager;
1314

1415
import com.getcapacitor.JSObject;
@@ -54,18 +55,20 @@ public void onGlobalLayout() {
5455
// cache properties for later use
5556
int rootViewHeight = rootView.getRootView().getHeight();
5657
int resultBottom = r.bottom;
57-
58-
// calculate screen height differently for android versions >= 21: Lollipop 5.x, Marshmallow 6.x
59-
//http://stackoverflow.com/a/29257533/3642890 beware of nexus 5
6058
int screenHeight;
6159

62-
if (Build.VERSION.SDK_INT >= 21) {
60+
if (Build.VERSION.SDK_INT >= 23) {
61+
WindowInsets windowInsets = rootView.getRootWindowInsets();
62+
int stableInsetBottom = windowInsets.getStableInsetBottom();
63+
screenHeight = rootViewHeight;
64+
resultBottom = resultBottom + stableInsetBottom;
65+
} else {
66+
// calculate screen height differently for android versions <23: Lollipop 5.x, Marshmallow 6.x
67+
//http://stackoverflow.com/a/29257533/3642890 beware of nexus 5
6368
Display display = getActivity().getWindowManager().getDefaultDisplay();
6469
Point size = new Point();
6570
display.getSize(size);
6671
screenHeight = size.y;
67-
} else {
68-
screenHeight = rootViewHeight;
6972
}
7073

7174
int heightDiff = screenHeight - resultBottom;

0 commit comments

Comments
 (0)