From 171c553ac92097ca5d3b65084af5bb2f18da3957 Mon Sep 17 00:00:00 2001 From: Swati Jha Date: Wed, 19 Aug 2020 11:03:00 -0400 Subject: [PATCH] (ios & android) Fixed resizing of the window when keyboard is open (apache#655) --- src/android/InAppBrowser.java | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java index a1ce2f75b..f08e7af25 100644 --- a/src/android/InAppBrowser.java +++ b/src/android/InAppBrowser.java @@ -1074,36 +1074,29 @@ public void postMessage(String data) { webViewLayout.addView(footer); } - WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); - lp.copyFrom(dialog.getWindow().getAttributes()); - lp.width = WindowManager.LayoutParams.MATCH_PARENT; - + int windowHeight = WindowManager.LayoutParams.MATCH_PARENT; + if (bottomReduceHeightBy != 0) { // Resize the window if it has to be reduced to less than the available screen height DisplayMetrics displayMetrics = new DisplayMetrics(); cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); // Make sure to convert height to density independent pixels (dip) - // The height is reduced by 1 pixel to correct 1 pixel dip error on high resolution/density devices - int reducedHeightDip = (int) ((float) bottomReduceHeightBy * displayMetrics.density) - 1; + int reducedHeightDip = (int) ((float) bottomReduceHeightBy * displayMetrics.density); - // Calculate visible display size - // Note that the visible display height differs from the device height by the status bar height if the device does not have a notch - // In devices with a notch, they are the same + // Calculate status bar height Rect rectangle = new Rect(); cordova.getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle); + int statusBarHeightDip = rectangle.top; - // Note that device height - visible display height is zero in devices with a notch, non zero on other devices - lp.height = rectangle.height() - reducedHeightDip; - - // Make sure the dialog is aligned to the bottom of the status bar as it is centered by default - lp.gravity = Gravity.TOP; + windowHeight = rectangle.height() + statusBarHeightDip - reducedHeightDip; } if (dialog != null) { dialog.setContentView(main); dialog.show(); - dialog.getWindow().setAttributes(lp); + dialog.getWindow().setGravity(Gravity.TOP); + dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, windowHeight); if (bottomReduceHeightBy != 0) { // Ensure the parent window respond to clicks when the web view is displayed on top of it