Skip to content

Commit

Permalink
fix(android): incorrect keyboard height (#2924)
Browse files Browse the repository at this point in the history
  • Loading branch information
duryno committed Jun 10, 2020
1 parent 7a2a45f commit 035f74e
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.Display;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.view.inputmethod.InputMethodManager;

import com.getcapacitor.JSObject;
Expand Down Expand Up @@ -54,18 +55,20 @@ public void onGlobalLayout() {
// cache properties for later use
int rootViewHeight = rootView.getRootView().getHeight();
int resultBottom = r.bottom;

// calculate screen height differently for android versions >= 21: Lollipop 5.x, Marshmallow 6.x
//http://stackoverflow.com/a/29257533/3642890 beware of nexus 5
int screenHeight;

if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT >= 23) {
WindowInsets windowInsets = rootView.getRootWindowInsets();
int stableInsetBottom = windowInsets.getStableInsetBottom();
screenHeight = rootViewHeight;
resultBottom = resultBottom + stableInsetBottom;
} else {
// calculate screen height differently for android versions <23: Lollipop 5.x, Marshmallow 6.x
//http://stackoverflow.com/a/29257533/3642890 beware of nexus 5
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenHeight = size.y;
} else {
screenHeight = rootViewHeight;
}

int heightDiff = screenHeight - resultBottom;
Expand Down

0 comments on commit 035f74e

Please sign in to comment.