Skip to content
Merged
Show file tree
Hide file tree
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 @@ -12,6 +12,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsAnimationCompat;
import androidx.core.view.WindowInsetsCompat;
Expand Down Expand Up @@ -57,14 +58,15 @@ public Keyboard(AppCompatActivity activity, boolean resizeOnFullScreen) {
FrameLayout content = activity.getWindow().getDecorView().findViewById(android.R.id.content);
rootView = content.getRootView();

ViewCompat.setOnApplyWindowInsetsListener(rootView, (v, insets) -> {
ViewCompat.setOnApplyWindowInsetsListener(content, (v, insets) -> {
boolean showingKeyboard = ViewCompat.getRootWindowInsets(rootView).isVisible(WindowInsetsCompat.Type.ime());

if (showingKeyboard && resizeOnFullScreen) {
possiblyResizeChildOfContent(true);
}

ViewCompat.onApplyWindowInsets(v, insets);
v.onApplyWindowInsets(insets.toWindowInsets());

return insets;
});

Expand Down Expand Up @@ -142,6 +144,11 @@ public boolean hide() {
}

private void possiblyResizeChildOfContent(boolean keyboardShown) {
if (isSystemBarsPluginPresent()) {
// SystemBars handles the inset sizing for visible keyboards
return;
}

int usableHeightNow = keyboardShown ? computeUsableHeight() : -1;
if (usableHeightPrevious != usableHeightNow) {
frameLayoutParams.height = usableHeightNow;
Expand All @@ -156,6 +163,15 @@ private int computeUsableHeight() {
return isOverlays() ? r.bottom : r.height();
}

private static boolean isSystemBarsPluginPresent() {
try {
Class.forName("com.getcapacitor.plugin.SystemBars");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

@SuppressWarnings("deprecation")
private boolean isOverlays() {
final Window window = activity.getWindow();
Expand Down
Loading